[gdal-dev] Inserting into PostGIS table with primary key using
ogr2ogr
Luca Sigfrido Percich
sigfrido at tiscali.it
Tue Dec 13 19:52:57 EST 2011
Thank you very much, Even. Apart from solving the problem, you're (as
always) opening new horizons to me :)
I'll test your solution tomorrow.
All the best!
Sig
Il giorno mar, 13/12/2011 alle 20.03 +0100, Even Rouault ha scritto:
> Le mardi 13 décembre 2011 14:47:40, Luca Sigfrido Percich a écrit :
> Yes, I've finally found how to do it without changing any line of code. Here
> come the power of the OGR VRT driver...
>
> 1) Fetch http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/ogr2vrt.py
> 2) Generate a templatpython ogr2vrt.py test_pk_data.shp test_pk_data.vrt
> 3) Edit test_pk_data.vrt to add a <FID> element that points to the ID column
> of your shapefile and remove/comment the <Field name="id"> element :
>
> <OGRVRTDataSource>
> <OGRVRTLayer name="test_pk_data">
> <SrcDataSource relativeToVRT="0"
> shared="1">test_pk_data.shp</SrcDataSource>
> <SrcLayer>test_pk_data</SrcLayer>
> <GeometryType>wkbPoint</GeometryType>
> <LayerSRS>PROJCS["Monte_Mario_Italy_zone_1",GEOGCS["GCS_Monte
> Mario",DATUM["Monte_Mario",SPHEROID["International_1924",6378388,297]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",9],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",1500000],PARAMETER["false_northing",0],UNIT["Meter",1]]</LayerSRS>
> <FID>id</FID>
> <!--<Field name="id" type="Integer" src="id" width="10"/>-->
> <Field name="name" type="String" src="name" width="50"/>
> </OGRVRTLayer>
> </OGRVRTDataSource>
>
> 4) ogr2ogr -update -append pg:dbname=XXXX test_pk_data.vrt -preserve_fid
>
> Enjoy !
>
> I've also added a short comment about the -preserve_fid option in ogr2ogr
> manual.
>
>
> Even
More information about the gdal-dev
mailing list