3

I have a .geojson file with line types that I'm trying to import into PostGIS with ogr2ogr. Following answers to similar questions on here, I tried the following:

ogr2ogr -f PostgreSQL PG:"dbname=gis user=alex" roads.geojson -nln roads

Using pgAdmin I can see that the roads table was created and the data imported, but when I go to add the table in QGIS in shows up as NoGeometry. I've tried adding -nlt with LINESTRING, MULTILINESTRING, and GEOMETRY, but no luck.

I'm new to PostGIS and ogr2ogr--can someone please shed some light on what I might be doing wrong?

  • 1
    Check that GDAL finds geometries from the data with ogrinfo - al. – user30184 Jan 16 '17 at 6:40
  • Looks like it's good, it comes back with OGRFeatures with LINESTRING like I would expect. – Alex Jan 16 '17 at 16:27
  • How about the PostGIS side, do you have a row about the new table in geometry_columns? – user30184 Jan 16 '17 at 16:32
  • No, I don't even seem to have a geometry_columns view – Alex Jan 16 '17 at 16:47
  • That is strange and the reason why QGIS does not find the geometry. – user30184 Jan 16 '17 at 16:51
2

Newbie mistake on my part. The PostGIS extension has to be enabled for each database before it can be used by running CREATE EXTENSION postgis;

  • Yes, if this was forgotten, ogr2ogr just automatically imports data to a "plain" table with geometry in wkb_geometry binary field and probably no client (like QGIS) can read it directly. Unfortunately it tries to be too automatic and does not give even warning that PostGIS was not enabled, and it is something you very likely need. – JaakL Oct 24 at 8:54

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.