<div dir="ltr"><div>Hi Even,<br><br></div>this solves my probelm, the example in the script is quite useful. Thanks.<br><br>chao<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Mar 30, 2013 at 12:41 PM, Even Rouault <span dir="ltr"><<a href="mailto:even.rouault@mines-paris.org" target="_blank">even.rouault@mines-paris.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Le samedi 30 mars 2013 12:22:25, Chao YUE a écrit :<br>
<div class="im">> Dear all,<br>
><br>
> I am trying to create a new polygon shapefile and copy features from<br>
> existing shapefile into it and I have some problems doing this.<br>
> the script is below:<br>
><br>
> num_feature_multipolygon is a dictionary of (fdi,feature) pairs (see at the<br>
> end of mail)<br>
><br>
> dsnew = driver.CreateDataSource('Multi_polygon.shp')<br>
> layernew = dsnew.CreateLayer('multi_polygon',geom_type=ogr.wkbMultiPolygon)<br>
<br>
</div>--> You need to setup the layernew field definition here, i.e. use<br>
layernew.CreateField()<br>
<div class="im"><br>
> for fid, feature_temp in num_feature_multipolygon.items():<br>
>     feature_new = feature_temp.Clone()<br>
<br>
</div>--> you need to create a new feature from the layernew field definition and copy<br>
the feature_temp into it with feature_new.SetFrom(feature_temp)<br>
<div class="im"><br>
>     layernew.CreateFeature(feature_new)<br>
>     #feature_new.Destroy()<br>
> ds.Destroy()<br>
><br>
><br>
> I tested the resulting feature from feature.Clone() has the same attribute<br>
> values and geometry with the original one.<br>
> I guess somewhere I am wrong in the script?<br>
<br>
</div>You can find something very close to what you are looking for in<br>
<a href="http://svn.osgeo.org/gdal/trunk/autotest/ogr/ogr_shape.py" target="_blank">http://svn.osgeo.org/gdal/trunk/autotest/ogr/ogr_shape.py</a> in the ogr_shape_2()<br>
test.<br>
</blockquote></div><br><br clear="all"><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>