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

geo.raster.raster2polygon(): Added auto-downscaling of input array and updated version info.

parent 53ff185b
Pipeline #1202 passed with stages
in 6 minutes and 12 seconds
# -*- coding: utf-8 -*-
from __future__ import (division, print_function, absolute_import, unicode_literals)
__version__ = '0.7.3'
__versionalias__ = '20170920_01'
__version__ = '0.7.4'
__versionalias__ = '20170920_02'
__author__ = 'Daniel Scheffler'
# Validate GDAL version
......
......@@ -4,6 +4,8 @@ __author__ = "Daniel Scheffler"
from six import PY3
from shapely.wkb import loads
import numpy as np
from skimage.transform import rescale
try:
import gdal
......@@ -38,6 +40,18 @@ def raster2polygon(array, gt, prj, DN2extract=1, exact=True, maxfeatCount=None,
assert array.ndim == 2, "Only 2D arrays are supported. Got a %sD array." % array.ndim
# downsample input array in case is has more than 144e6 pixels to prevent crash
if not exact and array.size > 144e6: # 12000 x 12000 px
zoom_factor = 0.5
# downsample to half size, nearest neighbour
array = rescale(array, zoom_factor, order=0, preserve_range=True, mode='edge').astype(np.bool)
# update pixel sizes within gt
gt = list(gt)
gt[1] /= zoom_factor
gt[5] /= zoom_factor
src_ds = get_GDAL_ds_inmem(array, gt, prj)
src_band = src_ds.GetRasterBand(1)
......
......@@ -17,7 +17,7 @@ test_requirements = requirements + ["coverage", "nose", "nose2", "nose-htmloutpu
setup(
name='py_tools_ds',
version='0.7.3',
version='0.7.4',
description="A collection of Python tools by Daniel Scheffler.",
long_description=readme + '\n\n' + history,
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