Esempio n. 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')
        object = Messtischblatt.by_id(object_id, dbsession)
        spatial_relation_objects = Messtischblatt.allForBlattnr(
            object.blattnr, dbsession)
        response = []
        for rel_object in spatial_relation_objects:
            if rel_object.isttransformiert:
                time = MdZeit.by_id(rel_object.id, dbsession).datierung
                response.append({
                    'id':
                    rel_object.id,
                    'time':
                    time,
                    'extent':
                    Messtischblatt.getExtent(rel_object.id, dbsession)
                })
        return json.dumps({'maps': response},
                          ensure_ascii=False,
                          encoding='utf-8')
    except DBAPIError:
        return Response(conn_err_msg,
                        content_type='text/plain',
                        status_int=500)
Esempio n. 2
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
            }            
    }
Esempio n. 3
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
            }
        }
Esempio n. 4
0
def getPage_profileMtb(request):
    try:
        messtischblatt_id = None
        if "objectid" in request.params:
            messtischblatt_id = request.params["objectid"]
            log.info("Receive get map profile page for id %s." % messtischblatt_id)

        georef = False
        if "georef" in request.params and request.params["georef"].lower() == "true":
            georef = True

        if georef:
            permalink = createPermalink(request, messtischblatt_id)
            return HTTPFound(location=permalink)

        messtischblatt = Messtischblatt.by_id(messtischblatt_id, request.db)
        metadata = MdCore.by_id(messtischblatt.id, request.db)
        metadata_datensatz = MdDatensatz.by_ObjectId(messtischblatt.id, request.db)
        return {
            "zoomify_prop": messtischblatt.zoomify_properties,
            "zoomify_width": messtischblatt.zoomify_width,
            "zoomify_height": messtischblatt.zoomify_height,
            "key": "vk20-md-%s" % messtischblatt.id,
            "titel_long": metadata.titel,
            "titel_short": metadata.titel_short,
            "permalink": metadata_datensatz.permalink,
        }
    except:
        log.error(
            "Internal server error while trying to get profile page. Please try again or contact the page administrator."
        )
        raise InternalAuthentificationError(
            "Internal server error while trying to get profile page. Please try again or contact the page administrator."
        )
Esempio n. 5
0
def updateDataSources(dbsession, database_params, vrt_target_dir, tmp_dir, cache_dir, logger, testing = True):   
    
    logger.info('Get georeference processing queue ...')
    processingQueue = getGeoreferenceProcessQueue(dbsession, logger)

    logger.info('Reset objects ...')
    for objectId in processingQueue['reset']:
        logger.info('Reset object with id %s ...'%objectId)
        resetMapObject(objectId, dbsession, logger, testing)
        
    logger.info('Update single georeferencing ...')
    for timestamp in processingQueue['georeference']:
        logger.info('Update timestamps %s ...'%timestamp)
        for georefProcess in processingQueue['georeference'][timestamp]:
            logger.info('Update georeferencing for objectid %s ...'%georefProcess.messtischblattid)
            processSingleGeorefProc(georefProcess, dbsession, logger, testing)
            logger.info('Calculating tms cache ...')
            messtischblatt = Messtischblatt.by_id(georefProcess.messtischblattid, dbsession)
            buildTsmCache(messtischblatt.verzeichnispfad, cache_dir, logger)
            
        logger.info('Recalculate virtualdataset ...')
        if not testing:
            dbsession.commit()
        
        updateVirtualdatasetForTimestamp('%s-01-01 00:00:00'%timestamp, vrt_target_dir, tmp_dir, database_params, dbsession, logger, testing=testing)
        
    logger.info('Finishing updating the single georeferencing ...')        
            
    return True
Esempio n. 6
0
def getPage_profileMtb(request):
    try:
        messtischblatt_id = None
        if 'id' in request.params:
            messtischblatt_id = request.params['id']
            log.info('Receive get profile mtb page for id %s.' %
                     messtischblatt_id)

        messtischblatt = Messtischblatt.by_id(messtischblatt_id, request.db)

        user_id = authenticated_userid(request)
        if user_id:
            groups = groupfinder(user_id, request)
            if groups and 'g:moderator' in groups or 'g:admin' in groups:
                return {
                    'with_modify': True,
                    'zoomify_prop': messtischblatt.zoomify_properties,
                    'zoomify_width': messtischblatt.zoomify_width,
                    'zoomify_height': messtischblatt.zoomify_height,
                    'key': messtischblatt.dateiname
                }

        return {
            'zoomify_prop': messtischblatt.zoomify_properties,
            'zoomify_width': messtischblatt.zoomify_width,
            'zoomify_height': messtischblatt.zoomify_height,
            'key': messtischblatt.dateiname
        }
    except:
        log.error(
            'Internal server error while trying to get profile page. Please try again or contact the page administrator.'
        )
        raise InternalAuthentificationError(
            'Internal server error while trying to get profile page. Please try again or contact the page administrator.'
        )
Esempio n. 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)
Esempio n. 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 {}
Esempio n. 9
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')
        object = Messtischblatt.by_id(object_id, dbsession)
        spatial_relation_objects = Messtischblatt.allForBlattnr(object.blattnr, dbsession)
        response = []
        for rel_object in spatial_relation_objects:
            if rel_object.isttransformiert:
                time = MdZeit.by_id(rel_object.id, dbsession).datierung
                response.append({'id':rel_object.id,'time':time,'extent':Messtischblatt.getExtent(rel_object.id, dbsession)})
        return json.dumps({'maps':response}, ensure_ascii=False, encoding='utf-8')
    except DBAPIError:
        return Response(conn_err_msg, content_type='text/plain', status_int=500)
Esempio n. 10
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
Esempio n. 11
0
def processSingleGeorefProc(georefProc, dbsession, logger, testing=False):
    logger.debug('Process single georeference process with id %s ...' %
                 georefProc.id)

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

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

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

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

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

    return str(destPath)
Esempio n. 12
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
                }            
        }
Esempio n. 13
0
def getCollectionForBlattnr(blattnr, session):
    coll =[]
    mtbs = Messtischblatt.allForBlattnr(blattnr, session)
    for mtb in mtbs:
        wms_url = getWmsUrlForMtb(mtb.id, session)
        metadata = MdCore.by_id(mtb.id, session)
        item = {'wms_url':wms_url,'mtbid':mtb.id,'layername':mtb.dateiname,'titel':metadata.titel,
                'zoomify_prop':mtb.zoomify_properties,'zoomify_width':mtb.zoomify_width,
                'zoomify_height':mtb.zoomify_height}
        coll.append(item)
    return coll
Esempio n. 14
0
def getZoomifyCollectionForBlattnr(request, blattnr, session, page=1):
    coll = []
    mtbs = Messtischblatt.allForBlattnr(blattnr, session)
    for mtb in mtbs:
        metadata = MdCore.by_id(mtb.id, session)
        if mtb.mdtype == 'M' and mtb.istaktiv and not mtb.isttransformiert and mtb.hasgeorefparams == 0:
            item = {'mtbid':mtb.id,'layername':mtb.dateiname,'titel':metadata.titel,'titel_short':metadata.titel_short,
                    'zoomify_prop':mtb.zoomify_properties,'zoomify_width':mtb.zoomify_width,'zoomify_height':mtb.zoomify_height}
            coll.append(item)
    # create paginator
    page_url = PageURL_WebOb(request)
    return Page(coll, page, url=page_url, items_per_page=10)
Esempio n. 15
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)
Esempio n. 16
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
        }
    }
Esempio n. 17
0
def pushCompleteData(target_dir, dbSession, logger):
    logger.info('Start creating service and parent metadata file ...')
    serviceMetadataFile = createServiceDescription(TEMPLATE_FILES['service'], target_dir, dbSession, logger)
    parentMetadataFile = os.path.join( target_dir, str(uuid.uuid4()) + '.xml')
    shutil.copyfile(TEMPLATE_FILES['parent'], parentMetadataFile)
    logger.info('Insert service and parent metdata file ...')
    gn_transaction_insert(serviceMetadataFile, GN_SETTINGS['gn_username'], GN_SETTINGS['gn_password'], logger)
    gn_transaction_insert(parentMetadataFile, GN_SETTINGS['gn_username'], GN_SETTINGS['gn_password'], logger)
    
    logger.info('Start pushing single metadata records to the geonetwork instance ...')
    messtischblaetter = Messtischblatt.all(dbSession)
    logger.debug('Start appending new messtischblatt resources')
    for messtischblatt in messtischblaetter:
        if messtischblatt.isttransformiert:
            logger.debug('Push metadata record for messtischblatt %s to cataloge service ...'%messtischblatt.id)
            insertMetadata(id=messtischblatt.id,db=dbSession,logger=logger)
Esempio n. 18
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)
Esempio n. 19
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        
Esempio n. 20
0
def createServiceDescription(template_path, target_dir, db, logger):
    logger.debug('Start creating service description')

    # create tempory copy
    mdServiceFile = os.path.join(target_dir, str(uuid.uuid4()) + '.xml')
    shutil.copyfile(template_path, mdServiceFile)

    # Helper method which define the prefix of the namespaces
    for key in Namespaces:
        ET.register_namespace(key, Namespaces[key].strip('}').strip('{'))

    # parse xml template file
    xmlTree = ET.parse(mdServiceFile)
    xmlElementRoot = xmlTree.getroot()

    # search xml element srv:SV_ServiceIdentification
    searchHierarchy = [
        Namespaces['gmd'] + 'identificationInfo',
        Namespaces['srv'] + 'SV_ServiceIdentification'
    ]
    xmlElementServiceId = xmlElementRoot.find('/'.join(searchHierarchy))

    # get all messtischblaetter
    i = 0
    messtischblaetter = Messtischblatt.all(db)
    logger.debug('Start appending new messtischblatt resources')
    for messtischblatt in messtischblaetter:
        metadata_core = MdCore.by_id(messtischblatt.id, db)
        appendCoupledResource(rootElement=xmlElementServiceId,
                              resourceId=str(messtischblatt.id),
                              resourceTitle=metadata_core.titel)

        # break condition for testing


#         if i == 10:
#             break
#         i += 1

    logger.debug('Save modified file in %s.' % mdServiceFile)

    #print 'Service document'
    #print '================'
    #print ET.tostring(xmlElementRoot, encoding='utf-8', method='xml')

    xmlTree.write(mdServiceFile, encoding="utf-8", xml_declaration=True)
    return mdServiceFile
Esempio n. 21
0
def resetMapObject(mapObjectId, dbsession, logger, testing = False):
    logger.debug('Reset map object into unreferenced state.')
    messtischblatt = Messtischblatt.by_id(mapObjectId, dbsession)
    messtischblatt.isttransformiert = False
    messtischblatt.hasgeorefparams = 0
    messtischblatt.verzeichnispfad = messtischblatt.original_path
    refmtblayer = RefMtbLayer.by_id(MTB_LAYER_ID, messtischblatt.id, dbsession)
    if refmtblayer:
        dbsession.delete(refmtblayer)
        
    if testing:
        dbsession.rollback()
    
    logger.debug('Remove metadata record from catalog instance')
    if not testing:
        gn_transaction_delete('vk20-md-%s'%messtischblatt.id, GN_SETTINGS['gn_username'], GN_SETTINGS['gn_password'], logger)
    return True
def 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 {}
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 {}
Esempio n. 24
0
def updateDataSources(dbsession,
                      database_params,
                      vrt_target_dir,
                      tmp_dir,
                      cache_dir,
                      logger,
                      testing=True):

    logger.info('Get georeference processing queue ...')
    processingQueue = getGeoreferenceProcessQueue(dbsession, logger)

    logger.info('Reset objects ...')
    for objectId in processingQueue['reset']:
        logger.info('Reset object with id %s ...' % objectId)
        resetMapObject(objectId, dbsession, logger, testing)

    logger.info('Update single georeferencing ...')
    for timestamp in processingQueue['georeference']:
        logger.info('Update timestamps %s ...' % timestamp)
        for georefProcess in processingQueue['georeference'][timestamp]:
            logger.info('Update georeferencing for objectid %s ...' %
                        georefProcess.messtischblattid)
            processSingleGeorefProc(georefProcess, dbsession, logger, testing)
            logger.info('Calculating tms cache ...')
            messtischblatt = Messtischblatt.by_id(
                georefProcess.messtischblattid, dbsession)
            buildTsmCache(messtischblatt.verzeichnispfad, cache_dir, logger)

        logger.info('Recalculate virtualdataset ...')
        if not testing:
            dbsession.commit()

        updateVirtualdatasetForTimestamp('%s-01-01 00:00:00' % timestamp,
                                         vrt_target_dir,
                                         tmp_dir,
                                         database_params,
                                         dbsession,
                                         logger,
                                         testing=testing)

    logger.info('Finishing updating the single georeferencing ...')

    return True
Esempio n. 25
0
def resetMapObject(mapObjectId, dbsession, logger, testing=False):
    logger.debug('Reset map object into unreferenced state.')
    messtischblatt = Messtischblatt.by_id(mapObjectId, dbsession)
    messtischblatt.isttransformiert = False
    messtischblatt.hasgeorefparams = 0
    messtischblatt.verzeichnispfad = messtischblatt.original_path
    refmtblayer = RefMtbLayer.by_id(MTB_LAYER_ID, messtischblatt.id, dbsession)
    if refmtblayer:
        dbsession.delete(refmtblayer)

    if testing:
        dbsession.rollback()

    logger.debug('Remove metadata record from catalog instance')
    if not testing:
        gn_transaction_delete('vk20-md-%s' % messtischblatt.id,
                              GN_SETTINGS['gn_username'],
                              GN_SETTINGS['gn_password'], logger)
    return True
def 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 {}
Esempio n. 27
0
def processSingleGeorefProc(georefProc, dbsession, logger, testing = False):
    logger.debug('Process single georeference process with id %s ...'%georefProc.id)
    
    # calculate georeference result 
    logger.debug('Create persistent georeference result ...')
    messtischblatt = Messtischblatt.by_id(georefProc.messtischblattid, dbsession)
    if str(georefProc.type) == 'update': 
        parsedGeorefParameter = ast.literal_eval(str(georefProc.clipparameter))['new']
    else:
        parsedGeorefParameter = ast.literal_eval(str(georefProc.clipparameter))
        
    epsg_code = int(str(parsedGeorefParameter['target']).split(':')[1])
    if parsedGeorefParameter['source'] == 'pixel' and epsg_code == 4314:
        gcps = parseGcps(parsedGeorefParameter['gcps'])
        clip_polygon = messtischblatt.BoundingBoxObj.asShapefile(os.path.join(TMP_DIR, messtischblatt.dateiname+'clip_polygon'))
        destPath = georeference(messtischblatt.original_path, os.path.join(GEOREF_TARGET_DIR,messtischblatt.dateiname+'.tif'), 
                         TMP_DIR, gcps, epsg_code, epsg_code, 'polynom', logger, clip_polygon)
        addOverviews(destPath, '2 4 8 16 32', logger)
        if destPath is None:
            logger.error('Something went wrong while trying to process a georeference process.')
            raise GeoreferenceProcessingError('Something went wrong while trying to process a georeference process.')
    
    if not testing:
        # push metadata to catalogue
        logger.debug('Push metadata record for messtischblatt %s to cataloge service ...'%messtischblatt.id)
        insertMetadata(id=messtischblatt.id,db=dbsession,logger=logger)
    
    # update database
    logger.debug('Update database ...')

    # update verzeichnispfad for messtischblatt
    georefProc.processed = True
    messtischblatt.verzeichnispfad = destPath
    messtischblatt.isttransformiert = True 
    refmtblayer = RefMtbLayer.by_id(MTB_LAYER_ID, messtischblatt.id, dbsession)
    if not refmtblayer:
        refmtblayer = RefMtbLayer(layer=MTB_LAYER_ID, messtischblatt=messtischblatt.id)
        dbsession.add(refmtblayer)
    dbsession.flush()   
        
    return str(destPath)
Esempio n. 28
0
def georeferenceValidation(request):
    log.info('Receive request for processing georeference validation result')
    
    try:
        request_data = None
        if request.method == 'POST':
            request_data = request.json_body
            
        if request_data:
            validateId(request_data['id'])
            log.debug('Request data is valide: %s'%request_data)
            
        log.debug('Start creating validation result ...')
        messtischblatt = Messtischblatt.by_id(request_data['id'], request.db)
        # actual only support this option if target srs is EPSG:4314
        epsg_code = int(str(request_data['georeference']['target']).split(':')[1])
        if request_data['georeference']['source'] == 'pixel' and epsg_code == 4314:
            log.debug('Parse gcps ...')
            gcps = parseGcps(request_data['georeference']['gcps'])
            
            log.debug('Process georeference parameter ...')
            destPath = georeference(messtischblatt.original_path, os.path.join(GEOREFERENCE_MAPFILE_FOLDER,messtischblatt.dateiname+"::"+str(getUniqueId())+".vrt"), 
                         GEOREFERENCE_TMP_DIR, gcps, epsg_code, epsg_code, 'polynom', log)
        
            log.debug('Create temporary mapfile ...')
            wms_url = createMapfile(messtischblatt.dateiname, destPath, GEOREFERENCE_MAPFILE_TEMPLATE, GEOREFERENCE_MAPFILE_FOLDER, GEOREFERENCE_MAPFILE_DEFAULT_PARAMS)
            
            log.debug('Create response ...')  
            response = {'wms_url':wms_url,'layer_id':messtischblatt.dateiname,'extent':Messtischblatt.getExtent(messtischblatt.id, request.db)}
            return json.dumps(response, ensure_ascii=False, encoding='utf-8') 
        else:
            raise GeoreferenceParameterError('Wrong or missing service parameter')
    except GeoreferenceParameterError as e:
        message = 'Wrong or missing service parameter - %s'%e.value
        log.error(message)
        return HTTPBadRequest(message) 
    except Exception as e:
        message = 'Problems while computing validation result - %s'%e.value
        log.error(message)
        return HTTPInternalServerError(message)
Esempio n. 29
0
def createServiceDescription(template_path, target_dir, db, logger):
    logger.debug('Start creating service description')
    
    # create tempory copy
    mdServiceFile = os.path.join( target_dir, str(uuid.uuid4()) + '.xml')
    shutil.copyfile(template_path, mdServiceFile)

    # Helper method which define the prefix of the namespaces
    for key in Namespaces:
        ET.register_namespace(key, Namespaces[key].strip('}').strip('{'))
        
    # parse xml template file
    xmlTree = ET.parse(mdServiceFile)
    xmlElementRoot = xmlTree.getroot()
    
    # search xml element srv:SV_ServiceIdentification
    searchHierarchy = [Namespaces['gmd']+'identificationInfo', Namespaces['srv']+'SV_ServiceIdentification']
    xmlElementServiceId = xmlElementRoot.find('/'.join(searchHierarchy))
        
    # get all messtischblaetter
    i = 0
    messtischblaetter = Messtischblatt.all(db)
    logger.debug('Start appending new messtischblatt resources')
    for messtischblatt in messtischblaetter:
        metadata_core = MdCore.by_id(messtischblatt.id, db)
        appendCoupledResource(rootElement = xmlElementServiceId, resourceId = str(messtischblatt.id), resourceTitle = metadata_core.titel)
        
        # break condition for testing
#         if i == 10:
#             break
#         i += 1

    logger.debug('Save modified file in %s.'%mdServiceFile)        
    
    #print 'Service document'
    #print '================'
    #print ET.tostring(xmlElementRoot, encoding='utf-8', method='xml')
    
    xmlTree.write(mdServiceFile, encoding="utf-8", xml_declaration=True)
    return mdServiceFile
Esempio n. 30
0
def getPage_profileMtb(request):
    try:
        messtischblatt_id = None
        if 'id' in request.params:
            messtischblatt_id = request.params['id']
            log.info('Receive get profile mtb page for id %s.'%messtischblatt_id)
        
        messtischblatt = Messtischblatt.by_id(messtischblatt_id, request.db)
        
        user_id = authenticated_userid(request)
        if user_id:
            groups = groupfinder(user_id, request)
            if groups and 'g:moderator' in groups or 'g:admin' in groups:
                return {'with_modify':True, 'zoomify_prop':messtischblatt.zoomify_properties,
                        'zoomify_width':messtischblatt.zoomify_width,'zoomify_height':messtischblatt.zoomify_height,
                        'key':messtischblatt.dateiname}
                
        return {'zoomify_prop':messtischblatt.zoomify_properties,'zoomify_width':messtischblatt.zoomify_width,
                'zoomify_height':messtischblatt.zoomify_height,'key':messtischblatt.dateiname}
    except:
        log.error('Internal server error while trying to get profile page. Please try again or contact the page administrator.')
        raise InternalAuthentificationError('Internal server error while trying to get profile page. Please try again or contact the page administrator.')
Esempio n. 31
0
def pushCompleteData(target_dir, dbSession, logger):
    logger.info('Start creating service and parent metadata file ...')
    serviceMetadataFile = createServiceDescription(TEMPLATE_FILES['service'],
                                                   target_dir, dbSession,
                                                   logger)
    parentMetadataFile = os.path.join(target_dir, str(uuid.uuid4()) + '.xml')
    shutil.copyfile(TEMPLATE_FILES['parent'], parentMetadataFile)
    logger.info('Insert service and parent metdata file ...')
    gn_transaction_insert(serviceMetadataFile, GN_SETTINGS['gn_username'],
                          GN_SETTINGS['gn_password'], logger)
    gn_transaction_insert(parentMetadataFile, GN_SETTINGS['gn_username'],
                          GN_SETTINGS['gn_password'], logger)

    logger.info(
        'Start pushing single metadata records to the geonetwork instance ...')
    messtischblaetter = Messtischblatt.all(dbSession)
    logger.debug('Start appending new messtischblatt resources')
    for messtischblatt in messtischblaetter:
        if messtischblatt.isttransformiert:
            logger.debug(
                'Push metadata record for messtischblatt %s to cataloge service ...'
                % messtischblatt.id)
            insertMetadata(id=messtischblatt.id, db=dbSession, logger=logger)
Esempio n. 32
0
def getPage_profileMtb(request):
    try:
        messtischblatt_id = None
        if 'objectid' in request.params:
            messtischblatt_id = request.params['objectid']
            log.info('Receive get map profile page for id %s.' %
                     messtischblatt_id)

        georef = False
        if 'georef' in request.params and request.params['georef'].lower(
        ) == 'true':
            georef = True

        if georef:
            permalink = createPermalink(request, messtischblatt_id)
            return HTTPFound(location=permalink)

        messtischblatt = Messtischblatt.by_id(messtischblatt_id, request.db)
        metadata = MdCore.by_id(messtischblatt.id, request.db)
        metadata_datensatz = MdDatensatz.by_ObjectId(messtischblatt.id,
                                                     request.db)
        return {
            'zoomify_prop': messtischblatt.zoomify_properties,
            'zoomify_width': messtischblatt.zoomify_width,
            'zoomify_height': messtischblatt.zoomify_height,
            'key': 'vk20-md-%s' % messtischblatt.id,
            'titel_long': metadata.titel,
            'titel_short': metadata.titel_short,
            'permalink': metadata_datensatz.permalink
        }
    except:
        log.error(
            'Internal server error while trying to get profile page. Please try again or contact the page administrator.'
        )
        raise InternalAuthentificationError(
            'Internal server error while trying to get profile page. Please try again or contact the page administrator.'
        )
Esempio n. 33
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)
Esempio n. 34
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)
Esempio n. 35
0
        mdEditor.updateIdCode(metadata['identifier'])
        mdEditor.updateOnlineResource(metadata['onlineresource'])
        
        print '============================'
        print mdEditor.tostring()
        print '============================'
        
        mdEditor.saveFile(file)
        return True
    except:
        logger.error('Problems while updating the metadata for the xml file %s'%file)
        raise




if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    dbSession = initializeDb(DBCONFIG)
    logger = logging.getLogger('sqlalchemy.engine')
    
    # get all messtischblätter
    messtischblaetter = Messtischblatt.all(dbSession)
    for messtischblatt in messtischblaetter:
        if messtischblatt.isttransformiert:
            #response = gn_transaction_delete(messtischblatt.dateiname, gn_settings['gn_username'], gn_settings['gn_password'], logger)
            response = insertMetadata(id=messtischblatt.id,db=dbSession,logger=logger)
            print "Response - delete record"
            print "========================"
            print response
            
Esempio n. 36
0
def getMetadataForMesstischblatt(id, db, logger):
    try:
        logger.debug('Start collection metadata information')
        mtb = Messtischblatt.by_id(id, db)
        metadata_core = MdCore.by_id(id, db)
        
        mdZeit = MdZeit.by_id(id, db)
        if mdZeit.datierung is None:
            metadata_time = ''
        else: 
            metadata_time = mdZeit.datierung
        metadata_dataset = MdDatensatz.by_ObjectId(id, db)
        
        logger.debug('Metadata collection finish. Creating response')
        metadata = {
                    'westBoundLongitude':str(mtb.BoundingBoxObj.llc.x),
                    'eastBoundLongitude':str(mtb.BoundingBoxObj.urc.x),
                    'southBoundLatitude':str(mtb.BoundingBoxObj.llc.y),
                    'northBoundLatitude':str(mtb.BoundingBoxObj.urc.y),
                    'identifier':'vk20-md-%s'%mtb.id,
                    'dateStamp': datetime.now().strftime('%Y-%m-%d'),
                    'title': metadata_core.titel,
                    'cite_date': str(metadata_time),
                    'abstract': metadata_core.beschreibung,
                    'temporalExtent_begin': '%s-01-01'%metadata_time,
                    'temporalExtent_end': '%s-12-31'%metadata_time,
                    'permalink': metadata_dataset.permalink, 
                    'hierarchylevel': 'Messtischblatt' if mtb.mdtype == 'M' else 'Äquidistantenkarte', 
                    'overviews': [
#                         'http://fotothek.slub-dresden.de/mids/df/dk/0010000/%s.jpg'%mtb.dateiname,
#                         
#                         TEMPLATE_OGC_SERVICE_LINK['wms_template']%({
#                             'westBoundLongitude':str(mtb.BoundingBoxObj.llc.x),
#                             'southBoundLatitude':str(mtb.BoundingBoxObj.llc.y),
#                             'eastBoundLongitude':str(mtb.BoundingBoxObj.urc.x),
#                             'northBoundLatitude':str(mtb.BoundingBoxObj.urc.y),
#                             'srid':DATABASE_SRID,
#                             'time':metadata_time.datierung,
#                             'width':256,
#                             'height':256
#                         }),
                        'http://fotothek.slub-dresden.de/thumbs/df/dk/0010000/%s.jpg'%mtb.dateiname
                    ],
                    'wms_params': {
                        'westBoundLongitude':str(mtb.BoundingBoxObj.llc.x),
                        'southBoundLatitude':str(mtb.BoundingBoxObj.llc.y),
                        'eastBoundLongitude':str(mtb.BoundingBoxObj.urc.x),
                        'northBoundLatitude':str(mtb.BoundingBoxObj.urc.y),
                        'srid':DATABASE_SRID,
                        'time':metadata_time,
                        'width':256,
                        'height':256
                    },
                    'onlineresource':[
                        {
                            'url':'http://kartenforum.slub-dresden.de/vkviewer/permalink?objectid=%s'%mtb.id,
                            'protocol':'HTTP',
                            'name':'Permalink'
                        },
                        {
                            'url':TEMPLATE_OGC_SERVICE_LINK['wms_template']%({
                                'westBoundLongitude':str(mtb.BoundingBoxObj.llc.x),
                                'southBoundLatitude':str(mtb.BoundingBoxObj.llc.y),
                                'eastBoundLongitude':str(mtb.BoundingBoxObj.urc.x),
                                'northBoundLatitude':str(mtb.BoundingBoxObj.urc.y),
                                'srid':DATABASE_SRID,
                                'time':metadata_time,
                                'width':256,
                                'height':256
                            }),
                            'protocol':'OGC:WMS-1.1.1-http-get-map',
                            'name':'WEB MAP SERVICE (WMS)'
                        },
                        {
                            'url':metadata_dataset.permalink,
                            'protocol':'HTTP',
                            'name':'Permalink'
                        }                        
                    ]
        }
        return metadata
    except:
        logger.error('Problems while trying to collect the metadata for the messtischblatt with id %s'%id)
        raise
Esempio n. 37
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)
Esempio n. 38
0
def createPermalink(request, objectid):
    dbsession = request.db
    centroid = Messtischblatt.getCentroid(objectid, dbsession, 900913)
    return request.host_url + '/vkviewer/?welcomepage=off&z=5&c=%s,%s&oid=%s'%(centroid[0],centroid[1],objectid)