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

Ensure raster2polygon uses uint8 internally (faster, less memory).

parent 1704173c
......@@ -66,16 +66,14 @@ def raster2polygon(array: np.ndarray,
:param q: quiet mode (default: False)
:return:
"""
array = array.astype(int)
# TODO
if maxfeatCount is not None:
warnings.warn("'maxfeatCount' is deprecated and will be removed soon.", DeprecationWarning) # pragma: no cover
# gdal.Polygonize ignores the 0
if DN2extract == 0:
array = array == 0
DN2extract = 1
if not isinstance(array.dtype, np.integer):
array = array.astype(int)
array = (array == DN2extract).astype(np.uint8)
assert array.ndim == 2, "Only 2D arrays are supported. Got a %sD array." % array.ndim
gt_orig = gt
......@@ -96,7 +94,7 @@ def raster2polygon(array: np.ndarray,
drv = gdal.GetDriverByName('GTiff')
path_tmp = '/vsimem/raster2polygon_gdalsieve.tif'
ds = drv.Create(path_tmp, cols, rows, 1, gdal.GDT_Int16)
ds = drv.Create(path_tmp, cols, rows, 1, gdal.GDT_Byte)
band = ds.GetRasterBand(1)
band.WriteArray(array)
......@@ -178,7 +176,7 @@ def raster2polygon(array: np.ndarray,
# extract polygons from GeoJSON dict
polys = []
for f in gjs['features']:
if f['properties']['DN'] == str(DN2extract):
if f['properties']['DN'] == str(1):
geom = shape(f["geometry"])
geom = get_valid_polys(geom)
......
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