[英]Why can't PHP insert new geometry on PostGIS?
我正在使用 ogr2ogr 將 GPX 文件上傳到 PostGIS。
當我在命令行(Ubuntu 14.04)上執行此操作時,它工作正常。
ogr2ogr -append -f PostgreSQL PG:"host=... dbname=... user=... password=..." 2016-04-26_15-32-01.xml
當我在 PHP (5.5.9) 上做這件事時,
exec("ogr2ogr -append -f PostgreSQL PG:\"host=".HOST." dbname=".DATABASE." user=".USER." password=".PASSWORD."\" /var/www/html/plantas/gps/2016-04-26_15-32-01.xml 2>&1",$output,$retval);
它給出了以下錯誤:
ERROR 1: INSERT command for new feature failed.
ERROR: Geometry SRID (0) does not match column SRID (4326)
Command: INSERT INTO "waypoints" ("wkb_geometry" , "ele", "time", "name", "cmt", "desc", "sym", "type", "gpxx_waypointextension", "wptx1_waypointextension", "ctx_creationtimeextension") VALUES ('010100000000008C76C2DF4EC00100C0A13A450E40'::GEOMETRY, 594, '2015/11/16 17:22:09+00', 'ROP_2904', '08-NOV-15 9:56:51
PONTO 60', '08-NOV-15 9:56:51
PONTO 60', 'Flag, Blue', 'user', ' SymbolAndName ', ' SymbolAndName ', ' 2015-11-16T17:22:09Z ') RETURNING "ogc_fid"
ERROR 1: Terminating translation prematurely after failed
translation of layer waypoints (use -skipfailures to skip errors)
我在這里缺少什么?
編輯
我嘗試了 Mike T 的建議:
$linha = "ogr2ogr -append -f PostgreSQL PG:\"host=".HOST." dbname=".DATABASE." user=".USER." password=".PASSWORD."\" -s_srs EPSG:4326 /var/www/html/plantas/gps/2016-04-26_15-32-01.xml 2>&1";
// or $linha = "ogr2ogr -s_srs EPSG:4326 -append -f PostgreSQL PG:\"host=".HOST." dbname=".DATABASE." user=".USER." password=".PASSWORD."\" /var/www/html/plantas/gps/2016-04-26_15-32-01.xml 2>&1";
exec($linha,$output,$retval);
無濟於事:
ERROR 1: INSERT command for new feature failed.
ERROR: Geometry SRID (0) does not match column SRID (4326)
真正奇怪的是,在終端上運行的命令完全相同。 所以我認為 PHP 可能有一些問題,也許是缺少庫或權限?
編輯 2
現在我看到有一些用戶需要運行的安裝
psql -d yourdatabase -f postgis.sql
在我的電腦中,我只做了
create extension postgis;
create extension postgis_topology;
去看看是不是這個問題
編輯 3 - 解決了!
我重新開始了這一切:
create extension postgis;
create extension postgis_topology;
ogr2ogr
創建額外的表(如waypoints
);看起來您的源圖層沒有空間參考系統 (SRID=0)。
使用ogr2ogr,您可以嘗試-s_srs EPSG:4326
來覆蓋源 SRS。
我重新開始了這一切:
create extension postgis;
create extension postgis_topology;
ogr2ogr
創建額外的表(如waypoints
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.