[gdal-dev] Shapefile read/write
Mullins, Steven
Steven.Mullins at dmme.virginia.gov
Mon Dec 3 14:41:45 EST 2007
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()
####################################################
More information about the gdal-dev
mailing list