如何将多个 gpx 文件加载到 PostGIS 中?
我有一堆来自 GPSLogger for Android 应用程序的 gpx 文件。
文件看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.0" creator="GPSLogger - http://gpslogger.mendhak.com/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/0"
xsi:schemaLocation="http://www.topografix.com/GPX/1/0
http://www.topografix.com/GPX/1/0/gpx.xsd" >
<time>2011-08-26T06:25:20Z</time>
<bounds></bounds>
<trk>
<trkseg>
<trkpt lat="46.94681501102746" lon="7.398453755309032" >
<ele>634.0</ele>
<speed>0.0</speed>
<src>gps</src>
<sat>6</sat>
<time>2011-08-26T06:25:20Z</time>
</trkpt>
<trkpt lat="46.94758878281887" lon="7.398622951942811" >
<ele>748.0</ele>
<speed>0.0</speed>
<src>gps</src>
<sat>5</sat>
<time>2011-08-26T06:30:56Z</time>
</trkpt>
... ... ...
</trkseg>
</trk>
</gpx>
是否可以使用 SQL 或 Python 遍历包含这些文件的目录并将它们加载到一个 PostGIS 表中?
我偶然发现这篇博客文章提到:
我不知道有什么可以直接从 GPX 转换为 PostGIS
I have a bunch of gpx files that come from GPSLogger for Android app.
Files look like:
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.0" creator="GPSLogger - http://gpslogger.mendhak.com/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/0"
xsi:schemaLocation="http://www.topografix.com/GPX/1/0
http://www.topografix.com/GPX/1/0/gpx.xsd" >
<time>2011-08-26T06:25:20Z</time>
<bounds></bounds>
<trk>
<trkseg>
<trkpt lat="46.94681501102746" lon="7.398453755309032" >
<ele>634.0</ele>
<speed>0.0</speed>
<src>gps</src>
<sat>6</sat>
<time>2011-08-26T06:25:20Z</time>
</trkpt>
<trkpt lat="46.94758878281887" lon="7.398622951942811" >
<ele>748.0</ele>
<speed>0.0</speed>
<src>gps</src>
<sat>5</sat>
<time>2011-08-26T06:30:56Z</time>
</trkpt>
... ... ...
</trkseg>
</trk>
</gpx>
Is it possible to traverse a directory containing these files and load them into one PostGIS table using either SQL or Python?
I've stubled upon this blog post mentioning that:
I’m not aware of anything that can convert straight from GPX to
PostGIS
This post gives an example of working with SQL to do that but I can't get my head around the code :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ogr2ogr (GDAL 的一部分)是一个简单直接的 Unix shell 工具,用于将 GPX 文件加载到 PostGIS 中。
ogr2ogr 在 PostGIS 中使用自己的模式创建自己的数据库表。
tracks
表中每个 GPS 轨迹占一行;tracks.wkb_geometry
包含 GPS 轨迹本身作为 MultiLineString。track_points
表包含各个位置修正(带有时间戳)。这是导入之前数据库
walks
的样子:...和导入之后:
ogr2ogr (part of GDAL) is a simple and straightforward Unix shell tool to load a GPX file into PostGIS.
ogr2ogr creates its own database tables in PostGIS with its own schema. The table
tracks
has one row per GPS track;tracks.wkb_geometry
contains the GPS track itself as a MultiLineString. The tabletrack_points
contains individual location fixes (with timestamps).Here is what the database
walks
looks like before the import:... and after the import:
如果您使用的是 Linux,您可以尝试以下操作:
使用程序将 GPX 转换为 SHP:gpx2shp
然后使用 shp2pgsql
将该文件加载到支持 postgis 的数据库中
您当然可以使用管道并在一个命令行中进行所有操作
有关详细信息,请参阅联机帮助页。
编辑
如果您仍然需要 python 脚本,可以在这里找到帮助
http://pypi.python.org/pypi/gpxtools
If you are using linux, you may try this:
Use a program to convert GPX to SHP: gpx2shp
then load that file into a postgis enabled database with shp2pgsql
you may of course use pipe and make all in one command line
For more info see the manpages.
EDIT
If you still want a python script, you may find help here
http://pypi.python.org/pypi/gpxtools