Commit 0c77bf00 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Changed warp_ndarray projection defaults. Added geo.projection.isLocal()....

Changed warp_ndarray projection defaults. Added geo.projection.isLocal(). Added module numeric.numbers. Updated version info.
parent a53ca2c0
Pipeline #1300 passed with stages
in 12 minutes and 27 seconds
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import (division, print_function, absolute_import, unicode_literals) from __future__ import (division, print_function, absolute_import, unicode_literals)
__version__ = '0.8.4' __version__ = '0.9.0'
__versionalias__ = '20170926_02' __versionalias__ = '20171009_01'
__author__ = 'Daniel Scheffler' __author__ = 'Daniel Scheffler'
# Validate GDAL version # Validate GDAL version
......
...@@ -89,6 +89,7 @@ def isProjectedOrGeographic(prj): ...@@ -89,6 +89,7 @@ def isProjectedOrGeographic(prj):
""" """
if prj is None: if prj is None:
return None return None
srs = osr.SpatialReference() srs = osr.SpatialReference()
if prj.startswith('EPSG:'): if prj.startswith('EPSG:'):
srs.ImportFromEPSG(int(prj.split(':')[1])) srs.ImportFromEPSG(int(prj.split(':')[1]))
...@@ -97,10 +98,33 @@ def isProjectedOrGeographic(prj): ...@@ -97,10 +98,33 @@ def isProjectedOrGeographic(prj):
elif prj.startswith('GEOGCS') or prj.startswith('PROJCS'): elif prj.startswith('GEOGCS') or prj.startswith('PROJCS'):
srs.ImportFromWkt(prj) srs.ImportFromWkt(prj)
else: else:
raise Exception('Unknown input projection.') raise RuntimeError('Unknown input projection.')
return 'projected' if srs.IsProjected() else 'geographic' if srs.IsGeographic() else None return 'projected' if srs.IsProjected() else 'geographic' if srs.IsGeographic() else None
def isLocal(prj):
# type: (Union[str, int, dict]) -> Union[bool, None]
"""
:param prj: accepts EPSG, Proj4 and WKT projections
"""
if not prj:
return True
srs = osr.SpatialReference()
if prj.startswith('EPSG:'):
srs.ImportFromEPSG(int(prj.split(':')[1]))
elif prj.startswith('+proj='):
srs.ImportFromProj4(prj)
elif prj.startswith('GEOGCS') or prj.startswith('PROJCS') or prj.startswith('LOCAL_CS'):
srs.ImportFromWkt(prj)
else:
raise RuntimeError('Unknown input projection.')
return srs.IsLocal()
def EPSG2Proj4(EPSG_code): def EPSG2Proj4(EPSG_code):
# type: (int) -> str # type: (int) -> str
if EPSG_code is not None: if EPSG_code is not None:
......
...@@ -232,8 +232,8 @@ def warp_GeoArray(geoArr, **kwargs): ...@@ -232,8 +232,8 @@ def warp_GeoArray(geoArr, **kwargs):
# return GeoArray(*warp_ndarray(ndarray, geoArr.geotransform, geoArr.projection, **kwargs)) # return GeoArray(*warp_ndarray(ndarray, geoArr.geotransform, geoArr.projection, **kwargs))
def warp_ndarray(ndarray, in_gt, in_prj, out_prj=None, out_dtype=None, out_gsd=(None, None), def warp_ndarray(ndarray, in_gt, in_prj=None, out_prj=None, out_dtype=None,
out_bounds=None, out_bounds_prj=None, out_XYdims=(None, None), out_gsd=(None, None), out_bounds=None, out_bounds_prj=None, out_XYdims=(None, None),
rspAlg='near', in_nodata=None, out_nodata=None, in_alpha=False, rspAlg='near', in_nodata=None, out_nodata=None, in_alpha=False,
out_alpha=False, targetAlignedPixels=False, gcpList=None, polynomialOrder=None, options=None, out_alpha=False, targetAlignedPixels=False, gcpList=None, polynomialOrder=None, options=None,
transformerOptions=None, warpOptions=None, CPUs=1, warpMemoryLimit=0, progress=True, q=False): transformerOptions=None, warpOptions=None, CPUs=1, warpMemoryLimit=0, progress=True, q=False):
...@@ -242,8 +242,10 @@ def warp_ndarray(ndarray, in_gt, in_prj, out_prj=None, out_dtype=None, out_gsd=( ...@@ -242,8 +242,10 @@ def warp_ndarray(ndarray, in_gt, in_prj, out_prj=None, out_dtype=None, out_gsd=(
:param ndarray: the numpy array to be warped :param ndarray: the numpy array to be warped
:param in_gt: input GDAL geotransform :param in_gt: input GDAL geotransform
:param in_prj: input GDAL projection (WKT string, 'EPSG:1234', <EPSG_int>) :param in_prj: input GDAL projection (WKT string, 'EPSG:1234', <EPSG_int>),
:param out_prj: output GDAL projection (WKT string, 'EPSG:1234', <EPSG_int>) default: "LOCAL_CS[\"MAP\"]"
:param out_prj: output GDAL projection (WKT string, 'EPSG:1234', <EPSG_int>),
default: "LOCAL_CS[\"MAP\"]"
:param out_dtype: gdal.DataType :param out_dtype: gdal.DataType
:param out_gsd: :param out_gsd:
:param out_bounds: [xmin,ymin,xmax,ymax] set georeferenced extents of output file to be created, :param out_bounds: [xmin,ymin,xmax,ymax] set georeferenced extents of output file to be created,
...@@ -279,6 +281,10 @@ def warp_ndarray(ndarray, in_gt, in_prj, out_prj=None, out_dtype=None, out_gsd=( ...@@ -279,6 +281,10 @@ def warp_ndarray(ndarray, in_gt, in_prj, out_prj=None, out_dtype=None, out_gsd=(
# TODO otherwise implment error_threshold=0.125 # TODO otherwise implment error_threshold=0.125
# how to implement: https://svn.osgeo.org/gdal/trunk/autotest/utilities/test_gdalwarp_lib.py # how to implement: https://svn.osgeo.org/gdal/trunk/autotest/utilities/test_gdalwarp_lib.py
# assume local coordinates if no projections are given
in_prj = in_prj or "LOCAL_CS[\"MAP\"]"
out_prj = out_prj or "LOCAL_CS[\"MAP\"]"
# assertions # assertions
assert str(np.dtype(ndarray.dtype)) in dTypeDic_NumPy2GDAL, "Unknown target datatype '%s'." % ndarray.dtype assert str(np.dtype(ndarray.dtype)) in dTypeDic_NumPy2GDAL, "Unknown target datatype '%s'." % ndarray.dtype
if rspAlg == 'average': if rspAlg == 'average':
...@@ -421,8 +427,8 @@ def warp_ndarray(ndarray, in_gt, in_prj, out_prj=None, out_dtype=None, out_gsd=( ...@@ -421,8 +427,8 @@ def warp_ndarray(ndarray, in_gt, in_prj, out_prj=None, out_dtype=None, out_gsd=(
srcAlpha=in_alpha, srcAlpha=in_alpha,
dstAlpha=out_alpha, dstAlpha=out_alpha,
options=options if options else [], options=options if options else [],
warpOptions=warpOptions if warpOptions else [], warpOptions=warpOptions or [],
transformerOptions=transformerOptions if transformerOptions else [], transformerOptions=transformerOptions or [],
targetAlignedPixels=targetAlignedPixels, targetAlignedPixels=targetAlignedPixels,
tps=True if gcpList else False, tps=True if gcpList else False,
polynomialOrder=polynomialOrder, polynomialOrder=polynomialOrder,
......
# -*- coding: utf-8 -*-
__author__ = 'Daniel Scheffler'
def is_number(num):
try:
float(num)
return True
except ValueError:
return False
...@@ -18,7 +18,7 @@ test_requirements = requirements + ["coverage", "nose", "nose2", "nose-htmloutpu ...@@ -18,7 +18,7 @@ test_requirements = requirements + ["coverage", "nose", "nose2", "nose-htmloutpu
setup( setup(
name='py_tools_ds', name='py_tools_ds',
version='0.8.4', version='0.9.0',
description="A collection of Python tools by Daniel Scheffler.", description="A collection of Python tools by Daniel Scheffler.",
long_description=readme + '\n\n' + history, long_description=readme + '\n\n' + history,
author="Daniel Scheffler", author="Daniel Scheffler",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment