def setUp(self): # create and insert test data to database self.testData = [ Map( id = 10000023, apsobjectid=90015724, apsdateiname = "df_dk_0010001_4630_1928", boundingbox = "POLYGON((16.9999980926514 51.7999992370605,16.9999980926514 51.9000015258789,17.1666679382324 51.9000015258789,17.1666679382324 51.7999992370605,16.9999980926514 51.7999992370605))", maptype="M", originalimage = os.path.join(self.testDataDir, "df_dk_0010001_4630_1928.tif"), georefimage = os.path.join(self.testDataDir, "df_dk_0010001_4630_1928.tif"), isttransformiert = True, recommendedsrid = 4314 ), Metadata( mapid = 10000023, imagezoomify = 'http://fotothek.slub-dresden.de/zooms/df/dk/0010000/df_dk_0010001_3352_1918/ImageProperties.xml', title = '', titleshort = '', scale = '1:25000', timepublish = datetime.now(), imagejpg = 'http://fotothek.slub-dresden.de/fotos/df/dk/0010000/df_dk_0010001_2655.jpg', thumbssmall = 'http://fotothek.slub-dresden.de/thumbs/df/dk/0010000/df_dk_0010001_6817.jpg', description = 'Ars an der Mosel. - Aufn. 1880, hrsg. 1882, Aufldr. 1916. - 1:25000. - [Berlin]: Kgl. Preuss. Landesaufnahme, 1916. - 1 Kt.', technic = 'Lithografie & Umdruck', type = 'Druckgraphik' ) ] self.georefProcess = Georeferenzierungsprozess( mapid = 10000023, messtischblattid = 90015724, nutzerid = self.user, clipparameter = {'source': 'pixel', 'target': 'EPSG:4314', 'gcps': [\ {'source': [467, 923], 'target': [10.6666660308838, 51.4000015258789]}, \ {'source': [7281, 999], 'target': [10.8333339691162, 51.4000015258789]}, \ {'source': [7224, 7432], 'target': [10.8333339691162, 51.2999992370605]},\ {'source': [258, 7471], 'target': [10.6666660308838, 51.2999992370605]}]}, georefparams = {'source': 'pixel', 'target': 'EPSG:4314', 'gcps': [\ {'source': [467, 923], 'target': [10.6666660308838, 51.4000015258789]}, \ {'source': [7281, 999], 'target': [10.8333339691162, 51.4000015258789]}, \ {'source': [7224, 7432], 'target': [10.8333339691162, 51.2999992370605]},\ {'source': [258, 7471], 'target': [10.6666660308838, 51.2999992370605]}]}, clippolygon = {'source': 'pixel', 'polygon': [[7813, 7517], [1652, 7523], [1677, 1666], [7830, 1661], [7813, 7517]]}, timestamp = "2014-08-09 12:20:26", type = 'update', isactive = False, processed = False, overwrites = 0, adminvalidation = '' ) try: for obj in self.testData: self.dbsession.add(obj) self.dbsession.flush() except Exception: raise
def setUp(self): self.config = testing.setUp() self.config.registry.dbmaker = self.Session # create and insert test data to database self.testData = [ Map(id=10000023, apsobjectid=90015724, apsdateiname="df_dk_0010001_3352_1890", recommendedsrid=4314, boundingbox= "POLYGON((16.9999980926514 51.7999992370605,16.9999980926514 51.9000015258789,17.1666679382324 51.9000015258789,17.1666679382324 51.7999992370605,16.9999980926514 51.7999992370605))", maptype="M"), Map(id=10000024, apsobjectid=90015725, apsdateiname="df_dk_0010001_3352_18901", maptype="GL"), Metadata( mapid=10000023, imagezoomify= 'http://fotothek.slub-dresden.de/zooms/df/dk/0010000/df_dk_0010001_3352_1918/ImageProperties.xml', title='', titleshort=''), Metadata( mapid=10000024, imagezoomify= 'http://fotothek.slub-dresden.de/zooms/df/dk/0010000/df_dk_0010001_3352_1918/ImageProperties.xml', title='', titleshort='') ] try: for obj in self.testData: self.dbsession.add(obj) self.dbsession.flush() except Exception: raise
def getGeneralMetadata(mapObj, request): """ Query the general metadata for a process response. :type mapObj: vkviewer.python.models.vkdb.Map :type request: pyramid.request :return: dict """ metadataObj = Metadata.by_id(mapObj.id, request.db) return { 'objectid': mapObj.id, 'maptype': mapObj.maptype, 'zoomify': metadataObj.imagezoomify, 'metadata': { 'dateiname': mapObj.apsdateiname, 'title_long': metadataObj.title, 'title_short': metadataObj.titleshort } }
def setUp(self): # create and insert test data to database self.testData = [ Map(id=10000023, apsobjectid=90015724, apsdateiname="df_dk_0010001_4630_1928", boundingbox= "POLYGON((16.9999980926514 51.7999992370605,16.9999980926514 51.9000015258789,17.1666679382324 51.9000015258789,17.1666679382324 51.7999992370605,16.9999980926514 51.7999992370605))", maptype="M", originalimage=os.path.join(self.testDataDir, "df_dk_0010001_4630_1928.tif"), georefimage=os.path.join(self.testDataDir, "df_dk_0010001_4630_1928.tif"), isttransformiert=True), Metadata( mapid=10000023, imagezoomify= 'http://fotothek.slub-dresden.de/zooms/df/dk/0010000/df_dk_0010001_3352_1918/ImageProperties.xml', title='', titleshort='', scale='1:25000', timepublish=datetime.now(), imagejpg= 'http://fotothek.slub-dresden.de/fotos/df/dk/0010000/df_dk_0010001_2655.jpg', thumbssmall= 'http://fotothek.slub-dresden.de/thumbs/df/dk/0010000/df_dk_0010001_6817.jpg', description= 'Ars an der Mosel. - Aufn. 1880, hrsg. 1882, Aufldr. 1916. - 1:25000. - [Berlin]: Kgl. Preuss. Landesaufnahme, 1916. - 1 Kt.', technic='Lithografie & Umdruck', type='Druckgraphik') ] try: for obj in self.testData: self.dbsession.add(obj) self.dbsession.flush() except Exception: raise
def setUp(self): self.config = testing.setUp() self.config.registry.dbmaker = self.Session # create dummy georefprocess self.notReferencedObjId = 10000023 self.dummyProcess = Georeferenzierungsprozess( mapid=10000023, messtischblattid=90015724, nutzerid=self.user, clipparameter="{'Test':'Test'}", georefparams="{'Test':'Test'}", timestamp="2014-08-09 12:20:26", type='new', isactive=True, processed=False, overwrites=0, adminvalidation='') self.dummyProcessUpdate = Georeferenzierungsprozess( mapid=10000023, messtischblattid=90015724, nutzerid=self.user, clipparameter= "{'new': {'source': 'pixel', 'target': 'EPSG:4314', 'gcps': [\ {'source': [467, 923], 'target': [10.6666660308838, 51.4000015258789]}, \ {'source': [7281, 999], 'target': [10.8333339691162, 51.4000015258789]}, \ {'source': [7224, 7432], 'target': [10.8333339691162, 51.2999992370605]},\ {'source': [258, 7471], 'target': [10.6666660308838, 51.2999992370605]}]},\ 'remove':{'source': 'pixel', 'target': 'EPSG:4314', 'gcps':[]}}", georefparams= "{'new': {'source': 'pixel', 'target': 'EPSG:4314', 'gcps': [\ {'source': [467, 923], 'target': [10.6666660308838, 51.4000015258789]}, \ {'source': [7281, 999], 'target': [10.8333339691162, 51.4000015258789]}, \ {'source': [7224, 7432], 'target': [10.8333339691162, 51.2999992370605]},\ {'source': [258, 7471], 'target': [10.6666660308838, 51.2999992370605]}]},\ 'remove':{'source': 'pixel', 'target': 'EPSG:4314', 'gcps':[]}}", timestamp="2014-08-09 12:20:26", type='update', isactive=False, processed=False, overwrites=0, adminvalidation='') # create and insert test data to database self.testData = [ Map(id=10000023, apsobjectid=90015724, apsdateiname="df_dk_0010001_3352_1890", boundingbox= "POLYGON((16.9999980926514 51.7999992370605,16.9999980926514 51.9000015258789,17.1666679382324 51.9000015258789,17.1666679382324 51.7999992370605,16.9999980926514 51.7999992370605))", maptype="M"), Map(id=10000024, apsobjectid=90015725, apsdateiname="df_dk_0010001_3352_18901", maptype="GL"), Metadata( mapid=10000023, imagezoomify= 'http://fotothek.slub-dresden.de/zooms/df/dk/0010000/df_dk_0010001_3352_1918/ImageProperties.xml', title='', titleshort=''), Metadata( mapid=10000024, imagezoomify= 'http://fotothek.slub-dresden.de/zooms/df/dk/0010000/df_dk_0010001_3352_1918/ImageProperties.xml', title='', titleshort='') ] try: for obj in self.testData: self.dbsession.add(obj) self.dbsession.flush() except Exception: raise
# -*- coding: utf-8 -*- ''' Copyright (c) 2015 Jacob Mendt Created on 02.10.15 @author: mendt @description: The following scripts updates the database path for all map files. ''' from os import path from georeference.settings import DBCONFIG_PARAMS from georeference.models.meta import getPostgresEngineString from georeference.models.meta import initializeDb from georeference.models.vkdb.map import Map from georeference.models.vkdb.metadata import Metadata TEMPLATE_THUMBSSMALL = 'http://fotothek.slub-dresden.de/thumbs/%s' TEMPLATE_THUMBSMID = 'http://fotothek.slub-dresden.de/mids/%s' if __name__ == '__main__': dbsession = initializeDb(getPostgresEngineString(DBCONFIG_PARAMS)) metadata = Metadata.all(dbsession) for metadataObj in metadata: if metadataObj.thumbssmall == '' or metadataObj.thumbssmall is None: newPathEnding = metadataObj.imagejpg[str(metadataObj.imagejpg).index('dk')-3:] metadataObj.thumbssmall = TEMPLATE_THUMBSSMALL%newPathEnding metadataObj.thumbsmid = TEMPLATE_THUMBSMID%newPathEnding dbsession.commit()
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 setUp(self): self.process = Georeferenzierungsprozess( mapid=10002567, nutzerid=TEST_LOGIN, clippolygon={ 'source': 'pixel', 'polygon': [[467, 923], [7281, 999], [7224, 7432], [258, 7471], [467, 923]] }, georefparams={ 'source': 'pixel', 'target': 'EPSG:4314', 'gcps': [{ 'source': [467, 923], 'target': [10.6666660308838, 51.4000015258789] }, { 'source': [7281, 999], 'target': [10.8333339691162, 51.4000015258789] }, { 'source': [7224, 7432], 'target': [10.8333339691162, 51.2999992370605] }, { 'source': [258, 7471], 'target': [10.6666660308838, 51.2999992370605] }], "algorithm": "affine", }, timestamp="2014-08-09 12:20:26", type='new', algorithm='affine', isactive=True, processed=False, overwrites=0, adminvalidation='') self.map = Map( id=10002567, apsobjectid=90015724, apsdateiname="df_dk_0010001_4630_1928", boundingbox= "POLYGON((10.6666660308838 51.2999992370605,10.6666660308838 51.4000015258789,10.8333339691162 51.4000015258789,10.8333339691162 51.2999992370605,10.6666660308838 51.2999992370605))", originalimage=os.path.join(TEST_DATA_DIR, "df_dk_0010001_4630_1928.tif")) self.metadata = Metadata( mapid=10002567, imagezoomify= 'http://fotothek.slub-dresden.de/zooms/df/dk/0010000/df_dk_0010001_3352_1918/ImageProperties.xml', title='', titleshort='', scale='1:25000', timepublish=datetime.now(), imagejpg= 'http://fotothek.slub-dresden.de/fotos/df/dk/0010000/df_dk_0010001_2655.jpg', thumbssmall= 'http://fotothek.slub-dresden.de/thumbs/df/dk/0010000/df_dk_0010001_6817.jpg', description= 'Ars an der Mosel. - Aufn. 1880, hrsg. 1882, Aufldr. 1916. - 1:25000. - [Berlin]: Kgl. Preuss. Landesaufnahme, 1916. - 1 Kt.', technic='Lithografie & Umdruck', type='Druckgraphik') try: self.dbsession.add(self.metadata) self.dbsession.add(self.map) self.dbsession.flush() except Exception: raise
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