There are many ways to retrieve the polygon information when you know that the information is already present somewhere (data locally or in database containing extracted info about polygon). But this question is to figure out, how do we retrieve a polygon info when you don't have any extracted info.
I found that using OpenStreetMaps (OSM), we could download the data containing all the info, so I downloaded the continent wise data from the below site.
Later I stored the information into Postgis using Osm2pgsql
. I am using postgis query plugins to select the information like polygon ID and other things. But how do I get the actual polygon geometry of a point containing lat/long of type=farmland.
Example:
SELECT Polygon_geom //random name
FROM planet_osm_polygon
WHERE
boundary = 'farmland' AND
AND ST_Intersects(
ST_GeomFromText('POINT(-122.679 45.519)', 4326),
ST_Transform(way, 4326)
)
EDIT: I am looking for something specific like this as shown below, say I have a point on a farm and I don't know the boundary.
And using OSM (Planet-OSM) data, I get the boundary. But not what I expected (querying for landuse='farmland') doesnt return result in few cases. Does the Planet-OSM data contains the polygon info of all the farmland in specific? or it depends on the country wise data with only administrative boundaries? Is it the right way or is there any other alternate solutions?
EDIT:2
As per NMS
comment got the output from overpass as follows. But my main concern still remains unanswered. How do I get an individual polygon? Now I either get a polygon with more than 3 in a single polygon or nothing (maybe OSM considers them non-farmland). Do I need to filter my query further. Please correct me if I am going in a wrong direction.
way
. Also you might want to transform your point to 3857 instead of projecting every polygons to 4326, as the spatial index is not used (or you would need a new spatial index onst_transform(way,4326)
). You could also add an index onboundary
– JGH Dec 3 '18 at 13:29farmland
boundary because in the EDIT;2 of my comment shows only few and also the polygon seems to merge more than 3 to 5 farmlands. Do i need to update my query to filter this out. – GeoFresher Dec 6 '18 at 14:43