Commit cfd3f794 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Added test and test data for geo.raster.conversion.raster2polygon(). Replaced...


Added test and test data for geo.raster.conversion.raster2polygon(). Replaced skimage downsampling by GDAL variant. Removed scikit-learn dependency.
Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 72c4c7c6
*.tif filter=lfs diff=lfs merge=lfs -text
*.bsq filter=lfs diff=lfs merge=lfs -text
......@@ -2,6 +2,14 @@
History
=======
0.16.10 (2021-05-07)
--------------------
* Added test and test data for geo.raster.conversion.raster2polygon().
* Replaced skimage downsampling by GDAL variant.
* Removed scikit-learn dependency.
0.16.9 (2021-05-07)
-------------------
......
......@@ -42,7 +42,6 @@ to resolve the following dependencies before the pip installer is run:
* geopandas
* numpy
* pyproj >=2.1.0
* scikit-image
* shapely
......
......@@ -31,6 +31,7 @@ from osgeo import gdal, osr, ogr
from ...io.raster.gdal import get_GDAL_ds_inmem
from ...processing.progress_mon import ProgressBar, Timer
from ...compatibility.python.exceptions import TimeoutError as TimeoutError_comp
from ..raster.reproject import warp_ndarray
def raster2polygon(array, gt, prj, DN2extract=1, exact=True, maxfeatCount=None,
......@@ -53,16 +54,12 @@ def raster2polygon(array, gt, prj, DN2extract=1, exact=True, maxfeatCount=None,
# downsample input array in case is has more than 1e8 pixels to prevent crash
if not exact and array.size > 1e8: # 10000 x 10000 px
zoom_factor = 1e8 / array.size
# downsample with nearest neighbour
from skimage.transform import rescale # import here to avoid static TLS import error
array = rescale(array, zoom_factor, order=0, preserve_range=True, mode='edge').astype(bool)
# update pixel sizes within gt
gt = list(gt)
gt[1] /= zoom_factor
gt[5] /= zoom_factor
zoom_factor = (8000 * 8000 / array.size) ** 0.5
array, gt, prj = warp_ndarray(array, gt, prj,
out_gsd=(gt[1] / zoom_factor, gt[5] / zoom_factor),
rspAlg='near',
q=True)
src_ds = get_GDAL_ds_inmem(array, gt, prj)
src_band = src_ds.GetRasterBand(1)
......
......@@ -43,13 +43,13 @@ requirements = [
'packaging', # remove when dropping Python 2.7 support
'pandas',
'pyproj>=2.2.0',
'scikit-image',
'shapely',
'six',
'spectral'
]
setup_requirements = ['setuptools']
test_requirements = requirements + ["coverage", "nose", "nose2", "nose-htmloutput", "rednose", "shapely", "urlchecker"]
test_requirements = requirements + ["coverage", "gdal", "nose", "nose2", "nose-htmloutput", "rednose", "shapely",
"urlchecker"]
setup(
name='py_tools_ds',
......
name: py_tools_ds
channels: &id1
- http://conda.anaconda.org/conda-forge
- conda-forge
dependencies:
- python=3.*.*
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# py_tools_ds
#
# Copyright (C) 2019 Daniel Scheffler (GFZ Potsdam, daniel.scheffler@gfz-potsdam.de)
#
# This software was developed within the context of the GeoMultiSens project funded
# by the German Federal Ministry of Education and Research
# (project grant code: 01 IS 14 010 A-C).
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""
test_conversion
---------------
Tests for `py_tools_ds.geo.raster.conversion` module.
"""
import os
from unittest import TestCase
from osgeo import gdal
from py_tools_ds.geo.raster.conversion import raster2polygon
import py_tools_ds
tests_path = os.path.abspath(os.path.join(py_tools_ds.__file__, "..", "..", "tests"))
class Test_raster2polygon(TestCase):
def setUp(self) -> None:
try:
# load a large mask containing an irregular binary shape with a complex footprint (27408x17604)
ds = gdal.Open(os.path.join(tests_path, 'data', 'mask_large.tif'))
self.mask = ds.ReadAsArray().astype(bool)
self.gt = ds.GetGeoTransform()
self.prj = ds.GetProjection()
finally:
del ds
def test_raster2polygon(self):
raster2polygon(self.mask, self.gt, self.prj, exact=False)
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