加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 如何将多个gpx文件加载到PostGIS中?

发布时间:2020-12-16 23:31:43 所属栏目:Python 来源:网络整理
导读:我有一堆来自 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
我有一堆来自 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表中?

我在this博客文章中提到过:

I’m not aware of anything that can convert straight from GPX to
PostGIS

This post给出了一个使用SQL来做到这一点的例子,但我无法理解代码:/

解决方法

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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读