mirror of
https://github.com/rasterio/rasterio.git
synced 2025-12-08 17:36:12 +00:00
67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
import logging
|
|
import pytest
|
|
import subprocess
|
|
import sys
|
|
|
|
import rasterio
|
|
from rasterio import crs
|
|
|
|
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
|
|
|
|
# When possible, Rasterio gives you the CRS in the form of an EPSG code.
|
|
def test_read_epsg(tmpdir):
|
|
with rasterio.drivers():
|
|
with rasterio.open('tests/data/RGB.byte.tif') as src:
|
|
assert src.crs == {'init': 'epsg:32618'}
|
|
|
|
def test_read_epsg3857(tmpdir):
|
|
tiffname = str(tmpdir.join('lol.tif'))
|
|
subprocess.call([
|
|
'gdalwarp', '-t_srs', 'EPSG:3857',
|
|
'tests/data/RGB.byte.tif', tiffname])
|
|
with rasterio.drivers():
|
|
with rasterio.open(tiffname) as src:
|
|
assert src.crs == {'init': 'epsg:3857'}
|
|
|
|
# Ensure that CRS sticks when we write a file.
|
|
def test_write_3857(tmpdir):
|
|
src_path = str(tmpdir.join('lol.tif'))
|
|
subprocess.call([
|
|
'gdalwarp', '-t_srs', 'EPSG:3857',
|
|
'tests/data/RGB.byte.tif', src_path])
|
|
dst_path = str(tmpdir.join('wut.tif'))
|
|
with rasterio.drivers():
|
|
with rasterio.open(src_path) as src:
|
|
with rasterio.open(dst_path, 'w', **src.meta) as dst:
|
|
assert dst.crs == {'init': 'epsg:3857'}
|
|
info = subprocess.check_output([
|
|
'gdalinfo', dst_path])
|
|
assert """PROJCS["WGS 84 / Pseudo-Mercator",
|
|
GEOGCS["WGS 84",
|
|
DATUM["WGS_1984",
|
|
SPHEROID["WGS 84",6378137,298.257223563,
|
|
AUTHORITY["EPSG","7030"]],
|
|
AUTHORITY["EPSG","6326"]],
|
|
PRIMEM["Greenwich",0],
|
|
UNIT["degree",0.0174532925199433],
|
|
AUTHORITY["EPSG","4326"]],
|
|
PROJECTION["Mercator_1SP"],
|
|
PARAMETER["central_meridian",0],
|
|
PARAMETER["scale_factor",1],
|
|
PARAMETER["false_easting",0],
|
|
PARAMETER["false_northing",0],
|
|
UNIT["metre",1,
|
|
AUTHORITY["EPSG","9001"]],
|
|
EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],
|
|
AUTHORITY["EPSG","3857"]]""" in info.decode('utf-8')
|
|
|
|
|
|
def test_bare_parameters():
|
|
""" Make sure that bare parameters (e.g., no_defs) are handled properly,
|
|
even if they come in with key=True. This covers interaction with pyproj,
|
|
which makes presents bare parameters as key=<bool>."""
|
|
|
|
# Example produced by pyproj
|
|
crs_dict = crs.from_string('+lon_0=-95 +ellps=GRS80 +y_0=0 +no_defs=True +proj=lcc +x_0=0 +units=m +lat_2=77 +lat_1=49 +lat_0=0')
|
|
assert crs_dict.get('no_defs', False) is True
|