def setUp(self): self.config = testing.setUp() self.config.registry.dbmaker = self.Session # create dummy georefprocess self.notReferencedObjId = 10000023 self.dummyProcess = Georeferenzierungsprozess( mapsid = 10000023, messtischblattid = 90015724, nutzerid = login, clipparameter = "{'Test':'Test'}", timestamp = "2014-08-09 12:20:26", type = 'new', refzoomify = True, isactive = True, processed = False, overwrites = 0, adminvalidation = '' ) self.dummyParams = {'georeference': {'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]}]}, 'id': 10000023}
def getDummyGeorefProcess(cls): return Georeferenzierungsprozess( messtischblattid=71055048, nutzerid='user', clipparameter= "{'source': 'pixel', 'target': 'EPSG:4314', 'gcps': [{'source': [451.0, 7662.0], 'target': [16.1666660308838, 50.2999992370605]}, {'source': [480.0, 1198.0], 'target': [16.1666660308838, 50.4000015258789]}, {'source': [7374.0, 1229.0], 'target': [16.3333339691162, 50.4000015258789]}, {'source': [7341.0, 7689.0], 'target': [16.3333339691162, 50.2999992370605]}]}", timestamp=getTimestampAsPGStr(), isvalide=True, type='new', refzoomify=True, publish=False, processed=False)
def registerNewGeoreferenceProcessInDb(objectid, userid, gcps, type, dbsession): log.debug('Create georeference process record ...') timestamp = getTimestampAsPGStr() georefProcess = Georeferenzierungsprozess(messtischblattid=objectid, nutzerid=userid, clipparameter=gcps, timestamp=timestamp, isvalide=True, type=type, refzoomify=True, publish=False, processed=False) dbsession.add(georefProcess) dbsession.flush() return georefProcess
def registerUpdateGeoreferenceProcessInDb(mapObj, userid, gcps, dbsession): log.debug('Create georeference process record ...') activeGeorefProcess = Georeferenzierungsprozess.getActualGeoreferenceProcessForMapId( mapObj.id, dbsession) georefProcess = Georeferenzierungsprozess( messtischblattid=mapObj.apsobjectid, nutzerid=userid, georefparams=ast.literal_eval(gcps), clipparameter=gcps, timestamp=getTimestampAsPGStr(), isactive=False, type='update', adminvalidation='', processed=False, mapid=mapObj.id, overwrites=activeGeorefProcess.id) dbsession.add(georefProcess) dbsession.flush() return georefProcess
def registerGeoreferenceProcess(self, messtischblattid, userid=None, clipParams=None, isvalide=False, typeValidation='none', refzoomify=True): # get timestamp timestamp = getTimestampAsPGStr() georefProcess = Georeferenzierungsprozess( messtischblattid=messtischblattid, nutzerid=userid, clipparameter=clipParams, timestamp=timestamp, isvalide=isvalide, typevalidierung='user', refzoomify=refzoomify) self.dbsession.add(georefProcess) self.dbsession.flush() return georefProcess
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)
def georeferenceConfirm(request): log.info('Receive request for processing georeference validation result') try: userid = checkIsUser(request) request_data = None if request.method == 'POST': request_data = request.json_body mapObj = parseMapObjForId(request_data, 'id', request.db) log.debug('Id is valide: %s' % request_data) log.debug( 'Check if there is already a registered georeference process for this messtischblatt ...' ) if Georeferenzierungsprozess.isGeoreferenced(mapObj.id, request.db): msg = 'There is already a georeference process for this process. Please load again and start on the latest changes.' log.debug(msg) georeferenceid = Georeferenzierungsprozess.getActualGeoreferenceProcessForMapId( mapObj.id, request.db).id response = {'text': msg, 'georeferenceid': georeferenceid} return response # 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=mapObj.apsobjectid, nutzerid=userid, georefparams=ast.literal_eval(georeference_parameter), clipparameter=georeference_parameter, timestamp=timestamp, isactive=True, type='new', adminvalidation='', processed=False, mapid=mapObj.id, overwrites=0) request.db.add(georefProcess) request.db.flush() log.debug('Create response ...') response = { 'text': 'Georeference result saved. It will soon be ready for use.', 'georeferenceid': georefProcess.id, 'points': 20, 'gcps': request_data['georeference'], 'type': 'confirm' } return response else: raise GeoreferenceParameterError( 'Wrong or missing service parameter') except GeoreferenceParameterError as e: log.error(e) log.error(traceback.format_exc()) raise HTTPBadRequest(ERROR_MSG) except Exception as e: log.error(e) log.error(traceback.format_exc()) raise HTTPInternalServerError(ERROR_MSG)