-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterrain.py
More file actions
51 lines (41 loc) · 1.23 KB
/
terrain.py
File metadata and controls
51 lines (41 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os, sys, time, gdal, numpy
from gdalconst import *
import mcpi.minecraft as minecraft
import mcpi.block as block
import server
mc = minecraft.Minecraft.create(server.address)
# register all of the drivers
gdal.AllRegister()
# open VRT created from the *.txt datasets
# http://www.gdal.org/gdalbuildvrt.html
ds = gdal.Open('montserrat.vrt', GA_ReadOnly)
if ds is None:
print 'Could not open image'
sys.exit(1)
# get georeference info
transform = ds.GetGeoTransform()
xOrigin = transform[0]
zOrigin = transform[3]
pixelWidth = transform[1]
pixelHeight = transform[5]
/
# 1-based index
band = ds.GetRasterBand(1)
# http://www.gdal.org/classGDALRasterBand.html#a6aa58b6f0a0c17722b9bf763a96ff069
minimum,maximum,mean,stddev = band.GetStatistics(True, True)
print 'minimum', minimum
print 'maximum', maximum
print 'XSize', band.XSize
print 'ZSize', band.YSize
# reset the space
#mc.setBlocks(0, 0, 0, band.XSize, int(maximum), band.YSize, block.AIR.id)
# read all band values and
data = band.ReadAsArray(0, 0, band.XSize, band.YSize)
counter = 0
for (x,z), value in numpy.ndenumerate(data):
y = int((value-minimum) / 5)
mc.setBlocks(x, 0, z, x, y, z, block.SANDSTONE)
counter+=1
if counter%20000 == 0:
print counter
print 'done'