Re: [gdal-dev] Updating shapefile "fields" name with ogr2ogr
I've also found this very confusing and unexpected. Once I did figure it out it has been very useful. Could ogrinfo CHEMIN.shp -sql "ALTER TABLE CHEMIN RENAME COLUMN prec_alti TO foo" or similar be added as an example to http://gdal.org/ogrinfo.html and perhaps also as a 'note about ogrinfo with OGR SQL' on http://gdal.org/ogr/ogr_sql.html? Perhaps http://gdal.org/ogr/ogr_sql.html could be updated from: -sql statement: Execute the indicated SQL statement and return the result. to something like: -sql statement: Execute the indicated SQL statement and return the result. In place updates (ALTER TABLE) are also permitted. Eli On Thu, Jun 21, 2012 at 11:03 PM, Hermann Peifer wrote: > On 2012-06-20 19:50, Even Rouault wrote: >> >> >> I know this is going to sound a bit counter-intutive at first... >> >> ogrinfo opens datasources in read/write mode by default... > > > Just out of curiosity: why does an ...info tool use read/write mode by > default? One would expect that it only needs to *read* some info in the data > source? > > Hermann > > ___ > gdal-dev mailing list > gdal-dev@lists.osgeo.org > http://lists.osgeo.org/mailman/listinfo/gdal-dev ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] Updating shapefile "fields" name with ogr2ogr
On 2012-06-20 19:50, Even Rouault wrote: I know this is going to sound a bit counter-intutive at first... ogrinfo opens datasources in read/write mode by default... Just out of curiosity: why does an ...info tool use read/write mode by default? One would expect that it only needs to *read* some info in the data source? Hermann ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] Updating shapefile "fields" name with ogr2ogr
Thanx for your answer. Working fine. On 06/20/2012 07:50 PM, Even Rouault wrote: Le mercredi 20 juin 2012 18:41:40, Emmanuel Séguin a écrit : Hi, This may be very easy but I did not find a way to use ogr2ogr to change a shapefile field (attribute) name. I've tried something like this : ' ogr2ogr -f "ESRI Shapefile" -sql "ALTER TABLE CHEMIN RENAME COLUMN prec_alti TO foo" CHEMIN2.shp CHEMIN.shp ' but I get the following error "ERROR 6: Can't alter field definition on a read-only shapefile layer." (I've tried to use the "AlterFieldDefn=TRUE" layer option with no success whatsoever) I know this is going to sound a bit counter-intutive at first... When doing ogr2ogr destination.shp source.shp [anything], there's no reason to open source.shp in read/write mode, so it is opened in read-only mode. When you issue a SQL command, it is meant as an action on the source dataset, not the target dataset. When this SQL command is a ALTER one, you obviously need read/write permissions. When you combine all the statements, you understand the error message... The good news is that you can solve it easily by using ogrinfo instead. ogrinfo opens datasources in read/write mode by default (unless you specify - ro). So you can run : ogrinfo CHEMIN.shp -sql "ALTER TABLE CHEMIN RENAME COLUMN prec_alti TO foo" Best regards, Even -- Emmanuel Séguin SIEL - Pôle technique du Géoportail Institut Géographique National 2/4, avenue Pasteur - 94165 Saint Mandé Cedex Phone : +33 1.43.98.83.54 http://fr.linkedin.com/in/emmmanuelseguin ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] Updating shapefile "fields" name with ogr2ogr
On Wed, Jun 20, 2012 at 7:50 PM, Even Rouault wrote: > > ogrinfo CHEMIN.shp -sql "ALTER TABLE CHEMIN RENAME COLUMN prec_alti TO foo" > really nice, I was not aware of this. Another option I have been always using is: ogr2ogr -sql 'select field1, field2, fieldn, ..., oldname as newname from input' output.shp input.shp but this way we need to regenerate the shapefile best regards p -- Paolo Corti Geospatial software developer web: http://www.paolocorti.net twitter: @capooti skype: capooti ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] Updating shapefile "fields" name with ogr2ogr
Le mercredi 20 juin 2012 18:41:40, Emmanuel Séguin a écrit : > Hi, > > This may be very easy but I did not find a way to use ogr2ogr to change > a shapefile field (attribute) name. > I've tried something like this : ' ogr2ogr -f "ESRI Shapefile" -sql > "ALTER TABLE CHEMIN RENAME COLUMN prec_alti TO foo" CHEMIN2.shp > CHEMIN.shp ' but I get the following error "ERROR 6: Can't alter field > definition on a read-only shapefile layer." (I've tried to use the > "AlterFieldDefn=TRUE" layer option with no success whatsoever) I know this is going to sound a bit counter-intutive at first... When doing ogr2ogr destination.shp source.shp [anything], there's no reason to open source.shp in read/write mode, so it is opened in read-only mode. When you issue a SQL command, it is meant as an action on the source dataset, not the target dataset. When this SQL command is a ALTER one, you obviously need read/write permissions. When you combine all the statements, you understand the error message... The good news is that you can solve it easily by using ogrinfo instead. ogrinfo opens datasources in read/write mode by default (unless you specify - ro). So you can run : ogrinfo CHEMIN.shp -sql "ALTER TABLE CHEMIN RENAME COLUMN prec_alti TO foo" Best regards, Even ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev