Use Fiona of Sean Gillies , a very simple wrapper of the OGR library (The Fiona User Manual)

All the elements of a shapefile (schema, records) are processed using Python dictionaries:

schema of one of my shapefiles as example:


  {'geometry': 'LineString', 'properties': {u'faille': 'str:20', u'type': 'str:20', u'id': 'int'}}


one record in the shapefile:


  {'geometry': {'type': 'LineString', 'coordinates': [(269884.20917418826, 151805.1917153612), (270409.89083992655, 153146.21637285672), (272298.05355768028, 154047.38494269375), (272941.74539327814, 155484.96337552898), (272169.31519056071, 156117.92701386689)]}, 'id': '1',  'properties': {'faille': u'de Salinas', 'type': u'normale'}}


so to duplicate a shapefile:

from shapely.geometry import mapping, shape
import fiona
# Read the original Shapefile
with fiona.collection('original.shp', 'r') as input:
    # The output has the same schema
    schema = input.schema.copy()
    # write a new shapefile
    with fiona.collection(''file1.shp', 'w', 'ESRI Shapefile', schema) as output:
        for elem in input:
             output.write({'properties': elem['properties'],'geometry': mapping(shape(elem['geometry']))})


If you want to split a large shapefile into many smaller ones, everything takes place in the for loop but all the schemas of the original shapefile are preserved in the dictionary with schema = input.schema.copy() and {'properties': elem['properties'] 

see How do I find vector line bearing in QGIS or GRASS? for an example of


spliting a shapefile
preserve the attributes of the original shapefile in the splitted shapefile
and add a new field in the splitted shapefile


For Mac OS X or Linux users, it is easy to install. For Windows users, use the version of  Christoph Gohlke Unofficial Windows Binaries for Python Extension Packages

better way to duplicate a layer using ogr in python?
'm using a custom control from the ObjectListView package. It's widely used by stackoveflow members so that's why i post it here.

But i find it very hard to show data results in the DataTreeListView control. 
This is my code:

         DataSet ds = LoadDatasetFromXml("FamilyTree.xml");

         if (ds.Tables.Count &gt; 0)
         {
             this.dataGridView1.DataSource = ds;
             this.dataGridView1.DataMember = "Person";

             this.dataTreeListView1.DataMember = "Person";
             this.dataTreeListView1.DataSource = new DataViewManager(ds);
         }


And this is the result:


I use the xml that's provided with the package, so that won't be the problem. I changed all the dataTreeListView propertys so they are just the same as the demo project.

I also tried it using Linq with an selfmade table but with the same results. The datagridview on the other hand works like a charm...

Does anyone have an idea?
