[gdal-dev] Shapefile read/write

Howard Butler hobu.inc at gmail.com
Mon Dec 3 15:05:39 EST 2007


I think you might need a data_source.SyncToDisk() call before  
destroying.

On Dec 3, 2007, at 1:55 PM, Mullins, Steven wrote:

> Thanks for the quick reply.  I am using GDAL 1.5dev, FWTools 1.3.9,  
> released 2007/10/11 on win32.
> I assume since it is a development build, it is the new bindings.
>
> -----Original Message-----
> From: Howard Butler [mailto:hobu.inc at gmail.com]
> Sent: Mon, December 03, 2007 2:52 PM
> To: Mullins, Steven
> Cc: gdal-dev at lists.osgeo.org
> Subject: Re: [gdal-dev] Shapefile read/write
>
>
> Which version of GDAL?
> Which bindings are you using, next-gen or old-gen?
>
> On Dec 3, 2007, at 1:41 PM, Mullins, Steven wrote:
>
>> I have written this short python program to update the northing and
>> easting datafields of a shapefile with the point locations for each
>> point.  I need to write this data back to the same shapefile.  Doing
>> a .Destroy() does not write back to the file.  I assume ogr.Open is
>> read only.  Is there a way to open a file read/write and write the
>> changes back when closing or Destroying?  Do I have to open a new
>> file and iterate over all the fields and points and write to a new
>> file?
>>
>> Thanks,
>>
>> Steve
>>
>> ###############################################
>> #!/usr/local/bin/python
>> #
>>
>> import ogr
>> import osr
>> import string
>>
>> ###############################################
>> # Data Source
>> data_source = ogr.Open('./shapefiles83/rainfalls-active/rainfalls-
>> active.shp', update = 1)
>> layer_0 = data_source.GetLayer(0)
>> ###############################################
>>
>>
>>
>> current_feature = layer_0.GetNextFeature()
>>
>> while current_feature is not None:
>>
>>   current_point = current_feature.GetGeometryRef()
>>
>>   # update coords from point X,Y
>>   current_feature.SetField ( 0, current_point.GetX())
>>   current_feature.SetField ( 1, current_point.GetY())
>>
>>   current_feature = layer_0.GetNextFeature()
>>
>> data_source.Destroy()
>> ####################################################
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev



More information about the gdal-dev mailing list