Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_coordinate_operation_towgs84_three():
crs = CRS("+proj=latlong +ellps=GRS80 +towgs84=-199.87,74.79,246.62")
assert crs.coordinate_operation.towgs84 == [-199.87, 74.79, 246.62]
def test_is_geocentric__bound():
with pytest.warns(FutureWarning):
ccs = CRS("+init=epsg:4328 +towgs84=0,0,0")
assert ccs.is_geocentric
assert crs.to_dict() == {
"proj": "omerc",
"lat_0": 10,
"lonc": 15,
"alpha": 0.35,
"gamma": 0.35,
"k": 1,
"x_0": 0,
"y_0": 0,
"ellps": "WGS84",
"units": "m",
"no_defs": None,
"type": "crs",
}
# test CRS with input as lon_0 from the user
lon0crs_cf = CRS(
{
"proj": "omerc",
"lat_0": 10,
"lon_0": 15,
"alpha": 0.35,
"gamma": 0.35,
"k": 1,
"x_0": 0,
"y_0": 0,
"ellps": "WGS84",
"units": "m",
"no_defs": None,
"type": "crs",
}
).to_cf()
assert lon0crs_cf.pop("crs_wkt").startswith("PROJCRS[")
def test_to_cf_transverse_mercator():
crs = CRS(
proj="tmerc",
lat_0=0,
lon_0=15,
k=0.9996,
x_0=2520000,
y_0=0,
ellps="intl",
units="m",
towgs84="-122.74,-34.27,-22.83,-1.884,-3.400,-3.030,-15.62",
)
with pytest.warns(UserWarning):
cf_dict = crs.to_cf(errcheck=True)
towgs84_test = [-122.74, -34.27, -22.83, -1.884, -3.4, -3.03, -15.62]
assert cf_dict.pop("crs_wkt").startswith("BOUNDCRS[")
assert cf_dict == {
"grid_mapping_name": "transverse_mercator",
def test_init_from_wkt_invalid():
with pytest.raises(CRSError):
CRS("trash-54322")
with pytest.raises(CRSError):
CRS("")
def test_to_string__no_auth():
proj = CRS("+proj=latlong +ellps=GRS80 +towgs84=-199.87,74.79,246.62")
assert (
proj.to_string()
== "+proj=latlong +ellps=GRS80 +towgs84=-199.87,74.79,246.62 +type=crs"
)
def box2shp(shape, crs, m):
hs, ws = shape[:2]
xx = np.linspace(0,ws,100).reshape((-1,1))*[1,0]
yy = np.linspace(0,hs,100).reshape((-1,1))*[0,1]
xy = np.vstack((xx, yy+[ws+1,0], xx[::-1]+[0,hs+1],yy[::-1]))
xy = np.dot(m[:,1:], xy.T) + m[:,:1]
return gpd.GeoSeries([Polygon(xy.T)], crs=pyproj.CRS(crs).to_proj4())
def get_proj(prj_code):
"""
Helper method for handling projection codes that are unknown to pyproj
Args:
prj_code (str): an epsg proj code
Returns:
projection: a pyproj projection
"""
if prj_code in CUSTOM_PRJ:
proj = pyproj.CRS(CUSTOM_PRJ[prj_code])
else:
proj = pyproj.CRS(prj_code)
return proj
try:
if ref[0] == 'WGS84' and ref[1] == 'UTM':
datum = ref[0]
utm_pole = (ref[2][len(ref[2]) - 1]).upper()
utm_zone = int(ref[2][:len(ref[2]) - 1])
proj_args = {
'zone': utm_zone,
'datum': datum
}
proj4 = '+proj=utm +zone={zone} +datum={datum} +units=m +no_defs=True'
if utm_pole == 'S':
proj4 += ' +south=True'
srs = CRS.from_proj4(proj4.format(**proj_args))
elif '+proj' in header:
srs = CRS.from_proj4(header.strip('\''))
elif header.lower().startswith("epsg:"):
srs = CRS.from_epsg(header.lower()[5:])
else:
raise RuntimeError('Could not parse coordinates. Bad SRS supplied: %s' % header)
except RuntimeError as e:
log.ODM_ERROR('Uh oh! There seems to be a problem with your coordinates/GCP file.\n\n'
'The line: %s\n\n'
'Is not valid. Projections that are valid include:\n'
' - EPSG:*****\n'
' - WGS84 UTM **(N|S)\n'
' - Any valid proj4 string (for example, +proj=utm +zone=32 +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs)\n\n'
'Modify your input and try again.' % header)
raise RuntimeError(e)