Пример #1
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
Пример #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 testRectifyImagePolynom3ForAK(self):
     destPath = os.path.join(self.dir, 'test-ak-rectified-polynom3.tif')
     file = os.path.join(self.dir,'test-ak.jpg')  
     clip = [(2327, 2118), (9214, 2099), (9195, 7235), (2297, 7234), (2327, 2118)]
     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 = rectifyPolynom(file, destPath, clip, gcps, srs, self.logger, self.dir, None, order=3)
     
     print '====================='
     print 'Test if testRectifyImagePolynom3ForAK  ...'
     print 'Response: %s'%response
     print '====================='
      
     self.assertEqual(response, destPath, "Response is not equal to %s"%destPath)
Пример #4
0
 def testRectifyImagePolynom1ForMtb(self):
     destPath = os.path.join(self.dir, 'test-mtb-rectified-polynom1.tif')
     response = rectifyPolynom(self.file, destPath, self.testData, self.testGcp, 4314, self.logger, self.dir, None, order=1)
     
     print '====================='
     print 'Test if testRectifyImagePolynom1ForMtb  ...'
     print 'Response: %s'%response
     print '====================='
      
     self.assertEqual(response, destPath, "Response is not equal to %s"%destPath)
     
     if os.path.exists(destPath):
         os.remove(destPath)