问题
I have this .gpx file that is formatted as follows:
<trk>
<name>Area1</name>
<extensions>
<gpxx:TrackExtension>
<gpxx:DisplayColor>Magenta</gpxx:DisplayColor>
</gpxx:TrackExtension>
</extensions>
<trkseg>
<trkpt lat="52.806521779700120" lon="5.795177063346190"/>
...
<trkpt lat="52.806521779700120" lon="5.795177063346190"/>
</trkseg>
</trk>
<trk>
<name>Area2</name>
<extensions>
<gpxx:TrackExtension>
<gpxx:DisplayColor>Magenta</gpxx:DisplayColor>
</gpxx:TrackExtension>
</extensions>
<trkseg>
<trkpt lat="52.764805147811629" lon="5.377259838276261"/>
...
This file that contains well over 18.000 coordinates, describes several (adjacent) areas.
My ultimate goal is to see, if a given GPS coordinate is within the borders of any of these areas. What would be the best approach for that?
Related, intermediate question: Will any method be reasonable fast to run through all these coordinates?
回答1:
Solution to check if a point is inside an polygonal area without holes
Just use a point-In-polygon function. And use x for longitude and y for latitude. You can directly pass in the long, lat cordinates. Such a function is easily found here or via google. E.g here, 7 lines of code: https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
The only possibility that this function fail, is when the region overlaps the datum limit (meridian at longitude -180, 180).
However since there is mostly water, it is unlikely that the region will overlap that line.
18.000 points is no problem for this task, there is no need for advanced algorithms.
来源:https://stackoverflow.com/questions/35457480/determine-if-a-gps-location-is-within-a-gpx-track-segment