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

前端之家收集整理的这篇文章主要介绍了python – 如何将多个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表中?

我在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)
原文链接:https://www.f2er.com/python/185847.html

猜你在找的Python相关文章