gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:32:34 54 4
gpt4 key购买 nike

我有一堆来自 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 中创建自己的数据库表。 tracks 表中每个 GPS 航迹一行; tracks.wkb_geometry 包含 GPS 轨迹本身作为 MultiLineString。 track_points 表包含各个位置定位(带有时间戳)。

这是数据库 walks 在导入之前的样子:

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)

关于python - 如何将多个 gpx 文件加载到 PostGIS 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7235743/

54 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com