Determine if a GPS location is within a gpx track segment

谁说我不能喝 提交于 2019-12-13 03:44:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!