Skip to content

Commit

Permalink
David/geojson for cql items (#320)
Browse files Browse the repository at this point in the history
* feat: ensure /cql and /object endpoints work with GeoJSON; include counts with /cql GeoJSON.

* chore: black code

* fix: revert incomplete/unnecessary change

* fix: add accidentally deleted poetry.lock

* fix: caching was not working correctly - key is now being set correctly
  • Loading branch information
recalcitrantsupplant authored Jan 12, 2025
1 parent e2138af commit 37bfb93
Show file tree
Hide file tree
Showing 12 changed files with 977 additions and 807 deletions.
1,093 changes: 590 additions & 503 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions prez/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ async def cql_get_parser_dependency(
query_params: QueryParams = Depends(),
queryable_props: list = Depends(get_queryable_props),
) -> CQLParser:
if query_params.filter:
if query_params._filter:
try:
crs = query_params.filter_crs
query = json.loads(query_params.filter)
query = json.loads(query_params._filter)
cql_parser = CQLParser(cql=query, crs=crs, queryable_props=queryable_props)
cql_parser.generate_jsonld()
try:
Expand All @@ -182,7 +182,7 @@ async def cql_get_parser_dependency(
return cql_parser
except json.JSONDecodeError:
raise HTTPException(status_code=400, detail="Invalid JSON format.")
except Exception:
except Exception as e:
raise HTTPException(
status_code=400, detail="Invalid CQL format: Parsing failed."
)
Expand Down
23 changes: 12 additions & 11 deletions prez/models/query_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,23 @@ def __init__(
),
datetime: Optional[tuple] = Depends(validate_datetime),
bbox: List[float] = Depends(reformat_bbox),
filter_lang: FilterLangEnum = Query(
filter_lang: Optional[FilterLangEnum] = Query(
default="cql2-json",
description="Language of the filter expression",
alias="filter-lang",
),
filter_crs: str = Query(
filter_crs: Optional[str] = Query(
"http://www.opengis.net/def/crs/OGC/1.3/CRS84",
description="CRS used for the filter expression",
),
q: str = Query(None, description="Search query", example="building"),
filter: str = Query(
default=None,
description="CQL JSON expression.",
q: Optional[str] = Query(None, description="Search query", example="building"),
_filter: Optional[str] = Query(
default=None, description="CQL JSON expression.", alias="filter"
),
order_by: Optional[str] = Query(
default=None, description="Optional: Field to order by"
),
order_by: str = Query(default=None, description="Optional: Field to order by"),
order_by_direction: OrderByDirectionEnum = Query(
order_by_direction: Optional[OrderByDirectionEnum] = Query(
default=None,
description="Optional: Order direction, must be 'ASC' or 'DESC'",
),
Expand All @@ -175,15 +176,15 @@ def __init__(
self.datetime = datetime
self.order_by = order_by
self.order_by_direction = order_by_direction
self.filter = filter
self._filter = _filter
self.mediatype = mediatype
self.subscription_key = subscription_key
self.validate_filter()

def validate_filter(self):
if self.filter:
if self._filter:
try:
json.loads(self.filter)
json.loads(self._filter)
except json.JSONDecodeError:
raise HTTPException(
status_code=400, detail="Filter criteria must be valid JSON."
Expand Down
8 changes: 4 additions & 4 deletions prez/reference_data/profiles/prez_default_profiles.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>


<https://prez.dev/profile/cqlgeo>
a prof:Profile , prez:ListingProfile;
a prof:Profile , prez:ListingProfile ;
dcterms:identifier "cqlgeo"^^xsd:token ;
dcterms:description "A CQL profile targeted towards listing CQL results, including geospatial information." ;
dcterms:title "CQL Geo profile" ;
altr-ext:constrainsClass rdfs:Resource ;
altr-ext:hasDefaultResourceFormat "text/anot+turtle" ;
altr-ext:hasResourceFormat "application/ld+json" ,
altr-ext:hasResourceFormat "application/geo+json" ,
"application/ld+json" ,
"application/anot+ld+json" ,
"application/rdf+xml" ,
"text/anot+turtle" ,
"text/turtle" ;
shext:bnode-depth 2 ;
sh:property [
sh:minCount 0 ;
sh:path (
sh:union (
rdf:type
shext:allPredicateValues
( geo:hasGeometry geo:asWKT )
)
)
Expand Down
Loading

0 comments on commit 37bfb93

Please sign in to comment.