コード例 #1
0
ファイル: grib.py プロジェクト: plkms/gdal
def grib_1():

    gdaltest.grib_drv = gdal.GetDriverByName('GRIB')
    if gdaltest.grib_drv is None:
        return 'skip'

    # Test proj4 presence
    import osr_ct
    osr_ct.osr_ct_1()

    tst = gdaltest.GDALTest('GRIB', 'ds.mint.bin', 2, 46927)
    return tst.testOpen()
コード例 #2
0
ファイル: osr_ct_proj.py プロジェクト: geo-data/go-gdal
    def testProj(self):

        import osr_ct
        osr_ct.osr_ct_1()
        if gdaltest.have_proj4 == 0:
            return 'skip'

        if self.requirements is not None and self.requirements[:5] == 'GRID:':
            try:
                proj_lib = os.environ['PROJ_LIB']
            except:
                #print( 'PROJ_LIB unset, skipping test.' )
                return 'skip'

            try:
                open( proj_lib + '/' + self.requirements[5:] )
            except:
                #print( 'Did not find GRID:%s' % self.requirements[5:] )
                return 'skip'

        src = osr.SpatialReference()
        if src.SetFromUserInput( self.src_srs ) != 0:
            gdaltest.post_reason('SetFromUserInput(%s) failed.' % self.src_srs)
            return 'fail'

        dst = osr.SpatialReference()
        if dst.SetFromUserInput( self.dst_srs ) != 0:
            gdaltest.post_reason('SetFromUserInput(%s) failed.' % self.dst_srs)
            return 'fail'

        if self.requirements is not None and self.requirements[0] != 'G':
            additionnal_error_str = ' Check that proj version is >= %s ' % self.requirements
        else:
            additionnal_error_str = ''

        try:
            gdal.PushErrorHandler( 'CPLQuietErrorHandler' )
            ct = osr.CoordinateTransformation( src, dst )
            gdal.PopErrorHandler()
            if gdal.GetLastErrorMsg().find('Unable to load PROJ.4') != -1:
                gdaltest.post_reason( 'PROJ.4 missing, transforms not available.' )
                return 'skip'
        except ValueError:
            gdal.PopErrorHandler()
            if gdal.GetLastErrorMsg().find('Unable to load PROJ.4') != -1:
                gdaltest.post_reason( 'PROJ.4 missing, transforms not available.' )
                return 'skip'
            else:
                gdaltest.post_reason( 'failed to create coordinate transformation. %s' % gdal.GetLastErrorMsg())
                return 'fail'
        except:
            gdal.PopErrorHandler()
            gdaltest.post_reason( 'failed to create coordinate transformation. %s' % gdal.GetLastErrorMsg())
            return 'fail'

        ######################################################################
        # Transform source point to destination SRS.

        result = ct.TransformPoint( self.src_xyz[0], self.src_xyz[1], self.src_xyz[2] )

        error = abs(result[0] - self.dst_xyz[0]) \
                + abs(result[1] - self.dst_xyz[1]) \
                + abs(result[2] - self.dst_xyz[2])

        if error > self.dst_error:
            gdaltest.post_reason( 'Dest error is %g, got (%.15g,%.15g,%.15g)%s' \
                                  % (error, result[0], result[1], result[2], additionnal_error_str) )
            return 'fail'

        ######################################################################
        # Now transform back.

        ct = osr.CoordinateTransformation( dst, src )

        result = ct.TransformPoint( result[0], result[1], result[2] )

        error = abs(result[0] - self.src_xyz[0]) \
                + abs(result[1] - self.src_xyz[1]) \
                + abs(result[2] - self.src_xyz[2])

        if error > self.src_error:
            gdaltest.post_reason( 'Back to source error is %g.%s' % (error, additionnal_error_str) )
            return 'fail'

        return 'success'
コード例 #3
0
    def testProj(self):

        import osr_ct
        osr_ct.osr_ct_1()
        if gdaltest.have_proj4 == 0:
            return 'skip'

        if self.requirements is not None and self.requirements[:5] == 'GRID:':
            try:
                proj_lib = os.environ['PROJ_LIB']
            except:
                #print( 'PROJ_LIB unset, skipping test.' )
                return 'skip'

            try:
                open( proj_lib + '/' + self.requirements[5:] )
            except:
                #print( 'Did not find GRID:%s' % self.requirements[5:] )
                return 'skip'

        src = osr.SpatialReference()
        if src.SetFromUserInput( self.src_srs ) != 0:
            gdaltest.post_reason('SetFromUserInput(%s) failed.' % self.src_srs)
            return 'fail'

        dst = osr.SpatialReference()
        if dst.SetFromUserInput( self.dst_srs ) != 0:
            gdaltest.post_reason('SetFromUserInput(%s) failed.' % self.dst_srs)
            return 'fail'

        if self.requirements is not None and self.requirements[0] != 'G':
            additionnal_error_str = ' Check that proj version is >= %s ' % self.requirements
        else:
            additionnal_error_str = ''

        try:
            gdal.PushErrorHandler( 'CPLQuietErrorHandler' )
            ct = osr.CoordinateTransformation( src, dst )
            gdal.PopErrorHandler()
            if gdal.GetLastErrorMsg().find('Unable to load PROJ.4') != -1:
                gdaltest.post_reason( 'PROJ.4 missing, transforms not available.' )
                return 'skip'
        except ValueError:
            gdal.PopErrorHandler()
            if gdal.GetLastErrorMsg().find('Unable to load PROJ.4') != -1:
                gdaltest.post_reason( 'PROJ.4 missing, transforms not available.' )
                return 'skip'
            else:
                gdaltest.post_reason( 'failed to create coordinate transformation. %s' % gdal.GetLastErrorMsg())
                return 'fail'
        except:
            gdal.PopErrorHandler()
            gdaltest.post_reason( 'failed to create coordinate transformation. %s' % gdal.GetLastErrorMsg())
            return 'fail'

        ######################################################################
        # Transform source point to destination SRS.

        result = ct.TransformPoint( self.src_xyz[0], self.src_xyz[1], self.src_xyz[2] )

        error = abs(result[0] - self.dst_xyz[0]) \
                + abs(result[1] - self.dst_xyz[1]) \
                + abs(result[2] - self.dst_xyz[2])

        if error > self.dst_error:
            gdaltest.post_reason( 'Dest error is %g, got (%.15g,%.15g,%.15g)%s' \
                                  % (error, result[0], result[1], result[2], additionnal_error_str) )
            return 'fail'

        ######################################################################
        # Now transform back.

        ct = osr.CoordinateTransformation( dst, src )

        result = ct.TransformPoint( result[0], result[1], result[2] )

        error = abs(result[0] - self.src_xyz[0]) \
                + abs(result[1] - self.src_xyz[1]) \
                + abs(result[2] - self.src_xyz[2])

        if error > self.src_error:
            gdaltest.post_reason( 'Back to source error is %g.%s' % (error, additionnal_error_str) )
            return 'fail'

        return 'success'
コード例 #4
0
ファイル: osr_ct_proj.py プロジェクト: nextgis-borsch/tests
    def testProj(self):

        import osr_ct

        osr_ct.osr_ct_1()
        if gdaltest.have_proj4 == 0:
            return "skip"

        if self.requirements is not None and self.requirements[:5] == "GRID:":
            try:
                proj_lib = os.environ["PROJ_LIB"]
            except:
                # print( 'PROJ_LIB unset, skipping test.' )
                return "skip"

            try:
                open(proj_lib + "/" + self.requirements[5:])
            except:
                # print( 'Did not find GRID:%s' % self.requirements[5:] )
                return "skip"

        src = osr.SpatialReference()
        if src.SetFromUserInput(self.src_srs) != 0:
            gdaltest.post_reason("SetFromUserInput(%s) failed." % self.src_srs)
            return "fail"

        dst = osr.SpatialReference()
        if dst.SetFromUserInput(self.dst_srs) != 0:
            gdaltest.post_reason("SetFromUserInput(%s) failed." % self.dst_srs)
            return "fail"

        if self.requirements is not None and self.requirements[0] != "G":
            additionnal_error_str = " Check that proj version is >= %s " % self.requirements
        else:
            additionnal_error_str = ""

        try:
            gdal.PushErrorHandler("CPLQuietErrorHandler")
            ct = osr.CoordinateTransformation(src, dst)
            gdal.PopErrorHandler()
            if gdal.GetLastErrorMsg().find("Unable to load PROJ.4") != -1:
                gdaltest.post_reason("PROJ.4 missing, transforms not available.")
                return "skip"
        except ValueError:
            gdal.PopErrorHandler()
            if gdal.GetLastErrorMsg().find("Unable to load PROJ.4") != -1:
                gdaltest.post_reason("PROJ.4 missing, transforms not available.")
                return "skip"
            else:
                gdaltest.post_reason("failed to create coordinate transformation. %s" % gdal.GetLastErrorMsg())
                return "fail"
        except:
            gdal.PopErrorHandler()
            gdaltest.post_reason("failed to create coordinate transformation. %s" % gdal.GetLastErrorMsg())
            return "fail"

        ######################################################################
        # Transform source point to destination SRS.

        result = ct.TransformPoint(self.src_xyz[0], self.src_xyz[1], self.src_xyz[2])

        error = abs(result[0] - self.dst_xyz[0]) + abs(result[1] - self.dst_xyz[1]) + abs(result[2] - self.dst_xyz[2])

        if error > self.dst_error:
            gdaltest.post_reason(
                "Dest error is %g, got (%.15g,%.15g,%.15g)%s"
                % (error, result[0], result[1], result[2], additionnal_error_str)
            )
            return "fail"

        ######################################################################
        # Now transform back.

        ct = osr.CoordinateTransformation(dst, src)

        result = ct.TransformPoint(result[0], result[1], result[2])

        error = abs(result[0] - self.src_xyz[0]) + abs(result[1] - self.src_xyz[1]) + abs(result[2] - self.src_xyz[2])

        if error > self.src_error:
            gdaltest.post_reason("Back to source error is %g.%s" % (error, additionnal_error_str))
            return "fail"

        return "success"
コード例 #5
0
ファイル: pdf.py プロジェクト: bpass/gdal
def pdf_write_ogr_with_reprojection():

    if gdaltest.pdf_drv is None:
        return 'skip'

    import osr_ct
    osr_ct.osr_ct_1()
    if gdaltest.have_proj4 == 0:
        return 'skip'

    f = gdal.VSIFOpenL('/vsimem/test.csv', 'wb')
    data = """WKT,id
"POINT (-117.641059792392142 33.902263065734573)",1
"POINT (-117.64098016484607 33.891620919037436)",2
"POINT (-117.62829768175105 33.902328822481238)",3
"POINT (-117.628219639160108 33.891686649558416)",4
"POINT (-117.634639319537328 33.896975031776485)",5
"POINT (-121.488694798047447 0.0)",6
"""

    gdal.VSIFWriteL(data, 1, len(data), f)
    gdal.VSIFCloseL(f)

    f = gdal.VSIFOpenL('/vsimem/test.vrt', 'wb')
    data = """<OGRVRTDataSource>
  <OGRVRTLayer name="test">
    <SrcDataSource relativeToVRT="0" shared="1">/vsimem/test.csv</SrcDataSource>
    <SrcLayer>test</SrcLayer>
    <GeometryType>wkbUnknown</GeometryType>
    <LayerSRS>+proj=longlat +datum=NAD27</LayerSRS>
    <Field name="id" type="Integer" src="id"/>
  </OGRVRTLayer>
</OGRVRTDataSource>
"""
    gdal.VSIFWriteL(data, 1, len(data), f)
    gdal.VSIFCloseL(f)

    options = [ 'OGR_DATASOURCE=/vsimem/test.vrt', 'OGR_DISPLAY_LAYER_NAMES=A_Layer', 'OGR_DISPLAY_FIELD=foo' ]

    src_ds = gdal.Open('data/byte.tif')
    ds = gdaltest.pdf_drv.CreateCopy('tmp/pdf_write_ogr.pdf', src_ds, options = options)
    ds = None
    src_ds = None

    ogr_ds = ogr.Open('tmp/pdf_write_ogr.pdf')
    ogr_lyr = ogr_ds.GetLayer(0)
    feature_count = ogr_lyr.GetFeatureCount()
    ogr_ds = None

    gdal.Unlink('tmp/pdf_write_ogr.pdf')

    gdal.Unlink('/vsimem/test.csv')
    gdal.Unlink('/vsimem/test.vrt')

    # Should have filtered out id = 6
    if feature_count != 5:
        gdaltest.post_reason('did not get expected feature count')
        print(feature_count)
        return 'fail'

    return 'success'