Last active
April 6, 2017 07:18
-
-
Save 1kastner/488bef97491402349f0a804d28117ad9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used to report irritating error message in rasterio/rasterio#1007.
np.int8 is not supported but e.g. np.uint8