本文整理汇总了Python中cartopy.crs.epsg方法的典型用法代码示例。如果您正苦于以下问题:Python crs.epsg方法的具体用法?Python crs.epsg怎么用?Python crs.epsg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cartopy.crs
的用法示例。
在下文中一共展示了crs.epsg方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_data
# 需要导入模块: from cartopy import crs [as 别名]
# 或者: from cartopy.crs import epsg [as 别名]
def plot_data(self, feature_name):
""" Plots the FeatureType.DATA of eopatch.
:param feature_name: name of the eopatch feature
:type feature_name: str
:return: visualization
:rtype: holoview/geoviews/bokeh
"""
crs = self.eopatch.bbox.crs
crs = CRS.POP_WEB if crs is CRS.WGS84 else crs
data_da = array_to_dataframe(self.eopatch, (FeatureType.DATA, feature_name), crs=crs)
if self.mask:
data_da = self.mask_data(data_da)
timestamps = self.eopatch.timestamp
crs = self.eopatch.bbox.crs
if not self.rgb:
return data_da.hvplot(x='x', y='y', crs=ccrs.epsg(crs.epsg))
data_rgb = self.eopatch_da_to_rgb(data_da, feature_name, crs)
rgb_dict = {timestamp_: self.plot_rgb_one(data_rgb, timestamp_) for timestamp_ in timestamps}
return hv.HoloMap(rgb_dict, kdims=['time'])
示例2: plot_raster
# 需要导入模块: from cartopy import crs [as 别名]
# 或者: from cartopy.crs import epsg [as 别名]
def plot_raster(self, feature_type, feature_name):
""" Makes visualization for raster data (except for FeatureType.DATA)
:param feature_type: type of eopatch feature
:type feature_type: FeatureType
:param feature_name: name of eopatch feature
:type feature_name: str
:return: visualization
:rtype: holoviews/geoviews/bokeh
"""
crs = self.eopatch.bbox.crs
crs = CRS.POP_WEB if crs is CRS.WGS84 else crs
data_da = array_to_dataframe(self.eopatch, (feature_type, feature_name), crs=crs)
data_min = data_da.values.min()
data_max = data_da.values.max()
data_levels = len(np.unique(data_da))
data_levels = 11 if data_levels > 11 else data_levels
data_da = data_da.where(data_da > 0).fillna(-1)
vis = data_da.hvplot(x='x', y='y',
crs=ccrs.epsg(crs.epsg)).opts(clim=(data_min, data_max),
clipping_colors={'min': 'transparent'},
color_levels=data_levels)
return vis
示例3: get_ccrs
# 需要导入模块: from cartopy import crs [as 别名]
# 或者: from cartopy.crs import epsg [as 别名]
def get_ccrs(filename):
"""
Loads WKT projection string from file and return
cartopy coordinate reference system.
"""
inproj = osr.SpatialReference()
proj = open(filename, 'r').readline()
inproj.ImportFromWkt(proj)
projcs = inproj.GetAuthorityCode('PROJCS')
return ccrs.epsg(projcs)
示例4: check_crs
# 需要导入模块: from cartopy import crs [as 别名]
# 或者: from cartopy.crs import epsg [as 别名]
def check_crs(crs):
"""
Checks if the crs represents a valid grid, projection or ESPG string.
(Code copied from https://github.com/fmaussion/salem)
Examples
--------
>>> p = check_crs('+units=m +init=epsg:26915')
>>> p.srs
'+proj=utm +zone=15 +datum=NAD83 +units=m +no_defs'
>>> p = check_crs('wrong')
>>> p is None
True
Returns
-------
A valid crs if possible, otherwise None
"""
import pyproj
if isinstance(crs, pyproj.Proj):
out = crs
elif isinstance(crs, dict) or isinstance(crs, basestring):
try:
out = pyproj.Proj(crs)
except RuntimeError:
try:
out = pyproj.Proj(init=crs)
except RuntimeError:
out = None
else:
out = None
return out
示例5: process_crs
# 需要导入模块: from cartopy import crs [as 别名]
# 或者: from cartopy.crs import epsg [as 别名]
def process_crs(crs):
"""
Parses cartopy CRS definitions defined in one of a few formats:
1. EPSG codes: Defined as string of the form "EPSG: {code}" or an integer
2. proj.4 string: Defined as string of the form "{proj.4 string}"
3. cartopy.crs.CRS instance
4. None defaults to crs.PlateCaree
"""
try:
import cartopy.crs as ccrs
import geoviews as gv # noqa
import pyproj
except:
raise ImportError('Geographic projection support requires GeoViews and cartopy.')
if crs is None:
return ccrs.PlateCarree()
if isinstance(crs, basestring) and crs.lower().startswith('epsg'):
try:
crs = ccrs.epsg(crs[5:].lstrip().rstrip())
except:
raise ValueError("Could not parse EPSG code as CRS, must be of the format 'EPSG: {code}.'")
elif isinstance(crs, int):
crs = ccrs.epsg(crs)
elif isinstance(crs, (basestring, pyproj.Proj)):
try:
crs = proj_to_cartopy(crs)
except:
raise ValueError("Could not parse EPSG code as CRS, must be of the format 'proj4: {proj4 string}.'")
elif not isinstance(crs, ccrs.CRS):
raise ValueError("Projection must be defined as a EPSG code, proj4 string, cartopy CRS or pyproj.Proj.")
return crs
示例6: setUp
# 需要导入模块: from cartopy import crs [as 别名]
# 或者: from cartopy.crs import epsg [as 别名]
def setUp(self):
try:
import xarray as xr
import rasterio # noqa
import geoviews # noqa
import cartopy.crs as ccrs
except:
raise SkipTest('xarray, rasterio, geoviews, or cartopy not available')
import hvplot.xarray # noqa
import hvplot.pandas # noqa
self.da = (xr.open_rasterio(
'https://github.com/mapbox/rasterio/raw/master/tests/data/RGB.byte.tif')
.sel(band=1))
self.crs = ccrs.epsg(self.da.crs.split('epsg:')[1])
示例7: get_projection_from_crs
# 需要导入模块: from cartopy import crs [as 别名]
# 或者: from cartopy.crs import epsg [as 别名]
def get_projection_from_crs(crs):
if crs == 4326:
# if data is in latlon system, return default map with latlon system
return ccrs.PlateCarree()
try:
return ccrs.epsg(crs)
except requests.RequestException:
logger.warning("A connection to http://epsg.io/ is "
"required for a projected coordinate reference system. "
"Falling back to latlong.")
except ValueError:
logger.warning("'{crs}' does not define a projected coordinate system. "
"Falling back to latlong.".format(crs=crs))
return ccrs.PlateCarree()
示例8: check_crs
# 需要导入模块: from cartopy import crs [as 别名]
# 或者: from cartopy.crs import epsg [as 别名]
def check_crs(crs):
"""
Checks if the crs represents a valid grid, projection or ESPG string.
(Code copied from https://github.com/fmaussion/salem)
Examples
--------
>>> p = check_crs('+units=m +init=epsg:26915')
>>> p.srs
'+proj=utm +zone=15 +datum=NAD83 +units=m +no_defs'
>>> p = check_crs('wrong')
>>> p is None
True
Returns
-------
A valid crs if possible, otherwise None
"""
import pyproj
if isinstance(crs, pyproj.Proj):
out = crs
elif isinstance(crs, dict) or isinstance(crs, basestring):
try:
out = pyproj.Proj(crs)
except RuntimeError:
try:
out = pyproj.Proj(init=crs)
except RuntimeError:
out = None
else:
out = None
return out
示例9: process_crs
# 需要导入模块: from cartopy import crs [as 别名]
# 或者: from cartopy.crs import epsg [as 别名]
def process_crs(crs):
"""
Parses cartopy CRS definitions defined in one of a few formats:
1. EPSG codes: Defined as string of the form "EPSG: {code}" or an integer
2. proj.4 string: Defined as string of the form "{proj.4 string}"
3. cartopy.crs.CRS instance
4. None defaults to crs.PlateCaree
"""
try:
import cartopy.crs as ccrs
import geoviews as gv # noqa
except:
raise ImportError('Geographic projection support requires GeoViews and cartopy.')
if crs is None:
return ccrs.PlateCarree()
if isinstance(crs, basestring) and crs.lower().startswith('epsg'):
try:
crs = ccrs.epsg(crs[5:].lstrip().rstrip())
except:
raise ValueError("Could not parse EPSG code as CRS, must be of the format 'EPSG: {code}.'")
elif isinstance(crs, int):
crs = ccrs.epsg(crs)
elif isinstance(crs, basestring) or is_pyproj(crs):
try:
crs = proj_to_cartopy(crs)
except:
raise ValueError("Could not parse EPSG code as CRS, must be of the format 'proj4: {proj4 string}.'")
elif not isinstance(crs, ccrs.CRS):
raise ValueError("Projection must be defined as a EPSG code, proj4 string, cartopy CRS or pyproj.Proj.")
return crs
示例10: plot_shapes_one
# 需要导入模块: from cartopy import crs [as 别名]
# 或者: from cartopy.crs import epsg [as 别名]
def plot_shapes_one(self, data_gpd, timestamp, crs):
""" Plots shapes for one timestamp from geopandas GeoDataFrame
:param data_gpd: data to plot
:type data_gpd: geopandas.GeoDataFrame
:param timestamp: timestamp to plot data for
:type timestamp: datetime
:param crs: in which crs is the data to plot
:type crs: sentinelhub.crs
:return: visualization
:rtype: geoviews
"""
out = data_gpd.loc[data_gpd[self.timestamp_column] == timestamp]
return gv.Polygons(out, crs=ccrs.epsg(int(crs.value)))
示例11: plot_vector_timeless
# 需要导入模块: from cartopy import crs [as 别名]
# 或者: from cartopy.crs import epsg [as 别名]
def plot_vector_timeless(self, feature_name):
""" Plot FeatureType.VECTOR_TIMELESS data
:param feature_name: name of the eopatch featrue
:type feature_name: str
:return: visalization
:rtype: geoviews
"""
crs = self.eopatch.bbox.crs
data_gpd = self.eopatch[FeatureType.VECTOR_TIMELESS][feature_name]
if crs is CRS.WGS84:
crs = CRS.POP_WEB
data_gpd = data_gpd.to_crs(crs.pyproj_crs())
return gv.Polygons(data_gpd, crs=ccrs.epsg(crs.epsg), vdims=self.vdims)
示例12: plot_global
# 需要导入模块: from cartopy import crs [as 别名]
# 或者: from cartopy.crs import epsg [as 别名]
def plot_global(xx,yy, data,
data_projection_code,
cmin, cmax, ax,
plot_type = 'pcolormesh',
show_colorbar=False,
cmap=None,
show_grid_lines = True,
show_grid_labels = True,
grid_linewidth = 1,
custom_background = False,
background_name = [],
background_resolution = [],
levels=20):
# assign cmap default
if cmap is None:
if cmin*cmax<0:
cmap = 'RdBu_r'
else:
cmap = 'viridis'
if show_grid_lines :
gl = ax.gridlines(crs=ccrs.PlateCarree(),
linewidth=1, color='black',
draw_labels = show_grid_labels,
alpha=0.5, linestyle='--', zorder=102)
else:
gl = []
if data_projection_code == 4326: # lat lon does nneed to be projected
data_crs = ccrs.PlateCarree()
else:
data_crs =ccrs.epsg(data_projection_code)
if custom_background:
ax.background_img(name=background_name, resolution=background_resolution)
if plot_type == 'pcolormesh':
p = ax.pcolormesh(xx, yy, data, transform=data_crs,
vmin=cmin, vmax=cmax, cmap=cmap)
elif plot_type =='contourf':
p = ax.contourf(xx, yy, data, levels, transform=data_crs,
vmin=cmin, vmax=cmax, cmap=cmap)
else:
raise ValueError('plot_type must be either "pcolormesh" or "contourf"')
if not custom_background:
ax.add_feature(cfeature.LAND, zorder=100)
ax.coastlines('110m', linewidth=grid_linewidth, zorder=101)
cbar = []
if show_colorbar:
sm = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(cmin,cmax))
sm._A = []
cbar = plt.colorbar(sm,ax=ax)
return p, gl, cbar
# -----------------------------------------------------------------------------