Commit 76dc9e3e authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Merge branch 'bugfix/fix_raster2polygon' into 'master'

Bugfix/fix raster2polygon

Closes #20

See merge request !36
parents a055e21a 771a4ffa
Pipeline #38602 passed with stages
in 11 minutes and 12 seconds
......@@ -2,6 +2,15 @@
History
=======
0.20.2 (2022-02-10)
-------------------
* `!36`_: Fixed #20 (Wrong output of raster2polygon in case exact=False).
Enabled GDAL exceptions in the whole project.
.. _!36: https://git.gfz-potsdam.de/danschef/py_tools_ds/-/merge_requests/33]
0.20.1 (2021-12-03)
-------------------
......
......@@ -25,5 +25,10 @@
# limitations under the License.
from .version import __version__, __versionalias__ # noqa (E402 + F401)
from osgeo.gdal import UseExceptions as _UseExceptions
__author__ = 'Daniel Scheffler'
# enable GDAL exceptions in the whole project
_UseExceptions()
......@@ -58,6 +58,7 @@ def raster2polygon(array: np.ndarray,
:param prj: projection as WKT string, 'EPSG:1234' or <EPSG_int>
:param DN2extract: <int, float> pixel value to create polygons for
:param exact: whether to compute the exact footprint polygon or a simplified one for speed
(exact=False downsamples large input datasets before polygonizing)
:param maxfeatCount: the maximum expected number of polygons. If more polygons are found, every further
processing is cancelled and a RunTimeError is raised.
:param min_npx: minmal polygon area to be included in the result (in numbers of pixels; default: 1)
......@@ -136,7 +137,7 @@ def raster2polygon(array: np.ndarray,
src_band, # .GetMaskBand(),
dst_layer,
0,
[] if exact else ["8CONNECTED=8"], # 4-connectedness for exact output
[], # uses 4-connectedness for exact output (["8CONNECTED=8"] is much slower below)
# callback=gdal.TermProgress_nocb)
callback=callback)
......@@ -171,8 +172,8 @@ def raster2polygon(array: np.ndarray,
val = val if val.is_valid else val.buffer(0)
if isinstance(val, Polygon):
return val
for g in val.geoms:
return get_valid_polys(g)
return [get_valid_polys(g) for g in val.geoms]
# extract polygons from GeoJSON dict
polys = []
......
Supports Markdown
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