[gdal-dev] copy (duplicate) feature with python ogr?

Chao YUE chaoyuejoy at gmail.com
Sat Mar 30 04:22:25 PDT 2013


Dear all,

I am trying to create a new polygon shapefile and copy features from
existing shapefile into it and I have some problems doing this.
the script is below:

num_feature_multipolygon is a dictionary of (fdi,feature) pairs (see at the
end of mail)

dsnew = driver.CreateDataSource('Multi_polygon.shp')
layernew = dsnew.CreateLayer('multi_polygon',geom_type=ogr.wkbMultiPolygon)
for fid, feature_temp in num_feature_multipolygon.items():
    feature_new = feature_temp.Clone()
    layernew.CreateFeature(feature_new)
    #feature_new.Destroy()
ds.Destroy()


I tested the resulting feature from feature.Clone() has the same attribute
values and geometry with the original one.
I guess somewhere I am wrong in the script?

Two other posts online point to similar issue but not very helpful:
http://lists.osgeo.org/pipermail/gdal-dev/2008-July/017635.html
http://gis.stackexchange.com/questions/56703/better-way-to-duplicate-a-layer-using-ogr-in-python

could anyone explain a bit?  thanks a lot in advance!!

Chao


In [11]:

num_feature_multipolygon

Out[11]:

{276: <osgeo.ogr.Feature; proxy of <Swig Object of type
'OGRFeatureShadow *' at 0x3f2ce70> >,
 303: <osgeo.ogr.Feature; proxy of <Swig Object of type
'OGRFeatureShadow *' at 0x3f2ce70> >,
 314: <osgeo.ogr.Feature; proxy of <Swig Object of type
'OGRFeatureShadow *' at 0x3f2ce70> >,
 315: <osgeo.ogr.Feature; proxy of <Swig Object of type
'OGRFeatureShadow *' at 0x3f2ce70> >,
 324: <osgeo.ogr.Feature; proxy of <Swig Object of type
'OGRFeatureShadow *' at 0x3f2ce70> >,
 326: <osgeo.ogr.Feature; proxy of <Swig Object of type
'OGRFeatureShadow *' at 0x3f2ce70> >,
 327: <osgeo.ogr.Feature; proxy of <Swig Object of type
'OGRFeatureShadow *' at 0x3f2ce70> >,
 387: <osgeo.ogr.Feature; proxy of <Swig Object of type
'OGRFeatureShadow *' at 0x3f2ce70> >,
 408: <osgeo.ogr.Feature; proxy of <Swig Object of type
'OGRFeatureShadow *' at 0x3f2ce70> >,
 409: <osgeo.ogr.Feature; proxy of <Swig Object of type
'OGRFeatureShadow *' at 0x3f2ce70> >,
 411: <osgeo.ogr.Feature; proxy of <Swig Object of type
'OGRFeatureShadow *' at 0x3f2ce70> >,
 442: <osgeo.ogr.Feature;

copy (duplicate) feature with python ogr?
[image: Minimize][image: Pop-out][image: Close]

gdal-dev at lists.osgeo.org



 proxy of <Swig Object of type 'OGRFeatureShadow *' at 0x3f2ce70> >,
 443: <osgeo.ogr.Feature; proxy of <Swig Object of type
'OGRFeatureShadow *' at 0x3f2ce70> >}


-- 
***********************************************************************************
Chao YUE
Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
UMR 1572 CEA-CNRS-UVSQ
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex
Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16
************************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20130330/6b9d270d/attachment.html>


More information about the gdal-dev mailing list