Commit 2d6dcacf authored by Ludvik Brodl's avatar Ludvik Brodl
Browse files

convert grid_tile deps to python3

parent f146e93f
......@@ -101,7 +101,8 @@ def read_raster(filename, band=1, bbox=None,
xur = xll + nx * dx
yur = yll - ny * dy
extent = (xll, yll, xur, yur)
extent = map(lambda v: round(v, 5), extent)
#print(extent)
#extent = map(lambda v: round(v, 5), extent)
if band <= ds.RasterCount:
band = ds.GetRasterBand(band)
else:
......@@ -139,13 +140,13 @@ def read_raster(filename, band=1, bbox=None,
return data, meta
def write_raster(data, filename, meta, driver_name=b'XYZ',
def write_raster(data, filename, meta, driver_name='XYZ',
proj=None, datatype=GDT_Float32, nodata=NODATA):
driver = gdal.GetDriverByName(driver_name.encode('ascii'))
driver = gdal.GetDriverByName('AAIGrid')
nrows, ncols = data.shape
nbands = 1
mem_ds = gdal.GetDriverByName(b'MEM').Create(
mem_ds = gdal.GetDriverByName('MEM').Create(
filename,
ncols,
nrows,
......@@ -154,7 +155,7 @@ def write_raster(data, filename, meta, driver_name=b'XYZ',
)
if mem_ds is None:
print "Error: could not create memory raster"
print("Error: could not create memory raster")
sys.exit(1)
x1, y1, x2, y2 = meta['extent']
......@@ -250,7 +251,7 @@ def main():
'proj': None
}
driver = ogr.GetDriverByName(b'ESRI Shapefile')
driver = ogr.GetDriverByName('ESRI Shapefile')
dataSource = driver.Open(args.infile, update=0)
if dataSource is None:
......@@ -262,7 +263,7 @@ def main():
for feature in layer:
if i % 1000 == 0:
log.info('processing point%i' % i)
Z = feature.GetFieldAsDouble(b'Z')
Z = feature.GetFieldAsDouble('Z')
geom = feature.GetGeometryRef()
X = geom.GetX()
Y = geom.GetY()
......@@ -275,7 +276,7 @@ def main():
write_raster(
dem_data, args.outfile, meta,
driver_name=b'GTiff', proj=meta['proj']
driver_name='GTiff', proj=meta['proj']
)
......
......@@ -99,7 +99,7 @@ def read_raster(filename, band=1, bbox=None,
if pad and bbox is not None:
data = np.pad(
data, padding, mode=b'constant',
data, padding, mode='constant',
constant_values=padding_values or (nodata, nodata)
)
else:
......@@ -115,13 +115,13 @@ def read_raster(filename, band=1, bbox=None,
return data, meta
def write_raster(data, filename, meta, driver_name=b'XYZ',
def write_raster(data, filename, meta, driver_name='XYZ',
proj=None, datatype=GDT_Float32, nodata=NODATA):
driver = gdal.GetDriverByName(driver_name.encode('ascii'))
driver = gdal.GetDriverByName('AAIGrid')
nrows, ncols = data.shape
nbands = 1
mem_ds = gdal.GetDriverByName(b'MEM').Create(
mem_ds = gdal.GetDriverByName('MEM').Create(
filename,
ncols,
nrows,
......@@ -130,7 +130,7 @@ def write_raster(data, filename, meta, driver_name=b'XYZ',
)
if mem_ds is None:
print "Error: could not create memory raster"
print("Error: could not create memory raster")
sys.exit(1)
x1, y1, x2, y2 = meta['extent']
......@@ -214,10 +214,10 @@ def main():
canopy[row, col] = 0
below_min_height += 1
print 'Filtered %i solitary vegetation cells' % solitary
print 'Set %i cells < min-height to zero' % below_min_height
print('Filtered %i solitary vegetation cells' % solitary)
print('Set %i cells < min-height to zero' % below_min_height)
write_raster(canopy,args.outfile, meta, driver_name=b'GTiff', proj=meta['proj'])
write_raster(canopy,args.outfile, meta, driver_name='GTiff', proj=meta['proj'])
if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment