<s> import os <EOL> from osgeo import ogr <EOL> import ospybook as pb <EOL> from ospybook . vectorplotter import VectorPlotter <EOL> data_dir = r'<STR_LIT>' <EOL> def print_layers ( fn ) : <EOL> ds = ogr . Open ( fn , <NUM_LIT:0> ) <EOL> if ds is None : <EOL> raise OSError ( '<STR_LIT>' . format ( fn ) ) <EOL> for i in range ( ds . GetLayerCount ( ) ) : <EOL> lyr = ds . GetLayer ( i ) <EOL> print ( '<STR_LIT>' . format ( i , lyr . GetName ( ) ) ) <EOL> print_layers ( os . path . join ( data_dir , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> pb . print_layers ( os . path . join ( data_dir , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> ds = ogr . Open ( os . path . join ( data_dir , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> lyr = ds . GetLayer ( '<STR_LIT>' ) <EOL> vp = VectorPlotter ( True ) <EOL> vp . plot ( lyr , '<STR_LIT>' ) <EOL> vp = VectorPlotter ( False ) <EOL> vp . plot ( lyr , '<STR_LIT>' ) <EOL> vp . draw ( ) <EOL> pb . print_layers ( '<STR_LIT>' ) <EOL> pb . print_layers ( os . path . join ( data_dir , '<STR_LIT>' ) ) <EOL> pb . print_layers ( os . path . join ( data_dir , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> pb . print_layers ( os . path . join ( data_dir , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> pb . print_layers ( os . path . join ( data_dir , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> driver = ogr . GetDriverByName ( '<STR_LIT>' ) <EOL> ds = driver . Open ( os . path . join ( data_dir , '<STR_LIT>' ) ) <EOL> print ( ds ) <EOL> fn = os . path . join ( data_dir , '<STR_LIT>' , '<STR_LIT>' ) <EOL> pb . print_layers ( fn ) <EOL> ds = ogr . Open ( fn ) <EOL> lyr = ds . GetLayer ( '<STR_LIT>' ) <EOL> pb . print_attributes ( lyr , <NUM_LIT:5> , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> out_folder = os . path . join ( data_dir , '<STR_LIT>' ) <EOL> gdb_ds = ogr . Open ( fn ) <EOL> gdb_lyr = gdb_ds . GetLayerByName ( '<STR_LIT>' ) <EOL> shp_ds = ogr . Open ( out_folder , <NUM_LIT:1> ) <EOL> shp_ds . CopyLayer ( gdb_lyr , '<STR_LIT>' ) <EOL> del shp_ds , gdb_ds <EOL> import listing4_2 <EOL> shp_folder = os . path . join ( data_dir , '<STR_LIT>' ) <EOL> gdb_fn = os . path . join ( shp_folder , '<STR_LIT>' ) <EOL> listing4_2 . layers_to_feature_dataset ( shp_folder , gdb_fn , '<STR_LIT>' ) <EOL> url = '<STR_LIT>' <EOL> pb . print_layers ( url ) <EOL> ds = ogr . Open ( url ) <EOL> lyr = ds . GetLayer ( <NUM_LIT:1> ) <EOL> print ( lyr . GetFeatureCount ( ) ) <EOL> feat = lyr . GetNextFeature ( ) <EOL> print ( feat . GetField ( '<STR_LIT>' ) ) <EOL> ds = ogr . Open ( url + '<STR_LIT>' ) <EOL> lyr = ds . GetLayer ( <NUM_LIT:1> ) <EOL> print ( lyr . GetFeatureCount ( ) ) <EOL> vp = VectorPlotter ( False ) <EOL> ds = ogr . Open ( os . path . join ( data_dir , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> lyr = ds . GetLayer ( <NUM_LIT:0> ) <EOL> vp . plot ( lyr , fill = False ) <EOL> ds = ogr . Open ( url ) <EOL> lyr = ds . GetLayer ( '<STR_LIT>' ) <EOL> vp . plot ( lyr ) <EOL> vp . draw ( ) <EOL> dirname = os . path . join ( data_dir , '<STR_LIT>' ) <EOL> ds = ogr . Open ( dirname ) <EOL> print ( ds . TestCapability ( ogr . ODsCCreateLayer ) ) <EOL> ds = ogr . Open ( dirname , <NUM_LIT:1> ) <EOL> print ( ds . TestCapability ( ogr . ODsCCreateLayer ) ) <EOL> original_fn = os . path . join ( data_dir , '<STR_LIT>' , '<STR_LIT>' ) <EOL> new_fn = os . path . join ( data_dir , '<STR_LIT>' , '<STR_LIT>' ) <EOL> pb . copy_datasource ( original_fn , new_fn ) <EOL> ds = ogr . Open ( new_fn , <NUM_LIT:0> ) <EOL> if ds is None : <EOL> sys . exit ( '<STR_LIT>' . format ( new_fn ) ) <EOL> lyr = ds . GetLayer ( <NUM_LIT:0> ) <EOL> if not lyr . TestCapability ( ogr . OLCCreateField ) : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> lyr . CreateField ( ogr . FieldDefn ( '<STR_LIT>' , ogr . OFTInteger ) ) <EOL> ds = ogr . Open ( new_fn , <NUM_LIT:1> ) <EOL> if ds is None : <EOL> sys . exit ( '<STR_LIT>' . format ( new_fn ) ) <EOL> lyr = ds . GetLayer ( <NUM_LIT:0> ) <EOL> if not lyr . TestCapability ( ogr . OLCCreateField ) : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> lyr . CreateField ( ogr . FieldDefn ( '<STR_LIT>' , ogr . OFTInteger ) ) <EOL> driver = ogr . GetDriverByName ( '<STR_LIT>' ) <EOL> pb . print_capabilities ( driver ) </s>
