Skip to main content
deleted 2 characters in body; deleted 2 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
SELECT r.osm_id
FROM osm_roads r, osm_places p
WHERE p.name = 'Hometown' AND ST_Intersects(p.way, r.way);

If you want only streets that are completely contained within the places polygon replace ST_Intersects with ST_Contains. Order matters to ST_Contains, it returns all geometries from the 2nd layer that are completely contained by the 1st.

A third way to get your answer is with ST_DWithin. It will return true if the two geometries are within a specified distance of each other, the distance will be in the units of the coordinate system the two layers use. Since most of the time Open Street MapOpenStreetMap data is imported in the "Google Mercator" projection (for me anyway) most likely your units will be meters.

Also, for me, the geometry field in my Open Street MapOpenStreetMap data is called way, it might be different for you depending on the tool you used to import the data.

SELECT r.osm_id
FROM osm_roads r, osm_places p
WHERE p.name = 'Hometown' AND ST_Intersects(p.way, r.way);

If you want only streets that are completely contained within the places polygon replace ST_Intersects with ST_Contains. Order matters to ST_Contains, it returns all geometries from the 2nd layer that are completely contained by the 1st.

A third way to get your answer is with ST_DWithin. It will return true if the two geometries are within a specified distance of each other, the distance will be in the units of the coordinate system the two layers use. Since most of the time Open Street Map data is imported in the "Google Mercator" projection (for me anyway) most likely your units will be meters.

Also, for me, the geometry field in my Open Street Map data is called way, it might be different for you depending on the tool you used to import the data.

SELECT r.osm_id
FROM osm_roads r, osm_places p
WHERE p.name = 'Hometown' AND ST_Intersects(p.way, r.way);

If you want only streets that are completely contained within the places polygon replace ST_Intersects with ST_Contains. Order matters to ST_Contains, it returns all geometries from the 2nd layer that are completely contained by the 1st.

A third way to get your answer is with ST_DWithin. It will return true if the two geometries are within a specified distance of each other, the distance will be in the units of the coordinate system the two layers use. Since most of the time OpenStreetMap data is imported in the "Google Mercator" projection (for me anyway) most likely your units will be meters.

Also, for me, the geometry field in my OpenStreetMap data is called way, it might be different for you depending on the tool you used to import the data.

Source Link
HeyOverThere
  • 7.9k
  • 1
  • 28
  • 42

SELECT r.osm_id
FROM osm_roads r, osm_places p
WHERE p.name = 'Hometown' AND ST_Intersects(p.way, r.way);

If you want only streets that are completely contained within the places polygon replace ST_Intersects with ST_Contains. Order matters to ST_Contains, it returns all geometries from the 2nd layer that are completely contained by the 1st.

A third way to get your answer is with ST_DWithin. It will return true if the two geometries are within a specified distance of each other, the distance will be in the units of the coordinate system the two layers use. Since most of the time Open Street Map data is imported in the "Google Mercator" projection (for me anyway) most likely your units will be meters.

Also, for me, the geometry field in my Open Street Map data is called way, it might be different for you depending on the tool you used to import the data.