Beispiel #1
0
def getTimestampsForId(request):
    """ Returns a json document which contains a a list of messtischblatt tuples which
        have the same blattnumber like the given object. """
    try:
        log.info('Receive request for timestamps for a given object number.')
        dbsession = request.db
        object_id = request.GET.get('id')
        metadataObj = Metadata.by_id(object_id, dbsession)
        spatial_relation_objects = VBlattschnittMtb.allForBlattnr(
            metadataObj.blattnr, dbsession)

        #create response
        response = []
        for rel_object in spatial_relation_objects:
            if rel_object.isttransformiert:
                response.append({
                    'id':
                    rel_object.mapid,
                    'time':
                    rel_object.time,
                    'extent':
                    Map.getExtent(rel_object.map, dbsession, DATABASE_SRID)
                })
        return {'maps': response}
    except DBAPIError as e:
        log.error(e)
        log.error(traceback.format_exc())
        raise HTTPInternalServerError(GENERAL_ERROR_MESSAGE)
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 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
            }
        }
def georeferenceValidation(request):
    log.info('Receive request for processing georeference validation result')
    
    try:
        request_data = None
        if request.method == 'POST':
            request_data = request.json_body
          
        mapObj = parseMapObjForId(request_data, 'id', request.db)
        log.debug('Id is valide: %s'%request_data)
                      
        log.debug('Start creating validation result ...')
        # actual only support this option if target srs is EPSG:4314
        epsg_code = int(str(request_data['georeference']['target']).split(':')[1])
        if request_data['georeference']['source'] == 'pixel' and epsg_code == 4314:
            log.debug('Parse gcps ...')
            gcps = parseGcps(request_data['georeference']['gcps'])
            
            log.debug('Process georeference parameter ...')
            destPath = georeference(mapObj.originalimage, os.path.join(GEOREFERENCE_MAPFILE_FOLDER,mapObj.apsdateiname+"::"+str(getUniqueId())+".vrt"), 
                         GEOREFERENCE_TMP_DIR, gcps, epsg_code, epsg_code, 'polynom', log)
        
            log.debug('Create temporary mapfile ...')
            wms_url = createMapfile(mapObj.apsdateiname, destPath, GEOREFERENCE_MAPFILE_TEMPLATE, GEOREFERENCE_MAPFILE_FOLDER, GEOREFERENCE_MAPFILE_DEFAULT_PARAMS)
            
            log.debug('Create response ...')  
            response = {'wms_url':wms_url,'layer_id':mapObj.apsdateiname,'extent':Map.getExtent(mapObj.id, request.db)}
            return response 
        else:
            raise GeoreferenceParameterError('Wrong or missing service parameter')
    except GeoreferenceParameterError as e:
        log.error(e)
        log.error(traceback.format_exc())
        raise HTTPBadRequest(ERROR_MSG) 
    except Exception as e:
        log.error(e)
        log.error(traceback.format_exc())
        raise HTTPInternalServerError(ERROR_MSG)
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
                }            
        }
Beispiel #7
0
def getTimestampsForId(request):
    """ Returns a json document which contains a a list of messtischblatt tuples which
        have the same blattnumber like the given object. """
    try:
        log.info('Receive request for timestamps for a given object number.')
        dbsession = request.db
        object_id = request.GET.get('id')
        metadataObj = Metadata.by_id(object_id, dbsession)
        spatial_relation_objects = VBlattschnittMtb.allForBlattnr(metadataObj.blattnr, dbsession)
        
        #create response
        response = []
        for rel_object in spatial_relation_objects:
            if rel_object.isttransformiert:
                response.append({'id':rel_object.mapid,'time':rel_object.time,'extent': Map.getExtent(rel_object.map, dbsession, DATABASE_SRID)})
        return {'maps':response}
    except DBAPIError as e:
        log.error(e)
        log.error(traceback.format_exc())
        raise HTTPInternalServerError(GENERAL_ERROR_MESSAGE)