def approx_equal(a, b): try: #Are they numeric? a, b = float(a), float(b) return gdaltest.approx_equal(a, b) except TypeError: #Maybe they're lists? eq = [gdaltest.approx_equal(a, b) for a, b in zip(a, b)] return 0 not in eq
def approx_equal( a, b ): try: #Are they numeric? a,b = float(a),float(b) return gdaltest.approx_equal(a,b) except TypeError: #Maybe they're lists? eq=[gdaltest.approx_equal(a,b) for a,b in zip(a,b)] return 0 not in eq
def test_osr_basic_2(): srs = osr.SpatialReference() srs.SetStatePlane(403, 1) # California III NAD83. # print srs.ExportToPrettyWkt() parm_list = \ [(osr.SRS_PP_STANDARD_PARALLEL_1, 38.43333333333333), (osr.SRS_PP_STANDARD_PARALLEL_2, 37.06666666666667), (osr.SRS_PP_LATITUDE_OF_ORIGIN, 36.5), (osr.SRS_PP_CENTRAL_MERIDIAN, -120.5), (osr.SRS_PP_FALSE_EASTING, 2000000.0), (osr.SRS_PP_FALSE_NORTHING, 500000.0)] for parm in parm_list: value = srs.GetProjParm(parm[0], -1111) assert gdaltest.approx_equal(parm[1], value), \ ('got %.16g for %s instead of %.16g.' % (value, parm[0], parm[1])) auth_list = [('GEOGCS', '4269'), ('DATUM', '6269'), ('PROJCS', '26943'), ('PROJCS|UNIT', '9001')] for auth in auth_list: assert srs.GetAuthorityName(auth[0]) == 'EPSG', \ ('Got authority %s instead of EPSG for %s' % (srs.GetAuthorityName(auth[0]), auth[0])) assert str(srs.GetAuthorityCode(auth[0])) == auth[1], \ ('Got code %s instead of %s for %s' % (srs.GetAuthorityCode(auth[0]), auth[1], auth[0]))
def test_osr_basic_3(): srs = osr.SpatialReference() # California III NAD83 (feet) srs.SetStatePlane(403, 1, 'Foot', 0.3048006096012192) # print srs.ExportToPrettyWkt() parm_list = \ [(osr.SRS_PP_STANDARD_PARALLEL_1, 38.43333333333333), (osr.SRS_PP_STANDARD_PARALLEL_2, 37.06666666666667), (osr.SRS_PP_LATITUDE_OF_ORIGIN, 36.5), (osr.SRS_PP_CENTRAL_MERIDIAN, -120.5), (osr.SRS_PP_FALSE_EASTING, 6561666.666666667), (osr.SRS_PP_FALSE_NORTHING, 1640416.666666667)] for parm in parm_list: value = srs.GetProjParm(parm[0], -1111) assert gdaltest.approx_equal(parm[1], value), \ ('got %.16g for %s instead of %.16g.' % (value, parm[0], parm[1])) auth_list = [('GEOGCS', '4269'), ('DATUM', '6269')] for auth in auth_list: assert srs.GetAuthorityName(auth[0]) == 'EPSG', \ ('Got authority %s instead of EPSG for %s' % (srs.GetAuthorityName(auth[0]), auth[0])) assert str(srs.GetAuthorityCode(auth[0])) == auth[1], \ ('Got code %s instead of %s for %s' % (srs.GetAuthorityCode(auth[0]), auth[1], auth[0])) assert srs.GetAuthorityName('PROJCS') is None, \ 'Got a PROJCS Authority but we should not' assert str(srs.GetAuthorityCode('PROJCS|UNIT')) != '9001', \ 'Got METER authority code on linear units.' assert srs.GetLinearUnitsName() == 'Foot', 'Didnt get Foot linear units' if srs.GetLinearUnits() != 0.3048006096012192: print('%.16g' % srs.GetLinearUnits()) pytest.fail('Didnt get Foot linear units') if srs.GetTargetLinearUnits('PROJCS') != 0.3048006096012192: print('%.16g' % srs.GetTargetLinearUnits('PROJCS')) pytest.fail('Didnt get Foot linear units') if srs.GetTargetLinearUnits(None) != 0.3048006096012192: print('%.16g' % srs.GetTargetLinearUnits(None)) pytest.fail('Didnt get Foot linear units')
def osr_basic_3(): srs = osr.SpatialReference() # California III NAD83 (feet) srs.SetStatePlane( 403, 1, 'Foot', 0.3048006096012192 ) #print srs.ExportToPrettyWkt() parm_list = \ [ (osr.SRS_PP_STANDARD_PARALLEL_1, 38.43333333333333), (osr.SRS_PP_STANDARD_PARALLEL_2, 37.06666666666667), (osr.SRS_PP_LATITUDE_OF_ORIGIN, 36.5), (osr.SRS_PP_CENTRAL_MERIDIAN, -120.5), (osr.SRS_PP_FALSE_EASTING, 6561666.666666667), (osr.SRS_PP_FALSE_NORTHING, 1640416.666666667) ] for parm in parm_list: value = srs.GetProjParm( parm[0], -1111 ) if not gdaltest.approx_equal(parm[1], value): gdaltest.post_reason( 'got %.16g for %s instead of %.16g.' \ % (value, parm[0], parm[1] ) ) return 'fail' auth_list = [ ('GEOGCS', '4269'), ('DATUM', '6269') ] for auth in auth_list: if srs.GetAuthorityName( auth[0] ) != 'EPSG': gdaltest.post_reason( 'Got authority %s instead of EPSG for %s' \ % (srs.GetAuthorityName( auth[0] ), auth[0]) ) return 'fail' if str(srs.GetAuthorityCode( auth[0] )) != auth[1]: gdaltest.post_reason( 'Got code %s instead of %s for %s' \ % (srs.GetAuthorityCode( auth[0] ), auth[1], auth[0]) ) return 'fail' if srs.GetAuthorityName( 'PROJCS' ) is not None: gdaltest.post_reason( 'Got a PROJCS Authority but we shouldnt' ) return 'fail' if str(srs.GetAuthorityCode( 'PROJCS|UNIT' )) is '9001': gdaltest.post_reason( 'Got METER authority code on linear units.' ) return 'fail' if srs.GetLinearUnitsName() != 'Foot': gdaltest.post_reason( 'Didnt get Foot linear units' ) return 'fail' return 'success'
def osr_basic_3(): srs = osr.SpatialReference() # California III NAD83 (feet) srs.SetStatePlane(403, 1, 'Foot', 0.3048006096012192) #print srs.ExportToPrettyWkt() parm_list = \ [ (osr.SRS_PP_STANDARD_PARALLEL_1, 38.43333333333333), (osr.SRS_PP_STANDARD_PARALLEL_2, 37.06666666666667), (osr.SRS_PP_LATITUDE_OF_ORIGIN, 36.5), (osr.SRS_PP_CENTRAL_MERIDIAN, -120.5), (osr.SRS_PP_FALSE_EASTING, 6561666.666666667), (osr.SRS_PP_FALSE_NORTHING, 1640416.666666667) ] for parm in parm_list: value = srs.GetProjParm(parm[0], -1111) if not gdaltest.approx_equal(parm[1], value): gdaltest.post_reason( 'got %.16g for %s instead of %.16g.' \ % (value, parm[0], parm[1] ) ) return 'fail' auth_list = [('GEOGCS', '4269'), ('DATUM', '6269')] for auth in auth_list: if srs.GetAuthorityName(auth[0]) != 'EPSG': gdaltest.post_reason( 'Got authority %s instead of EPSG for %s' \ % (srs.GetAuthorityName( auth[0] ), auth[0]) ) return 'fail' if str(srs.GetAuthorityCode(auth[0])) != auth[1]: gdaltest.post_reason( 'Got code %s instead of %s for %s' \ % (srs.GetAuthorityCode( auth[0] ), auth[1], auth[0]) ) return 'fail' if srs.GetAuthorityName('PROJCS') is not None: gdaltest.post_reason('Got a PROJCS Authority but we shouldnt') return 'fail' if str(srs.GetAuthorityCode('PROJCS|UNIT')) is '9001': gdaltest.post_reason('Got METER authority code on linear units.') return 'fail' if srs.GetLinearUnitsName() != 'Foot': gdaltest.post_reason('Didnt get Foot linear units') return 'fail' return 'success'