Skip to content

gc-sommer/wkb-raster

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

WKB Raster

Read WKB rasters to Numpy arrays and convert any raster to WKB format.

Docs

wkb_raster.read_wkb_raster(wkb)

Parameters

  • wkb - file-like object. Binary raster in WKB format.

Returns

{
    'version': int,
    'scaleX': float,
    'scaleY': float,
    'ipX': float,
    'ipY': float,
    'skewX': float,
    'skewY': float,
    'srid': int,
    'width': int,
    'height': int,
    'bands': [{
        'nodata': bool|int|float,
        'isOffline': bool,
        'hasNodataValue': bool,
        'isNodataValue': bool,
        'ndarray': numpy.ndarray((width, height), bool|int|float)
    }, ...]
}

Usage

Reading WKB

With a binary WKB file:

from wkb_raster import read_wkb_raster

with open('img.wkb') as f:
    raster = read_wkb_raster(f)
    raster['bands'][0]

With WKB from PostGIS Raster. Use ST_AsBinary to return the WKB representation of the raster.

SELECT ST_AsBinary(rast) FROM rasters;

Wrap the binary buffer in cStringIO.StringIO:

from cStringIO import StringIO
from wkb_raster import read_wkb_raster

raster = read_wkb_raster(StringIO(buf))
raster['bands'][0]

Writing WKB

Write rasterio rasters to binary WKB:

import rasterio
from wkb_raster import write_wkb_raster

with rasterio.open('example.tif') as dataset:
    wkb = write_wkb_raster(dataset)

Links

About

Read WKB rasters to Numpy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%