1010import osdatahub
1111from osdatahub import Extent
1212from osdatahub .NGD .crs import get_crs
13+ from osdatahub .NGD .models import NGDFeatureCollection
1314
1415
1516def _merge_geojsons (gj1 : Union [dict ], gj2 : Union [dict ]) -> Union [dict ]:
@@ -96,7 +97,8 @@ def query(
9697 filter_crs : Union [str , int , None ] = None ,
9798 max_results : int = 100 ,
9899 offset : int = 0 ,
99- ) -> Union [dict ]:
100+ output_as_collection : bool = False
101+ ) -> Union [dict , NGDFeatureCollection ]:
100102 """
101103 Retrieves features from a Collection
102104
@@ -121,9 +123,11 @@ def query(
121123 max_results (int, optional): The maximum number of features to return. Defaults to 100
122124 offset (int, optional): The offset number skips past the specified number of features in the collection.
123125 Defaults to 0
124-
125- Returns:
126- FeatureCollection: The results of the query in GeoJSON format
126+ output_as_collection (bool, optional): Outputs as a NGDFeatureCollection which is more pythonic and structured.
127+ Defaults to False to ensure backwards compatibility.
128+ Returns either:
129+ Dict: The results of the query in GeoJSON format (if output_as_collection is set to False)
130+ NGDFeatureCollection: The results of the query in structured form (if output_as_collection is set to True)
127131 """
128132
129133 assert max_results > 0 , (
@@ -209,9 +213,16 @@ def query(
209213 else :
210214 n_required -= resp_json ["numberReturned" ]
211215
216+ # Added to allow the NGD Sync to work with the NGD ASync
217+ if output_as_collection :
218+ data = NGDFeatureCollection .from_dict (data )
219+
212220 return data
213221
214- def query_feature (self , feature_id : str , crs : Union [str , int ] = None ) -> dict :
222+ def query_feature (self ,
223+ feature_id : str ,
224+ crs : Union [str , int ] = None
225+ ) -> dict :
215226 """
216227 Retrieves a single feature from a collection
217228
0 commit comments