Ejemplo n.º 1
0
def getAdminEvaluationPage(request):
    log.info('Request - Get georeference profile page.')
    try:
        resultSet = request.db.execute(georeference_evaluation_query)

        log.debug('Create response list')
        georef_profile = []
        for record in resultSet:
            encoded_clip_params = str(
                convertUnicodeDictToUtf(ast.literal_eval(
                    record['clip_params']))).replace('\'', '"')
            georef_profile.append({
                'georef_id': record['georef_id'],
                'mtb_id': record['mtbid'],
                'clip_params': encoded_clip_params,
                'time': record['time'],
                'transformed': record['isttransformiert'],
                'isvalide': record['isvalide'],
                'titel': record['titel'],
                'key': record['key'],
                'time_georef': record['time_georef'],
                'type': record['type'],
                'userid': record['userid'],
                'published': record['published']
            })

        log.debug('Response: %s' % georef_profile)

        return {'georef_profile': georef_profile}
    except Exception as e:
        log.error(
            'Error while trying to request georeference history information')
        log.error(e)
        return {}
Ejemplo n.º 2
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

        mapObj = parseMapObjForId(request_data, 'id', request.db)
        log.debug('Id is valide: %s' % request_data)

        log.debug(
            'Check if there exists a registered georeference process for this messtischblatt ...'
        )
        if Georeferenzierungsprozess.isGeoreferenced(mapObj.id,
                                                     request.db) == False:
            response = {
                'text':
                'There is no registered georeference process for this messtischblatt. Please move back to the confirm process.'
            }
            return response

        # 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 = registerUpdateGeoreferenceProcessInDb(
                mapObj, userid, str(encoded_clip_params), request.db)

            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
            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 response
        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:
        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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
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
            
        mapObj = parseMapObjForId(request_data, 'id', request.db)
        log.debug('Id is valide: %s'%request_data)
            
        log.debug('Check if there exists a registered georeference process for this messtischblatt ...')
        if Georeferenzierungsprozess.isGeoreferenced(mapObj.id, request.db) == False:
            response = {'text':'There is no registered georeference process for this messtischblatt. Please move back to the confirm process.'}
            return response
        
        # 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 = registerUpdateGeoreferenceProcessInDb(mapObj, userid, str(encoded_clip_params), request.db)
            
            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  
            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 response
        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:
        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)
Ejemplo n.º 6
0
def getProcesses(request):
    try:
        log.info('Request - Get georeference processes.')
        
        if 'mapid' in request.params:
            log.debug('Get processes for mapid %s ...'%request.params['mapid'])
            queryData = request.db.query(Georeferenzierungsprozess, Metadata).join(Metadata, Georeferenzierungsprozess.mapid == Metadata.mapid)\
                .filter(Georeferenzierungsprozess.mapid == request.params['mapid'])\
                .order_by(desc(Georeferenzierungsprozess.id))
        elif 'userid' in request.params:
            log.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:
            log.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:
            log.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]
            # use encoded_georefParams for visualisation as string on the client side
            encoded_georefParams = str(convertUnicodeDictToUtf(georef.georefparams)).replace('\'','"')
            response.append({'georef_id':georef.id, 'mapid':georef.mapid, 
                'georef_params': encoded_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})
        return response
    except Exception as e:
        log.error(e)
        log.error(traceback.format_exc())
        return HTTPInternalServerError(GENERAL_ERROR_MESSAGE);
Ejemplo n.º 7
0
def getAdminEvaluationPage(request):
    log.info('Request - Get georeference profile page.')
    try:            
        resultSet = request.db.execute(georeference_evaluation_query)
        
        log.debug('Create response list')
        georef_profile = []
        for record in resultSet:   
            encoded_clip_params = str(convertUnicodeDictToUtf(ast.literal_eval(record['clip_params']))).replace('\'','"')           
            georef_profile.append({'georef_id':record['georef_id'], 'mtb_id':record['mtbid'], 
                    'clip_params': encoded_clip_params, 'time': record['time'], 'transformed': record['isttransformiert'],
                    'isvalide': record['isvalide'], 'titel': record['titel'], 'key': record['key'],
                    'time_georef':record['time_georef'],'type':record['type'], 'userid': record['userid'],
                    'published':record['published']})
             
        log.debug('Response: %s'%georef_profile) 
        
        return {'georef_profile':georef_profile}
    except Exception as e:
        log.error('Error while trying to request georeference history information');
        log.error(e)
        return {}
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
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)