[gdal-dev] Updating shapefile "fields" name with ogr2ogr

Emmanuel Séguin emmanuel.seguin at ign.fr
Thu Jun 21 06:29:32 PDT 2012


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




More information about the gdal-dev mailing list