Skip to content

Instantly share code, notes, and snippets.

@1kastner
Last active April 6, 2017 07:18
Show Gist options
  • Save 1kastner/488bef97491402349f0a804d28117ad9 to your computer and use it in GitHub Desktop.
Save 1kastner/488bef97491402349f0a804d28117ad9 to your computer and use it in GitHub Desktop.
import random
import numpy as np
import rasterio
def draw_map():
x_size_raster = 500
y_size_raster = 300
raster_map = np.ones((x_size_raster, y_size_raster), np.uint8) # be careful with numpy array types, not all are supported!
for shape_record in range(200):
row = random.randint(0, x_size_raster - 1)
col = random.randint(0, y_size_raster - 1)
raster_map[row, col] = random.randint(-10, 40)
return raster_map
def save_map(path, raster_map):
new_dataset = rasterio.open(path, 'w', driver='GTiff',
height=raster_map.shape[0], width=raster_map.shape[1], count=1,
dtype=raster_map.dtype, crs='EPSG:4326')
new_dataset.write(raster_map, 1)
new_dataset.close()
def demo():
m1 = draw_map()
save_map("m1.tif", m1)
demo()
@1kastner
Copy link
Author

1kastner commented Apr 6, 2017

Used to report irritating error message in rasterio/rasterio#1007.
np.int8 is not supported but e.g. np.uint8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment