本文整理汇总了Python中rasterio.crs.CRS.from_epsg方法的典型用法代码示例。如果您正苦于以下问题:Python CRS.from_epsg方法的具体用法?Python CRS.from_epsg怎么用?Python CRS.from_epsg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rasterio.crs.CRS
的用法示例。
在下文中一共展示了CRS.from_epsg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_epsg
# 需要导入模块: from rasterio.crs import CRS [as 别名]
# 或者: from rasterio.crs.CRS import from_epsg [as 别名]
def test_from_epsg():
crs_dict = CRS.from_epsg(4326)
assert crs_dict['init'].lower() == 'epsg:4326'
# Test with invalid EPSG code
with pytest.raises(ValueError):
assert CRS.from_epsg(0)
示例2: test_issue_1446
# 需要导入模块: from rasterio.crs import CRS [as 别名]
# 或者: from rasterio.crs.CRS import from_epsg [as 别名]
def test_issue_1446():
"""Confirm resolution of #1446"""
g = transform_geom(
CRS.from_epsg(4326),
CRS.from_epsg(32610),
{"type": "Point", "coordinates": (-122.51403808499907, 38.06106733107932)},
)
assert round(g["coordinates"][0], 1) == 542630.9
assert round(g["coordinates"][1], 1) == 4212702.1
示例3: main
# 需要导入模块: from rasterio.crs import CRS [as 别名]
# 或者: from rasterio.crs.CRS import from_epsg [as 别名]
def main():
samplefile = r'bxk1-d-ck.idf'
tiffile = samplefile.replace('.idf', '.geotiff')
dtype = rasterio.float64
driver = 'AAIGrid'
crs = CRS.from_epsg(28992)
# read data from idf file
idffile = idfpy.IdfFile(filepath=samplefile, mode='rb')
geotransform = idffile.geotransform
height = idffile.header['nrow']
width = idffile.header['ncol']
nodata = idffile.header['nodata']
transform = Affine.from_gdal(*geotransform)
# write data from idf file to geotiff with rasterio
profile = {
'width': width,
'height': height,
'count': 1,
'dtype': dtype,
'driver': driver,
'crs': crs,
'transform': transform,
'nodata': nodata,
}
# the default profile would be sufficient for the example, however the profile dict shows how to make the export
# profile
idffile.to_raster(tiffile, **profile)
示例4: test_reproject_init_dest_nodata
# 需要导入模块: from rasterio.crs import CRS [as 别名]
# 或者: from rasterio.crs.CRS import from_epsg [as 别名]
def test_reproject_init_dest_nodata():
"""No pixels should transfer over"""
crs = CRS.from_epsg(4326)
transform = Affine.identity()
source = np.zeros((1, 100, 100))
destination = np.ones((1, 100, 100))
reproject(
source, destination, src_crs=crs, src_transform=transform,
dst_crs=crs, dst_transform=transform,
src_nodata=0, init_dest_nodata=False
)
assert destination.all()
示例5: test_linear_units_factor
# 需要导入模块: from rasterio.crs import CRS [as 别名]
# 或者: from rasterio.crs.CRS import from_epsg [as 别名]
def test_linear_units_factor():
"""CRS linear units can be had"""
assert CRS.from_epsg(3857).linear_units_factor[0] == 'metre'
assert CRS.from_epsg(3857).linear_units_factor[1] == 1.0
assert CRS.from_epsg(2261).linear_units_factor[0] == 'US survey foot'
assert CRS.from_epsg(2261).linear_units_factor[1] == pytest.approx(0.3048006096012192)
with pytest.raises(CRSError):
CRS.from_epsg(4326).linear_units_factor
示例6: feature_to_mercator
# 需要导入模块: from rasterio.crs import CRS [as 别名]
# 或者: from rasterio.crs.CRS import from_epsg [as 别名]
def feature_to_mercator(feature):
'''Normalize feature and converts coords to 3857.
Args:
feature: geojson feature to convert to mercator geometry.
'''
# Ref: https://gist.github.com/dnomadb/5cbc116aacc352c7126e779c29ab7abe
src_crs = CRS.from_epsg(4326)
dst_crs = CRS.from_epsg(3857)
geometry = feature['geometry']
if geometry['type'] == 'Polygon':
xys = (zip(*part) for part in geometry['coordinates'])
xys = (list(zip(*transform(src_crs, dst_crs, *xy))) for xy in xys)
yield {'coordinates': list(xys), 'type': 'Polygon'}
elif geometry['type'] == 'MultiPolygon':
for component in geometry['coordinates']:
xys = (zip(*part) for part in component)
xys = (list(zip(*transform(src_crs, dst_crs, *xy))) for xy in xys)
yield {'coordinates': list(xys), 'type': 'Polygon'}
开发者ID:AhlamMD,项目名称:Artificial-Intelligence-Deep-Learning-Machine-Learning-Tutorials,代码行数:26,代码来源:rasterize.py
示例7: example_reproject
# 需要导入模块: from rasterio.crs import CRS [as 别名]
# 或者: from rasterio.crs.CRS import from_epsg [as 别名]
def example_reproject():
import idfpy
from matplotlib import pyplot as plt
from rasterio import Affine
from rasterio.crs import CRS
from rasterio.warp import reproject, Resampling
import numpy as np
with idfpy.open('bxk1-d-ck.idf') as src:
a = src.read(masked=True)
nr, nc = src.header['nrow'], src.header['ncol']
dx, dy = src.header['dx'], src.header['dy']
src_transform = Affine.from_gdal(*src.geotransform)
# define new grid transform (same extent, 10 times resolution)
dst_transform = Affine.translation(src_transform.c, src_transform.f)
dst_transform *= Affine.scale(dx / 10., -dy / 10.)
# define coordinate system (here RD New)
src_crs = CRS.from_epsg(28992)
# initialize new data array
b = np.empty((10*nr, 10*nc))
# reproject using Rasterio
reproject(
source=a,
destination=b,
src_transform=src_transform,
dst_transform=dst_transform,
src_crs=src_crs,
dst_crs=src_crs,
resampling=Resampling.bilinear,
)
# result as masked array
b = np.ma.masked_equal(b, a.fill_value)
# plot images
fig, axes = plt.subplots(nrows=2, ncols=1)
axes[0].imshow(a.filled(np.nan))
axes[0].set_title('bxk1 original')
axes[1].imshow(b.filled(np.nan))
axes[1].set_title('bxk1 resampled')
plt.show()
示例8: __init__
# 需要导入模块: from rasterio.crs import CRS [as 别名]
# 或者: from rasterio.crs.CRS import from_epsg [as 别名]
def __init__(self, ul, crs, res, size, desc=None):
self.ul = ul
if isinstance(crs, six.string_types):
self.crs = CRS.from_string(crs)
elif isinstance(crs, int):
self.crs = CRS.from_epsg(crs)
else:
self.crs = crs
if not self.crs.is_valid:
raise ValueError('Could not parse coordinate reference system '
'string to a valid projection ({})'.format(crs))
self.crs_str = self.crs.to_string()
self.res = res
self.size = size
self.desc = desc or 'unnamed'
self._tiles = {}
示例9: to_raster
# 需要导入模块: from rasterio.crs import CRS [as 别名]
# 或者: from rasterio.crs.CRS import from_epsg [as 别名]
def to_raster(self, fp=None, epsg=28992, driver='AAIGrid'):
"""export Idf to a geotiff"""
self.check_read()
if fp is None:
fp = self.filepath.replace('.idf', '.geotiff')
logging.warning('no filepath was given, exported to {fp}'.format(fp=fp))
# set profile
profile = {
'width': self.header['ncol'],
'height': self.header['nrow'],
'transform': Affine.from_gdal(*self.geotransform),
'nodata': self.header['nodata'],
'count': 1,
'dtype': rasterio.float64,
'driver': driver,
'crs': CRS.from_epsg(epsg),
}
logging.info('writing to {f:}'.format(f=fp))
with rasterio.open(fp, 'w', **profile) as dst:
dst.write(self.masked_data.astype(profile['dtype']), 1)
示例10: test_issue1131
# 需要导入模块: from rasterio.crs import CRS [as 别名]
# 或者: from rasterio.crs.CRS import from_epsg [as 别名]
def test_issue1131():
"""Confirm that we don't run out of memory"""
transform, w, h = calculate_default_transform(CRS.from_epsg(4326), CRS.from_epsg(3857), 455880, 454450, 13.0460235139, 42.6925552354, 13.2511695428, 42.8970561511)
assert (w, h) == (381595, 518398)
示例11: test_crs_hash_unequal
# 需要导入模块: from rasterio.crs import CRS [as 别名]
# 或者: from rasterio.crs.CRS import from_epsg [as 别名]
def test_crs_hash_unequal():
"""hashes of non-equivalent CRS are not equal"""
assert hash(CRS.from_epsg(3857)) != hash(CRS.from_epsg(4326))
示例12: test_crs_hash
# 需要导入模块: from rasterio.crs import CRS [as 别名]
# 或者: from rasterio.crs.CRS import from_epsg [as 别名]
def test_crs_hash():
"""hashes of equivalent CRS are equal"""
assert hash(CRS.from_epsg(3857)) == hash(CRS.from_epsg(3857))
示例13: test_crs_copy
# 需要导入模块: from rasterio.crs import CRS [as 别名]
# 或者: from rasterio.crs.CRS import from_epsg [as 别名]
def test_crs_copy():
"""CRS can be copied"""
assert copy.copy(CRS.from_epsg(3857)).wkt.startswith('PROJCS["WGS 84 / Pseudo-Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84"')
示例14: test_linear_units
# 需要导入模块: from rasterio.crs import CRS [as 别名]
# 或者: from rasterio.crs.CRS import from_epsg [as 别名]
def test_linear_units():
"""CRS linear units can be had"""
assert CRS.from_epsg(3857).linear_units == 'metre'
assert CRS.from_epsg(2261).linear_units == 'US survey foot'
assert CRS.from_epsg(4326).linear_units == 'unknown'
示例15: test_environ_patch
# 需要导入模块: from rasterio.crs import CRS [as 别名]
# 或者: from rasterio.crs.CRS import from_epsg [as 别名]
def test_environ_patch(gdalenv, monkeypatch):
"""PROJ_LIB is patched when rasterio._crs is imported"""
monkeypatch.delenv('GDAL_DATA', raising=False)
monkeypatch.delenv('PROJ_LIB', raising=False)
with env_ctx_if_needed():
assert CRS.from_epsg(4326) != CRS(units='m', proj='aeqd', ellps='WGS84', datum='WGS84', lat_0=-17.0, lon_0=-44.0)