I have the following query:
SELECT row_to_json(fc)
FROM (
SELECT ST_AsGeoJSON(lg.geometry)::json As geometry,
(
select row_to_json(t)
from (
select name, type, admin_level
) t
)
As properties
FROM osm_admin As lg
)
As fc;
This returns all data in table as GeoJSON.
How can I additionally restrict the results to only within the bounding box? (As the second image below.)
I need to get full GeoJSON for a tile. The PostGIS data is probably in 3857, as it's OSM imported as pbf with imposm3
.
Have tried this, as per Mark C's suggestion:
SELECT row_to_json(fc)
FROM (
SELECT ST_AsGeoJSON(lg.geometry)::json As geometry,
(SELECT row_to_json(t)
FROM (SELECT name, type, admin_level)
WHERE the_geom && ST_SetSRID(ST_MakeBox2D(ST_Point(-73.9980, 40.726), ST_Point(-73.995, 40.723)), 4326)
As t
)
As properties
FROM osm_admin As lg
)
As fc;
But I get the following error:
ERROR: subquery in FROM must have an alias
LINE 6: FROM (SELECT name, type, admin_level)