def create_dataset(args): """ Parse the shapefile and source definitions, but do not render any of the DEM. """ paths = args.path # field.CompositeField has a generic interface for sources, via # a 'factory' method. def factory(attrs): geo_bounds = attrs['geom'].bounds if attrs['src_name'].startswith('py:'): expr = attrs['src_name'][3:] # something like 'ConstantField(-1.0)' # a little sneaky... make it look like it's running # after a "from stompy.spatial.field import *" # and also it gets fields of the shapefile field_hash = dict(field.__dict__) # convert the attrs into a dict suitable for passing to eval attrs_dict = {} for name in attrs.dtype.names: attrs_dict[name] = attrs[name] return eval(expr, field_hash, attrs_dict) # Otherwise assume src_name is a file name or file pattern. for p in paths: full_path = os.path.join(p, attrs['src_name']) files = glob.glob(full_path) if len(files) > 1: mrf = field.MultiRasterField(files) return mrf elif len(files) == 1: gg = field.GdalGrid(files[0], geo_bounds=geo_bounds) gg.default_interpolation = 'linear' return gg log.warning("Source %s was not found -- ignoring" % attrs['src_name']) return None comp_field = field.CompositeField(shp_fn=args.shapefile, shp_query=args.query, target_date=args.date, factory=factory, priority_field='priority', data_mode='data_mode', alpha_mode='alpha_mode') return comp_field
priority=95, src=field.ConstantField(0.7), alpha_mode='blur_alpha(4.0)', data_mode='min()') south_channel_dem = field.GdalGrid("north_channel_and_ditch-1m.tif") # And now include that channel params('marsh_south_channel', priority=90, src=south_channel_dem, data_mode='min()', alpha_mode='valid(),feather_in(2.0)', geom=field_bounds(lagoon_dem)) comp_field = field.CompositeField(shp_data=shp_data, factory=factory) res = 2.0 # This can then be used below with the ContourInterpolator dem_dry = comp_field.to_grid(dx=res, dy=res, bounds=clip) # Assume the western pan is sort of radially similar. from stompy.grid import unstructured_grid, exact_delaunay from stompy.spatial import interp_concentric west = adj_regions['geom'][adj_regions['name'] == 'west_marsh_inundated'][0] center = adj_regions['geom'][adj_regions['name'] == 'center_marsh_inundated_west'][0] # Go out about 10.0m to get some dry land to pull from the DEM region = west.union(center).buffer(10.0)
# a little sneaky... make it look like it's running # after a "from stompy.spatial.field import *" # and also it gets fields of the shapefile field_hash = dict(field.__dict__) # convert the attrs into a dict suitable for passing to eval attrs_dict = {} for name in attrs.dtype.names: attrs_dict[name] = attrs[name] return eval(expr, field_hash, attrs_dict) assert False src_shp = 'roughness_sources.shp' mbf = field.CompositeField(shp_fn=src_shp, factory=factory, priority_field='priority', data_mode='data_mode', alpha_mode='alpha_mode') xxyy = [642800, 649400, 4183200, 4188400] bleed = 50 xxyy_pad = [xxyy[0] - bleed, xxyy[1] + bleed, xxyy[2] - bleed, xxyy[3] + bleed] dem = mbf.to_grid(dx=2, dy=2, bounds=xxyy_pad) dem = dem.crop(xxyy) out_fn = 'composite-roughness.tif' os.path.exists(out_fn) and os.unlink(out_fn) dem.write_gdal(out_fn)