fix(api): /parcels/by-bbox 500 — area via ST_Area, drop missing land_category #347
1 changed files with 6 additions and 3 deletions
|
|
@ -1034,6 +1034,9 @@ async def get_parcels_by_bbox(
|
|||
lon_km = (max_lon - min_lon) * 111.32 * math.cos(math.radians(lat_mid))
|
||||
bbox_area_km2 = round(lat_km * lon_km, 4)
|
||||
|
||||
# cad_parcels has only (cad_num, geom) — area derived via ST_Area on geography
|
||||
# cast for meter accuracy. land_category not stored on this table; returned NULL
|
||||
# until enrichment from EGRN is wired (tracking: vault B5 EGRN contract note).
|
||||
sql = text("""
|
||||
WITH bbox AS (
|
||||
SELECT ST_MakeEnvelope(
|
||||
|
|
@ -1048,8 +1051,8 @@ async def get_parcels_by_bbox(
|
|||
p.cad_num,
|
||||
ST_Y(ST_Centroid(p.geom)) AS centroid_lat,
|
||||
ST_X(ST_Centroid(p.geom)) AS centroid_lon,
|
||||
p.area_m2,
|
||||
p.land_category,
|
||||
ST_Area(p.geom::geography) AS area_m2,
|
||||
NULL::text AS land_category,
|
||||
pus.status AS user_status
|
||||
FROM cad_parcels p
|
||||
CROSS JOIN bbox
|
||||
|
|
@ -1058,7 +1061,7 @@ async def get_parcels_by_bbox(
|
|||
AND pus.user_id = CAST(:user_id AS text)
|
||||
WHERE p.geom IS NOT NULL
|
||||
AND ST_Intersects(p.geom, bbox.env)
|
||||
ORDER BY p.area_m2 DESC NULLS LAST
|
||||
ORDER BY ST_Area(p.geom::geography) DESC NULLS LAST
|
||||
LIMIT CAST(:limit AS int)
|
||||
""")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue