我有一堆来自
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表中?
I’m not aware of anything that can convert straight from GPX to
PostGIS
解决方法
ogr2ogr(GDAL的一部分)是一个简单直接的Unix shell工具,用于将GPX文件加载到PostGIS中.
ogr2ogr -append -f Postgresql PG:dbname=walks walk.gpx
ogr2ogr在PostGIS中使用自己的模式创建自己的数据库表.桌面轨道每个GPS轨道有一行; tracks.wkb_geometry包含GPS轨道本身作为MultiLineString.表track_points包含各个位置修复(带有时间戳).
walks=# \d List of relations Schema | Name | Type | Owner --------+-------------------+-------+---------- public | geography_columns | view | postgres public | geometry_columns | view | postgres public | raster_columns | view | postgres public | raster_overviews | view | postgres public | spatial_ref_sys | table | postgres (5 rows)
……并在导入后:
walks=# \d List of relations Schema | Name | Type | Owner --------+--------------------------+----------+---------- public | geography_columns | view | postgres public | geometry_columns | view | postgres public | raster_columns | view | postgres public | raster_overviews | view | postgres public | route_points | table | postgres public | route_points_ogc_fid_seq | sequence | postgres public | routes | table | postgres public | routes_ogc_fid_seq | sequence | postgres public | spatial_ref_sys | table | postgres public | track_points | table | postgres public | track_points_ogc_fid_seq | sequence | postgres public | tracks | table | postgres public | tracks_ogc_fid_seq | sequence | postgres public | waypoints | table | postgres public | waypoints_ogc_fid_seq | sequence | postgres (15 rows)