コード例 #1
0
def runningUpdateJobs(dbsession, logger, testing=False):
    logger.info('Fetch overwrite id for unprocessed georeference jobs ...')
    overwrites = Georeferenzierungsprozess.by_getOverwriteIdsOfUnprocessedGeorefProcessesTypeOfUpdate(
        dbsession)

    counter = 0
    # clear all unnecessary overwrites and run update process for the actual process
    for overwrite in overwrites:
        # check if there is an old race conflict
        if not clearRaceConflicts(overwrite, dbsession):
            counter += 1
            jobs = Georeferenzierungsprozess.getJobsWithSameOverwrites(
                overwrite, dbsession)
            pendingJob = None
            for job in jobs:
                if pendingJob is None:
                    pendingJob = job
                else:
                    dbsession.delete(job)

            logger.debug('Process a update georeference process with id - %s' %
                         job.id)
            runUpdateGeoreferenceProcess(pendingJob, dbsession, logger,
                                         testing)

    logger.debug('Processed %s update georeference process.' % counter)
コード例 #2
0
ファイル: adminjobs.py プロジェクト: UAVE6MN/vkviewer
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'
コード例 #3
0
def getGeoreferenceProcessQueue(dbsession, logger):
    """ This functions build a georeference process queue. For this it looks for entries 
        in the georeference table with status unprocessed and extends it with georeference process
        for which the equivalent map object has status updated. 
        
        Arguments:
            dbsession {sqlalchemy.orm.session.Session}
            logger (Logger)
        Returns:
            dictionary where the key is a timestamp and the value a list object containing 
            tuple which contain orm mapper for the tables georeferenzierungsprozess and
            messtischblatt """
    try:
        # response object
        response = {'georeference': {}, 'reset': []}

        # get unprocessed georeference process
        dictProcessingQueueGeoref = {}
        unprocessedGeorefProcs = Georeferenzierungsprozess.by_getUnprocessedGeorefProcesses(
            dbsession)
        for georefProc in unprocessedGeorefProcs:
            dictProcessingQueueGeoref[georefProc.messtischblattid] = georefProc

        # get updated messtischblätter
        updatedMesstischblaetter = Messtischblatt.getUpdatedMesstischblaetter(
            dbsession)
        for messtischblatt in updatedMesstischblaetter:
            # if there is no process for this mtb in the dictProcessingQueueGeoref than get one and add it
            if not messtischblatt.id in dictProcessingQueueGeoref:
                georefProc = Georeferenzierungsprozess.getLatestGeorefProcessForObjectId(
                    messtischblatt.id, dbsession)
                # if georefProc is None there is no more georeference process and the map object
                # should be resetted
                if georefProc is None:
                    response['reset'].append(messtischblatt.id)
                else:
                    dictProcessingQueueGeoref[messtischblatt.id] = georefProc

        # sort the georeference process by timestamps
        for key in dictProcessingQueueGeoref:
            # get timestamp for the equivalent map object to the georeference process
            time = MdZeit.by_id(
                dictProcessingQueueGeoref[key].messtischblattid,
                dbsession).time.year
            if time in response['georeference']:
                response['georeference'][time].append(
                    dictProcessingQueueGeoref[key])
            else:
                response['georeference'][time] = [
                    dictProcessingQueueGeoref[key]
                ]
        return response
    except:
        logger.error(
            'Unknown error while trying to create the georeference processing queue ...'
        )
        raise
コード例 #4
0
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
コード例 #5
0
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
コード例 #6
0
ファイル: GeoreferenceConfirm.py プロジェクト: slub/vkviewer
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)
コード例 #7
0
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)
コード例 #8
0
def publishGeorefParameters(request):
    log.info('Request - Publish georeference result.')
    try:
        log.debug('Parse parameters ...')
        objectid = request.params['objectid']
        georeferenceid = request.params['georeferenceid']
        messtischblatt = Messtischblatt.by_id(objectid, request.db)
        georeferenceprocess = Georeferenzierungsprozess.by_id(
            georeferenceid, request.db)

        log.debug('Udpate parameters')
        georeferenceprocess.publish = True
        messtischblatt.updated = False

        return json.dumps(
            {
                'message':
                'The georeference process is now published. The georeference map will soon be updated and than ready for accessing.'
            },
            ensure_ascii=False,
            encoding='utf-8')
    except Exception as e:
        log.error(
            'Error while trying to request georeference history information')
        log.error(e)
        return {}
コード例 #9
0
def georeferenceGetProcess(request):
    log.info('Receive request GetGeoreferenceProcess')
    
    try:
        request_data = None
        if request.method == 'POST':
            request_data = request.json_body     
               
        if 'georeferenceid' in request_data:
            georeferenceid = int(request_data['georeferenceid'])
            log.debug('Parsed parameters - georeferenceid: %s'%georeferenceid)
            mapObj = Map.by_id(int(Georeferenzierungsprozess.by_id(georeferenceid, request.db).mapid), request.db)
            response = createResponseForSpecificGeoreferenceProcess(mapObj, request, georeferenceid)
        elif 'objectid' in request_data:
            mapObjId = request_data['objectid']
            log.debug('Parsed parameters - mapid: %s'%mapObjId)
            mapObj = Map.by_id(int(mapObjId), request.db)
            response = createGeneralResponse(mapObj, request)
        else:
            log.error('Could not find a georeferenceid or and objectid in the post request parameters ...')
            raise GeoreferenceParameterError
        return response    
    except GeoreferenceParameterError as e:
        log.error(e)
        log.error(traceback.format_exc())
        raise HTTPBadRequest(ERROR_MSG) 
    except ProcessIsInvalideException as e:
        log.error(e)
        log.error(traceback.format_exc())
        raise HTTPBadRequest('This georeference process is blocked for further work!')
    except Exception as e:
        log.error(e)
        log.error(traceback.format_exc())
        raise HTTPInternalServerError(ERROR_MSG)
コード例 #10
0
ファイル: GetPage.py プロジェクト: slub/vkviewer
def getGeoreferencePage(request):
    log.info('Call view getGeoreferencePage.')
    if 'id' in request.params:
        return {'objectid':request.params['id']}
    elif 'georeferenceid' in request.params:
        georefProcess = Georeferenzierungsprozess.by_id(request.params['georeferenceid'], request.db)
        return {'objectid':georefProcess.mapid}
コード例 #11
0
 def setUp(self):     
     self.config = testing.setUp()   
     self.config.registry.dbmaker = self.Session  
     
     # create dummy georefprocess
     self.notReferencedObjId = 10000023
     self.dummyProcess = Georeferenzierungsprozess(
                 mapsid = 10000023, 
                 messtischblattid = 90015724, 
                 nutzerid = login, 
                 clipparameter = "{'Test':'Test'}", 
                 timestamp = "2014-08-09 12:20:26", 
                 type = 'new', 
                 refzoomify = True,
                 isactive = True,
                 processed = False,
                 overwrites = 0,
                 adminvalidation = ''
     )
     self.dummyParams = {'georeference': 
             {'source': 'pixel', 'target': 'EPSG:4314', 'gcps': [
                     {'source': [467, 923], 'target': [10.6666660308838, 51.4000015258789]}, 
                     {'source': [7281, 999], 'target': [10.8333339691162, 51.4000015258789]}, 
                     {'source': [7224, 7432], 'target': [10.8333339691162, 51.2999992370605]},
                     {'source': [258, 7471], 'target': [10.6666660308838, 51.2999992370605]}]}, 
             'id': 10000023}
コード例 #12
0
def createResponseForSpecificGeoreferenceProcess(objectid, georeferenceid, request):
    log.debug('Create response for specific georeference process ...')
    messtischblatt = Messtischblatt.by_id(objectid, request.db)
    mtb_extent = Messtischblatt.getExtent(objectid, request.db)
    georeferenceprocess = Georeferenzierungsprozess.by_id(georeferenceid, request.db)
    pure_clipparameters = ast.literal_eval(str(georeferenceprocess.clipparameter))
    gcps = None
    if 'new' in pure_clipparameters:
        # in case of an update process
        gcps = pure_clipparameters['new']
    else:
        # in case of a new registered clip_parameter
        gcps = pure_clipparameters
          
    # get zoomify and metadata information
    log.debug('Create response ...')  
    metadata = MdCore.by_id(messtischblatt.id, request.db)
    return {
            'type':'update',
            'objectid': messtischblatt.id,
            'georeferenceid':georeferenceid, 
            'timestamp':str(georeferenceprocess.timestamp), 
            'gcps':gcps, 
            'extent': mtb_extent,
            'zoomify': {
                'properties': messtischblatt.zoomify_properties,
                'width': messtischblatt.zoomify_width,
                'height': messtischblatt.zoomify_height
            },
            'metadata': {
                'dateiname': messtischblatt.dateiname,
                'titel_long': metadata.titel,
                'titel_short': metadata.titel_short
            }            
    }
コード例 #13
0
ファイル: UpdateDataSource.py プロジェクト: JSchwzr/vkviewer
def getGeoreferenceProcessQueue(dbsession, logger):
    """ This functions build a georeference process queue. For this it looks for entries 
        in the georeference table with status unprocessed and extends it with georeference process
        for which the equivalent map object has status updated. 
        
        Arguments:
            dbsession {sqlalchemy.orm.session.Session}
            logger (Logger)
        Returns:
            dictionary where the key is a timestamp and the value a list object containing 
            tuple which contain orm mapper for the tables georeferenzierungsprozess and
            messtischblatt """
    try:
        # response object 
        response = { 'georeference':{}, 'reset': [] }
        
        # get unprocessed georeference process
        dictProcessingQueueGeoref = {}
        unprocessedGeorefProcs = Georeferenzierungsprozess.by_getUnprocessedGeorefProcesses(dbsession)
        for georefProc in unprocessedGeorefProcs:
            dictProcessingQueueGeoref[georefProc.messtischblattid] = georefProc
            
        # get updated messtischblätter
        updatedMesstischblaetter = Messtischblatt.getUpdatedMesstischblaetter(dbsession)
        for messtischblatt in updatedMesstischblaetter:
            # if there is no process for this mtb in the dictProcessingQueueGeoref than get one and add it
            if not messtischblatt.id in dictProcessingQueueGeoref:
                georefProc = Georeferenzierungsprozess.getLatestGeorefProcessForObjectId(messtischblatt.id, dbsession)
                # if georefProc is None there is no more georeference process and the map object 
                # should be resetted
                if georefProc is None:
                    response['reset'].append(messtischblatt.id)
                else:
                    dictProcessingQueueGeoref[messtischblatt.id] = georefProc
        
        # sort the georeference process by timestamps
        for key in dictProcessingQueueGeoref:
            # get timestamp for the equivalent map object to the georeference process
            time = MdZeit.by_id(dictProcessingQueueGeoref[key].messtischblattid, dbsession).time.year
            if time in response['georeference']:
                response['georeference'][time].append(dictProcessingQueueGeoref[key])
            else:
                response['georeference'][time] = [dictProcessingQueueGeoref[key]]
        return response
    except:
        logger.error('Unknown error while trying to create the georeference processing queue ...')
        raise        
コード例 #14
0
def georeferenceUpdate(request):
    log.info('Receive request for processing georeference update 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 exists a registered georeference process for this messtischblatt ...'
        )
        if Georeferenzierungsprozess.isGeoreferenced(mapObj.id,
                                                     request.db) == False:
            response = {
                'text':
                'There is no registered georeference process for this messtischblatt. Please move back to the confirm process.'
            }
            return response

        # actual only support this option if target srs is EPSG:4314
        log.debug('Saving georeference process in the database ...')
        if request_data['georeference']:
            encoded_clip_params = convertUnicodeDictToUtf(
                request_data['georeference'])
            georefProcess = registerUpdateGeoreferenceProcessInDb(
                mapObj, userid, str(encoded_clip_params), request.db)

            log.debug('Create response ...')
            # right now the premise is that for the updated gcps are equal to the removed gcps. For every
            # updated gcps the users get new points
            achievement_points = len(
                request_data['georeference']['remove']['gcps']) * 5
            response = {
                'text':
                'Georeference result updated. It will soon be ready for use.',
                'georeferenceid': georefProcess.id,
                'points': achievement_points,
                'gcps': request_data['georeference']['new'],
                'type': 'update'
            }
            return response
        else:
            log.error('The remove and new parameters are not valide - %s')
            raise GeoreferenceParameterError(
                'The remove and new parameters are not valide.')

    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)
コード例 #15
0
ファイル: GetPage.py プロジェクト: UAVE6MN/vkviewer
def getGeoreferencePage(request):
    log.info('Call view getGeoreferencePage.')
    if 'id' in request.params:
        return {'objectid': request.params['id']}
    elif 'georeferenceid' in request.params:
        georefProcess = Georeferenzierungsprozess.by_id(
            request.params['georeferenceid'], request.db)
        return {'objectid': georefProcess.mapid}
コード例 #16
0
ファイル: GeoreferenceUpdate.py プロジェクト: slub/vkviewer
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
コード例 #17
0
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
コード例 #18
0
ファイル: georeferenceupdate.py プロジェクト: slub/vkviewer
def runningNewJobs(dbsession, logger, testing = False):
    logger.info('Check for unprocessed georeference jobs ...')
    unprocessedJobs = Georeferenzierungsprozess.by_getUnprocessedGeorefProcessesTypeOfNew(dbsession)
    
    counterNew = 0
    for job in unprocessedJobs:
        logger.debug('Process a new georeference process with id - %s'%job.id)
        runNewGeoreferenceProcess(job, dbsession, logger, testing)
        counterNew += 1
    
    logger.debug('Processed %s new georeference process.'%counterNew)
コード例 #19
0
 def getDummyGeorefProcess(cls):
     return Georeferenzierungsprozess(
         messtischblattid=71055048,
         nutzerid='user',
         clipparameter=
         "{'source': 'pixel', 'target': 'EPSG:4314', 'gcps': [{'source': [451.0, 7662.0], 'target': [16.1666660308838, 50.2999992370605]}, {'source': [480.0, 1198.0], 'target': [16.1666660308838, 50.4000015258789]}, {'source': [7374.0, 1229.0], 'target': [16.3333339691162, 50.4000015258789]}, {'source': [7341.0, 7689.0], 'target': [16.3333339691162, 50.2999992370605]}]}",
         timestamp=getTimestampAsPGStr(),
         isvalide=True,
         type='new',
         refzoomify=True,
         publish=False,
         processed=False)
コード例 #20
0
def createGeneralResponse(objectid, request):
    log.debug('Create general response ...')
    lastGeoreferenceId = ''
    lastTimestamp = ''
    messtischblatt = Messtischblatt.by_id(objectid, request.db)
    mtb_extent = Messtischblatt.getExtent(objectid, request.db)
    isAlreadyGeorefProcess = Georeferenzierungsprozess.by_getLatestValidGeorefProcessForObjectId(
        messtischblatt.id, request.db)
    if isAlreadyGeorefProcess:
        return createResponseForSpecificGeoreferenceProcess(
            objectid, isAlreadyGeorefProcess.id, request)
    else:
        gcps = {
            'source':
            'pixel',
            'target':
            'EPSG:4314',
            'gcps': [{
                "source": [],
                "target": [mtb_extent[0], mtb_extent[1]]
            }, {
                "source": [],
                "target": [mtb_extent[0], mtb_extent[3]]
            }, {
                "source": [],
                "target": [mtb_extent[2], mtb_extent[1]]
            }, {
                "source": [],
                "target": [mtb_extent[2], mtb_extent[3]]
            }]
        }

        # get zoomify and metadata information
        log.debug('Create response ...')
        metadata = MdCore.by_id(messtischblatt.id, request.db)
        return {
            'type': 'new',
            'objectid': messtischblatt.id,
            'georeferenceid': lastGeoreferenceId,
            'timestamp': str(lastTimestamp),
            'gcps': gcps,
            'extent': mtb_extent,
            'zoomify': {
                'properties': messtischblatt.zoomify_properties,
                'width': messtischblatt.zoomify_width,
                'height': messtischblatt.zoomify_height
            },
            'metadata': {
                'dateiname': messtischblatt.dateiname,
                'titel_long': metadata.titel,
                'titel_short': metadata.titel_short
            }
        }
コード例 #21
0
def runningNewJobs(dbsession, logger, testing=False):
    logger.info('Check for unprocessed georeference jobs ...')
    unprocessedJobs = Georeferenzierungsprozess.by_getUnprocessedGeorefProcessesTypeOfNew(
        dbsession)

    counterNew = 0
    for job in unprocessedJobs:
        logger.debug('Process a new georeference process with id - %s' %
                     job.id)
        runNewGeoreferenceProcess(job, dbsession, logger, testing)
        counterNew += 1

    logger.debug('Processed %s new georeference process.' % counterNew)
コード例 #22
0
ファイル: georeferenceupdate.py プロジェクト: slub/vkviewer
def runningUpdateJobs(dbsession, logger, testing = False):
    logger.info('Fetch overwrite id for unprocessed georeference jobs ...')
    overwrites = Georeferenzierungsprozess.by_getOverwriteIdsOfUnprocessedGeorefProcessesTypeOfUpdate(dbsession)
                 
    counter = 0
    # clear all unnecessary overwrites and run update process for the actual process
    for overwrite in overwrites:
        # check if there is an old race conflict
        if not clearRaceConflicts(overwrite, dbsession):
            counter += 1
            jobs = Georeferenzierungsprozess.getJobsWithSameOverwrites(overwrite, dbsession)
            pendingJob = None
            for job in jobs:
                if pendingJob is None:
                    pendingJob = job
                else:
                    dbsession.delete(job)
                    
            logger.debug('Process a update georeference process with id - %s'%job.id)
            runUpdateGeoreferenceProcess(pendingJob, dbsession, logger, testing)
    
    logger.debug('Processed %s update georeference process.'%counter)
コード例 #23
0
def georeferenceUpdate(request):
    log.info('Receive request for processing georeference update result')
    
    try:
        userid = checkIsUser(request)
        
        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('Check if there exists a registered georeference process for this messtischblatt ...')
        messtischblatt = Messtischblatt.by_id(request_data['id'], request.db)
        isAlreadyGeorefProcess = Georeferenzierungsprozess.by_messtischblattid(messtischblatt.id, request.db)
        if isAlreadyGeorefProcess is None:
            response = {'text':'There is no registered georeference process for this messtischblatt. Please move back to the confirm process.'}
            return json.dumps(response, ensure_ascii=False, encoding='utf-8')        
        
        # actual only support this option if target srs is EPSG:4314
        log.debug('Saving georeference process in the database ...')
        if request_data['georeference']:
            encoded_clip_params = convertUnicodeDictToUtf(request_data['georeference'])
            georefProcess = registerNewGeoreferenceProcessInDb(messtischblatt.id, userid, str(encoded_clip_params), 'update', request.db)
            
            log.debug('Set update status for messtischblatt ...')
            messtischblatt.setIsUpdated(True)
            
            log.debug('Create response ...')
            # right now the premise is that for the updated gcps are equal to the removed gcps. For every
            # updated gcps the users get new points
            achievement_points = len(request_data['georeference']['remove']['gcps'])*5  
            #gcps = getJsonDictPasspointsForMapObject(messtischblatt.id, request.db)
            response = {'text':'Georeference result updated. It will soon be ready for use.','georeferenceid':georefProcess.id, 'points':achievement_points, 
                        'gcps':request_data['georeference']['new'] ,'type':'update'}
            return json.dumps(response, ensure_ascii=False, encoding='utf-8') 
        else:
            log.error('The remove and new parameters are not valide - %s')
            raise GeoreferenceParameterError('The remove and new parameters are not valide.')
      
        
    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
        log.error(message)
        return HTTPInternalServerError(message)
コード例 #24
0
ファイル: adminjobs.py プロジェクト: UAVE6MN/vkviewer
def getLastValidGeoreferenceProcess(overwritesId, dbsession, logger):
    """ This function goes down the overwrite chain and looks for the last valid
        georeference process
        
        @param Integer: job
        @param sqlalchemy.orm.session.Session: dbsession
        @param logging.Logger: logger
    """ 
    georefProcess = Georeferenzierungsprozess.by_id(overwritesId, dbsession)
    if georefProcess.adminvalidation == 'isvalide' or georefProcess.adminvalidation == '':
        return georefProcess
    elif georefProcess.overwrites > 0:
        return getLastValidGeoreferenceProcess(georefProcess.overwrites, dbsession, logger)
    else:
        return None
コード例 #25
0
 def confirmExistingGeoreferenceProcess(self, georefid, isvalide=False, typeValidation='user'):
         # get georef data from database and parse them
         georefProc = Georeferenzierungsprozess.by_id(georefid, self.dbsession)
         
         # change valdation status of georeference process in database
         georefProc.isvalide = isvalide
         georefProc.typevalidierung = typeValidation
         self.dbsession.flush()
         self.logger.debug("Change validation status of georeference process with id %s!"%georefid)
         
         # register passpunkte
         #self.updatePasspunkte(georefProc)
         #self.dbSession.commit()
         #self.logger.info("Ground control points for georeference process with id %s registered!"%georefid)
         return georefid       
コード例 #26
0
    def testRunningResetJobs(self):
        print "--------------------------------------------------------------------------------------------"
        print "\n"
        print "Test if runningResetJobs runs correctly ..."

        dbsession = loadDbSession(DBCONFIG_PARAMS, self.logger)
        response = runningResetJobs(dbsession, self.logger, True)

        # check if the reset functions
        resetJobs = Georeferenzierungsprozess.getResetJobs(dbsession)
        counter = 0
        for job in resetJobs:
            counter += 1
        self.assertTrue(counter == 0, 'There are unprocessed reset jobs ...')

        dbsession.rollback()
コード例 #27
0
def registerNewGeoreferenceProcessInDb(objectid, userid, gcps, type,
                                       dbsession):
    log.debug('Create georeference process record ...')
    timestamp = getTimestampAsPGStr()
    georefProcess = Georeferenzierungsprozess(messtischblattid=objectid,
                                              nutzerid=userid,
                                              clipparameter=gcps,
                                              timestamp=timestamp,
                                              isvalide=True,
                                              type=type,
                                              refzoomify=True,
                                              publish=False,
                                              processed=False)
    dbsession.add(georefProcess)
    dbsession.flush()
    return georefProcess
コード例 #28
0
 def testRunningResetJobs(self):
     print "--------------------------------------------------------------------------------------------"
     print "\n"
     print "Test if runningResetJobs runs correctly ..." 
     
     dbsession = loadDbSession(DBCONFIG_PARAMS, self.logger)      
     response = runningResetJobs(dbsession, self.logger, True)
     
     # check if the reset functions
     resetJobs = Georeferenzierungsprozess.getResetJobs(dbsession)
     counter = 0
     for job in resetJobs:
         counter += 1
     self.assertTrue(counter == 0, 'There are unprocessed reset jobs ...')
     
     dbsession.rollback()
コード例 #29
0
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)
コード例 #30
0
def createGeneralResponse(mapObj, request):
    log.debug('Create general response ...')

    isAlreadyGeorefProcess = Georeferenzierungsprozess.isGeoreferenced(
        mapObj.id, request.db)
    if isAlreadyGeorefProcess:
        return createResponseForSpecificGeoreferenceProcess(mapObj, request)
    else:
        mtb_extent = Map.getExtent(mapObj.id, request.db)
        gcps = {
            'source':
            'pixel',
            'target':
            'EPSG:4314',
            'gcps': [{
                "source": [],
                "target": [mtb_extent[0], mtb_extent[1]]
            }, {
                "source": [],
                "target": [mtb_extent[0], mtb_extent[3]]
            }, {
                "source": [],
                "target": [mtb_extent[2], mtb_extent[1]]
            }, {
                "source": [],
                "target": [mtb_extent[2], mtb_extent[3]]
            }]
        }

        # get zoomify and metadata information
        log.debug('Create response ...')
        metadata = Metadata.by_id(mapObj.id, request.db)
        return {
            'type': 'new',
            'objectid': mapObj.id,
            'georeferenceid': "",
            'timestamp': "",
            'gcps': gcps,
            'extent': mtb_extent,
            'zoomify': metadata.imagezoomify,
            'metadata': {
                'dateiname': mapObj.apsdateiname,
                'titel_long': metadata.title,
                'titel_short': metadata.titleshort
            }
        }
コード例 #31
0
def publishGeorefParameters(request):
    log.info('Request - Publish georeference result.')
    try:
        log.debug('Parse parameters ...')            
        objectid = request.params['objectid']
        georeferenceid = request.params['georeferenceid']
        messtischblatt = Messtischblatt.by_id(objectid, request.db)
        georeferenceprocess = Georeferenzierungsprozess.by_id(georeferenceid, request.db)
        
        log.debug('Udpate parameters')
        georeferenceprocess.publish = True
        messtischblatt.updated = False
        
        return json.dumps({'message':'The georeference process is now published. The georeference map will soon be updated and than ready for accessing.'}, ensure_ascii=False, encoding='utf-8')  
    except Exception as e:
        log.error('Error while trying to request georeference history information');
        log.error(e)
        return {}
コード例 #32
0
def deleteGeorefParameters(request):
    log.info('Request - Delete georeference result.')
    try:           
        # remove georeference process
        georeferenceid = request.params['georeferenceid']
        georeferenceprocess = Georeferenzierungsprozess.by_id(georeferenceid, request.db)
        messtischblattid = georeferenceprocess.messtischblattid
        request.db.delete(georeferenceprocess)
        
        # mark the messtischblatt as updated
        messtischblatt = Messtischblatt.by_id(messtischblattid, request.db)
        messtischblatt.udpated = True
                
        return json.dumps({'message':'The georeference process has been removed.'}, ensure_ascii=False, encoding='utf-8') 
    except Exception as e:
        log.error('Error while trying to request georeference history information');
        log.error(e)
        return {}
コード例 #33
0
ファイル: georeferenceupdate.py プロジェクト: slub/vkviewer
def clearRaceConflicts(overwrite, dbsession):
    # double check if there are jobs which should be deleted
    # this clears the case that while there was on job activated in the past
    # there was still because of concurrency another jobs registered with the same
    # overwrites id
    possibleConflictJobs = Georeferenzierungsprozess.getJobsWithSameOverwrites(overwrite, dbsession)

    alreadyActiveJob = None
    for conflictJob in possibleConflictJobs:
        if conflictJob.isactive == True:
            alreadyActiveJob = conflictJob
            
    if alreadyActiveJob is not None:
        for conflictJob in possibleConflictJobs:
            if conflictJob.id != alreadyActiveJob.id:
                dbsession.delete(conflictJob)  
        return True
    return False
コード例 #34
0
ファイル: GeoreferenceUpdate.py プロジェクト: slub/vkviewer
def georeferenceUpdate(request):
    log.info('Receive request for processing georeference update 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 exists a registered georeference process for this messtischblatt ...')
        if Georeferenzierungsprozess.isGeoreferenced(mapObj.id, request.db) == False:
            response = {'text':'There is no registered georeference process for this messtischblatt. Please move back to the confirm process.'}
            return response
        
        # actual only support this option if target srs is EPSG:4314
        log.debug('Saving georeference process in the database ...')
        if request_data['georeference']:
            encoded_clip_params = convertUnicodeDictToUtf(request_data['georeference'])
            georefProcess = registerUpdateGeoreferenceProcessInDb(mapObj, userid, str(encoded_clip_params), request.db)
            
            log.debug('Create response ...')
            # right now the premise is that for the updated gcps are equal to the removed gcps. For every
            # updated gcps the users get new points
            achievement_points = len(request_data['georeference']['remove']['gcps'])*5  
            response = {'text':'Georeference result updated. It will soon be ready for use.','georeferenceid':georefProcess.id, 'points':achievement_points, 
                        'gcps':request_data['georeference']['new'] ,'type':'update'}
            return response
        else:
            log.error('The remove and new parameters are not valide - %s')
            raise GeoreferenceParameterError('The remove and new parameters are not valide.')
      
        
    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)
コード例 #35
0
def georeferenceGetProcess(request):
    log.info('Receive request GetGeoreferenceProcess')

    try:
        request_data = None
        if request.method == 'POST':
            request_data = request.json_body

        if 'georeferenceid' in request_data:
            georeferenceid = int(request_data['georeferenceid'])
            log.debug('Parsed parameters - georeferenceid: %s' %
                      georeferenceid)
            mapObj = Map.by_id(
                int(
                    Georeferenzierungsprozess.by_id(georeferenceid,
                                                    request.db).mapid),
                request.db)
            response = createResponseForSpecificGeoreferenceProcess(
                mapObj, request, georeferenceid)
        elif 'objectid' in request_data:
            mapObjId = request_data['objectid']
            log.debug('Parsed parameters - mapid: %s' % mapObjId)
            mapObj = Map.by_id(int(mapObjId), request.db)
            response = createGeneralResponse(mapObj, request)
        else:
            log.error(
                'Could not find a georeferenceid or and objectid in the post request parameters ...'
            )
            raise GeoreferenceParameterError
        return response
    except GeoreferenceParameterError as e:
        log.error(e)
        log.error(traceback.format_exc())
        raise HTTPBadRequest(ERROR_MSG)
    except ProcessIsInvalideException as e:
        log.error(e)
        log.error(traceback.format_exc())
        raise HTTPBadRequest(
            'This georeference process is blocked for further work!')
    except Exception as e:
        log.error(e)
        log.error(traceback.format_exc())
        raise HTTPInternalServerError(ERROR_MSG)
コード例 #36
0
def clearRaceConflicts(overwrite, dbsession):
    # double check if there are jobs which should be deleted
    # this clears the case that while there was on job activated in the past
    # there was still because of concurrency another jobs registered with the same
    # overwrites id
    possibleConflictJobs = Georeferenzierungsprozess.getJobsWithSameOverwrites(
        overwrite, dbsession)

    alreadyActiveJob = None
    for conflictJob in possibleConflictJobs:
        if conflictJob.isactive == True:
            alreadyActiveJob = conflictJob

    if alreadyActiveJob is not None:
        for conflictJob in possibleConflictJobs:
            if conflictJob.id != alreadyActiveJob.id:
                dbsession.delete(conflictJob)
        return True
    return False
コード例 #37
0
ファイル: updatejobs.py プロジェクト: slub/vkviewer
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)    
コード例 #38
0
def createGeneralResponse(objectid, request):
    log.debug('Create general response ...')
    lastGeoreferenceId = ''
    lastTimestamp = ''
    messtischblatt = Messtischblatt.by_id(objectid, request.db)
    mtb_extent = Messtischblatt.getExtent(objectid, request.db)
    isAlreadyGeorefProcess = Georeferenzierungsprozess.by_getLatestValidGeorefProcessForObjectId(messtischblatt.id, request.db)
    if isAlreadyGeorefProcess:
        return createResponseForSpecificGeoreferenceProcess(objectid, isAlreadyGeorefProcess.id, request)
    else: 
        gcps = {
            'source':'pixel',
            'target':'EPSG:4314',
            'gcps': [
                {"source":[], "target":[mtb_extent[0],mtb_extent[1]]},
                {"source":[], "target":[mtb_extent[0],mtb_extent[3]]},
                {"source":[], "target":[mtb_extent[2],mtb_extent[1]]},
                {"source":[], "target":[mtb_extent[2],mtb_extent[3]]}
            ]
        }
            
        # get zoomify and metadata information
        log.debug('Create response ...')  
        metadata = MdCore.by_id(messtischblatt.id, request.db)
        return {
                'type':'new',
                'objectid': messtischblatt.id,
                'georeferenceid':lastGeoreferenceId, 
                'timestamp':str(lastTimestamp), 
                'gcps':gcps, 
                'extent': mtb_extent,
                'zoomify': {
                    'properties': messtischblatt.zoomify_properties,
                    'width': messtischblatt.zoomify_width,
                    'height': messtischblatt.zoomify_height
                },
                'metadata': {
                    'dateiname': messtischblatt.dateiname,
                    'titel_long': metadata.titel,
                    'titel_short': metadata.titel_short
                }            
        }
コード例 #39
0
def deleteGeorefParameters(request):
    log.info("Request - Delete georeference result.")
    try:
        # remove georeference process
        georeferenceid = request.params["georeferenceid"]
        georeferenceprocess = Georeferenzierungsprozess.by_id(georeferenceid, request.db)
        messtischblattid = georeferenceprocess.messtischblattid
        request.db.delete(georeferenceprocess)

        # mark the messtischblatt as updated
        messtischblatt = Messtischblatt.by_id(messtischblattid, request.db)
        messtischblatt.udpated = True

        return json.dumps(
            {"message": "The georeference process has been removed."}, ensure_ascii=False, encoding="utf-8"
        )
    except Exception as e:
        log.error("Error while trying to request georeference history information")
        log.error(e)
        return {}
コード例 #40
0
    def confirmExistingGeoreferenceProcess(self,
                                           georefid,
                                           isvalide=False,
                                           typeValidation='user'):
        # get georef data from database and parse them
        georefProc = Georeferenzierungsprozess.by_id(georefid, self.dbsession)

        # change valdation status of georeference process in database
        georefProc.isvalide = isvalide
        georefProc.typevalidierung = typeValidation
        self.dbsession.flush()
        self.logger.debug(
            "Change validation status of georeference process with id %s!" %
            georefid)

        # register passpunkte
        #self.updatePasspunkte(georefProc)
        #self.dbSession.commit()
        #self.logger.info("Ground control points for georeference process with id %s registered!"%georefid)
        return georefid
コード例 #41
0
 def registerGeoreferenceProcess(self,
                                 messtischblattid,
                                 userid=None,
                                 clipParams=None,
                                 isvalide=False,
                                 typeValidation='none',
                                 refzoomify=True):
     # get timestamp
     timestamp = getTimestampAsPGStr()
     georefProcess = Georeferenzierungsprozess(
         messtischblattid=messtischblattid,
         nutzerid=userid,
         clipparameter=clipParams,
         timestamp=timestamp,
         isvalide=isvalide,
         typevalidierung='user',
         refzoomify=refzoomify)
     self.dbsession.add(georefProcess)
     self.dbsession.flush()
     return georefProcess
コード例 #42
0
def setProcessToIsValide(request):
    log.info('Request - Set admin evaluation of georeference process to isvalide ....')
    try:           
        # remove georeference process
        if 'georeferenceid' in request.params:
            georeferenceid = request.params['georeferenceid']
            userid = checkIsUser(request)
            comment = '' if 'comment' not in request.params else request.params['comment']
            
            # check if georeference id exist
            georeferenceprocess = Georeferenzierungsprozess.by_id(georeferenceid, request.db)
            if georeferenceprocess:
                newJob = createNewAdminJob(georeferenceprocess, 'isvalide', userid, comment)
                request.db.add(newJob)
                
            return {'message':'The georeference process has been set to isvalide.'}
        else:
            raise Exception('Missing parameter (georeferenceid) ...')
    except Exception as e:
        log.error(e)
        log.error(traceback.format_exc())
        return HTTPBadRequest(GENERAL_ERROR_MESSAGE);
コード例 #43
0
ファイル: adminjobs.py プロジェクト: UAVE6MN/vkviewer
def setInValide(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)
    
    # update map object and datasource
    mapObj = Map.by_id(georefProcess.mapid, dbsession)
    if georefProcess.isactive == True and georefProcess.overwrites > 0:
        logger.info('Deactive georeference process and activate georeference process with id %s ...'%georefProcess.overwrites)
        
        # deactive the georeference process
        deactivate(georefProcess, mapObj, dbsession, logger)
            
        # look if there is a valid overwrite id and if yes activate the matching 
        # process
        newGeorefProcess = getLastValidGeoreferenceProcess(georefProcess.overwrites, dbsession, logger)
        if newGeorefProcess:
            activate(newGeorefProcess, mapObj, dbsession, logger)   
            
    elif georefProcess.isactive == True and georefProcess.overwrites == 0:
        logger.info('Deactive georeference process %s ...'%georefProcess.overwrites)
        
        # deactive the georeference process
        deactivate(georefProcess, mapObj, dbsession, logger)
        
    logger.debug('Set georeference process with id %s to inactive ...'%georefProcess.overwrites)        
    if georefProcess.adminvalidation != 'invalide':
        georefProcess.adminvalidation = 'invalide'
        mapObj.hasgeorefparams = 0 if mapObj.hasgeorefparams - 1 < 0 else mapObj.hasgeorefparams - 1
コード例 #44
0
def createResponseForSpecificGeoreferenceProcess(objectid, georeferenceid,
                                                 request):
    log.debug('Create response for specific georeference process ...')
    messtischblatt = Messtischblatt.by_id(objectid, request.db)
    mtb_extent = Messtischblatt.getExtent(objectid, request.db)
    georeferenceprocess = Georeferenzierungsprozess.by_id(
        georeferenceid, request.db)
    pure_clipparameters = ast.literal_eval(
        str(georeferenceprocess.clipparameter))
    gcps = None
    if 'new' in pure_clipparameters:
        # in case of an update process
        gcps = pure_clipparameters['new']
    else:
        # in case of a new registered clip_parameter
        gcps = pure_clipparameters

    # get zoomify and metadata information
    log.debug('Create response ...')
    metadata = MdCore.by_id(messtischblatt.id, request.db)
    return {
        'type': 'update',
        'objectid': messtischblatt.id,
        'georeferenceid': georeferenceid,
        'timestamp': str(georeferenceprocess.timestamp),
        'gcps': gcps,
        'extent': mtb_extent,
        'zoomify': {
            'properties': messtischblatt.zoomify_properties,
            'width': messtischblatt.zoomify_width,
            'height': messtischblatt.zoomify_height
        },
        'metadata': {
            'dateiname': messtischblatt.dateiname,
            'titel_long': metadata.titel,
            'titel_short': metadata.titel_short
        }
    }
コード例 #45
0
def createGeneralResponse(mapObj, request):
    log.debug('Create general response ...')
    
    isAlreadyGeorefProcess = Georeferenzierungsprozess.isGeoreferenced(mapObj.id, request.db)
    if isAlreadyGeorefProcess:
        return createResponseForSpecificGeoreferenceProcess(mapObj, request)
    else: 
        mtb_extent = Map.getExtent(mapObj.id, request.db)
        gcps = {
            'source':'pixel',
            'target':'EPSG:4314',
            'gcps': [
                {"source":[], "target":[mtb_extent[0],mtb_extent[1]]},
                {"source":[], "target":[mtb_extent[0],mtb_extent[3]]},
                {"source":[], "target":[mtb_extent[2],mtb_extent[1]]},
                {"source":[], "target":[mtb_extent[2],mtb_extent[3]]}
            ]
        }
            
        # get zoomify and metadata information
        log.debug('Create response ...')  
        metadata = Metadata.by_id(mapObj.id, request.db)
        return {
                'type':'new',
                'objectid': mapObj.id,
                'georeferenceid':"", 
                'timestamp':"", 
                'gcps':gcps, 
                'extent': mtb_extent,
                'zoomify': metadata.imagezoomify,
                'metadata': {
                    'dateiname': mapObj.apsdateiname,
                    'titel_long': metadata.title,
                    'titel_short': metadata.titleshort
                }            
        }
コード例 #46
0
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)
コード例 #47
0
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)
コード例 #48
0
def georeferenceUpdate(request):
    log.info('Receive request for processing georeference update result')

    try:
        userid = checkIsUser(request)

        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(
            'Check if there exists a registered georeference process for this messtischblatt ...'
        )
        messtischblatt = Messtischblatt.by_id(request_data['id'], request.db)
        isAlreadyGeorefProcess = Georeferenzierungsprozess.by_messtischblattid(
            messtischblatt.id, request.db)
        if isAlreadyGeorefProcess is None:
            response = {
                'text':
                'There is no registered georeference process for this messtischblatt. Please move back to the confirm process.'
            }
            return json.dumps(response, ensure_ascii=False, encoding='utf-8')

        # actual only support this option if target srs is EPSG:4314
        log.debug('Saving georeference process in the database ...')
        if request_data['georeference']:
            encoded_clip_params = convertUnicodeDictToUtf(
                request_data['georeference'])
            georefProcess = registerNewGeoreferenceProcessInDb(
                messtischblatt.id, userid, str(encoded_clip_params), 'update',
                request.db)

            log.debug('Set update status for messtischblatt ...')
            messtischblatt.setIsUpdated(True)

            log.debug('Create response ...')
            # right now the premise is that for the updated gcps are equal to the removed gcps. For every
            # updated gcps the users get new points
            achievement_points = len(
                request_data['georeference']['remove']['gcps']) * 5
            #gcps = getJsonDictPasspointsForMapObject(messtischblatt.id, request.db)
            response = {
                'text':
                'Georeference result updated. It will soon be ready for use.',
                'georeferenceid': georefProcess.id,
                'points': achievement_points,
                'gcps': request_data['georeference']['new'],
                'type': 'update'
            }
            return json.dumps(response, ensure_ascii=False, encoding='utf-8')
        else:
            log.error('The remove and new parameters are not valide - %s')
            raise GeoreferenceParameterError(
                'The remove and new parameters are not valide.')

    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
        log.error(message)
        return HTTPInternalServerError(message)
コード例 #49
0
def georeferenceConfirm(request):
    log.info('Receive request for processing georeference validation result')

    try:
        userid = checkIsUser(request)
        user = Users.by_username(userid, request.db)
        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(
            'Check if there is already a registered georeference process for this messtischblatt ...'
        )
        messtischblatt = Messtischblatt.by_id(request_data['id'], request.db)
        isAlreadyGeorefProcess = Georeferenzierungsprozess.by_messtischblattid(
            messtischblatt.id, request.db)
        if isAlreadyGeorefProcess is not None:
            response = {
                'text':
                'There is already a registered georeference process for this messtischblatt. Please move forward to the update process.',
                'georeferenceid': isAlreadyGeorefProcess.id
            }
            return json.dumps(response, ensure_ascii=False, encoding='utf-8')

        # 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=messtischblatt.id,
                nutzerid=userid,
                clipparameter=georeference_parameter,
                timestamp=timestamp,
                isvalide=True,
                type='new',
                refzoomify=True,
                publish=False,
                processed=False)
            request.db.add(georefProcess)
            request.db.flush()

            log.debug('Creating passpoints ...')
            #             gcps = request_data['georeference']['gcps']
            #             passpoints = []
            #             for i in range(0,len(gcps)):
            #                 unrefPoint = [gcps[i]['source'][0],gcps[i]['source'][1]]
            #                 refPoint = 'POINT(%s %s)'%(gcps[i]['target'][0], gcps[i]['target'][1])
            #                 passpoint = Passpoint(objectid = messtischblatt.id, userid = user.id, unrefpoint = unrefPoint,
            #                                       refpoint = refPoint, deprecated = False, timestamp = timestamp, georeferenceprocessid =  georefProcess.id)
            #                 request.db.add(passpoint)
            #                 passpoints.append(passpoints)

            log.debug('Create response ...')
            ##gcps = getJsonDictPasspointsForMapObject(messtischblatt.id, request.db)
            response = {
                'text':
                'Georeference result saved. It will soon be ready for use.',
                'georeferenceid': georefProcess.id,
                'points': 20,
                'gcps': request_data['georeference'],
                'type': 'confirm'
            }
            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
        log.error(message)
        return HTTPInternalServerError(message)
コード例 #50
0
def georeferenceConfirm(request):
    log.info('Receive request for processing georeference validation result')
    
    try:
        userid = checkIsUser(request)
        user = Users.by_username(userid, request.db)
        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('Check if there is already a registered georeference process for this messtischblatt ...')
        messtischblatt = Messtischblatt.by_id(request_data['id'], request.db)
        isAlreadyGeorefProcess = Georeferenzierungsprozess.by_messtischblattid(messtischblatt.id, request.db)
        if isAlreadyGeorefProcess is not None:
            response = {'text':'There is already a registered georeference process for this messtischblatt. Please move forward to the update process.','georeferenceid':isAlreadyGeorefProcess.id}
            return json.dumps(response, ensure_ascii=False, encoding='utf-8')        
        
        # 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 = messtischblatt.id, nutzerid = userid, 
                clipparameter = georeference_parameter, timestamp = timestamp, isvalide = True, type = 'new', refzoomify = True, publish = False, processed = False)
            request.db.add(georefProcess)
            request.db.flush()
            
            log.debug('Creating passpoints ...')
#             gcps = request_data['georeference']['gcps']
#             passpoints = []
#             for i in range(0,len(gcps)):
#                 unrefPoint = [gcps[i]['source'][0],gcps[i]['source'][1]]
#                 refPoint = 'POINT(%s %s)'%(gcps[i]['target'][0], gcps[i]['target'][1])
#                 passpoint = Passpoint(objectid = messtischblatt.id, userid = user.id, unrefpoint = unrefPoint,
#                                       refpoint = refPoint, deprecated = False, timestamp = timestamp, georeferenceprocessid =  georefProcess.id)
#                 request.db.add(passpoint)
#                 passpoints.append(passpoints)
                
            log.debug('Create response ...')  
            ##gcps = getJsonDictPasspointsForMapObject(messtischblatt.id, request.db)
            response = {'text':'Georeference result saved. It will soon be ready for use.','georeferenceid':georefProcess.id, 'points':20,
                         'gcps':request_data['georeference'] ,'type':'confirm'}
            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
        log.error(message)
        return HTTPInternalServerError(message)