Hi all!
I’m getting the city boundaries with this query:
(SELECT * FROM
(SELECT
planet_osm_polygon.way,
planet_osm_polygon.admin_level,
planet_osm_point.place,
CASE
WHEN (planet_osm_point.tags->'population' ~ '^[0-9]{1,8}$') THEN (planet_osm_point.tags->'population')::INTEGER ELSE 0
END as population,
(ST_Area(ST_Transform(planet_osm_polygon.way, 4326)::geography) / 1000000) AS km2
FROM planet_osm_polygon
JOIN (
SELECT name, MAX(admin_level) AS al
FROM planet_osm_polygon
WHERE boundary = 'administrative' AND admin_level IN ('4', '6', '8') AND osm_id < 0 GROUP BY name
) size USING(name)
JOIN planet_osm_point USING (name)
WHERE planet_osm_polygon.boundary = 'administrative' AND
planet_osm_polygon.admin_level = size.al AND
(
(
planet_osm_polygon.admin_level IN ('6', '8') AND
planet_osm_point.place IN ('city', 'town')
) OR
(
planet_osm_polygon.admin_level = '4' AND
planet_osm_point.place = 'city'
)
) AND
planet_osm_polygon.osm_id < 0 AND
planet_osm_polygon.way_area > 1*!pixel_width!::real*!pixel_height!::real
) AS boundaries
WHERE (admin_level = '4' AND km2 >= 100) OR
(
population > 20000 AND
(
(admin_level = '6' AND km2 >= 50) OR
(admin_level = '8' AND km2 >= 25)
)
) OR
(
population > 10000 AND admin_level = '8' AND km2 >= 100
)
) AS city_boundaries
So I can get the political boundaries (administrative) of cities the have some requisites.
It works, but for my maps (using by flying) the geographical boundaries are better. I can see many little town in my map with a big area, but on the area is just “pampa”.
Is it possible to restrict the area to the part of the city where the are more than X buildings?
Thanks a lot
Luca