def resetGeorefParameters(request):
    try:
        log.info('Receive a reset georeference parameter requests.')
        login = checkIsUser(request)
        dbsession = request.db
        messtischblatt_id = request.params['mtbid']
        georeference_process = Georeferenzierungsprozess.by_messtischblattid(messtischblatt_id, dbsession)
        referenz = georeference_process.clipparameter
        fehlerbeschreibung = 'Zuruecksetzen von Georeferenzierungsparameter für GeorefId=%s'%georeference_process.id
        if login and messtischblatt_id and referenz and fehlerbeschreibung and Users.by_username(login, dbsession):
            log.debug('Save reset process in table fehlermeldungen ...')
            newFehlermeldung = Fehlermeldung(objektid = messtischblatt_id, referenz = referenz, nutzerid = login,
                        fehlerbeschreibung = fehlerbeschreibung, timestamp = getTimestampAsPGStr())
            dbsession.add(newFehlermeldung)
            
            log.debug('Remove georeference process ...')
            dbsession.delete(georeference_process)
            
            log.debug('Remove refmtblayer ...')
            try:
                refmtblayer = RefMtbLayer.by_id(MTB_LAYER_ID, messtischblatt_id, dbsession)
                dbsession.delete(refmtblayer)
            except:
                log.debug('No entry for refmtblayer found ...')
                pass
            
            log.debug('Update messtischblatt db ...')
            messtischblatt = Messtischblatt.by_id(messtischblatt_id, dbsession) 
            messtischblatt.isttransformiert = False
            
            return json.dumps({'status':'confirmed'}, ensure_ascii=False, encoding='utf-8')
    except DBAPIError:
        log.error('Problems while trying to remove georeference parameter from the database ...')
        return Response(conn_err_msg, content_type='text/plain', status_int=500)
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)
Exemple #3
0
def resetGeorefParameters(request):
    try:
        log.info('Receive a reset georeference parameter requests.')
        login = checkIsUser(request)
        dbsession = request.db
        messtischblatt_id = request.params['mtbid']
        georeference_process = Georeferenzierungsprozess.by_messtischblattid(
            messtischblatt_id, dbsession)
        referenz = georeference_process.clipparameter
        fehlerbeschreibung = 'Zuruecksetzen von Georeferenzierungsparameter für GeorefId=%s' % georeference_process.id
        if login and messtischblatt_id and referenz and fehlerbeschreibung and Users.by_username(
                login, dbsession):
            log.debug('Save reset process in table fehlermeldungen ...')
            newFehlermeldung = Fehlermeldung(
                objektid=messtischblatt_id,
                referenz=referenz,
                nutzerid=login,
                fehlerbeschreibung=fehlerbeschreibung,
                timestamp=getTimestampAsPGStr())
            dbsession.add(newFehlermeldung)

            log.debug('Remove georeference process ...')
            dbsession.delete(georeference_process)

            log.debug('Remove refmtblayer ...')
            try:
                refmtblayer = RefMtbLayer.by_id(MTB_LAYER_ID,
                                                messtischblatt_id, dbsession)
                dbsession.delete(refmtblayer)
            except:
                log.debug('No entry for refmtblayer found ...')
                pass

            log.debug('Update messtischblatt db ...')
            messtischblatt = Messtischblatt.by_id(messtischblatt_id, dbsession)
            messtischblatt.isttransformiert = False

            return json.dumps({'status': 'confirmed'},
                              ensure_ascii=False,
                              encoding='utf-8')
    except DBAPIError:
        log.error(
            'Problems while trying to remove georeference parameter from the database ...'
        )
        return Response(conn_err_msg,
                        content_type='text/plain',
                        status_int=500)
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)
Exemple #5
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)
Exemple #6
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)