Skip to content

Commit

Permalink
Updated layers for tile size specification in meters
Browse files Browse the repository at this point in the history
  • Loading branch information
kcartier-wri committed Nov 4, 2024
1 parent e02bd25 commit 74f6d25
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions city_metrix/layers/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import shapely.geometry as geometry
import pandas as pd

MAX_TILE_SIZE = 0.5
MAX_TILE_SIDE_SIZE_METERS = 60000 # Approx. 0.5 degrees latitudinal offset. TODO How selected?

class Layer:
def __init__(self, aggregate=None, masks=[]):
Expand Down Expand Up @@ -136,7 +136,7 @@ def count(self):
return self._zonal_stats("count")

def _zonal_stats(self, stats_func):
if box(*self.zones.total_bounds).area <= MAX_TILE_SIZE**2:
if box(*self.zones.total_bounds).area <= MAX_TILE_SIDE_SIZE_METERS**2:
stats = self._zonal_stats_tile(self.zones, [stats_func])
else:
stats = self._zonal_stats_fishnet(stats_func)
Expand All @@ -160,7 +160,7 @@ def group_layer_values(df):

def _zonal_stats_fishnet(self, stats_func):
# fishnet GeoDataFrame into smaller tiles
fishnet = create_fishnet_grid(*self.zones.total_bounds, MAX_TILE_SIZE)
fishnet = create_fishnet_grid(*self.zones.total_bounds, MAX_TILE_SIDE_SIZE_METERS)

# spatial join with fishnet grid and then intersect geometries with fishnet tiles
joined = self.zones.sjoin(fishnet)
Expand Down

0 comments on commit 74f6d25

Please sign in to comment.