def __runFastGeoreferencing__(self, georefObject, messtischblatt, tmpDir, destPath):    
     try:                           
         gcps = createGCPs(georefObject.clipparameter, messtischblatt.BoundingBoxObj.getCornerPointsAsList(), messtischblatt.zoomify_height)
         return georeference(messtischblatt.original_path, destPath, tmpDir, gcps, DATABASE_SRID, DATABASE_SRID, 'polynom', self.logger)
     except:
         self.logger.error('Something went wrong while trying to process a fast georefercing process')
         raise
Beispiel #2
0
    def __runStableGeoreferencing__(self, georefObject, messtischblatt, tmpDir,
                                    destPath):
        try:
            # create a shapefile which represents the boundingbox of the messtischblatt and is latery used for clipping
            shpPath = messtischblatt.BoundingBoxObj.asShapefile(
                os.path.join(tmpDir, "shape"))
            gcps = createGCPs(
                georefObject.clipparameter,
                messtischblatt.BoundingBoxObj.getCornerPointsAsList(),
                messtischblatt.zoomify_height)
            georeference_result_file = georeference(
                messtischblatt.original_path, destPath, tmpDir, gcps,
                DATABASE_SRID, DATABASE_SRID, 'polynom', self.logger, shpPath)

            # add overviews
            if self.__executeCommands__(
                    "gdaladdo --config GDAL_CACHEMAX 500 -r average %s %s" %
                (georeference_result_file, GEOREFERENCE_OVERVIEW_LEVELS)):
                return destPath
            else:
                raise GeoreferenceProcessRunningError(
                    'Something went wrong while trying to process a georefercing process'
                )
        except:
            self.logger.error(
                'Something went wrong while trying to process a georefercing process'
            )
            raise
Beispiel #3
0
def processSingleGeorefProc(georefProc, dbsession, logger, testing=False):
    logger.debug('Process single georeference process with id %s ...' %
                 georefProc.id)

    # calculate georeference result
    logger.debug('Create persistent georeference result ...')
    messtischblatt = Messtischblatt.by_id(georefProc.messtischblattid,
                                          dbsession)
    if str(georefProc.type) == 'update':
        parsedGeorefParameter = ast.literal_eval(str(
            georefProc.clipparameter))['new']
    else:
        parsedGeorefParameter = ast.literal_eval(str(georefProc.clipparameter))

    epsg_code = int(str(parsedGeorefParameter['target']).split(':')[1])
    if parsedGeorefParameter['source'] == 'pixel' and epsg_code == 4314:
        gcps = parseGcps(parsedGeorefParameter['gcps'])
        clip_polygon = messtischblatt.BoundingBoxObj.asShapefile(
            os.path.join(TMP_DIR, messtischblatt.dateiname + 'clip_polygon'))
        destPath = georeference(
            messtischblatt.original_path,
            os.path.join(GEOREF_TARGET_DIR,
                         messtischblatt.dateiname + '.tif'), TMP_DIR, gcps,
            epsg_code, epsg_code, 'polynom', logger, clip_polygon)
        addOverviews(destPath, '2 4 8 16 32', logger)
        if destPath is None:
            logger.error(
                'Something went wrong while trying to process a georeference process.'
            )
            raise GeoreferenceProcessingError(
                'Something went wrong while trying to process a georeference process.'
            )

    if not testing:
        # push metadata to catalogue
        logger.debug(
            'Push metadata record for messtischblatt %s to cataloge service ...'
            % messtischblatt.id)
        insertMetadata(id=messtischblatt.id, db=dbsession, logger=logger)

    # update database
    logger.debug('Update database ...')

    # update verzeichnispfad for messtischblatt
    georefProc.processed = True
    messtischblatt.verzeichnispfad = destPath
    messtischblatt.isttransformiert = True
    refmtblayer = RefMtbLayer.by_id(MTB_LAYER_ID, messtischblatt.id, dbsession)
    if not refmtblayer:
        refmtblayer = RefMtbLayer(layer=MTB_LAYER_ID,
                                  messtischblatt=messtischblatt.id)
        dbsession.add(refmtblayer)
    dbsession.flush()

    return str(destPath)
Beispiel #4
0
def processGeorefImage(mapObj, georefParams, dbsession, logger):
    clip_polygon = Map.getBoundingBoxObjWithEpsg(
        mapObj.id, dbsession, DATABASE_SRID).asShapefile(
            os.path.join(TMP_DIR, mapObj.apsdateiname + 'clip_polygon'))
    destPath = georeference(
        mapObj.originalimage,
        os.path.join(GEOREF_TARGET_DIR,
                     mapObj.apsdateiname + '.tif'), TMP_DIR, georefParams,
        DATABASE_SRID, DATABASE_SRID, 'polynom', logger, clip_polygon)
    addOverviews(destPath, '2 4 8 16 32', logger)
    return destPath
Beispiel #5
0
 def testGeoreferenceWithClip(self):
     print 'Test georeference with clipfunction ...'
     dst_path = os.path.join(self.dir, 'test_georeference_clip.tif')
     response_file = georeference(self.file, dst_path, self.dir, self.gcps, 4314, 4314, 'polynom', self.logger, self.clip_shp)
     self.assertTrue(os.path.exists(dst_path), 'Could not find created vrt file ...')
     self.assertEqual(response_file, dst_path, 'Response is not like expected ...')
     
     response_dataset = gdal.Open(response_file, GA_ReadOnly)
     self.assertTrue(response_dataset.GetProjection() == 'GEOGCS["DHDN",DATUM["Deutsches_Hauptdreiecksnetz",SPHEROID["Bessel 1841",6377397.155,299.1528128000008,AUTHORITY["EPSG","7004"]],TOWGS84[598.1,73.7,418.2,0.202,0.045,-2.455,6.7],AUTHORITY["EPSG","6314"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4314"]]', 'Response has not expected coordinate system ...')
     del response_dataset
     os.remove(dst_path)
     print '=============='
    def __runStableGeoreferencing__(self, georefObject, messtischblatt, tmpDir, destPath):    
        try:
            # create a shapefile which represents the boundingbox of the messtischblatt and is latery used for clipping
            shpPath = messtischblatt.BoundingBoxObj.asShapefile(os.path.join(tmpDir,"shape"))
            gcps = createGCPs(georefObject.clipparameter, messtischblatt.BoundingBoxObj.getCornerPointsAsList(), messtischblatt.zoomify_height)
            georeference_result_file = georeference(messtischblatt.original_path, destPath, tmpDir, gcps, DATABASE_SRID, DATABASE_SRID, 'polynom', self.logger, shpPath)        

            # add overviews
            if self.__executeCommands__("gdaladdo --config GDAL_CACHEMAX 500 -r average %s %s"%(georeference_result_file,GEOREFERENCE_OVERVIEW_LEVELS)):
                return destPath
            else:
                raise GeoreferenceProcessRunningError('Something went wrong while trying to process a georefercing process')
        except:
            self.logger.error('Something went wrong while trying to process a georefercing process')
            raise
Beispiel #7
0
 def __runFastGeoreferencing__(self, georefObject, messtischblatt, tmpDir,
                               destPath):
     try:
         gcps = createGCPs(
             georefObject.clipparameter,
             messtischblatt.BoundingBoxObj.getCornerPointsAsList(),
             messtischblatt.zoomify_height)
         return georeference(messtischblatt.original_path, destPath, tmpDir,
                             gcps, DATABASE_SRID, DATABASE_SRID, 'polynom',
                             self.logger)
     except:
         self.logger.error(
             'Something went wrong while trying to process a fast georefercing process'
         )
         raise
Beispiel #8
0
    def testGeoreference(self):
        print 'Test georeference function ...'
        dst_path = os.path.join(self.dir, 'test_georeference.tif')
        response_file = georeference(self.file, dst_path, self.dir, self.gcps,
                                     4314, 4314, 'polynom', self.logger)
        self.assertTrue(os.path.exists(dst_path),
                        'Could not find created vrt file ...')
        self.assertEqual(response_file, dst_path,
                         'Response is not like expected ...')

        response_dataset = gdal.Open(response_file, GA_ReadOnly)
        self.assertTrue(
            response_dataset.GetProjection() ==
            'GEOGCS["DHDN",DATUM["Deutsches_Hauptdreiecksnetz",SPHEROID["Bessel 1841",6377397.155,299.1528128000008,AUTHORITY["EPSG","7004"]],TOWGS84[598.1,73.7,418.2,0.202,0.045,-2.455,6.7],AUTHORITY["EPSG","6314"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4314"]]',
            'Response has not expected coordinate system ...')
        del response_dataset
        os.remove(dst_path)
        print '=============='
Beispiel #9
0
def processSingleGeorefProc(georefProc, dbsession, logger, testing = False):
    logger.debug('Process single georeference process with id %s ...'%georefProc.id)
    
    # calculate georeference result 
    logger.debug('Create persistent georeference result ...')
    messtischblatt = Messtischblatt.by_id(georefProc.messtischblattid, dbsession)
    if str(georefProc.type) == 'update': 
        parsedGeorefParameter = ast.literal_eval(str(georefProc.clipparameter))['new']
    else:
        parsedGeorefParameter = ast.literal_eval(str(georefProc.clipparameter))
        
    epsg_code = int(str(parsedGeorefParameter['target']).split(':')[1])
    if parsedGeorefParameter['source'] == 'pixel' and epsg_code == 4314:
        gcps = parseGcps(parsedGeorefParameter['gcps'])
        clip_polygon = messtischblatt.BoundingBoxObj.asShapefile(os.path.join(TMP_DIR, messtischblatt.dateiname+'clip_polygon'))
        destPath = georeference(messtischblatt.original_path, os.path.join(GEOREF_TARGET_DIR,messtischblatt.dateiname+'.tif'), 
                         TMP_DIR, gcps, epsg_code, epsg_code, 'polynom', logger, clip_polygon)
        addOverviews(destPath, '2 4 8 16 32', logger)
        if destPath is None:
            logger.error('Something went wrong while trying to process a georeference process.')
            raise GeoreferenceProcessingError('Something went wrong while trying to process a georeference process.')
    
    if not testing:
        # push metadata to catalogue
        logger.debug('Push metadata record for messtischblatt %s to cataloge service ...'%messtischblatt.id)
        insertMetadata(id=messtischblatt.id,db=dbsession,logger=logger)
    
    # update database
    logger.debug('Update database ...')

    # update verzeichnispfad for messtischblatt
    georefProc.processed = True
    messtischblatt.verzeichnispfad = destPath
    messtischblatt.isttransformiert = True 
    refmtblayer = RefMtbLayer.by_id(MTB_LAYER_ID, messtischblatt.id, dbsession)
    if not refmtblayer:
        refmtblayer = RefMtbLayer(layer=MTB_LAYER_ID, messtischblatt=messtischblatt.id)
        dbsession.add(refmtblayer)
    dbsession.flush()   
        
    return str(destPath)
def georeferenceValidation(request):
    log.info('Receive request for processing georeference validation result')
    
    try:
        request_data = None
        if request.method == 'POST':
            request_data = request.json_body
            
        if request_data:
            validateId(request_data['id'])
            log.debug('Request data is valide: %s'%request_data)
            
        log.debug('Start creating validation result ...')
        messtischblatt = Messtischblatt.by_id(request_data['id'], request.db)
        # actual only support this option if target srs is EPSG:4314
        epsg_code = int(str(request_data['georeference']['target']).split(':')[1])
        if request_data['georeference']['source'] == 'pixel' and epsg_code == 4314:
            log.debug('Parse gcps ...')
            gcps = parseGcps(request_data['georeference']['gcps'])
            
            log.debug('Process georeference parameter ...')
            destPath = georeference(messtischblatt.original_path, os.path.join(GEOREFERENCE_MAPFILE_FOLDER,messtischblatt.dateiname+"::"+str(getUniqueId())+".vrt"), 
                         GEOREFERENCE_TMP_DIR, gcps, epsg_code, epsg_code, 'polynom', log)
        
            log.debug('Create temporary mapfile ...')
            wms_url = createMapfile(messtischblatt.dateiname, destPath, GEOREFERENCE_MAPFILE_TEMPLATE, GEOREFERENCE_MAPFILE_FOLDER, GEOREFERENCE_MAPFILE_DEFAULT_PARAMS)
            
            log.debug('Create response ...')  
            response = {'wms_url':wms_url,'layer_id':messtischblatt.dateiname,'extent':Messtischblatt.getExtent(messtischblatt.id, request.db)}
            return json.dumps(response, ensure_ascii=False, encoding='utf-8') 
        else:
            raise GeoreferenceParameterError('Wrong or missing service parameter')
    except GeoreferenceParameterError as e:
        message = 'Wrong or missing service parameter - %s'%e.value
        log.error(message)
        return HTTPBadRequest(message) 
    except Exception as e:
        message = 'Problems while computing validation result - %s'%e.value
        log.error(message)
        return HTTPInternalServerError(message)
def georeferenceValidation(request):
    log.info('Receive request for processing georeference validation result')
    
    try:
        request_data = None
        if request.method == 'POST':
            request_data = request.json_body
          
        mapObj = parseMapObjForId(request_data, 'id', request.db)
        log.debug('Id is valide: %s'%request_data)
                      
        log.debug('Start creating validation result ...')
        # actual only support this option if target srs is EPSG:4314
        epsg_code = int(str(request_data['georeference']['target']).split(':')[1])
        if request_data['georeference']['source'] == 'pixel' and epsg_code == 4314:
            log.debug('Parse gcps ...')
            gcps = parseGcps(request_data['georeference']['gcps'])
            
            log.debug('Process georeference parameter ...')
            destPath = georeference(mapObj.originalimage, os.path.join(GEOREFERENCE_MAPFILE_FOLDER,mapObj.apsdateiname+"::"+str(getUniqueId())+".vrt"), 
                         GEOREFERENCE_TMP_DIR, gcps, epsg_code, epsg_code, 'polynom', log)
        
            log.debug('Create temporary mapfile ...')
            wms_url = createMapfile(mapObj.apsdateiname, destPath, GEOREFERENCE_MAPFILE_TEMPLATE, GEOREFERENCE_MAPFILE_FOLDER, GEOREFERENCE_MAPFILE_DEFAULT_PARAMS)
            
            log.debug('Create response ...')  
            response = {'wms_url':wms_url,'layer_id':mapObj.apsdateiname,'extent':Map.getExtent(mapObj.id, request.db)}
            return response 
        else:
            raise GeoreferenceParameterError('Wrong or missing service parameter')
    except GeoreferenceParameterError as e:
        log.error(e)
        log.error(traceback.format_exc())
        raise HTTPBadRequest(ERROR_MSG) 
    except Exception as e:
        log.error(e)
        log.error(traceback.format_exc())
        raise HTTPInternalServerError(ERROR_MSG)
Beispiel #12
0
def processGeorefImage(mapObj, georefParams, dbsession, logger):  
    clip_polygon = Map.getBoundingBoxObjWithEpsg(mapObj.id, dbsession, DATABASE_SRID).asShapefile(os.path.join(TMP_DIR, mapObj.apsdateiname+'clip_polygon'))
    destPath = georeference(mapObj.originalimage, os.path.join(GEOREF_TARGET_DIR, mapObj.apsdateiname+'.tif'), 
                TMP_DIR, georefParams, DATABASE_SRID, DATABASE_SRID, 'polynom', logger, clip_polygon)
    addOverviews(destPath, '2 4 8 16 32', logger)
    return destPath