2020-12-24 02:18:05 +00:00
|
|
|
from osgeo import osr
|
|
|
|
from osgeo import gdal
|
|
|
|
from osgeo.gdalconst import GA_Update
|
2020-02-04 20:50:43 +00:00
|
|
|
from opendm import io
|
|
|
|
from opendm import log
|
|
|
|
|
2020-05-15 17:51:46 +00:00
|
|
|
def get_pseudogeo_utm():
|
|
|
|
return '+proj=utm +zone=30 +ellps=WGS84 +datum=WGS84 +units=m +no_defs'
|
|
|
|
|
2020-05-15 20:30:08 +00:00
|
|
|
def get_pseudogeo_scale():
|
|
|
|
return 0.1 # Arbitrarily chosen
|
|
|
|
|
|
|
|
def add_pseudo_georeferencing(geotiff):
|
2020-02-04 20:50:43 +00:00
|
|
|
if not io.file_exists(geotiff):
|
|
|
|
log.ODM_WARNING("Cannot add pseudo georeferencing, %s does not exist" % geotiff)
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
log.ODM_INFO("Adding pseudo georeferencing (raster should show up at the equator) to %s" % geotiff)
|
|
|
|
|
|
|
|
dst_ds = gdal.Open(geotiff, GA_Update)
|
|
|
|
srs = osr.SpatialReference()
|
2020-09-08 17:08:57 +00:00
|
|
|
srs.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
|
2020-05-15 17:51:46 +00:00
|
|
|
srs.ImportFromProj4(get_pseudogeo_utm())
|
2020-02-04 20:50:43 +00:00
|
|
|
dst_ds.SetProjection( srs.ExportToWkt() )
|
2020-05-15 20:30:08 +00:00
|
|
|
dst_ds.SetGeoTransform( [ 0.0, get_pseudogeo_scale(), 0.0, 0.0, 0.0, -get_pseudogeo_scale() ] )
|
2020-02-04 20:50:43 +00:00
|
|
|
dst_ds = None
|
|
|
|
|
|
|
|
except Exception as e:
|
2022-01-08 10:38:36 +00:00
|
|
|
log.ODM_WARNING("Cannot add pseudo georeferencing to %s (%s), skipping..." % (geotiff, str(e)))
|