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