예제 #1
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
            }            
    }
예제 #2
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."
        )
예제 #3
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
예제 #4
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)
예제 #5
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
            }
        }
예제 #6
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
예제 #7
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
                }            
        }
예제 #8
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
예제 #9
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
        }
    }
예제 #10
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.'
        )
예제 #11
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