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()
def get_lulc_source(ds): """For a given input dataset extent, select the appropriate mask source (NLCD vs. global bareground) """ ds_geom = geolib.ds_geom(ds) lulc_fn = get_nlcd_fn() lulc_ds = gdal.Open(lulc_fn) lulc_geom = geolib.ds_geom(lulc_ds) #If the dem geom is within CONUS (nlcd extent), use it geolib.geom_transform(ds_geom, t_srs=lulc_geom.GetSpatialReference()) #This was lulc_geom.Contains, but changed to force LULC for CONUS ds that extend beyond LULC domain if lulc_geom.Intersects(ds_geom): print("Using NLCD 30m data for rockmask") lulc_source = 'nlcd' else: print("Using global 30m bare ground data for rockmask") #Otherwise for Global, use 30 m Bare Earth percentage lulc_source = 'bareground' #lulc_fn = get_bareground_fn() #lulc_ds = gdal.Open(lulc_fn) return lulc_source
#Could output json here stackdir = os.path.join(outdir, site_name) if not os.path.exists(stackdir): os.makedirs(stackdir) out_fn = os.path.join(stackdir, 'site_%s.csv' % site_name) f = open(out_fn, 'w') site_geom_orig = site_feat.GetGeometryRef() 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)