Skip to content

Commit

Permalink
Merge pull request #27 from Sujanadh/fix/split-by-sq
Browse files Browse the repository at this point in the history
Clip square grid with AOI
  • Loading branch information
spwoodcock authored Mar 21, 2024
2 parents 22889e6 + 29c8b96 commit e1d8d68
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fmtm_splitter/splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from geojson import Feature, FeatureCollection, GeoJSON
from osm_rawdata.postgres import PostgresClient
from psycopg2.extensions import connection
from shapely.geometry import Polygon, box, shape
from shapely.geometry import Polygon, shape
from shapely.ops import unary_union

from fmtm_splitter.db import aoi_to_postgis, close_connection, create_connection, create_tables, drop_tables, insert_geom
Expand Down Expand Up @@ -154,7 +154,10 @@ def splitBySquare( # noqa: N802
polygons = []
for x in cols[:-1]:
for y in rows[:-1]:
polygons.append(box(x, y, x + width, y + length))
grid_polygon = Polygon([(x, y), (x + width, y), (x + width, y + length), (x, y + length)])
clipped_polygon = grid_polygon.intersection(self.aoi)
if not clipped_polygon.is_empty:
polygons.append(clipped_polygon)

self.split_features = FeatureCollection([Feature(geometry=poly) for poly in polygons])
return self.split_features
Expand Down

0 comments on commit e1d8d68

Please sign in to comment.