<div dir="ltr"><div><div>Dear all,<br><br></div>I am trying to create a new polygon shapefile and copy features from existing shapefile into it and I have some problems doing this.<br></div><div>the script is below:<br><br>
</div>num_feature_multipolygon is a dictionary of (fdi,feature) pairs (see at the end of mail)<br><div><div><br>dsnew = driver.CreateDataSource('Multi_polygon.shp')<br>layernew = dsnew.CreateLayer('multi_polygon',geom_type=ogr.wkbMultiPolygon)<br>
for fid, feature_temp in num_feature_multipolygon.items():<br>    feature_new = feature_temp.Clone()<br>    layernew.CreateFeature(feature_new)<br>    #feature_new.Destroy()<br>ds.Destroy()<br><br><br></div><div>I tested the resulting feature from feature.Clone() has the same attribute values and geometry with the original one.<br>
</div><div>I guess somewhere I am wrong in the script? <br><br></div><div>Two other posts online point to similar issue but not very helpful:<br><a href="http://lists.osgeo.org/pipermail/gdal-dev/2008-July/017635.html">http://lists.osgeo.org/pipermail/gdal-dev/2008-July/017635.html</a> <br>
<a href="http://gis.stackexchange.com/questions/56703/better-way-to-duplicate-a-layer-using-ogr-in-python">http://gis.stackexchange.com/questions/56703/better-way-to-duplicate-a-layer-using-ogr-in-python</a><br><br></div>
<div>could anyone explain a bit?  thanks a lot in advance!!<br><br></div><div>Chao<br><br clear="all"></div><div><div><div><br><div class=""><div class="">In [11]:</div><div class=""><div class=""><div style="overflow:hidden;width:3px;height:0px">
<textarea style="padding:0px;width:1px;height:1em"></textarea></div><div class="" tabindex="-1"><div style="height:29.6px"><div style><div class=""><div style="outline:medium none"><div style="width:100%;height:0px;overflow:hidden">
<pre><span class=""></span><span id="CodeMirror-temp-436a5e"></span></pre></div><div style><pre><span class="">num_feature_multipolygon</span></pre></div></div></div></div></div></div></div></div></div><div style="display:-moz-box" class="">
<div class=""><div class="">Out[11]:</div><div class=""><pre>{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;</pre><div></div><div class=""><div class=""><div class=""><div class="" style="margin-left:3px"><div class="" style="padding:0px 0px 4px;margin:0px 3px 0px 0px"><div class=""><div class=""><table class="" cellpadding="0">
<tbody><tr id=":zb"><td><div id=":ug" class="">copy (duplicate) feature with python ogr?</div></td><td class=""><img class="" id=":uj" tabindex="undefined" src="https://mail.google.com/mail/u/0/images/cleardot.gif" alt="Minimize"><img class="" id=":ui" tabindex="undefined" src="https://mail.google.com/mail/u/0/images/cleardot.gif" alt="Pop-out"><img class="" id=":uh" tabindex="undefined" src="https://mail.google.com/mail/u/0/images/cleardot.gif" alt="Close"></td>
</tr></tbody></table></div></div></div></div></div></div></div><table id=":wd" class=""><tbody><tr><td class=""><br></td><td id=":xa" class=""><form id=":vk" action="" method="POST" enctype="multipart/form-data" accept-charset="utf-8">
<div id=":x9" class="" tabindex="1" style><div style id=":w7" class=""><span><a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a></span></div></div><div id=":x1" class=""><input dir="ltr" name="subjectbox" id=":x0" class="" tabindex="1"></div>
</form><table class=""><tbody><tr><td class=""><div style="max-height:267px;min-height:267px;height:267px" id=":vc" class=""><div style="max-height:267px" id=":vb" class=""><div id=":vd" class=""><div id=":wi" class=""><div>
<table class="" id=":10l" cellpadding="0"><tbody><tr><td class=""><div style="display:block" id=":ue" class=""><div style="line-height:0" id=":zx" class=""></div></div><br></td></tr></tbody></table></div></div></div></div>
</div><br></td></tr><tr><td class=""><br></td></tr></tbody></table></td></tr></tbody></table><pre> proxy of <Swig Object of type 'OGRFeatureShadow *' at 0x3f2ce70> >,
 443: <osgeo.ogr.Feature; proxy of <Swig Object of type 'OGRFeatureShadow *' at 0x3f2ce70> >}</pre></div></div></div><br>-- <br><div>***********************************************************************************</div>

<div>Chao YUE<br>Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)<br>UMR 1572 CEA-CNRS-UVSQ<br>Batiment 712 - Pe 119<br>91191 GIF Sur YVETTE Cedex</div>
<div>Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16<br></div>

<div>************************************************************************************</div>
</div></div></div></div></div>