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 resetGeorefParameters(request): try: log.info('Receive a reset georeference parameter requests.') login = checkIsUser(request) dbsession = request.db messtischblatt_id = request.params['mtbid'] georeference_process = Georeferenzierungsprozess.by_messtischblattid(messtischblatt_id, dbsession) referenz = georeference_process.clipparameter fehlerbeschreibung = 'Zuruecksetzen von Georeferenzierungsparameter für GeorefId=%s'%georeference_process.id if login and messtischblatt_id and referenz and fehlerbeschreibung and Users.by_username(login, dbsession): log.debug('Save reset process in table fehlermeldungen ...') newFehlermeldung = Fehlermeldung(objektid = messtischblatt_id, referenz = referenz, nutzerid = login, fehlerbeschreibung = fehlerbeschreibung, timestamp = getTimestampAsPGStr()) dbsession.add(newFehlermeldung) log.debug('Remove georeference process ...') dbsession.delete(georeference_process) log.debug('Remove refmtblayer ...') try: refmtblayer = RefMtbLayer.by_id(MTB_LAYER_ID, messtischblatt_id, dbsession) dbsession.delete(refmtblayer) except: log.debug('No entry for refmtblayer found ...') pass log.debug('Update messtischblatt db ...') messtischblatt = Messtischblatt.by_id(messtischblatt_id, dbsession) messtischblatt.isttransformiert = False return json.dumps({'status':'confirmed'}, ensure_ascii=False, encoding='utf-8') except DBAPIError: log.error('Problems while trying to remove georeference parameter from the database ...') return Response(conn_err_msg, content_type='text/plain', status_int=500)
def resetGeorefParameters(request): try: log.info('Receive a reset georeference parameter requests.') login = checkIsUser(request) dbsession = request.db messtischblatt_id = request.params['mtbid'] georeference_process = Georeferenzierungsprozess.by_messtischblattid( messtischblatt_id, dbsession) referenz = georeference_process.clipparameter fehlerbeschreibung = 'Zuruecksetzen von Georeferenzierungsparameter für GeorefId=%s' % georeference_process.id if login and messtischblatt_id and referenz and fehlerbeschreibung and Users.by_username( login, dbsession): log.debug('Save reset process in table fehlermeldungen ...') newFehlermeldung = Fehlermeldung( objektid=messtischblatt_id, referenz=referenz, nutzerid=login, fehlerbeschreibung=fehlerbeschreibung, timestamp=getTimestampAsPGStr()) dbsession.add(newFehlermeldung) log.debug('Remove georeference process ...') dbsession.delete(georeference_process) log.debug('Remove refmtblayer ...') try: refmtblayer = RefMtbLayer.by_id(MTB_LAYER_ID, messtischblatt_id, dbsession) dbsession.delete(refmtblayer) except: log.debug('No entry for refmtblayer found ...') pass log.debug('Update messtischblatt db ...') messtischblatt = Messtischblatt.by_id(messtischblatt_id, dbsession) messtischblatt.isttransformiert = False return json.dumps({'status': 'confirmed'}, ensure_ascii=False, encoding='utf-8') except DBAPIError: log.error( 'Problems while trying to remove georeference parameter from the database ...' ) return Response(conn_err_msg, content_type='text/plain', status_int=500)
def resetMapObject(mapObjectId, dbsession, logger, testing = False): logger.debug('Reset map object into unreferenced state.') messtischblatt = Messtischblatt.by_id(mapObjectId, dbsession) messtischblatt.isttransformiert = False messtischblatt.hasgeorefparams = 0 messtischblatt.verzeichnispfad = messtischblatt.original_path refmtblayer = RefMtbLayer.by_id(MTB_LAYER_ID, messtischblatt.id, dbsession) if refmtblayer: dbsession.delete(refmtblayer) if testing: dbsession.rollback() logger.debug('Remove metadata record from catalog instance') if not testing: gn_transaction_delete('vk20-md-%s'%messtischblatt.id, GN_SETTINGS['gn_username'], GN_SETTINGS['gn_password'], logger) return True
def resetMapObject(mapObjectId, dbsession, logger, testing=False): logger.debug('Reset map object into unreferenced state.') messtischblatt = Messtischblatt.by_id(mapObjectId, dbsession) messtischblatt.isttransformiert = False messtischblatt.hasgeorefparams = 0 messtischblatt.verzeichnispfad = messtischblatt.original_path refmtblayer = RefMtbLayer.by_id(MTB_LAYER_ID, messtischblatt.id, dbsession) if refmtblayer: dbsession.delete(refmtblayer) if testing: dbsession.rollback() logger.debug('Remove metadata record from catalog instance') if not testing: gn_transaction_delete('vk20-md-%s' % messtischblatt.id, GN_SETTINGS['gn_username'], GN_SETTINGS['gn_password'], logger) return True
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)