1

(Copied this question from stackoverflow, since it may have more answers here.)

I'm using ogr2ogr to upload a GPX file to PostGIS.

When I do it on command line (Ubuntu 14.04), it works fine.

ogr2ogr -append -f PostgreSQL PG:"host=... dbname=... user=... password=..." 2016-04-26_15-32-01.xml

When I do it on 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);

it gives the following error:

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)

What am I missing here?

EDIT

I tried Mike T suggestion:

$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);

to no avail:

ERROR 1: INSERT command for new feature failed.
ERROR: Geometry SRID (0) does not match column SRID (4326)

What's really strange is that exactly the same command works on terminal. So I think PHP might have some issue, perhaps a missing library or permission?

  • Is PHP able to read a file in that path? Maybe user rights are a problem. – bugmenot123 Apr 28 '16 at 20:19
  • @bugmenot123 Yes, PHP can read the file. Just did $texto = file_get_contents('/var/www/html/plantas/gps/2016-04-26_15-32-01.xml'); echo "[$texto]"; and it worked fine. – Rodrigo Apr 28 '16 at 20:34
1

I started it all again:

  1. restored a previous database from backup;
  2. create extension postgis;
  3. create extension postgis_topology;
  4. ogr2ogr from console creates additional tables (like waypoints);
  5. after this I need to grant access in those additional tables to php/apache user.
  • Ah, the SELECT permissions were not granted for the role to see the SRS info from the spatial_ref_sys table. This would cause the odd "SRID (0)" error. – Mike T May 1 '16 at 2:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.