From 0a3cc856333ac15290ede79be89ee84cfb08b1f3 Mon Sep 17 00:00:00 2001 From: sujanadh Date: Tue, 19 Mar 2024 09:43:40 +0545 Subject: [PATCH 1/2] fix: clip square grid with AOI --- fmtm_splitter/splitter.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fmtm_splitter/splitter.py b/fmtm_splitter/splitter.py index 18ede23..334b386 100755 --- a/fmtm_splitter/splitter.py +++ b/fmtm_splitter/splitter.py @@ -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 From 29c8b9612a4f796ad7610d54b7ac997e575e4027 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 04:29:07 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- fmtm_splitter/splitter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fmtm_splitter/splitter.py b/fmtm_splitter/splitter.py index 334b386..fe12b0f 100755 --- a/fmtm_splitter/splitter.py +++ b/fmtm_splitter/splitter.py @@ -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