Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Daniel Scheffler
py_tools_ds
Commits
bee0b152
Commit
bee0b152
authored
Sep 25, 2017
by
Daniel Scheffler
Browse files
Fixed issue#3 (typing).S
parent
7b940f12
Pipeline
#1230
passed with stages
in 6 minutes and 4 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
py_tools_ds/geo/coord_trafo.py
View file @
bee0b152
...
...
@@ -7,7 +7,7 @@ import pyproj
import
numpy
as
np
from
shapely.geometry
import
Polygon
from
shapely.ops
import
transform
from
typing
import
Union
,
TypeVar
,
TYPE_CHECKING
from
typing
import
Union
# noqa F401 # flake8 issue
try
:
from
osgeo
import
osr
...
...
@@ -20,9 +20,6 @@ from .projection import get_proj4info, proj4_to_dict
__author__
=
"Daniel Scheffler"
if
TYPE_CHECKING
:
_T_xycoords
=
TypeVar
(
Union
[
tuple
,
np
.
ndarray
])
def
transform_utm_to_wgs84
(
easting
,
northing
,
zone
,
south
=
False
):
# ''' returns lon, lat, altitude '''
...
...
@@ -124,7 +121,7 @@ def transform_coordArray(prj_src, prj_tgt, Xarr, Yarr, Zarr=None):
def
mapXY2imXY
(
mapXY
,
gt
):
# type: (tuple, Union[list, tuple]) ->
_T_xycoords
# type: (tuple, Union[list, tuple]) ->
Union[tuple, np.ndarray]
"""Translates given geo coordinates into pixel locations according to the given image geotransform.
:param mapXY: <tuple, np.ndarray> The geo coordinates to be translated in the form (x,y) or as np.ndarray [Nx1].
...
...
@@ -144,7 +141,7 @@ def mapXY2imXY(mapXY, gt):
def
imXY2mapXY
(
imXY
,
gt
):
# type: (tuple, Union[list, tuple]) ->
_T_xycoords
# type: (tuple, Union[list, tuple]) ->
Union[tuple, np.ndarray]
"""Translates given pixel locations into geo coordinates according to the given image geotransform.
:param imXY: <tuple, np.ndarray> The image coordinates to be translated in the form (x,y) or as np.ndarray [Nx1].
...
...
py_tools_ds/geo/map_info.py
View file @
bee0b152
# -*- coding: utf-8 -*-
from
typing
import
TYPE_CHECKING
,
Union
,
TypeVar
from
typing
import
Union
# noqa F401 # flake8 issue
try
:
from
osgeo
import
osr
except
ImportError
:
...
...
@@ -11,9 +11,6 @@ from .coord_trafo import transform_utm_to_wgs84
__author__
=
"Daniel Scheffler"
if
TYPE_CHECKING
:
_T_mapinfo_out
=
TypeVar
(
Union
[
list
,
None
])
def
geotransform2mapinfo
(
gt
,
prj
):
"""Builds an ENVI geo info from given GDAL GeoTransform and Projection (compatible with UTM and LonLat projections).
...
...
@@ -49,7 +46,7 @@ def geotransform2mapinfo(gt, prj):
def
mapinfo2geotransform
(
map_info
):
# type: (list) ->
_T_mapinfo_out
# type: (list) ->
Union[list, None]
"""Builds GDAL GeoTransform tuple from an ENVI geo info.
:param map_info: ENVI geo info (list), e.g., ['UTM', 1, 1, 192585.0, 5379315.0, 30.0, 30.0, 41, 'North', 'WGS-84']
...
...
py_tools_ds/geo/projection.py
View file @
bee0b152
...
...
@@ -2,7 +2,7 @@
import
re
import
pyproj
from
typing
import
Union
,
TypeVar
,
TYPE_CHECKING
from
typing
import
Union
# noqa F401 # flake8 issue
# custom
try
:
...
...
@@ -16,9 +16,6 @@ from ..environment import gdal_env
__author__
=
"Daniel Scheffler"
if
TYPE_CHECKING
:
_T_prj1
=
TypeVar
(
Union
[
None
,
int
,
str
])
_T_prj2
=
TypeVar
(
Union
[
str
,
int
,
dict
])
# try to set GDAL_DATA if unnot set or invalid
gdal_env
.
try2set_GDAL_DATA
()
...
...
@@ -72,7 +69,7 @@ def proj4_to_WKT(proj4str):
def
prj_equal
(
prj1
,
prj2
):
# type: (
_T_prj1, _T_prj1
) -> bool
# type: (
Union[None, int, str], Union[None, int, str]
) -> bool
"""Checks if the given two projections are equal.
:param prj1: projection 1 (WKT or 'epsg:1234' or <EPSG_int>)
...
...
@@ -85,7 +82,7 @@ def prj_equal(prj1, prj2):
def
isProjectedOrGeographic
(
prj
):
# type: (
_T_prj2) -> TypeVar(
Union[str, None]
)
# type: (
Union[str, int, dict]) ->
Union[str, None]
"""
:param prj: accepts EPSG, Proj4 and WKT projections
...
...
@@ -135,7 +132,7 @@ def EPSG2WKT(EPSG_code):
def
WKT2EPSG
(
wkt
,
epsgfile
=
''
):
# type: (str) ->
TypeVar(
Union[int, None]
)
# type: (str) -> Union[int, None]
""" Transform a WKT string to an EPSG code
:param wkt: WKT definition
:param epsgfile: the proj.4 epsg file (automatically located if no path is provided)
...
...
@@ -193,7 +190,7 @@ def get_UTMzone(ds=None, prj=None):
def
get_prjLonLat
(
fmt
=
'wkt'
):
# type: (str) ->
TypeVar(
Union[str, dict]
)
# type: (str) -> Union[str, dict]
"""Returns standard geographic projection (EPSG 4326) in the WKT or PROJ4 format.
:param fmt: <str> target format - 'WKT' or 'PROJ4'
"""
...
...
py_tools_ds/geo/vector/conversion.py
View file @
bee0b152
# -*- coding: utf-8 -*-
import
numpy
as
np
from
typing
import
TypeVar
# custom
from
shapely.geometry
import
shape
,
mapping
,
box
,
Polygon
from
shapely.geometry
import
shape
,
mapping
,
box
from
shapely.geometry
import
Polygon
# noqa F401 # flake8 issue
try
:
from
osgeo
import
ogr
...
...
@@ -20,8 +20,6 @@ from ...dtypes.conversion import get_dtypeStr, dTypeDic_NumPy2GDAL
__author__
=
"Daniel Scheffler"
_T_polygon
=
TypeVar
(
Polygon
)
def
shapelyImPoly_to_shapelyMapPoly_withPRJ
(
shapelyImPoly
,
gt
,
prj
):
# ACTUALLY PRJ IS NOT NEEDED BUT THIS FUNCTION RETURNS OTHER VALUES THAN shapelyImPoly_to_shapelyMapPoly
...
...
@@ -49,7 +47,7 @@ def shapelyBox2BoxYX(shapelyBox, coord_type='image'):
def
get_boxImXY_from_shapelyPoly
(
shapelyPoly
,
im_gt
):
# type: (
_T_p
olygon, tuple) -> list
# type: (
P
olygon, tuple) -> list
"""Converts each vertex coordinate of a shapely polygon into image coordinates corresponding to the given
geotransform without respect to invalid image coordinates. Those must be filtered later.
:param shapelyPoly: <shapely.Polygon>
...
...
py_tools_ds/geo/vector/topology.py
View file @
bee0b152
...
...
@@ -3,18 +3,16 @@
import
math
import
warnings
import
numpy
as
np
from
typing
import
TypeVar
,
Union
from
typing
import
Union
# noqa F401 # flake8 issue
from
geopandas
import
GeoDataFrame
from
shapely.geometry
import
shape
,
Polygon
,
box
,
Point
,
MultiPolygon
from
shapely.geometry
import
shape
,
Polygon
,
box
,
Point
from
shapely.geometry
import
MultiPolygon
# noqa F401 # flake8 issue
from
..coord_trafo
import
mapYX2imYX
from
..coord_grid
import
find_nearest_grid_coord
__author__
=
"Daniel Scheffler"
_T_polygon
=
TypeVar
(
Polygon
)
_T_multipoly_poly
=
Union
[
TypeVar
(
Polygon
),
TypeVar
(
MultiPolygon
)]
def
get_overlap_polygon
(
poly1
,
poly2
,
v
=
False
):
""" Returns a dict with the overlap of two shapely.Polygon() objects, the overlap percentage and the overlap area.
...
...
@@ -127,7 +125,7 @@ def polyVertices_outside_poly(inner_poly, outer_poly):
def
fill_holes_within_poly
(
poly
):
# type: (
_T_m
ulti
p
oly
_poly
) ->
_T_p
olygon
# type: (
Union[Polygon, M
ulti
P
oly
gon]
) ->
P
olygon
"""Fills the holes within a shapely Polygon or MultiPolygon and returns a Polygon with only the outer boundary.
:param poly: <shapely.geometry.Polygon, shapely.geometry.MultiPolygon>, shapely.geometry.GeometryCollection>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment