[gdal-dev] ogr2ogr - id field in database table is not being written to geojson file

David McKelvie dmck at interactive.co.uk
Fri Sep 14 08:25:27 PDT 2018


Hi;

I have a question about ogr2ogr output from a postgres database to geojson.

One of the fields in my table, ie the primary key called 'id' is not being
output to the json file. I wonder if this is a bug or a 'feature'.

Can anybody clarify this?

The database table is:
-------------------------------
\d areas
              Table "public.areas"
      Column       |            Type             
-------------------+-----------------------------
 id                | integer                     
 type              | character varying(31)       
 name              | character varying(255)      
 created           | timestamp without time zone 
 last_modified     | timestamp without time zone 
 location          | geometry(Geometry,27700)    
 is_deleted        | boolean                     
 ons_code          | character varying(9)        
 extended_location | geometry(Geometry,27700)    
 uprn              | character varying(12)       
 info              | text                        
 name_vector       | tsvector                    
--------------------------

The command run was:
----------------------
ogr2ogr -f "GeoJSON" \
-lco "COORDINATE_PRECISION=2" \
/tmp/divisions.json \
"PG:dbname=capetown" areas
----------------------

The output file /tmp/divisions.json
had entries with properties like:
--------------------------------------
properties": { 
   "type": "division", 
   "name": "Divn  01", 
   "created": "2018\/09\/14 12:19:41", 
   "last_modified": "2018\/09\/14 12:19:41", 
   "is_deleted": 0, 
   "ons_code": null, 
   "uprn": null, 
   "info": null, 
   "name_vector": "'01':2 'divn':1" 
}
---------------------------------------

So all the database table fields EXCEPT for
the geometry fields and 'id' which is defined as
    id | integer | not null default nextval('areas_id_seq'::regclass)
and is the primary key for the table.

https://www.gdal.org/drv_geojson.html does not mention anything special about
'id' or primary key fields.

I am using ogr2ogr on Ubuntu Linux from the gdal-bin package . version 1.11.3+dfsg-3build2

David McKelvie



More information about the gdal-dev mailing list