mirror of
https://github.com/rasterio/rasterio.git
synced 2026-02-01 14:34:43 +00:00
Cleanup of imports in _features.pyx. Switched band IO to use _io.io_ubyte instead of duplicate in _featuers.pyx
This commit is contained in:
parent
66643fd8ef
commit
0b4d353fe7
@ -4,9 +4,7 @@ import logging
|
||||
import json
|
||||
import numpy as np
|
||||
cimport numpy as np
|
||||
|
||||
from rasterio cimport _gdal, _ogr, _io
|
||||
from rasterio.dtypes import dtype_rev
|
||||
|
||||
|
||||
log = logging.getLogger('rasterio')
|
||||
@ -16,9 +14,6 @@ class NullHandler(logging.Handler):
|
||||
log.addHandler(NullHandler())
|
||||
|
||||
|
||||
ctypedef np.uint8_t DTYPE_UBYTE_t
|
||||
|
||||
|
||||
def _shapes(image, mask, connectivity, transform):
|
||||
"""Return an iterator over Fiona-style features extracted from the
|
||||
image.
|
||||
@ -63,7 +58,7 @@ def _shapes(image, mask, connectivity, transform):
|
||||
hband = _gdal.GDALGetRasterBand(hds, 1)
|
||||
if hband == NULL:
|
||||
raise ValueError("NULL band")
|
||||
retval = io_ubyte(hband, 1, 0, 0, cols, rows, image)
|
||||
retval = _io.io_ubyte(hband, 1, 0, 0, cols, rows, image)
|
||||
elif isinstance(image, tuple):
|
||||
rdr = image.ds
|
||||
hband = rdr.band(image.bidx)
|
||||
@ -85,7 +80,7 @@ def _shapes(image, mask, connectivity, transform):
|
||||
a = np.ones(mask.shape, dtype=np.uint8)
|
||||
a[mask == False] = 0
|
||||
a[mask == True] = 1
|
||||
retval = io_ubyte(hmaskband, 1, 0, 0, cols, rows, a)
|
||||
retval = _io.io_ubyte(hmaskband, 1, 0, 0, cols, rows, a)
|
||||
elif isinstance(mask, tuple):
|
||||
if mask.shape != image.shape:
|
||||
raise ValueError("Mask must have same shape as image")
|
||||
@ -165,7 +160,7 @@ def _sieve(image, size, connectivity=4, output=None):
|
||||
hbandin = _gdal.GDALGetRasterBand(hdsin, 1)
|
||||
if hbandin == NULL:
|
||||
raise ValueError("NULL input band")
|
||||
retval = io_ubyte(hbandin, 1, 0, 0, cols, rows, image)
|
||||
retval = _io.io_ubyte(hbandin, 1, 0, 0, cols, rows, image)
|
||||
elif isinstance(image, tuple):
|
||||
rdr = image.ds
|
||||
hband = rdr.band(image.bidx)
|
||||
@ -192,7 +187,7 @@ def _sieve(image, size, connectivity=4, output=None):
|
||||
NULL, NULL, NULL)
|
||||
|
||||
out = output or np.zeros(image.shape, np.uint8)
|
||||
retval = io_ubyte(hbandout, 0, 0, 0, cols, rows, out)
|
||||
retval = _io.io_ubyte(hbandout, 0, 0, 0, cols, rows, out)
|
||||
|
||||
if hdsin != NULL:
|
||||
_gdal.GDALClose(hdsin)
|
||||
@ -264,7 +259,7 @@ def _rasterize(shapes, image, transform, all_touched):
|
||||
pixel_values[i] = <double>value
|
||||
|
||||
# First, copy image data to the in-memory band.
|
||||
retval = io_ubyte(out_band, 1, 0, 0, width, height, image)
|
||||
retval = _io.io_ubyte(out_band, 1, 0, 0, width, height, image)
|
||||
|
||||
# Burn the shapes in.
|
||||
retval = _gdal.GDALRasterizeGeometries(
|
||||
@ -274,7 +269,7 @@ def _rasterize(shapes, image, transform, all_touched):
|
||||
options, NULL, NULL)
|
||||
|
||||
# Write the in-memory band back to the image.
|
||||
retval = io_ubyte(out_band, 0, 0, 0, width, height, image)
|
||||
retval = _io.io_ubyte(out_band, 0, 0, 0, width, height, image)
|
||||
|
||||
finally:
|
||||
for i in range(num_geometries):
|
||||
@ -287,19 +282,6 @@ def _rasterize(shapes, image, transform, all_touched):
|
||||
_gdal.CSLDestroy(options)
|
||||
|
||||
|
||||
cdef int io_ubyte(
|
||||
void *hband,
|
||||
int mode,
|
||||
int xoff,
|
||||
int yoff,
|
||||
int width,
|
||||
int height,
|
||||
np.ndarray[DTYPE_UBYTE_t, ndim=2, mode='c'] buffer):
|
||||
return _gdal.GDALRasterIO(
|
||||
hband, mode, xoff, yoff, width, height,
|
||||
&buffer[0, 0], buffer.shape[1], buffer.shape[0], 1, 0, 0)
|
||||
|
||||
|
||||
# Mapping of OGR integer geometry types to GeoJSON type names.
|
||||
GEOMETRY_TYPES = {
|
||||
0: 'Unknown',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user