[gdal-dev] Shapefile read/write
Howard Butler
hobu.inc at gmail.com
Mon Dec 3 14:52:21 EST 2007
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