Skip to content

Commit

Permalink
fix: allow parsing geojson string for execQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Feb 11, 2024
1 parent 1391464 commit 338807e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions osm_rawdata/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ def createDB(self, dburi: uriParser):

def execQuery(
self,
boundary: Union[FeatureCollection, Feature, dict],
boundary: Union[FeatureCollection, Feature, dict, str],
customsql: str = None,
allgeom: bool = True,
extra_params: dict = {},
Expand All @@ -671,7 +671,7 @@ def execQuery(
database, or a remote one that uses the Underpass schema.
Args:
boundary (FeatureCollection, Feature, dict): The boundary polygon.
boundary (FeatureCollection, Feature, dict, str): The boundary polygon.
customsql (str): Don't create the SQL, use the one supplied.
allgeom (bool): Whether to return centroids or all the full geometry.
Expand All @@ -680,6 +680,10 @@ def execQuery(
"""
log.info("Parsing AOI geojson for data extract")

# Parse JSON string type
if isinstance(boundary, str):
boundary = json.loads(boundary)

if (geom_type := boundary.get("type")) == "FeatureCollection":
# Convert each feature into a Shapely geometry
geometries = [shape(feature.get("geometry")) for feature in boundary.get("features", [])]
Expand Down

0 comments on commit 338807e

Please sign in to comment.