I want to add a gpx file to a PostgreSQL/PostGIS table using ogr2ogr, but my table does not have any of the fields that are attributes of the GPX file. There are previous questions here dealing with selecting some attributes to copy using -select or -sql rather than copying all of them, but I want to copy no attributes, as any attribute fields that try to go into the table will result in an error. I know this must be possible, given the option in QGIS to "Skip attribute creation" on file conversion. How do you do it in the command line? Something like:

ogr2ogr -update -append -f PostgreSQL PG:dbname=mydb -nln mytable filename.gpx layer -select [none? 0? null? none of these work]
  • I did figure out that it DOES work to insert the feature into the table and just skips the unrecognized attributes. But it would still be nice to know how to strip all attributes when converting a file. – northlandiguana Mar 23 '16 at 20:47
  • 3
    From gdal.org/ogr2ogr.html Starting with OGR 1.11, geometry fields can also be specified in the list. I would try -select geometry with GDAL version 1.11 or higher. Another option is to use -sql "select geometry from layer". – user30184 Mar 23 '16 at 21:44

I usually try to convert any files to Shapefiles via ogr2ogr and then load it to PostgreSQL, usingogr2ogrorshp2pgsql`. A little bit complex, but i save files for history and it's easy to see changes in attributes.

ogr2ogr -f "ESRI Shapefile" your_shape.shp your_qpx.qpx -sql "SELECT somefieldfromgpx AS somefieldfromdatabase FROM your_qpx"

note that somefieldfromgpx and somefieldfromdatabase must be the same type.

And next step - loading shape to PostGIS

| improve this answer | |

In your select statement just include geometry none of the attribute fields/keys

| improve this answer | |

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.