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.

enter image description here

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?

enter image description here

EDIT:2 As per NMScomment 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. enter image description here

  • 3
    It looks OK, what is the issue? The geom doesn't have a random name but 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 on st_transform(way,4326)). You could also add an index on boundary – JGH Dec 3 at 13:29
  • @JGH I am interested to know whether OpenStreetMap data (planet-osm) considers all the polygon of farmland. I am getting the output as the last pic,. My main goal is to find the polygon boundary of the red icon. – GeoFresher Dec 6 at 9:20
  • 1
    Do you want to find the polygon boundary of just the red icon? seems interesting. Try considering overpass turbo - overpass-turbo.eu , its all the same I guess, might be a handy tool to check your query. – NMS Dec 6 at 13:25
  • @NMS, as per your comment, I tried using overpass and found the same result. But also this was more easy to test. My main concern is to know, does open street map assigns every farmland 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 at 14:43
  • @GeoFresher Can you post your overpass query? – NMS Dec 6 at 15:02
up vote 1 down vote accepted

By your above description and polygon boundary photos, I assume that maybe you are concerned about just polygon boundary rather than just landuse=farmland. However if you check the Openstreet map wiki you might see various values for landuse in all farm details. Since you are only accquainted to farmland you get polygons related to that. If you want boundary of every bit of farm specific details. Then consider all the key value such as:

landuse = brownfield 
landuse = farmland 
landuse = grass 
landuse = greenfield 
landuse = meadow  
landuse = orchard  
landuse = plant_nursery

Then you might be able to get all polygon specific boundary. Hope this answers your question.

Edit: The query could be updated as follows, not going w.r.t SRS:

select ST_AsText(way) from planet_osm_polygon where landuse='farmland' OR landuse='meadow' OR landuse='green' OR landuse='orchard';

You could keep adding more landuse values based on your constraints.

  • Well...that's reveals the reason why i got the polygon boundaries like that. Thanks. So its just updating the query right – GeoFresher yesterday
  • 1
    Yes. You can find the answer edited – NMS yesterday

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.