I have a OSM file (I'm actually using OSRM), and I have a list of coordinates of the type (lat,lon). I need a way to test whether each coordinate is inside the boundaries of the OSM file (as the file can be of only a small region of the world, i.e., I'm using Berlin for testing purposes).

I tried searching for solutions, but none seemed clear enough to me. I've read some suggestions on using PostGIS, though I'm not particularly aware of how this would work, as I need to test the existence of a coordinate that not necessarily has a corresponding node in the OSM file to begin with (only a closest one).

Note: I'm building an application in C++, to run solely as a local application. Speed on this test is not a particular issue, although I'll be using lists with a few thousands coordinates.

Any hints on how to proceed?

asked 01 Aug '18, 02:09

Lonatico's gravatar image

Lonatico
11113
accept rate: 0%

edited 01 Aug '18, 12:18

What does "a valid coordinate in the OSM file" mean exactly? That the coordinate is inside the bounding box / polygon of your OSM file? Or that something (a POI, a street) exists at this coordinate?

(01 Aug '18, 07:38) scai ♦

@scai, thanks for the comment. It would be the first option, that is, whether the coordinate is inside the boundaries of my OSM file. I don't really care what is in this coordinate, as long as I can know it is a coordinate inside the file limits. (edit: I have updated the question to better state this).

(01 Aug '18, 12:16) Lonatico

At least the XML format for OSM data will contain a "bounds" object with a bounding box, see https://wiki.openstreetmap.org/wiki/OSM_XML That is however just a rough approximation of the area covered by the data, in particular if you extracted OSM data using a polygon it will be too large. If that is the case (that you extracted data using a polygon), I would suggest simply doing a point in/covered by polygon test to determine if the location is covered. While this is built into PostGIS, if you are not using it anyway you can simply use one of the many C++ libraries (depending a bit in what format you have the polygon).

permanent link

answered 01 Aug '18, 16:52

SimonPoole's gravatar image

SimonPoole ♦
38.6k13287612
accept rate: 19%

edited 02 Aug '18, 08:53

Yes, but as you said it is a rough approximation (sadly too rough for my need). I think I didn't extract OSM data using a polygon (in fact I'm not sure what this means).

I have managed to locate a polygon file in Geofabrik website, which appears to give me a set of coordinates that define the borders of the entire region/polygon. From that I could just use an algorithm for checking point-in-polygon, but the problem is that for wide areas (e.g., a continental country) I would have the problem of earth's curvature in the calculation. Do you have any suggestion on that?

(02 Aug '18, 00:31) Lonatico

@Lonatico This is a question for http://gis.stackexchange.com/ since it isn't OSM-specific.

(02 Aug '18, 07:39) scai ♦

@Lonatico you would be using the WGS84 coordinates (which are defined on the WGS84 geoid) as coordinates on a plane which is the plate carrée projection. While the result is (naturally) distorted, simple topological relationships still hold (except over the -180°/180° boundary where if you limit the coordinate range to -180° - 180° you will need to split the boundary polygons).

(02 Aug '18, 08:02) SimonPoole ♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×549
×166
×119
×56

question asked: 01 Aug '18, 02:09

question was seen: 530 times

last updated: 02 Aug '18, 08:53

powered by OSQA