def setIsValide(job, dbsession, logger, testing = False): """ This function sets a georeference process as 'isvalide' and if there is no other newer georeference process for this map its activate this georeference process for this map. @param vkviewer.python.models.messtischblatt.AdminJobs: job @param sqlalchemy.orm.session.Session: dbsession @param logging.Logger: logger @param boolean: testing (Default: False) """ logger.debug('Set georeference process for id %s to isvalide ...'%(job.georefid)) # set georeferenceprocess to isvalide georefProcess = Georeferenzierungsprozess.by_id(job.georefid, dbsession) # check if there is an other process which is newer and more up to date activeGeorefProcess = Georeferenzierungsprozess.getActualGeoreferenceProcessForMapId(georefProcess.mapid, dbsession) mapObj = Map.by_id(georefProcess.mapid, dbsession) if activeGeorefProcess and activeGeorefProcess.id >= georefProcess.id: logger.info('The georeference process with the id %s or younger process is already active for this map object.'%georefProcess.id) pass elif activeGeorefProcess and activeGeorefProcess.id < georefProcess.id: logger.info('Activate the is valide georeference process and deactive old one ...') deactivate(activeGeorefProcess, mapObj, dbsession, logger) activate(georefProcess, mapObj, dbsession, logger) else: logger.info('Activate georeference process %s for the map object %s ...'%(georefProcess.id, georefProcess.mapid)) activate(georefProcess, mapObj, dbsession, logger) if georefProcess.adminvalidation == 'invalide': mapObj.hasgeorefparams = mapObj.hasgeorefparams + 1 georefProcess.adminvalidation = 'isvalide'
def registerUpdateGeoreferenceProcessInDb(mapObj, userid, gcps, dbsession): log.debug('Create georeference process record ...') activeGeorefProcess = Georeferenzierungsprozess.getActualGeoreferenceProcessForMapId(mapObj.id, dbsession) georefProcess = Georeferenzierungsprozess(messtischblattid = mapObj.apsobjectid, nutzerid = userid, georefparams = ast.literal_eval(gcps), clipparameter = gcps, timestamp = getTimestampAsPGStr(), isactive = False, type = 'update', adminvalidation = '', processed = False, mapid = mapObj.id, overwrites = activeGeorefProcess.id) dbsession.add(georefProcess) dbsession.flush() return georefProcess
def createResponseForSpecificGeoreferenceProcess(mapObj, request, georeferenceid=None): log.debug('Create response for specific georeference process ...') mtb_extent = Map.getExtent(mapObj.id, request.db) if georeferenceid is None: georeferenceprocess = Georeferenzierungsprozess.getActualGeoreferenceProcessForMapId( mapObj.id, request.db) else: georeferenceprocess = Georeferenzierungsprozess.by_id( georeferenceid, request.db) pure_clipparameters = georeferenceprocess.georefparams # get the actual valide gcps gcps = None if georeferenceprocess.type == 'new': # in case of a new registered clip_parameter gcps = pure_clipparameters else: # in case of an update process gcps = pure_clipparameters['new'] # get zoomify and metadata information log.debug('Create response ...') metadata = Metadata.by_id(mapObj.id, request.db) response = { 'type': 'update', 'objectid': mapObj.id, 'georeferenceid': georeferenceprocess.id, 'timestamp': str(georeferenceprocess.timestamp), 'gcps': gcps, 'extent': mtb_extent, 'zoomify': metadata.imagezoomify, 'metadata': { 'dateiname': mapObj.apsdateiname, 'titel_long': metadata.title, 'titel_short': metadata.titleshort } } # check if there is an other user is working on this map right now # @TODO use babel lingua fpr translation try: areTherePendingUpdateProcesses = Georeferenzierungsprozess.arePendingProcessForMapId( mapObj.id, request.db) if areTherePendingUpdateProcesses: if request.locale_name == 'de': warnMsg = 'Aktuell wird das Kartenblatt von anderen Nutzern bearbeitet. Um Informationsverluste zu vermeiden versuchen Sie es bitte noch einmal in ein 15 Minuten.' else: warnMsg = 'Right now another users is working on the georeferencing of this map sheet. For preventing information losses please try again in 15 minutes.' response['warn'] = warnMsg return response except ProcessIsInvalideException as e: pass return response
def createResponseForSpecificGeoreferenceProcess(mapObj, request, georeferenceid = None): log.debug('Create response for specific georeference process ...') mtb_extent = Map.getExtent(mapObj.id, request.db) if georeferenceid is None: georeferenceprocess = Georeferenzierungsprozess.getActualGeoreferenceProcessForMapId(mapObj.id, request.db) else: georeferenceprocess = Georeferenzierungsprozess.by_id(georeferenceid, request.db) pure_clipparameters = georeferenceprocess.georefparams # get the actual valide gcps gcps = None if georeferenceprocess.type == 'new': # in case of a new registered clip_parameter gcps = pure_clipparameters else: # in case of an update process gcps = pure_clipparameters['new'] # get zoomify and metadata information log.debug('Create response ...') metadata = Metadata.by_id(mapObj.id, request.db) response = { 'type':'update', 'objectid': mapObj.id, 'georeferenceid':georeferenceprocess.id, 'timestamp':str(georeferenceprocess.timestamp), 'gcps':gcps, 'extent': mtb_extent, 'zoomify': metadata.imagezoomify, 'metadata': { 'dateiname': mapObj.apsdateiname, 'titel_long': metadata.title, 'titel_short': metadata.titleshort } } # check if there is an other user is working on this map right now # @TODO use babel lingua fpr translation try: areTherePendingUpdateProcesses = Georeferenzierungsprozess.arePendingProcessForMapId(mapObj.id, request.db) if areTherePendingUpdateProcesses: if request.locale_name == 'de': warnMsg = 'Aktuell wird das Kartenblatt von anderen Nutzern bearbeitet. Um Informationsverluste zu vermeiden versuchen Sie es bitte noch einmal in ein 15 Minuten.' else: warnMsg = 'Right now another users is working on the georeferencing of this map sheet. For preventing information losses please try again in 15 minutes.' response['warn'] = warnMsg return response except ProcessIsInvalideException as e: pass return response
def georeferenceConfirm(request): log.info('Receive request for processing georeference validation result') try: userid = checkIsUser(request) 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('Check if there is already a registered georeference process for this messtischblatt ...') if Georeferenzierungsprozess.isGeoreferenced(mapObj.id, request.db): msg = 'There is already a georeference process for this process. Please load again and start on the latest changes.' log.debug(msg) georeferenceid = Georeferenzierungsprozess.getActualGeoreferenceProcessForMapId(mapObj.id, request.db).id response = {'text':msg,'georeferenceid':georeferenceid} return response # actual only support this option if target srs is EPSG:4314 log.debug('Start saving georeference process in the database ...') epsg_code = int(str(request_data['georeference']['target']).split(':')[1]) if request_data['georeference']['source'] == 'pixel' and epsg_code == 4314: log.debug('Create georeference process record ...') timestamp = getTimestampAsPGStr() georeference_parameter = str(convertUnicodeDictToUtf(request_data['georeference'])) georefProcess = Georeferenzierungsprozess(messtischblattid = mapObj.apsobjectid, nutzerid = userid, georefparams = ast.literal_eval(georeference_parameter), clipparameter = georeference_parameter, timestamp = timestamp, isactive = True, type = 'new', adminvalidation = '', processed = False, mapid = mapObj.id, overwrites = 0) request.db.add(georefProcess) request.db.flush() log.debug('Create response ...') response = {'text':'Georeference result saved. It will soon be ready for use.','georeferenceid':georefProcess.id, 'points':20, 'gcps':request_data['georeference'] ,'type':'confirm'} 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)
def runUpdateGeoreferenceProcess(georefProcess, dbsession, logger, testing = False): """ This function update the georeference result for a given map object. @param vkviewer.python.models.messtischblatt.AdminJobs: georefProcess @param sqlalchemy.orm.session.Session: dbsession @param logging.Logger: logger @param boolean: testing (Default: False) """ logger.info('Run georeference process with type "update" with id %s ...'%georefProcess.id) activeGeorefProcess = Georeferenzierungsprozess.getActualGeoreferenceProcessForMapId(georefProcess.mapid, dbsession) mapObj = Map.by_id(georefProcess.mapid, dbsession) logger.info('Deactivate old georeference processes ...') if activeGeorefProcess: deactivate(activeGeorefProcess, mapObj, dbsession, logger) logger.info('Activate new georeference processes ...') activate(georefProcess, mapObj, dbsession, logger)
def registerUpdateGeoreferenceProcessInDb(mapObj, userid, gcps, dbsession): log.debug('Create georeference process record ...') activeGeorefProcess = Georeferenzierungsprozess.getActualGeoreferenceProcessForMapId( mapObj.id, dbsession) georefProcess = Georeferenzierungsprozess( messtischblattid=mapObj.apsobjectid, nutzerid=userid, georefparams=ast.literal_eval(gcps), clipparameter=gcps, timestamp=getTimestampAsPGStr(), isactive=False, type='update', adminvalidation='', processed=False, mapid=mapObj.id, overwrites=activeGeorefProcess.id) dbsession.add(georefProcess) dbsession.flush() return georefProcess
def runUpdateGeoreferenceProcess(georefProcess, dbsession, logger, testing=False): """ This function update the georeference result for a given map object. @param vkviewer.python.models.messtischblatt.AdminJobs: georefProcess @param sqlalchemy.orm.session.Session: dbsession @param logging.Logger: logger @param boolean: testing (Default: False) """ logger.info('Run georeference process with type "update" with id %s ...' % georefProcess.id) activeGeorefProcess = Georeferenzierungsprozess.getActualGeoreferenceProcessForMapId( georefProcess.mapid, dbsession) mapObj = Map.by_id(georefProcess.mapid, dbsession) logger.info('Deactivate old georeference processes ...') if activeGeorefProcess: deactivate(activeGeorefProcess, mapObj, dbsession, logger) logger.info('Activate new georeference processes ...') activate(georefProcess, mapObj, dbsession, logger)
def georeferenceConfirm(request): log.info('Receive request for processing georeference validation result') try: userid = checkIsUser(request) 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( 'Check if there is already a registered georeference process for this messtischblatt ...' ) if Georeferenzierungsprozess.isGeoreferenced(mapObj.id, request.db): msg = 'There is already a georeference process for this process. Please load again and start on the latest changes.' log.debug(msg) georeferenceid = Georeferenzierungsprozess.getActualGeoreferenceProcessForMapId( mapObj.id, request.db).id response = {'text': msg, 'georeferenceid': georeferenceid} return response # actual only support this option if target srs is EPSG:4314 log.debug('Start saving georeference process in the database ...') epsg_code = int( str(request_data['georeference']['target']).split(':')[1]) if request_data['georeference'][ 'source'] == 'pixel' and epsg_code == 4314: log.debug('Create georeference process record ...') timestamp = getTimestampAsPGStr() georeference_parameter = str( convertUnicodeDictToUtf(request_data['georeference'])) georefProcess = Georeferenzierungsprozess( messtischblattid=mapObj.apsobjectid, nutzerid=userid, georefparams=ast.literal_eval(georeference_parameter), clipparameter=georeference_parameter, timestamp=timestamp, isactive=True, type='new', adminvalidation='', processed=False, mapid=mapObj.id, overwrites=0) request.db.add(georefProcess) request.db.flush() log.debug('Create response ...') response = { 'text': 'Georeference result saved. It will soon be ready for use.', 'georeferenceid': georefProcess.id, 'points': 20, 'gcps': request_data['georeference'], 'type': 'confirm' } 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)