In [14]:
from rasterio.transform import Affine
In [15]:
def transform_from_corner(ulx, uly, dx, dy):
return Affine.translation(ulx, uly)*Affine.scale(dx, -dy)
print transform_from_corner(bounds[0], bounds[3], 1.0/3600, 1.0/3600).to_gdal()
In [16]:
from rasterio.features import rasterize
from shapely.geometry import Polygon, mapping
# image transform
bounds = (119.52, -21.6, 120.90, -20.5)
transform = transform_from_corner(bounds[0], bounds[3], 1.0/3600, 1.0/3600)
# Make raster image, burn in vector data which lies completely inside the bounding box
poly = Polygon(((120, -21), (120.5, -21), (120.5, -21.2), (120, -21.2)))
output = rasterize([poly], transform=transform, out_shape=(3961, 4969))
print output
In [17]:
%matplotlib inline
In [18]:
import matplotlib.pyplot as plt
In [19]:
plt.imshow(output)
Out[19]:
In [ ]:
import json
output = rasterize([json.dumps(mapping(poly))], transform=transform, out_shape=(3961, 4969))
print output
In [ ]: