Пример #1
0
    def testRectifyImageAffineForAKWithoutClop(self):
        destPath = os.path.join(self.dir, 'test-ak-rectified-affine.tif')
        file = os.path.join(self.dir,'test-ak.jpg')
        srs = 4314
        gcps = [
            gdal.GCP(13.322571166912697, 50.869534359847236, 0, 5473, 6079),
            gdal.GCP(13.346566162286086, 50.91926655702792, 0, 5670, 5589),
            gdal.GCP(13.53735995082988, 50.802610870942374, 0, 7020, 6807),
            gdal.GCP(13.667546305614797, 50.89755275702876, 0, 7812, 5913),
            gdal.GCP(13.741126714401176, 51.05625639529854, 0, 8338, 4161),
            gdal.GCP(13.681169234684086, 51.1685499300691, 0, 7942, 2791),
            gdal.GCP(13.47756543137287, 51.16569220735402, 0, 6609, 2882),
            gdal.GCP(13.300067220165836, 51.06061124738151, 0, 5102, 4096),
            gdal.GCP(13.310932518222272, 51.19680951127774, 0, 5295, 2447),
            gdal.GCP(12.921352950966174, 50.83419856543994, 0, 2536, 6561),
            gdal.GCP(12.983108161200633, 50.984707383627985, 0, 3048, 5009),
            gdal.GCP(12.973153769483801, 51.099562229978154, 0, 3091, 3676),
            gdal.GCP(13.119775225375355, 51.12445831286638, 0, 4017, 3228),
            gdal.GCP(13.124513229340627, 50.97154471762153, 0, 4037, 4961),
        ]
        response = rectifyImageAffine(file, destPath, [], gcps, srs, self.logger)

        print '====================='
        print 'Test if testRectifyImageForAK  ...'
        print 'Response: %s'%response
        print '====================='

        self.assertEqual(response, destPath, "Response is not equal to %s"%destPath)

        if os.path.exists(destPath):
            os.remove(destPath)
Пример #2
0
def createValidationResult(requestParams, gcps, gcpstargetSrs, LOGGER):
    """ Function creates a process image and creates a temporary wms.

    :type requestParams: dict
    :type gcps: List.<gdal.GCP>
    :type georefTargetSRS: int
    :type LOGGER: logging.LOGGER
    :return: str
    :raise: vkviewer.python.georef.georeferenceexceptions.ParameterException """
    LOGGER.debug('Process georeference result ...')
    tmpFile = os.path.join(GEOREFERENCE_MAPFILE_FOLDER,requestParams['mapObj'].apsdateiname+"::"+str(uuid.uuid4())+".tif")
    destPath = None
    if requestParams['georeference']['algorithm'] == 'affine':
        destPath = rectifyImageAffine(requestParams['mapObj'].originalimage, tmpFile,
                [], gcps, gcpstargetSrs, LOGGER)
    elif requestParams['georeference']['algorithm'] == 'polynom':
        destPath = rectifyPolynomWithVRT(requestParams['mapObj'].originalimage, tmpFile, gcps, gcpstargetSrs, LOGGER, TMP_DIR)
    elif requestParams['georeference']['algorithm'] == 'tps':
        destPath = rectifyTpsWithVrt(requestParams['mapObj'].originalimage, tmpFile, gcps, gcpstargetSrs, LOGGER, TMP_DIR)
    else:
        raise ParameterException('Transformation algorithm - %s - is not supported yet.'%requestParams['georeference']['algorithm'])

    LOGGER.debug('Create temporary mapfile ...')
    wmsUrl = createMapfile(requestParams['mapObj'].apsdateiname, destPath, gcpstargetSrs, GEOREFERENCE_MAPFILE_TEMPLATE, GEOREFERENCE_MAPFILE_FOLDER, GEOREFERENCE_MAPFILE_DEFAULT_PARAMS)

    LOGGER.debug('Calculate extent ...')
    dataset = gdal.Open(destPath, GA_ReadOnly)
    extent = getBoundsFromDataset(dataset)
    LOGGER.debug('Deliver results.')
    return {'wmsUrl':wmsUrl,'layerId':requestParams['mapObj'].apsdateiname, 'extent': extent}
Пример #3
0
    def testRectifyImageAffineWithEmptyClip(self):
        destPath = os.path.join(self.dir, 'test-rectifyImageWithOutClip.tif')
        response = rectifyImageAffine(self.file, destPath, [], self.testGcp, 4314, self.logger)

        print '====================='
        print 'Test if testRectifyImageAffineWithEmptyClip ...'
        print 'Response: %s'%response
        print '====================='

        self.assertEqual(response, destPath, "Response is not equal to %s"%destPath)

        if os.path.exists(destPath):
            os.remove(destPath)
def createValidationResult(requestParams, gcps, gcpstargetSrs, LOGGER):
    """ Function creates a process image and creates a temporary wms.

    :type requestParams: dict
    :type gcps: List.<gdal.GCP>
    :type georefTargetSRS: int
    :type LOGGER: logging.LOGGER
    :return: str
    :raise: vkviewer.python.georef.georeferenceexceptions.ParameterException """
    LOGGER.debug("Process georeference result ...")
    tmpFile = os.path.join(
        GEOREFERENCE_MAPFILE_FOLDER, requestParams["mapObj"].apsdateiname + "::" + str(uuid.uuid4()) + ".tif"
    )
    destPath = None
    if requestParams["georeference"]["algorithm"] == "affine":
        destPath = rectifyImageAffine(requestParams["mapObj"].originalimage, tmpFile, [], gcps, gcpstargetSrs, LOGGER)
    elif requestParams["georeference"]["algorithm"] == "polynom":
        destPath = rectifyPolynomWithVRT(
            requestParams["mapObj"].originalimage, tmpFile, gcps, gcpstargetSrs, LOGGER, TMP_DIR
        )
    elif requestParams["georeference"]["algorithm"] == "tps":
        destPath = rectifyTpsWithVrt(
            requestParams["mapObj"].originalimage, tmpFile, gcps, gcpstargetSrs, LOGGER, TMP_DIR
        )
    else:
        raise ParameterException(
            "Transformation algorithm - %s - is not supported yet." % requestParams["georeference"]["algorithm"]
        )

    LOGGER.debug("Create temporary mapfile ...")
    wmsUrl = createMapfile(
        requestParams["mapObj"].apsdateiname,
        destPath,
        gcpstargetSrs,
        GEOREFERENCE_MAPFILE_TEMPLATE,
        GEOREFERENCE_MAPFILE_FOLDER,
        GEOREFERENCE_MAPFILE_DEFAULT_PARAMS,
    )

    LOGGER.debug("Calculate extent ...")
    dataset = gdal.Open(destPath, GA_ReadOnly)
    extent = getBoundsFromDataset(dataset)
    LOGGER.debug("Deliver results.")
    return {"wmsUrl": wmsUrl, "layerId": requestParams["mapObj"].apsdateiname, "extent": extent}