CopyHelper

class ogr_utils.copy_helper.CopyHelper(fields=None, attr=None, driver='ESRI Shapefile', ordered=False)

Intended to function as convienence class that helps to save and convert files and selections on them. Only knows one method so far that saves an ogr layer as a shapefile.

lyr_2_shp(in_lyr, out_shp, geom_type)
rtype:None
Parameters:
  • in_lyr (ogr layer object) – input layer
  • out_shp (ESRI shapefile) – name of the output shapefile (full path)
  • geom_type (point or line or polygon or ring) – key as inherited from ogrUtils

Example

Easily saves some attribute or spatial selection to a shape file:

import ogr
from ogr_utils.copy_helper import CopyHelper
c = CopyHelper()
f = '/home/.../border_segs.shp'
shp =ogr.Open(f,0)
lyr = shp.GetLayer()
lyr.GetFeatureCount()
>>> 13411
fo = '/home/.../border_segs_test.shp'
lyr_sel = shp.ExecuteSQL("select * from 'border_segs' where 'FID' < 100 ")
lyr_sel.GetFeatureCount()
>>> 100
c.lyr_2_shp(lyr_sel,fo,'line')

Table Of Contents

Previous topic

Research

This Page