Exemplo n.º 1
0
def georeferenceGetProcess(request):
    log.info('Receive request GetGeoreferenceProcess')
    
    try:
        request_data = None
        if request.method == 'POST':
            request_data = request.json_body
        
        objectid = None
        if 'objectid' in request_data:
            validateId(request_data['objectid'])
            objectid = int(request_data['objectid'])
            log.debug('Objectid is valide: %s'%request_data)
        
        georeferenceid = None
        if 'georeferenceid' in request_data:
            georeferenceid = int(request_data['georeferenceid'])
            
        if georeferenceid:
            response = createResponseForSpecificGeoreferenceProcess(objectid, georeferenceid, request)
        else:
            response = createGeneralResponse(objectid, request)
        return json.dumps(response, ensure_ascii=False, encoding='utf-8')               
    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 creating response for getprocess request - %s'%e
        log.error(message)
        return HTTPInternalServerError(message)
Exemplo n.º 2
0
def georeferenceGetProcess(request):
    log.info('Receive request GetGeoreferenceProcess')

    try:
        request_data = None
        if request.method == 'POST':
            request_data = request.json_body

        objectid = None
        if 'objectid' in request_data:
            validateId(request_data['objectid'])
            objectid = int(request_data['objectid'])
            log.debug('Objectid is valide: %s' % request_data)

        georeferenceid = None
        if 'georeferenceid' in request_data:
            georeferenceid = int(request_data['georeferenceid'])

        if georeferenceid:
            response = createResponseForSpecificGeoreferenceProcess(
                objectid, georeferenceid, request)
        else:
            response = createGeneralResponse(objectid, request)
        return json.dumps(response, ensure_ascii=False, encoding='utf-8')
    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 creating response for getprocess request - %s' % e
        log.error(message)
        return HTTPInternalServerError(message)
Exemplo n.º 3
0
def parseMapObjForId(request_data, name, dbsession):
    """ This functions parses a map objectid from an objectid """
    if name in request_data:
        validateId(request_data[name])         
        # @deprecated     
        # do mapping for support of new name schema
        mapObj = Map.by_id(int(request_data[name]), dbsession)
        if mapObj is None:
            raise GeoreferenceParameterError('Missing or wrong objectid parameter.')           
        else:
            return mapObj
    raise GeoreferenceParameterError('Missing or wrong objectid parameter.')  
Exemplo n.º 4
0
def parseMapObjForId(request_data, name, dbsession):
    """ This functions parses a map objectid from an objectid """
    if name in request_data:
        validateId(request_data[name])
        # @deprecated
        # do mapping for support of new name schema
        mapObj = Map.by_id(int(request_data[name]), dbsession)
        if mapObj is None:
            raise GeoreferenceParameterError(
                'Missing or wrong objectid parameter.')
        else:
            return mapObj
    raise GeoreferenceParameterError('Missing or wrong objectid parameter.')
Exemplo 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
            
        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)
Exemplo n.º 6
0
def georeferenceValidation(request):
    log.info('Receive request for processing georeference validation result')
    
    try:
        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('Start creating validation result ...')
        messtischblatt = Messtischblatt.by_id(request_data['id'], request.db)
        # actual only support this option if target srs is EPSG:4314
        epsg_code = int(str(request_data['georeference']['target']).split(':')[1])
        if request_data['georeference']['source'] == 'pixel' and epsg_code == 4314:
            log.debug('Parse gcps ...')
            gcps = parseGcps(request_data['georeference']['gcps'])
            
            log.debug('Process georeference parameter ...')
            destPath = georeference(messtischblatt.original_path, os.path.join(GEOREFERENCE_MAPFILE_FOLDER,messtischblatt.dateiname+"::"+str(getUniqueId())+".vrt"), 
                         GEOREFERENCE_TMP_DIR, gcps, epsg_code, epsg_code, 'polynom', log)
        
            log.debug('Create temporary mapfile ...')
            wms_url = createMapfile(messtischblatt.dateiname, destPath, GEOREFERENCE_MAPFILE_TEMPLATE, GEOREFERENCE_MAPFILE_FOLDER, GEOREFERENCE_MAPFILE_DEFAULT_PARAMS)
            
            log.debug('Create response ...')  
            response = {'wms_url':wms_url,'layer_id':messtischblatt.dateiname,'extent':Messtischblatt.getExtent(messtischblatt.id, request.db)}
            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.value
        log.error(message)
        return HTTPInternalServerError(message)
Exemplo n.º 7
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)
Exemplo 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)
Exemplo n.º 9
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)