Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update routes.py - Feat Geom in param #34

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/ref_geo/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,27 @@ def get_areas():
.options(joinedload("area_type").load_only("type_code"))
.order_by(LAreas.area_name.asc())
)

# Detect geom in param
geom_param = request.args.get('geom')
if geom_param:
try:
# print("Received geometry parameter:", geom_param)
geom_shape = wkt.loads(geom_param)
# Detect the SRID of the input geometry
input_srid = 4326 # Default to 4326
if geom_shape.is_valid and hasattr(geom_shape, 'srid'):
input_srid = geom_shape.srid if geom_shape.srid else 4326
# print("Input geometry SRID:", input_srid)
geom_filter = from_shape(geom_shape, srid=input_srid)
# Transform geometry to match the database's SRID (2154) if needed
if input_srid != 2154:
geom_filter = func.ST_Transform(geom_filter, 2154)
query = query.where(LAreas.geom.ST_Intersects(geom_filter))
# print("Query after adding geometry filter:", query)
except Exception as e:
# print("Error processing geometry:", str(e))
return {"message": "Invalid geometry format.", "status": "error"}, 400

if "enable" in params:
enable_param = params["enable"].lower()
accepted_enable_values = ["true", "false", "all"]
Expand Down