tgt_dir = r"D:\tmp\veg" tgt_file = "wh_plots_2011.shp" tgt_path = os.path.join(tgt_dir, tgt_file) tgt_sr = osr.SpatialReference() tgt_sr.SetWellKnownGeogCS('WGS84') tgt_sr.SetUTM(32) record = OrderedDict() record['plot_id'] = 0 record['editor'] = "" record['x'] = 0.0 record['y'] = 0.0 ds, ly = ogr_utils.create_shapefile(tgt_path, ogr.wkbPoint, tgt_sr) ogr_utils.create_feature_definition_from_record(record, ly) coords_1 = read_coordinates(veg_src_uh) coords_2 = read_coordinates(veg_src_df) for c in sorted(coords_1): x, y = coords_1[c] print "%d\t%d\t%d" % (c, coords_1[c][0], coords_1[c][1]) pnt_gm = ogr.Geometry(ogr.wkbPoint) pnt_gm.SetPoint_2D(0, x, y) pnt_ft = ogr.Feature(ly.GetLayerDefn()) pnt_ft.SetGeometry(pnt_gm) pnt_ft.SetField('plot_id', c) pnt_ft.SetField('editor', 'uh') pnt_ft.SetField('x', x)
if __name__ == '__main__': shp_src = r"D:\work\ms.monina\wp5\doeberitzer_heide\field\doeberitzer_heide_plots.shp" txt_src = r"D:\work\ms.monina\wp5\doeberitzer_heide\field\doeberitzer_heide_releve_plots.txt" link_field = "LINK_ID" tgt_shp = r"D:\work\ms.monina\wp5\doeberitzer_heide\field\releve_plots_xxx.shp" plt_ds = ogr.Open(shp_src) plt_ly = plt_ds.GetLayer(0) plt_name = plt_ly.GetName() tgt_ds, tgt_ly = ogr_utils.create_shapefile(tgt_shp, ogr.wkbPoint, plt_ly.GetSpatialRef()) tgt_rec = dict() tgt_rec['plot_id'] = '' tgt_rec['src_cnt'] = 0 tgt_rec['x'] = 0. tgt_rec['y'] = 0. ogr_utils.create_feature_definition_from_record(tgt_rec, tgt_ly) releve_plot_ids = [l.strip() for l in open(txt_src).readlines()] i = 0 for r_plot_id in releve_plot_ids: sel_ly = plt_ds.ExecuteSQL("SELECT * FROM %s WHERE %s LIKE '%s'" % (plt_name, link_field, r_plot_id)) if sel_ly is None: continue
# setting up target spatial reference sr = osr.SpatialReference() sr.SetWellKnownGeogCS('WGS84') # preparing attributes to be stored for each sheet tile record = OrderedDict() record['id'] = '' record['name'] = '' record['lva'] = '' record['ll_lat'] = 0.0 record['ll_lon'] = 0.0 record['ur_lat'] = 0.0 record['ur_lon'] = 0.0 # creating shape file ds, ly = ogr_utils.create_shapefile(tgt_shp, ogr.wkbPolygon, sr) ogr_utils.create_feature_definition_from_record(record, ly) # setting up initial corner initial_corner = GeographicCoordinates(DMSCoordinate(56, 0, 0, 'N'), DMSCoordinate(5, 50, 0, 'E')) initial_lat = initial_corner.latitude initial_lon = initial_corner.longitude # setting up sheet dimensions # TK25 delta_lat = DMSCoordinate(0, 6) delta_lon = DMSCoordinate(0, 10) # TK10 delta_lat = DMSCoordinate(0, 3) delta_lon = DMSCoordinate(0, 5)
occ_data = species_lut[key] quad_ids = set() tk25_ids = set() tmp_ids = set() all_occ = dict() if len(occ_data[0]) == 3: suffix = occ_data[0][-1] record['suffix'] = '' else: suffix = '' # creating target shape file for current species tgt_file = key.lower().replace(" ", "_") + ".shp" tgt_shp = os.path.join(tgt_dir, tgt_file) tgt_ds, tgt_ly = ogr_utils.create_shapefile(tgt_shp, ogr.wkbPolygon, tk25_ly.GetSpatialRef()) ogr_utils.create_feature_definition_from_record(record, tgt_ly) # iterating over all occurrences for current species for entry in sorted(occ_data, key = itemgetter(0), reverse = False): # retrieving location by quadrant id and symbol quad_location, symbol = entry[:2] # extracting mtb location by extracting it from quad location tk25_location = quad_location[:-1] # setting quadrant, i.e. 1, 2, 3 or 4 quadrant = quad_location[-1] # using dictionary to hold occurrence information occ_dict = dict() occ_dict['species'] = key occ_dict['symbol'] = symbol
""" import numpy as np from osgeo import ogr from _utils import ogr_utils if __name__ == '__main__': del_src = r"D:\work\ms.monina\wp5\kalmthoutse_heide\field\kh_forest_plots.txt" geo_src = r"D:\work\ms.monina\wp5\kalmthoutse_heide\field\kalmthoutse_heide_releve_plots.shp" geo_tgt = r"D:\work\ms.monina\wp5\kalmthoutse_heide\field\kalmthoutse_heide_releve_plots_wo_forest.shp" src_ds = ogr.Open(geo_src) src_ly = src_ds.GetLayer(0) src_sr = src_ly.GetSpatialRef() tgt_ds, tgt_ly = ogr_utils.create_shapefile(geo_tgt, ogr.wkbPoint, src_sr) ogr_utils.create_feature_definition_from_template(src_ly, tgt_ly) del_ft = [int(n) for n in np.loadtxt(del_src)] plot_idx = src_ly.GetLayerDefn().GetFieldIndex('plot_id') for ft in src_ly: src_id = ft.GetField(plot_idx) if src_id in del_ft: continue tgt_ly.CreateFeature(ft)
if __name__ == '__main__': shp_src = r"D:\tmp\ahs1_coverage_b.shp" shp_src = r"d:\tmp\skel_test.shp" shp_src = r"D:\work\ms.monina\wp5\kalmthoutse_heide\2007-07-02_ahs\coverage\shp\ahs_1_coverage_reduced.shp" shp_src = r"Z:\fabi\shp\_wet_orig.shp" tgt_file = r"Z:\fabi\shp\_nf_orig_pnt.shp" tgt_type = 'nf' ds = ogr.Open(shp_src) ly = ds.GetLayer(0) sr = ly.GetSpatialRef() tgt_ds, tgt_ly = ogr_utils.create_shapefile(tgt_file, ogr.wkbPoint, sr) ogr_utils.create_feature_definition_from_template(ly, tgt_ly) new_field = ogr.FieldDefn('x', ogr.OFTReal) tgt_ly.CreateField(new_field) new_field = ogr.FieldDefn('y', ogr.OFTReal) tgt_ly.CreateField(new_field) i = 0 for ft in ly: t = ft.GetFieldAsString('type') if t != tgt_type: continue gm = ft.GetGeometryRef()
from _utils import ogr_utils if __name__ == '__main__': shp_src = r"D:\work\ms.monina\wp5\doeberitzer_heide\field\doeberitzer_heide_plots.shp" txt_src = r"D:\work\ms.monina\wp5\doeberitzer_heide\field\doeberitzer_heide_releve_plots.txt" link_field = "LINK_ID" tgt_shp = r"D:\work\ms.monina\wp5\doeberitzer_heide\field\releve_plots_xxx.shp" plt_ds = ogr.Open(shp_src) plt_ly = plt_ds.GetLayer(0) plt_name = plt_ly.GetName() tgt_ds, tgt_ly = ogr_utils.create_shapefile(tgt_shp, ogr.wkbPoint, plt_ly.GetSpatialRef()) tgt_rec = dict() tgt_rec['plot_id'] = '' tgt_rec['src_cnt'] = 0 tgt_rec['x'] = 0. tgt_rec['y'] = 0. ogr_utils.create_feature_definition_from_record(tgt_rec, tgt_ly) releve_plot_ids = [l.strip() for l in open(txt_src).readlines()] i = 0 for r_plot_id in releve_plot_ids: sel_ly = plt_ds.ExecuteSQL("SELECT * FROM %s WHERE %s LIKE '%s'" % (plt_name, link_field, r_plot_id)) if sel_ly is None: