def raster_file_upload(filepath, **kwargs): data = rg.read_raster(filepath) layer = file_upload(filepath, overwrite=True, **kwargs) _sld = get_sld(data, layer.name) cat = gs_catalog style = cat.get_style(layer.name) style.update_body(_sld) return layer, style
def get_trawling2(grid): _r = rg.read_raster( '/usr/share/geoserver/data/data/geonode/number_ais_clip/number_ais_clip.geotiff' ) raster = grid.copy() raster.reproject(_r) # raster.lognorm() return raster
def get_layerinfo(fpath): l = rg.read_raster(fpath) layerinfo = { 'bounds': l.bounds, 'resolution': l.resolution, 'projection': l.crs.to_proj4(), 'epsg': 3035 } # Makeit dynamic return layerinfo
def get_traffic(grid, truncate=None): _r = rg.read_raster( '/var/www/geonode/uploaded/layers/traffic_density_2014.tif') raster = grid.copy() raster.reproject(_r) raster.positive() if truncate is not None: raster[raster < truncate] = 0 raster.lognorm() return raster
def localgeonode(l): """Get a geo dataset from local GeoNonde installation. It returns a Rectifiedgrid object for raster layers and a GeoDataFrame for vector layers. """ import rectifiedgrid as rg if not geonode: raise ModuleNotFoundError( "GeoNode module is not installed or not configured in the project") return False if isinstance(l, int): l = Layer.objects.get(pk=l) elif isinstance(l, str): l = Layer.objects.get(typename=l) if l.is_vector(): return get_df(l.name) else: path = l.upload_session.file_set.all()[0].file.path return rg.read_raster(path)
def layer_to_raster(l, grid=None, res=None, **kwargs): if isinstance(l, int): l = Layer.objects.get(pk=l) gdf = None if hasattr(l, 'name'): if l.typename == 'geonode:traffic_density_2014': _r = rg.read_raster( '/var/www/geonode/uploaded/layers/traffic_density_2014.tif') raster = grid.copy() raster.reproject(_r) raster.positive() print("OLD TRAFFIC") return raster elif l.typename == 'geonode:traffic_density_lines_gener_2014_2015_ais_3857_nocolor': _r = rg.read_raster( '/var/www/geonode/uploaded/layers/traffic_density_lines_gener_2014_2015_ais_3857_nocolor.tiff' ) raster = grid.copy() raster.reproject(_r.astype(np.float)) raster.positive() print("NEW TRAFFIC") return raster elif l.typename == 'geonode:malta_aisdata_hm250_r500': _r = rg.read_raster( '/var/www/geonode/uploaded/layers/malta_aisdata_hm250_r500.tif' ) raster = grid.copy() raster.reproject(_r.astype(np.float)) raster.positive() print("TRAFFIC MALTA") return raster elif l.typename == 'geonode:loggerheadturtlesclean_quartico_30km_100m_clip': _r = rg.read_raster( '/var/www/geonode/uploaded/layers/loggerheadturtlesclean_quartico_30km_100m_clip.tif' ) raster = grid.copy() raster.reproject(_r.astype(np.float)) raster.positive() print("NEW TURTLES") return raster elif l.typename == 'geonode:marinemammals_quartico_60km_100m_clip': _r = rg.read_raster( '/var/www/geonode/uploaded/layers/marinemammals_quartico_60km_100m_clip_UdCUElw.tif' ) raster = grid.copy() raster.reproject(_r.astype(np.float)) raster.positive() print("NEW MAMMALS") return raster elif l.name in [ 'lba_pressure_plume_threshold', 'lba_pressure_om', 'lba_pressure_nptot' ]: _r = rg.read_raster( '/var/www/geonode/uploaded/layers/{}.tiff'.format(l.name), masked=True) _r[:] = _r.filled(0) raster = grid.copy() raster.reproject(_r) return raster if not l.is_vector(): raise Exception("RASTER is not implemented") gdf = get_df(l.name) elif isinstance(l, str) or isinstance(l, str): gdf = get_df(l) if grid is not None: raster = rg.read_df_like(grid, gdf, **kwargs) else: raster = rg.read_df(gdf, res, **kwargs) return raster
def read_raster(self, fname): filepath = path.join(self.layersdir, fname) return rg.read_raster(filepath)
def test_read_raster(self): raster = os.path.join(GOOD_DATA, 'raster', 'test_grid.tif') grid = rg.read_raster(raster) assert grid.shape == (7, 5)
def test_fix_fill_value(self, shared_datadir): file_path = shared_datadir / 'wrong_fill_value.tiff' grid = rg.read_raster(str(file_path)) assert(grid.fill_value == 32767)