def geom_attributes(self, srs=None): if srs is not None: #Should reproject here to equal area, before geom_attributes #self.glac_geom.AssignSpatialReference(glac_shp_srs) #self.glac_geom_local = geolib.geom2localortho(self.glac_geom) geolib.geom_transform(self.glac_geom, srs) self.glac_geom_extent = geolib.geom_extent(self.glac_geom) self.glac_area = self.glac_geom.GetArea() self.cx, self.cy = self.glac_geom.Centroid().GetPoint_2D()
cmd_fn = os.path.splitext(dem_index_fn)[0] + '_%s-%s_km2_stack_cmd.sh' % ( min_glac_area, max_glac_area) f = open(cmd_fn, "w") glac_dict = None #glac_dict = ['15.03473', '15.03733', '15.10070', '15.09991'] for n, feat in enumerate(glac_shp_lyr): #glac_geom_orig = geolib.geom_dup(feat.GetGeometryRef()) feat_fn = rgi_name(feat) if glac_dict is not None: if not feat_fn in glac_dict: continue print(n, feat_fn) glac_geom = geolib.geom_dup(feat.GetGeometryRef()) glac_geom_extent = geolib.geom_extent(glac_geom) #print(glac_geom_extent) #Should buffer by ~1 km here, preserve surrounding pixels for uncertainty analysis glac_geom = glac_geom.Buffer(buffer_m) glac_geom_extent = geolib.geom_extent(glac_geom) #print(glac_geom_extent) #glac_geom_extent = geolib.pad_extent(glac_geom_extent, width=1000) #Spatial filter dem_index_lyr.SetSpatialFilter(glac_geom) dem_count = dem_index_lyr.GetFeatureCount() print("dem count after spatial filter: %i" % dem_count) if dem_count > min_dem_count: fn_list = [] for dem_feat in dem_index_lyr: #Only 1 field from gdaltindex, 'location'
site_geom_orig.AssignSpatialReference(site_shp_srs) #This will automatically select appropriate UTM zone or polar stereographic if dst_srs is None: dst_srs = geolib.get_proj(site_geom_orig) geolib.geom_transform(site_geom_orig, dst_srs) if buffer is not None: site_geom_buff = site_geom_orig.Buffer(buffer) site_geom = site_geom_buff else: site_geom = site_geom_orig #This is xmin, xmax, ymin, ymax site_extent = geolib.geom_extent(site_geom) site_extent_str = ' '.join(map(str, site_extent)) print("Extent:", site_extent) print("Width/Height (km)", np.array(geolib.geom_wh(site_geom)) / 1000.) print("Area (km2)", site_geom.Area() / 1E6) #Get output filename from feature, make sure datestr is included f.write(site_name + '\n') f.write(str(site_extent) + '\n') #Can also set spatial filter for each site #https://pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html#spatial-filter dem_fn_list = [] dem_shp_lyr.ResetReading()