Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#~ pf('')
ld('self.src_path',self.src_path, self.src)
# check for source raster type
src_ds = gdal.Open(self.src_path, GA_ReadOnly)
self.src_ds = src_ds
self.description = self.src_ds.GetMetadataItem('DESCRIPTION')
# source is successfully opened, then create destination dir
os.makedirs(self.dest)
src_geotr = src_ds.GetGeoTransform()
src_proj = txt2proj4(src_ds.GetProjection())
gcps = src_ds.GetGCPs()
if gcps:
ld('src GCPsToGeoTransform', gdal.GCPsToGeoTransform(gcps))
if not src_proj and gcps :
src_proj = txt2proj4(src_ds.GetGCPProjection())
override_srs = self.options.srs
if override_srs is not None:
src_proj = txt2proj4(override_srs)
ld('src_proj', src_proj, 'src geotr', src_geotr)
assert src_proj, 'The source does not have a spatial reference system assigned'
src_bands = src_ds.RasterCount
band1 = src_ds.GetRasterBand(1)
if src_bands == 1 and band1.GetColorInterpretation() == GCI_PaletteIndex : # source is a paletted raster
transparency = None
if self.base_resampling == 'NearestNeighbour' and self.resampling == Image.NEAREST :
def gdal_get_transform(src_image):
geo_trans = src_image.GetGeoTransform()
if geo_trans == (0.0, 1.0, 0.0, 0.0, 0.0, 1.0):
geo_trans = gdal.GCPsToGeoTransform(src_image.GetGCPs())
return geo_trans
def gdal_get_transform(src_image):
geo_trans = src_image.GetGeoTransform()
if geo_trans == (0.0, 1.0, 0.0, 0.0, 0.0, 1.0):
geo_trans = gdal.GCPsToGeoTransform(src_image.GetGCPs())
return geo_trans
continue
output_dataset = output_driver.Create(
'', clip_shp_1, clip_shp_0,
src_image.RasterCount, raster_band.DataType)
# Copy All metadata data from src to dst
domains = src_image.GetMetadataDomainList()
for tag in domains:
md = src_image.GetMetadata(tag)
if md:
output_dataset.SetMetadata(md, tag)
# Rewrite the rpc_md that we modified above.
output_dataset.SetMetadata(rpc_md, 'RPC')
output_dataset.SetGeoTransform(gdal.GCPsToGeoTransform(corner_gcps))
output_dataset.SetProjection(gdal_get_projection(src_image))
# End logging, print blank line for clarity
print('')
bands = src_image.RasterCount
if bands > 1:
for i in range(bands):
outBand = output_dataset.GetRasterBand(i + 1)
outBand.SetNoDataValue(nodata_values[i])
outBand.WriteArray(clip[i])
else:
outBand = output_dataset.GetRasterBand(1)
outBand.SetNoDataValue(nodata_values[0])
outBand.WriteArray(clip)
if dst_img_file:
#~ pf('')
ld('self.src_path',self.src_path, self.src)
# check for source raster type
src_ds = gdal.Open(self.src_path, GA_ReadOnly)
self.src_ds = src_ds
self.description = self.src_ds.GetMetadataItem('DESCRIPTION')
# source is successfully opened, then create destination dir
os.makedirs(self.dest)
src_geotr = src_ds.GetGeoTransform()
src_proj = txt2proj4(src_ds.GetProjection())
gcps = src_ds.GetGCPs()
if gcps:
ld('src GCPsToGeoTransform', gdal.GCPsToGeoTransform(gcps))
if not src_proj and gcps :
src_proj = txt2proj4(src_ds.GetGCPProjection())
override_srs = self.options.srs
if override_srs is not None:
src_proj = txt2proj4(override_srs)
ld('src_proj', src_proj, 'src geotr', src_geotr)
assert src_proj, 'The source does not have a spatial reference system assigned'
src_bands = src_ds.RasterCount
band1 = src_ds.GetRasterBand(1)
if src_bands == 1 and band1.GetColorInterpretation() == GCI_PaletteIndex : # source is a paletted raster
transparency = None
if self.base_resampling == 'NearestNeighbour' and self.resampling == Image.NEAREST :
continue
output_dataset = output_driver.Create(
'', clip_shp_1, clip_shp_0,
src_image.RasterCount, raster_band.DataType)
# Copy All metadata data from src to dst
domains = src_image.GetMetadataDomainList()
for tag in domains:
md = src_image.GetMetadata(tag)
if md:
output_dataset.SetMetadata(md, tag)
# Rewrite the rpc_md that we modified above.
output_dataset.SetMetadata(rpc_md, 'RPC')
output_dataset.SetGeoTransform(gdal.GCPsToGeoTransform(corner_gcps))
output_dataset.SetProjection(gdal_get_projection(src_image))
# End logging, print blank line for clarity
print('')
bands = src_image.RasterCount
if bands > 1:
for i in range(bands):
outBand = output_dataset.GetRasterBand(i + 1)
outBand.SetNoDataValue(nodata_values[i])
outBand.WriteArray(clip[i])
else:
outBand = output_dataset.GetRasterBand(1)
outBand.SetNoDataValue(nodata_values[0])
outBand.WriteArray(clip)
if dst_img_file:
if args.render_cls:
eType = gdal.GDT_Byte
else:
eType = gdal.GDT_Float32
dsm = dtmDriver.Create(
args.output_dsm, xsize=dtm.RasterXSize,
ysize=dtm.RasterYSize, bands=1, eType=eType,
options=options)
if (projection):
# georeference through affine geotransform
dsm.SetProjection(projection)
dsm.SetGeoTransform(transform)
else:
# georeference through GCPs
dsm.SetGCPs(gcps, gcpProjection)
gdal.GCPsToGeoTransform(gcps, transform)
corners = [[0, 0], [0, dtm.RasterYSize],
[dtm.RasterXSize, dtm.RasterYSize], [dtm.RasterXSize, 0]]
geoCorners = numpy.zeros((4, 2))
for i, corner in enumerate(corners):
geoCorners[i] = [
transform[0] + corner[0] * transform[1] +
corner[1] * transform[2],
transform[3] + corner[0] * transform[4] +
corner[1] * transform[5]]
dtmBounds[0] = numpy.min(geoCorners[:, 0])
dtmBounds[1] = numpy.max(geoCorners[:, 0])
dtmBounds[2] = numpy.min(geoCorners[:, 1])
dtmBounds[3] = numpy.max(geoCorners[:, 1])
if args.render_cls:
# label for no building