示例#1
0
def updateClipPolygonFromOldPolygon(georefObj):
    """ Function generates a new polygon string from and old polygon string.

    :type georeference.models.vkdb.georeferenzierungsprozess.Georeferenzierungsprozess: georefObj
    :return:
    """
    print 'Update clip for georeference process with id %s ...' % georefObj.id
    # generate clip polygon
    polygon = georefObj.clippolygon['polygon']
    gcps = parseGcps(georefObj.georefparams['gcps'])
    geoTransform = gdal.GCPsToGeoTransform(gcps)
    transformedClipPolygon = transformClipPolygon(polygon, geoTransform)
    correctedPolygon = sortPolygonCoordinates(transformedClipPolygon)

    # generate clip polygon string
    polygonAsStr = 'POLYGON(('
    for coordinate in correctedPolygon:
        polygonAsStr += str(coordinate[0]) + ' ' + str(coordinate[1]) + ','
    polygonAsStr = polygonAsStr[:-1] + '))'

    # get srid
    srid = georefObj.georefparams['target'].split(':')[1]

    # update database
    if len(correctedPolygon) > 4:
        georefObj.setClip(polygonAsStr, srid, dbsession)
示例#2
0
def processGeorefImage(mapObj, georefObj, dbsession, logger):
    """ Function process a persistent georeference image

    :type georeference.models.vkdb.map.Map: mapObj
    :type georeference.models.vkdb.georeferenzierungsprozess.Georeferenzierungsprozess: georefObj
    :type sqlalchemy.orm.session.Session: dbsession
    :type logging.Logger: logger
    :return: str """
    gcps = parseGcps(georefObj.georefparams['gcps'])
    georefTargetSRS = stripSRIDFromEPSG(georefObj.georefparams['target'])
    targetPath = os.path.join(GEOREFERENCE_PERSITENT_TARGETDIR, os.path.join(str(mapObj.maptype).lower(), mapObj.apsdateiname+'.tif'))
    transformationAlgorithm = georefObj.georefparams['algorithm'] if 'algorithm' in georefObj.georefparams else 'affine'
    destPath = None

    # create clip shape if exists
    clipShpPath = None
    if georefObj.clip is not None:
        clipShpPath = os.path.join(TMP_DIR, '%s' % uuid.uuid4())
        clipShpPath = createClipShapefile(convertPostgisStringToList(georefObj.clip), clipShpPath, georefObj.getSRIDClip(dbsession))

    logger.debug('Process georeference result ...')
    if transformationAlgorithm == 'affine':
        destPath = rectifyPolynom(mapObj.originalimage, targetPath, [], gcps, georefTargetSRS, logger, TMP_DIR, clipShpPath, order=1)
    elif transformationAlgorithm == 'polynom':
        destPath = rectifyPolynom(mapObj.originalimage, targetPath, [], gcps, georefTargetSRS, logger, TMP_DIR, clipShpPath)
    elif transformationAlgorithm == 'tps':
        destPath = rectifyTps(mapObj.originalimage, targetPath, [], gcps, georefTargetSRS, logger, TMP_DIR, clipShpPath)

    logger.debug('Add overviews to the image ...')
    addOverviews(destPath, '2 4 8 16 32', logger)

    return destPath
示例#3
0
def processGeorefImage(mapObj, georefObj, dbsession, logger):
    """ Function process a persistent georeference image

    :type georeference.models.vkdb.map.Map: mapObj
    :type georeference.models.vkdb.georeferenzierungsprozess.Georeferenzierungsprozess: georefObj
    :type sqlalchemy.orm.session.Session: dbsession
    :type logging.Logger: logger
    :return: str """
    gcps = parseGcps(georefObj.georefparams['gcps'])
    georefTargetSRS = stripSRIDFromEPSG(georefObj.georefparams['target'])
    targetPath = os.path.join(
        GEOREFERENCE_PERSITENT_TARGETDIR,
        os.path.join(
            str(mapObj.maptype).lower(), mapObj.apsdateiname + '.tif'))
    transformationAlgorithm = georefObj.georefparams[
        'algorithm'] if 'algorithm' in georefObj.georefparams else 'affine'
    destPath = None

    # create clip shape if exists
    clipShpPath = None
    if georefObj.clip is not None:
        clipShpPath = os.path.join(TMP_DIR, '%s' % uuid.uuid4())
        clipShpPath = createClipShapefile(
            convertPostgisStringToList(georefObj.clip), clipShpPath,
            georefObj.getSRIDClip(dbsession))

    logger.debug('Process georeference result ...')
    if transformationAlgorithm == 'affine':
        destPath = rectifyPolynom(mapObj.originalimage,
                                  targetPath, [],
                                  gcps,
                                  georefTargetSRS,
                                  logger,
                                  TMP_DIR,
                                  clipShpPath,
                                  order=1)
    elif transformationAlgorithm == 'polynom':
        destPath = rectifyPolynom(mapObj.originalimage, targetPath, [], gcps,
                                  georefTargetSRS, logger, TMP_DIR,
                                  clipShpPath)
    elif transformationAlgorithm == 'tps':
        destPath = rectifyTps(mapObj.originalimage, targetPath, [], gcps,
                              georefTargetSRS, logger, TMP_DIR, clipShpPath)

    logger.debug('Add overviews to the image ...')
    addOverviews(destPath, '2 4 8 16 32', logger)

    return destPath
示例#4
0
def georeferenceValidation(request):
    """ The function generates a process validation result and publish it via a WMS instance. The
        wms references are returned.

        :type request: pyramid.request
        :return: dict
        :raise: HTTPBadRequest
        :raise: HTTPInternalServerError """
    LOGGER.info('Receive process validation request with parameters: %s'%request.json_body)

    try:
        # extract validation data
        LOGGER.debug('Parse request params ...')
        requestParams = parseGeoreferenceParamsFromRequest(request)

        LOGGER.debug('Parse and validate SRS params ...')
        georefSourceSRS = requestParams['georeference']['source']
        if str(georefSourceSRS).lower() != 'pixel':
            raise ParameterException('Only "pixel" is yet supported as source srs.')

        if ':' not in str(requestParams['georeference']['target']):
            raise ParameterException('Missing "EPSG:...." syntax for target srs.')
        georefTargetSRS = stripSRIDFromEPSG(requestParams['georeference']['target'])

        # generate a temporary process result and publish it via wms
        LOGGER.debug('Parse and validate gcps params ...')
        if len(requestParams['georeference']['gcps']) < 2:
            raise ParameterException('Not enough gcps for valid georeferencing ...')
        gcps = parseGcps(requestParams['georeference']['gcps'])

        # calculate validation result
        return createValidationResult(requestParams, gcps, georefTargetSRS, LOGGER)

    except ParameterException as e:
        LOGGER.error(e)
        LOGGER.error(traceback.format_exc())
        raise HTTPBadRequest(ERROR_MSG)
    except Exception as e:
        LOGGER.error(e)
        LOGGER.error(traceback.format_exc())
        raise HTTPInternalServerError(ERROR_MSG)
def georeferenceValidation(request):
    """ The function generates a process validation result and publish it via a WMS instance. The
        wms references are returned.

        :type request: pyramid.request
        :return: dict
        :raise: HTTPBadRequest
        :raise: HTTPInternalServerError """
    LOGGER.info("Receive process validation request with parameters: %s" % request.json_body)

    try:
        # extract validation data
        LOGGER.debug("Parse request params ...")
        requestParams = parseGeoreferenceParamsFromRequest(request)

        LOGGER.debug("Parse and validate SRS params ...")
        georefSourceSRS = requestParams["georeference"]["source"]
        if str(georefSourceSRS).lower() != "pixel":
            raise ParameterException('Only "pixel" is yet supported as source srs.')

        if ":" not in str(requestParams["georeference"]["target"]):
            raise ParameterException('Missing "EPSG:...." syntax for target srs.')
        georefTargetSRS = stripSRIDFromEPSG(requestParams["georeference"]["target"])

        # generate a temporary process result and publish it via wms
        LOGGER.debug("Parse and validate gcps params ...")
        if len(requestParams["georeference"]["gcps"]) < 2:
            raise ParameterException("Not enough gcps for valid georeferencing ...")
        gcps = parseGcps(requestParams["georeference"]["gcps"])

        # calculate validation result
        return createValidationResult(requestParams, gcps, georefTargetSRS, LOGGER)

    except ParameterException as e:
        LOGGER.error(e)
        LOGGER.error(traceback.format_exc())
        raise HTTPBadRequest(ERROR_MSG)
    except Exception as e:
        LOGGER.error(e)
        LOGGER.error(traceback.format_exc())
        raise HTTPInternalServerError(ERROR_MSG)