def getSpecificGeoreferenceData(georefObj, mapObj, srid,  dbsession):
    """ Query the specific process information for a process response.

    :type georefObj: georeference.models.vkdb.georeferenzierungsprozess.Georeferenzierungsprozess
    :type mapObj: georeference.models.vkdb.map.Map
    :type srid: str
    :type sqlalchemy.orm.session.Session: dbsession
    :return: dict """
    params = {
        'georeference': georefObj.georefparams,
        'timestamp': str(georefObj.timestamp),
        'type': 'update',
        'georeferenceid': georefObj.id
    }

    # if mapObj is georeference
    if mapObj.isttransformiert:
        params['extent'] = mapObj.getExtent(dbsession, srid)

    # if clip params exist add them
    if georefObj.clip is not None:
        params['clippolygon'] = {
            'source': 'EPSG:%s'%georefObj.getSRIDClip(dbsession),
            'polygon': convertPostgisStringToList(georefObj.clip)
        }

    # check if algorithm is set in georefparams, if not set to default 'affine'
    if 'algorithm' not in params['georeference']:
        params['georeference']['algorithm'] = georefObj.algorithm

    return params
def getSpecificGeoreferenceData(georefObj, mapObj, srid,  dbsession):
    """ Query the specific process information for a process response.

    :type georefObj: georeference.models.vkdb.georeferenzierungsprozess.Georeferenzierungsprozess
    :type mapObj: georeference.models.vkdb.map.Map
    :type srid: str
    :type sqlalchemy.orm.session.Session: dbsession
    :return: dict """
    params = {
        'extent': mapObj.getExtent(dbsession, srid),
        'georeference': georefObj.georefparams,
        'timestamp': str(georefObj.timestamp),
        'type': 'update',
        'georeferenceid': georefObj.id
    }

    # if clip params exist add them
    if georefObj.clip is not None:
        params['clippolygon'] = {
            'source': 'EPSG:%s'%georefObj.getSRIDClip(dbsession),
            'polygon': convertPostgisStringToList(georefObj.clip)
        }

    # check if algorithm is set in georefparams, if not set to default 'affine'
    if 'algorithm' not in params['georeference']:
        params['georeference']['algorithm'] = georefObj.algorithm

    return params
Esempio n. 3
0
def processGeorefImage(mapObj, georefObj, dbsession, logger):
    """ Function process a persistent georeference image

    :type georeference.models.vkdb.map.Map: mapObj
    :type georeference.models.vkdb.georeferenzierungsprozess.Georeferenzierungsprozess: georefObj
    :type sqlalchemy.orm.session.Session: dbsession
    :type logging.Logger: logger
    :return: str """
    gcps = parseGcps(georefObj.georefparams['gcps'])
    georefTargetSRS = stripSRIDFromEPSG(georefObj.georefparams['target'])
    targetPath = os.path.join(GEOREFERENCE_PERSITENT_TARGETDIR, os.path.join(str(mapObj.maptype).lower(), mapObj.apsdateiname+'.tif'))
    transformationAlgorithm = georefObj.georefparams['algorithm'] if 'algorithm' in georefObj.georefparams else 'affine'
    destPath = None

    # create clip shape if exists
    clipShpPath = None
    if georefObj.clip is not None:
        clipShpPath = os.path.join(TMP_DIR, '%s' % uuid.uuid4())
        clipShpPath = createClipShapefile(convertPostgisStringToList(georefObj.clip), clipShpPath, georefObj.getSRIDClip(dbsession))

    logger.debug('Process georeference result ...')
    if transformationAlgorithm == 'affine':
        destPath = rectifyPolynom(mapObj.originalimage, targetPath, [], gcps, georefTargetSRS, logger, TMP_DIR, clipShpPath, order=1)
    elif transformationAlgorithm == 'polynom':
        destPath = rectifyPolynom(mapObj.originalimage, targetPath, [], gcps, georefTargetSRS, logger, TMP_DIR, clipShpPath)
    elif transformationAlgorithm == 'tps':
        destPath = rectifyTps(mapObj.originalimage, targetPath, [], gcps, georefTargetSRS, logger, TMP_DIR, clipShpPath)

    logger.debug('Add overviews to the image ...')
    addOverviews(destPath, '2 4 8 16 32', logger)

    return destPath
Esempio n. 4
0
    def testConvertPostgisStringToList(self):
        response = convertPostgisStringToList('POLYGON((16.9999980926514 51.7999992370605,16.9999980926514 51.9000015258789,17.1666679382324 51.9000015258789,17.1666679382324 51.7999992370605,16.9999980926514 51.7999992370605))')

        print '====================='
        print 'Test if testConvertPostgisStringToList ...'
        print 'Response: %s'%response
        print '====================='

        self.assertTrue(len(response) == 5)
Esempio n. 5
0
    def testConvertPostgisStringToList(self):
        response = convertPostgisStringToList(
            'POLYGON((16.9999980926514 51.7999992370605,16.9999980926514 51.9000015258789,17.1666679382324 51.9000015258789,17.1666679382324 51.7999992370605,16.9999980926514 51.7999992370605))'
        )

        print '====================='
        print 'Test if testConvertPostgisStringToList ...'
        print 'Response: %s' % response
        print '====================='

        self.assertTrue(len(response) == 5)
Esempio n. 6
0
def processGeorefImage(mapObj, georefObj, dbsession, logger):
    """ Function process a persistent georeference image

    :type georeference.models.vkdb.map.Map: mapObj
    :type georeference.models.vkdb.georeferenzierungsprozess.Georeferenzierungsprozess: georefObj
    :type sqlalchemy.orm.session.Session: dbsession
    :type logging.Logger: logger
    :return: str """
    gcps = parseGcps(georefObj.georefparams['gcps'])
    georefTargetSRS = stripSRIDFromEPSG(georefObj.georefparams['target'])
    targetPath = os.path.join(
        GEOREFERENCE_PERSITENT_TARGETDIR,
        os.path.join(
            str(mapObj.maptype).lower(), mapObj.apsdateiname + '.tif'))
    transformationAlgorithm = georefObj.georefparams[
        'algorithm'] if 'algorithm' in georefObj.georefparams else 'affine'
    destPath = None

    # create clip shape if exists
    clipShpPath = None
    if georefObj.clip is not None:
        clipShpPath = os.path.join(TMP_DIR, '%s' % uuid.uuid4())
        clipShpPath = createClipShapefile(
            convertPostgisStringToList(georefObj.clip), clipShpPath,
            georefObj.getSRIDClip(dbsession))

    logger.debug('Process georeference result ...')
    if transformationAlgorithm == 'affine':
        destPath = rectifyPolynom(mapObj.originalimage,
                                  targetPath, [],
                                  gcps,
                                  georefTargetSRS,
                                  logger,
                                  TMP_DIR,
                                  clipShpPath,
                                  order=1)
    elif transformationAlgorithm == 'polynom':
        destPath = rectifyPolynom(mapObj.originalimage, targetPath, [], gcps,
                                  georefTargetSRS, logger, TMP_DIR,
                                  clipShpPath)
    elif transformationAlgorithm == 'tps':
        destPath = rectifyTps(mapObj.originalimage, targetPath, [], gcps,
                              georefTargetSRS, logger, TMP_DIR, clipShpPath)

    logger.debug('Add overviews to the image ...')
    addOverviews(destPath, '2 4 8 16 32', logger)

    return destPath
Esempio n. 7
0
def createSearchRecord(mapObj, dbsession, logger, georefObj=None):
    """ Function creates an elasticsearch record for a given mapObj
        
    :type mapObj: vkviewer.python.models.vkdb.Map
    :type dbsession: sqlalchemy.orm.session.Session
    :type logger: logging.Logger
    :type georefObj: georeference.models.vkdb.georeferenzierungsprozess.Georeferenzierungsprozess|None
    """
    mapData = {}
    # check if map is georeferenced because only
    # georeferenced map should be published via the index
    metadataObj = Metadata.by_id(mapObj.id, dbsession)
    timepublish = metadataObj.timepublish.date()
    oai = OAI_ID_PATTERN%mapObj.id
    onlineResList = getOnlineResourceData(mapObj, metadataObj, metadataObj.timepublish.year, oai, dbsession)

    mapData["oai:de:slub-dresden:vk:id-%s"%mapObj.id] = {
        "id": mapObj.id,
        "dataid": mapObj.apsdateiname,
        "title": metadataObj.titleshort,
        "titlelong": metadataObj.title,
        "description": metadataObj.description,
        "online-resources": onlineResList,
        "denominator": int(metadataObj.scale.split(':')[1]),
        "keywords": ";".join([metadataObj.type,metadataObj.technic]),
        "time": "%s-%s-%s"%(timepublish.year, timepublish.month, timepublish.day),
        "plink": metadataObj.apspermalink,
        "org":metadataObj.imagejpg,
        "georeference": mapObj.isttransformiert,
        "maptype": mapObj.maptype,
        "thumb": metadataObj.thumbssmall,
        "zoomify":metadataObj.imagezoomify
    }
            
    # if there is a geometry then add it to the record
    boundingbox = None
    try:
        elasticsearchSRS = int(ELASTICSEARCH_SRS.split(':')[1])
        extent = mapObj.getExtent(dbsession, elasticsearchSRS)
        boundingbox = {
            "type": "polygon",
            "coordinates": [[
                [extent[0],extent[1]],
                [extent[0],extent[3]],
                [extent[2],extent[3]],
                [extent[2],extent[1]],
                [extent[0],extent[1]]
            ]]
        } 
    except AttributeError:
        logger.debug('Missing geometry')
        pass
            
    if boundingbox is not None and mapObj.isttransformiert:
        mapData[oai]["geometry"] = boundingbox

    # if georeferenced add tms cache
    if mapObj.isttransformiert:
        # create tms url
        file_name, file_extension = os.path.splitext(os.path.basename(mapObj.georefimage))
        tmsUrl = GEOREFERENCE_PERSITENT_TMS_URL + '/' + os.path.join(str(mapObj.maptype).lower(), file_name)
        mapData[oai]["tms"] = tmsUrl

    if georefObj is not None and georefObj.clip is not None:
        mapData[oai]["clippolygon"] = convertPostgisStringToList(georefObj.getClipAsString(dbsession, stripSRIDFromEPSG(ELASTICSEARCH_SRS.lower())))

    return mapData
def adminEvaluationGeoreferenceProcess(request):
    try:
        LOGGER.info('Request - Get georeference processes.')

        if 'mapid' in request.params:
            LOGGER.debug('Get processes for mapid %s ...'%request.params['mapid'])
            # parse the id
            mapid = None
            if '-' in request.params['mapid']:
                namespace, mapid = request.params['mapid'].rsplit('-', 1)
                # check if it is the correct namespace
                if namespace != OAI_ID_PATTERN.rsplit('-', 1)[0]:
                    return []
            queryData = request.db.query(Georeferenzierungsprozess, Metadata).join(Metadata, Georeferenzierungsprozess.mapid == Metadata.mapid)\
                .filter(Georeferenzierungsprozess.mapid == mapid)\
                .order_by(desc(Georeferenzierungsprozess.id))
        elif 'userid' in request.params:
            LOGGER.debug('Get processes for userid %s ...'%request.params['userid'])
            queryData = request.db.query(Georeferenzierungsprozess, Metadata).join(Metadata, Georeferenzierungsprozess.mapid == Metadata.mapid)\
                .filter(Georeferenzierungsprozess.nutzerid == request.params['userid'])\
                .order_by(desc(Georeferenzierungsprozess.id))
        elif 'validation' in request.params:
            LOGGER.debug('Get processes for adminvalidation %s ...'%request.params['validation'])
            queryData = request.db.query(Georeferenzierungsprozess, Metadata).join(Metadata, Georeferenzierungsprozess.mapid == Metadata.mapid)\
                .filter(Georeferenzierungsprozess.adminvalidation == request.params['validation'])\
                .order_by(desc(Georeferenzierungsprozess.id))
        else:
            LOGGER.debug('Get all pending processes ...')
            queryData = request.db.query(Georeferenzierungsprozess, Metadata).join(Metadata, Georeferenzierungsprozess.mapid == Metadata.mapid)\
                .filter(or_(Georeferenzierungsprozess.adminvalidation == '', Georeferenzierungsprozess.adminvalidation == None))\
                .order_by(desc(Georeferenzierungsprozess.id))

        response = []
        for record in queryData:
            georef = record[0]
            metadata = record[1]
            dict = {
                    'georef_id':georef.id,
                    'mapid':georef.mapid,
                    'georef_params': georef.georefparams,
                    'time': str(metadata.timepublish),
                    'processed': georef.processed,
                    'adminvalidation': georef.adminvalidation,
                    'title': metadata.title,
                    'apsobjectid': georef.messtischblattid,
                    'georef_time':str(georef.timestamp),
                    'type':georef.type,
                    'userid': georef.nutzerid,
                    'georef_isactive':georef.isactive
                }

            if georef.clip is not None:
                dict['clippolygon'] = {
                    'source': 'EPSG:%s' % georef.getSRIDClip(request.db),
                    'polygon': convertPostgisStringToList(georef.clip)
                }

            response.append(dict)
        return response
    except Exception as e:
        LOGGER.error(e)
        LOGGER.error(traceback.format_exc())
        return HTTPInternalServerError(GENERAL_ERROR_MESSAGE)
Esempio n. 9
0
def createSearchRecord(mapObj, dbsession, logger, georefObj=None):
    """ Function creates an elasticsearch record for a given mapObj
        
    :type mapObj: vkviewer.python.models.vkdb.Map
    :type dbsession: sqlalchemy.orm.session.Session
    :type logger: logging.Logger
    :type georefObj: georeference.models.vkdb.georeferenzierungsprozess.Georeferenzierungsprozess|None
    """
    mapData = {}
    # check if map is georeferenced because only
    # georeferenced map should be published via the index
    metadataObj = Metadata.by_id(mapObj.id, dbsession)
    timepublish = metadataObj.timepublish.date()
    oai = OAI_ID_PATTERN % mapObj.id
    onlineResList = getOnlineResourceData(mapObj, metadataObj,
                                          metadataObj.timepublish.year, oai,
                                          dbsession)

    mapData["oai:de:slub-dresden:vk:id-%s" % mapObj.id] = {
        "id": mapObj.id,
        "dataid": mapObj.apsdateiname,
        "title": metadataObj.titleshort,
        "titlelong": metadataObj.title,
        "description": metadataObj.description,
        "online-resources": onlineResList,
        "denominator": int(metadataObj.scale.split(':')[1]),
        "keywords": ";".join([metadataObj.type, metadataObj.technic]),
        "time":
        "%s-%s-%s" % (timepublish.year, timepublish.month, timepublish.day),
        "plink": metadataObj.apspermalink,
        "org": metadataObj.imagejpg,
        "georeference": mapObj.isttransformiert,
        "maptype": mapObj.maptype,
        "thumb": metadataObj.thumbssmall,
        "zoomify": metadataObj.imagezoomify
    }

    # if there is a geometry then add it to the record
    boundingbox = None
    try:
        elasticsearchSRS = int(ELASTICSEARCH_SRS.split(':')[1])
        extent = mapObj.getExtent(dbsession, elasticsearchSRS)
        boundingbox = {
            "type":
            "polygon",
            "coordinates": [[[extent[0], extent[1]], [extent[0], extent[3]],
                             [extent[2], extent[3]], [extent[2], extent[1]],
                             [extent[0], extent[1]]]]
        }
    except AttributeError:
        logger.debug('Missing geometry')
        pass

    if boundingbox is not None and mapObj.isttransformiert:
        mapData[oai]["geometry"] = boundingbox

    # if georeferenced add tms cache
    if mapObj.isttransformiert:
        # create tms url
        file_name, file_extension = os.path.splitext(
            os.path.basename(mapObj.georefimage))
        tmsUrl = GEOREFERENCE_PERSITENT_TMS_URL + '/' + os.path.join(
            str(mapObj.maptype).lower(), file_name)
        mapData[oai]["tms"] = tmsUrl

    if georefObj is not None and georefObj.clip is not None:
        mapData[oai]["clippolygon"] = convertPostgisStringToList(
            georefObj.getClipAsString(
                dbsession, stripSRIDFromEPSG(ELASTICSEARCH_SRS.lower())))

    return mapData