void object::test<1>() { ensure("SRS handle is NULL", NULL != srs_); err_ = OSRSetUTM(srs_, 11, TRUE); ensure_equals("Can't set UTM zone", err_, OGRERR_NONE); err_ = OSRSetWellKnownGeogCS(srs_, "WGS84"); ensure_equals("Can't set GeogCS", err_, OGRERR_NONE); double val = 0; val = OSRGetProjParm(srs_, SRS_PP_CENTRAL_MERIDIAN, -1111, &err_); ensure("Invalid UTM central meridian", std::fabs(val - (-117.0)) <= .00000000000010); val = OSRGetProjParm(srs_, SRS_PP_LATITUDE_OF_ORIGIN, -1111, &err_); ensure("Invalid UTM latitude of origin", std::fabs(val - 0.0) <= .00000000000010); val = OSRGetProjParm(srs_, SRS_PP_SCALE_FACTOR, -1111, &err_); ensure("Invalid UTM scale factor", std::fabs(val - 0.9996) <= .00000000000010); val = OSRGetProjParm(srs_, SRS_PP_FALSE_EASTING, -1111, &err_); ensure("Invalid UTM false easting", std::fabs(val - 500000.0) <= .00000000000010); val = OSRGetProjParm(srs_, SRS_PP_FALSE_NORTHING, -1111, &err_); ensure("Invalid UTM false northing", std::fabs(val - 0.0) <= .00000000000010); ensure_equals("Invalid authority name", std::string(OSRGetAuthorityName(srs_, "GEOGCS")), std::string("EPSG")); ensure_equals("Invalid authority code", std::string(OSRGetAuthorityCode(srs_, "GEOGCS")), std::string("4326")); ensure_equals("Invalid authority name", std::string(OSRGetAuthorityName(srs_, "DATUM")), std::string("EPSG")); ensure_equals("Invalid authority code", std::string(OSRGetAuthorityCode(srs_, "DATUM")), std::string("6326")); }
void object::test<2>() { ensure("SRS handle is NULL", NULL != srs_); std::string wkt("+proj=lcc +x_0=0.6096012192024384e+06 +y_0=0" "+lon_0=90dw +lat_0=42dn +lat_1=44d4'n +lat_2=42d44'n" "+a=6378206.400000 +rf=294.978698 +nadgrids=conus,ntv1_can.dat"); err_ = OSRImportFromProj4(srs_, wkt.c_str()); ensure_equals("OSRImportFromProj4)( failed", err_, OGRERR_NONE); const double maxError = 0.0005; double val = 0; val = OSRGetProjParm(srs_, SRS_PP_FALSE_EASTING, -1111, &err_); ensure_equals("OSRGetProjParm() failed", err_, OGRERR_NONE); ensure("Parsing exponents not supported", std::fabs(val - 609601.219) <= maxError); }
void object::test<3>() { ensure("SRS handle is NULL", NULL != srs_); // California III NAD83 (feet) OSRSetStatePlaneWithUnits(srs_, 403, 1, "Foot", 0.3048006096012192); double val = 0; val = OSRGetProjParm(srs_, SRS_PP_STANDARD_PARALLEL_1, -1111, &err_); ensure_approx_equals(val, 38.43333333333333); val = OSRGetProjParm(srs_, SRS_PP_STANDARD_PARALLEL_2, -1111, &err_); ensure_approx_equals(val, 37.06666666666667); val = OSRGetProjParm(srs_, SRS_PP_LATITUDE_OF_ORIGIN, -1111, &err_); ensure_approx_equals(val, 36.5); val = OSRGetProjParm(srs_, SRS_PP_CENTRAL_MERIDIAN, -1111, &err_); ensure_approx_equals(val, -120.5); val = OSRGetProjParm(srs_, SRS_PP_FALSE_EASTING, -1111, &err_); ensure_approx_equals(val, 6561666.666666667); val = OSRGetProjParm(srs_, SRS_PP_FALSE_NORTHING, -1111, &err_); ensure_approx_equals(val, 1640416.666666667); ensure_equals("Invalid authority name", std::string(OSRGetAuthorityName(srs_, "GEOGCS")), std::string("EPSG")); ensure_equals("Invalid authority code", std::string(OSRGetAuthorityCode(srs_, "GEOGCS")), std::string("4269")); ensure_equals("Invalid authority name", std::string(OSRGetAuthorityName(srs_, "DATUM")), std::string("EPSG")); ensure_equals("Invalid authority code", std::string(OSRGetAuthorityCode(srs_, "DATUM")), std::string("6269")); ensure("Got a PROJCS Authority but we should not", NULL == OSRGetAuthorityName(srs_, "PROJCS")); ensure("Got METER authority code on linear units", NULL == OSRGetAuthorityCode(srs_, "PROJCS|UNIT")); char* unitsName = NULL; val = OSRGetLinearUnits(srs_, &unitsName); ensure("Units name is NULL", NULL != unitsName); ensure( "Did not get Foot linear units", std::string("Foot") == unitsName); }
void object::test<2>() { ensure("SRS handle is NULL", NULL != srs_); // California III NAD83 OSRSetStatePlane(srs_, 403, 1); double val = 0; val = OSRGetProjParm(srs_, SRS_PP_STANDARD_PARALLEL_1, -1111, &err_); ensure_approx_equals(val, 38.43333333333333); val = OSRGetProjParm(srs_, SRS_PP_STANDARD_PARALLEL_2, -1111, &err_); ensure_approx_equals(val, 37.06666666666667); val = OSRGetProjParm(srs_, SRS_PP_LATITUDE_OF_ORIGIN, -1111, &err_); ensure_approx_equals(val, 36.5); val = OSRGetProjParm(srs_, SRS_PP_CENTRAL_MERIDIAN, -1111, &err_); ensure_approx_equals(val, -120.5); val = OSRGetProjParm(srs_, SRS_PP_FALSE_EASTING, -1111, &err_); ensure_approx_equals(val, 2000000.0); val = OSRGetProjParm(srs_, SRS_PP_FALSE_NORTHING, -1111, &err_); ensure_approx_equals(val, 500000.0); ensure_equals("Invalid authority name", std::string(OSRGetAuthorityName(srs_, "GEOGCS")), std::string("EPSG")); ensure_equals("Invalid authority code", std::string(OSRGetAuthorityCode(srs_, "GEOGCS")), std::string("4269")); ensure_equals("Invalid authority name", std::string(OSRGetAuthorityName(srs_, "DATUM")), std::string("EPSG")); ensure_equals("Invalid authority code", std::string(OSRGetAuthorityCode(srs_, "DATUM")), std::string("6269")); ensure_equals("Invalid authority name", std::string(OSRGetAuthorityName(srs_, "PROJCS")), std::string("EPSG")); ensure_equals("Invalid authority code", std::string(OSRGetAuthorityCode(srs_, "PROJCS")), std::string("26943")); ensure_equals("Invalid authority name", std::string(OSRGetAuthorityName(srs_, "PROJCS|UNIT")), std::string("EPSG")); ensure_equals("Invalid authority code", std::string(OSRGetAuthorityCode(srs_, "PROJCS|UNIT")), std::string("9001")); }
void object::test<1>() { ensure("SRS handle is NULL", NULL != srs_); std::string wkt("+proj=tmerc +lat_0=53.5000000000 +lon_0=-8.0000000000" "+k_0=1.0000350000 +x_0=200000.0000000000 +y_0=250000.0000000000" "+a=6377340.189000 +rf=299.324965 +towgs84=482.530," "-130.596,564.557,-1.042,-0.214,-0.631,8.15"); err_ = OSRImportFromProj4(srs_, wkt.c_str()); ensure_equals("OSRImportFromProj4)( failed", err_, OGRERR_NONE); // TODO: Check max error value const double maxError = 0.00005; // 0.0000005 double val = 0; val = OSRGetProjParm(srs_, SRS_PP_SCALE_FACTOR, -1111, &err_); ensure_equals("OSRGetProjParm() failed", err_, OGRERR_NONE); ensure("+k_0 not supported on import from PROJ.4", std::fabs(val - 1.000035) <= maxError); }
void object::test<1>() { ensure("SRS handle is NULL", NULL != srs_); const int size = 17; double params[size] = { 0.0, 0.0, 45.0, 54.5, 47.0, 62.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; err_ = OSRImportFromPCI(srs_, "EC E015", "METRE", params); ensure_equals("Can't import Equidistant Conic projection", err_, OGRERR_NONE); const double maxError = 0.0000005; double val = 0; val = OSRGetProjParm(srs_, SRS_PP_STANDARD_PARALLEL_1, -1111, &err_); ensure_equals("OSRGetProjParm() failed", err_, OGRERR_NONE); ensure("Standard parallel 1 is invalid", std::fabs(val - 47.0) <= maxError); val = OSRGetProjParm(srs_, SRS_PP_STANDARD_PARALLEL_2, -1111, &err_); ensure_equals("OSRGetProjParm() failed", err_, OGRERR_NONE); ensure("Standard parallel 2 is invalid", std::fabs(val - 62.0) <= maxError); val = OSRGetProjParm(srs_, SRS_PP_LATITUDE_OF_CENTER, -1111, &err_); ensure_equals("OSRGetProjParm() failed", err_, OGRERR_NONE); ensure("Latitude of center is invalid", std::fabs(val - 54.5) <= maxError); val = OSRGetProjParm(srs_, SRS_PP_LONGITUDE_OF_CENTER, -1111, &err_); ensure_equals("OSRGetProjParm() failed", err_, OGRERR_NONE); ensure("Longtitude of center is invalid", std::fabs(val - 45.0) <= maxError); val = OSRGetProjParm(srs_, SRS_PP_FALSE_EASTING, -1111, &err_); ensure_equals("OSRGetProjParm() failed", err_, OGRERR_NONE); ensure("False easting is invalid", std::fabs(val - 0.0) <= maxError); val = OSRGetProjParm(srs_, SRS_PP_FALSE_NORTHING, -1111, &err_); ensure_equals("OSRGetProjParm() failed", err_, OGRERR_NONE); ensure("False northing is invalid", std::fabs(val - 0.0) <= maxError); }
bool rspfOgcWktTranslator::toOssimKwl( const rspfString& wktString, rspfKeywordlist &kwl, const char *prefix)const { static const char MODULE[] = "rspfOgcWktTranslator::toOssimKwl"; if(traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << MODULE << " entered...\n"; } const char* wkt = wktString.c_str(); OGRSpatialReferenceH hSRS = NULL; rspfDpt falseEastingNorthing; hSRS = OSRNewSpatialReference(NULL); if( OSRImportFromWkt( hSRS, (char **) &wkt ) != OGRERR_NONE ) { OSRDestroySpatialReference( hSRS ); return false; } rspfString rspfProj = ""; const char* epsg_code = OSRGetAttrValue( hSRS, "AUTHORITY", 1 ); if(traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << "epsg_code: " << (epsg_code?epsg_code:"null") << "\n"; } const char* units = NULL; OGR_SRSNode* node = ((OGRSpatialReference *)hSRS)->GetRoot(); int nbChild = node->GetChildCount(); for (int i = 0; i < nbChild; i++) { OGR_SRSNode* curChild = node->GetChild(i); if (strcmp(curChild->GetValue(), "UNIT") == 0) { units = curChild->GetChild(0)->GetValue(); } } if(traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << "units: " << (units?units:"null") << "\n"; } rspfString rspf_units; bool bGeog = OSRIsGeographic(hSRS); if ( bGeog == false ) { rspf_units = "meters"; if ( units != NULL ) { rspfString s = units; s.downcase(); if( ( s == rspfString("us survey foot") ) || ( s == rspfString("u.s. foot") ) || ( s == rspfString("foot_us") ) ) { rspf_units = "us_survey_feet"; } else if( s == rspfString("degree") ) { rspf_units = "degrees"; } else if( ( s == rspfString("meter") ) || ( s == rspfString("metre") ) ) { rspf_units = "meters"; } } } else { rspf_units = "degrees"; } if(traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << "rspf_units: " << rspf_units << "\n"; } if (epsg_code) { rspfString epsg_spec ("EPSG:"); epsg_spec += rspfString::toString(epsg_code); rspfProjection* proj = rspfEpsgProjectionFactory::instance()->createProjection(epsg_spec); if (proj) rspfProj = proj->getClassName(); delete proj; } if(rspfProj == "") { const char* pszProjection = OSRGetAttrValue( hSRS, "PROJECTION", 0 ); if(pszProjection) { rspfProj = wktToOssimProjection(pszProjection); } else { rspfString localCs = OSRGetAttrValue( hSRS, "LOCAL_CS", 0 ); localCs = localCs.upcase(); if(localCs == "GREATBRITAIN_GRID") { rspfProj = "rspfBngProjection"; } else if (rspf_units.contains("degree")) { rspfProj = "rspfEquDistCylProjection"; } } } if(rspfProj == "rspfEquDistCylProjection" ) rspf_units = "degrees"; kwl.add(prefix, rspfKeywordNames::UNITS_KW, rspf_units, true); if (traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << MODULE << "DEBUG:" << "\nrspfProj = " << rspfProj << endl; } kwl.add(prefix, rspfKeywordNames::TYPE_KW, rspfProj.c_str(), true); falseEastingNorthing.x = OSRGetProjParm(hSRS, SRS_PP_FALSE_EASTING, 0.0, NULL); falseEastingNorthing.y = OSRGetProjParm(hSRS, SRS_PP_FALSE_NORTHING, 0.0, NULL); if (epsg_code) { kwl.add(prefix, rspfKeywordNames::PCS_CODE_KW, epsg_code, true); } if(rspfProj == "rspfBngProjection") { kwl.add(prefix, rspfKeywordNames::TYPE_KW, "rspfBngProjection", true); } else if(rspfProj == "rspfCylEquAreaProjection") { kwl.add(prefix, rspfKeywordNames::STD_PARALLEL_1_KW, OSRGetProjParm(hSRS, SRS_PP_STANDARD_PARALLEL_1, 0.0, NULL), true); kwl.add(prefix, rspfKeywordNames::ORIGIN_LATITUDE_KW, OSRGetProjParm(hSRS, SRS_PP_STANDARD_PARALLEL_1, 0.0, NULL), true); rspfUnitType units = static_cast<rspfUnitType>(rspfUnitTypeLut::instance()-> getEntryNumber(rspf_units.c_str())); if ( units == RSPF_METERS || units == RSPF_FEET || units == RSPF_US_SURVEY_FEET ) { kwl.add(prefix, rspfKeywordNames::FALSE_EASTING_NORTHING_KW, falseEastingNorthing.toString(), true); kwl.add(prefix, rspfKeywordNames::FALSE_EASTING_NORTHING_UNITS_KW, rspf_units, true); } } else if(rspfProj == "rspfEquDistCylProjection") { kwl.add(prefix, rspfKeywordNames::TYPE_KW, "rspfEquDistCylProjection", true); rspfUnitType units = static_cast<rspfUnitType>(rspfUnitTypeLut::instance()-> getEntryNumber(rspf_units.c_str())); if ( units == RSPF_METERS || units == RSPF_FEET || units == RSPF_US_SURVEY_FEET ) { kwl.add(prefix, rspfKeywordNames::FALSE_EASTING_NORTHING_KW, falseEastingNorthing.toString(), true); kwl.add(prefix, rspfKeywordNames::FALSE_EASTING_NORTHING_UNITS_KW, rspf_units, true); } kwl.add(prefix, rspfKeywordNames::ORIGIN_LATITUDE_KW, OSRGetProjParm(hSRS, SRS_PP_LATITUDE_OF_ORIGIN, 0.0, NULL), true); kwl.add(prefix, rspfKeywordNames::CENTRAL_MERIDIAN_KW, OSRGetProjParm(hSRS, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL), true); } else if( (rspfProj == "rspfLambertConformalConicProjection") || (rspfProj == "rspfAlbersProjection") ) { kwl.add(prefix, rspfKeywordNames::TYPE_KW, rspfProj.c_str(), true); kwl.add(prefix, rspfKeywordNames::FALSE_EASTING_NORTHING_KW, falseEastingNorthing.toString(), true); kwl.add(prefix, rspfKeywordNames::FALSE_EASTING_NORTHING_UNITS_KW, rspf_units, true); kwl.add(prefix, rspfKeywordNames::ORIGIN_LATITUDE_KW, OSRGetProjParm(hSRS, SRS_PP_LATITUDE_OF_ORIGIN, 0.0, NULL), true); kwl.add(prefix, rspfKeywordNames::CENTRAL_MERIDIAN_KW, OSRGetProjParm(hSRS, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL), true); kwl.add(prefix, rspfKeywordNames::STD_PARALLEL_1_KW, OSRGetProjParm(hSRS, SRS_PP_STANDARD_PARALLEL_1, 0.0, NULL), true); kwl.add(prefix, rspfKeywordNames::STD_PARALLEL_2_KW, OSRGetProjParm(hSRS, SRS_PP_STANDARD_PARALLEL_2, 0.0, NULL), true); } else if(rspfProj == "rspfMercatorProjection") { kwl.add(prefix, rspfKeywordNames::TYPE_KW, "rspfMercatorProjection", true); kwl.add(prefix, rspfKeywordNames::ORIGIN_LATITUDE_KW, OSRGetProjParm(hSRS, SRS_PP_LATITUDE_OF_ORIGIN, 0.0, NULL), true); kwl.add(prefix, rspfKeywordNames::CENTRAL_MERIDIAN_KW, OSRGetProjParm(hSRS, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL), true); kwl.add(prefix, rspfKeywordNames::FALSE_EASTING_NORTHING_KW, falseEastingNorthing.toString(), true); kwl.add(prefix, rspfKeywordNames::FALSE_EASTING_NORTHING_UNITS_KW, rspf_units, true); } else if(rspfProj == "rspfSinusoidalProjection") { kwl.add(prefix, rspfKeywordNames::TYPE_KW, "rspfSinusoidalProjection", true); kwl.add(prefix, rspfKeywordNames::CENTRAL_MERIDIAN_KW, OSRGetProjParm(hSRS, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL), true); kwl.add(prefix, rspfKeywordNames::FALSE_EASTING_NORTHING_KW, falseEastingNorthing.toString(), true); kwl.add(prefix, rspfKeywordNames::FALSE_EASTING_NORTHING_UNITS_KW, rspf_units, true); } else if(rspfProj == "rspfTransMercatorProjection") { int bNorth; int nZone = OSRGetUTMZone( hSRS, &bNorth ); if( nZone != 0 ) { kwl.add(prefix, rspfKeywordNames::TYPE_KW, "rspfUtmProjection", true); kwl.add(prefix, rspfKeywordNames::ZONE_KW, nZone, true); if( bNorth ) { kwl.add(prefix, rspfKeywordNames::HEMISPHERE_KW, "N", true); } else { kwl.add(prefix, rspfKeywordNames::HEMISPHERE_KW, "S", true); } } else { kwl.add(prefix, rspfKeywordNames::TYPE_KW, "rspfTransMercatorProjection", true); kwl.add(prefix, rspfKeywordNames::SCALE_FACTOR_KW, OSRGetProjParm(hSRS, SRS_PP_SCALE_FACTOR, 1.0, NULL), true); kwl.add(prefix, rspfKeywordNames::ORIGIN_LATITUDE_KW, OSRGetProjParm(hSRS, SRS_PP_LATITUDE_OF_ORIGIN, 0.0, NULL), true); kwl.add(prefix, rspfKeywordNames::CENTRAL_MERIDIAN_KW, OSRGetProjParm(hSRS, SRS_PP_CENTRAL_MERIDIAN, 0.0, NULL), true); kwl.add(prefix, rspfKeywordNames::FALSE_EASTING_NORTHING_KW, falseEastingNorthing.toString(), true); kwl.add(prefix, rspfKeywordNames::FALSE_EASTING_NORTHING_UNITS_KW, rspf_units, true); } } else { if (traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << "rspfOgcWktTranslator::toOssimKwl DEBUG:\n" << "Projection conversion to RSPF not supported !!!!!!!!!\n" << "Please send the following string to the development staff\n" << "to be added to the transaltion to RSPF\n" << wkt << endl; } return false; } const char *datum = OSRGetAttrValue( hSRS, "DATUM", 0 ); rspfString oDatum = "WGE"; if( datum ) { oDatum = wktToOssimDatum(datum); if(oDatum == "") { oDatum = "WGE"; } } kwl.add(prefix, rspfKeywordNames::DATUM_KW, oDatum, true); OSRDestroySpatialReference( hSRS ); if (traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << MODULE << " exit status = true" << std::endl; } return true; }