diff --git a/Code/Projections/otbGenericMapProjection.txx b/Code/Projections/otbGenericMapProjection.txx index f0d9b8449cd5f84b116a687556db22d493120346..3fef8e43517ce88b664a43cf2c0a19eb19adba0d 100644 --- a/Code/Projections/otbGenericMapProjection.txx +++ b/Code/Projections/otbGenericMapProjection.txx @@ -124,7 +124,17 @@ GenericMapProjection<Transform, TScalarType, NInputDimensions, NOutputDimensions return false; } + //we don't want to have a ossimEquDistCylProjection here: + //see discussion in May 2009 on ossim list; + //a better solution might be available... + if (std::string(kwl.find("type")) == "ossimEquDistCylProjection") + { + std::cout << "WARNING: Not instanciating a ossimEquDistCylProjection"<< std::endl; + return false; + } + m_MapProjection = ossimMapProjectionFactory::instance()->createProjection(kwl); + this->reinstanciateProjection = false; return true; } diff --git a/Utilities/otbossimplugins/gdal/ossimOgcWktTranslator.cpp b/Utilities/otbossimplugins/gdal/ossimOgcWktTranslator.cpp index 917952315e19691f960507d5680b4ea083b45ce2..0f1340953894d72fe829559b57179d8fea96292d 100644 --- a/Utilities/otbossimplugins/gdal/ossimOgcWktTranslator.cpp +++ b/Utilities/otbossimplugins/gdal/ossimOgcWktTranslator.cpp @@ -1,6 +1,8 @@ //******************************************************************* // -// License: See top level LICENSE.txt file. +// License: LGPL +// +// See LICENSE.txt file in the top level directory for more details. // // Author: Frank Warmerdam (warmerda@home.com) // Contributor: David A. Horner @@ -8,12 +10,12 @@ // Description: // // Contains code implementation translation between OGC WKT format, -// and OSSIM projection keyword lists. Note that services from +// and OSSIM projection keyword lists. Note that services from // GDAL's OGRSpatialReference class are used via the GDAL bridge to -// accomplish the translation. +// accomplish the translation. // //******************************************************************* -// $Id: ossimOgcWktTranslator.cpp 14028 2009-02-13 13:12:17Z gpotts $ +// $Id: ossimOgcWktTranslator.cpp 14589 2009-05-20 23:51:14Z dburken $ #include <cstdio> #include <gdal.h> @@ -34,7 +36,7 @@ #include <ossim/base/ossimUnitConversionTool.h> #include <ossim/base/ossimUnitTypeLut.h> - + static const double SEMI_MAJOR_AXIS_WGS84 = 6378137.0; static const double SEMI_MINOR_AXIS_WGS84 = 6356752.3142; @@ -54,15 +56,15 @@ ossimString ossimOgcWktTranslator::fromOssimKwl(const ossimKeywordlist &kwl, { ossimString projType = kwl.find(ossimKeywordNames::TYPE_KW); ossimString datumType = kwl.find(ossimKeywordNames::DATUM_KW); - + ossimString wktString; OGRSpatialReference oSRS; - + if(projType == "") { return wktString; } - + ossimString zone = kwl.find(prefix, ossimKeywordNames::ZONE_KW); ossimString hemisphere = kwl.find(prefix, ossimKeywordNames::HEMISPHERE_KW); ossimString parallel1 = kwl.find(prefix, ossimKeywordNames::STD_PARALLEL_1_KW); @@ -82,13 +84,13 @@ ossimString ossimOgcWktTranslator::fromOssimKwl(const ossimKeywordlist &kwl, ossimUnitType units = static_cast<ossimUnitType>(ossimUnitTypeLut::instance()-> getEntryNumber(lookup)); - + lookup = kwl.find(prefix, ossimKeywordNames::FALSE_EASTING_NORTHING_KW); if (lookup) { ossimDpt eastingNorthing; eastingNorthing.toPoint(std::string(lookup)); - + switch (units) { case OSSIM_METERS: @@ -113,14 +115,14 @@ ossimString ossimOgcWktTranslator::fromOssimKwl(const ossimKeywordlist &kwl, << "ossimOgcWktTranslator::fromOssimKwl WARNING!" << "Unhandled unit type for " << ossimKeywordNames::FALSE_EASTING_NORTHING_UNITS_KW - << ": " + << ": " << ( ossimUnitTypeLut::instance()-> getEntryString(units).c_str() ) << endl; break; } } // End of switch (units) - + } // End of if (FALSE_EASTING_NORTHING_KW) } // End of if (FALSE_EASTING_NORTHING_UNITS_KW) @@ -132,7 +134,7 @@ ossimString ossimOgcWktTranslator::fromOssimKwl(const ossimKeywordlist &kwl, { falseEastingNorthing.x = fabs(ossimString(lookup).toFloat64()); } - + lookup = kwl.find(prefix, ossimKeywordNames::FALSE_NORTHING_KW); if(lookup) { @@ -141,11 +143,11 @@ ossimString ossimOgcWktTranslator::fromOssimKwl(const ossimKeywordlist &kwl, } oSRS.SetLinearUnits("Meter", 1.0); - + if(projType == "ossimUtmProjection") { hemisphere = hemisphere.trim().upcase(); - + if(hemisphere != "") { oSRS.SetUTM(zone.toLong(), hemisphere != "S"); @@ -158,26 +160,26 @@ ossimString ossimOgcWktTranslator::fromOssimKwl(const ossimKeywordlist &kwl, else if(projType == "ossimLlxyProjection") { OGRSpatialReference oGeogCS; - + oGeogCS.SetEquirectangular(0.0, 0.0, 0.0, 0.0); oGeogCS.SetAngularUnits(SRS_UA_DEGREE, atof(SRS_UA_DEGREE_CONV)); - - oSRS.CopyGeogCSFrom( &oGeogCS ); + + oSRS.CopyGeogCSFrom( &oGeogCS ); } else if(projType == "ossimEquDistCylProjection") { OGRSpatialReference oGeogCS; - + oGeogCS.SetEquirectangular(originLat.toDouble(), centralMeridian.toDouble(), falseEastingNorthing.x, falseEastingNorthing.y); oGeogCS.SetAngularUnits(SRS_UA_DEGREE, atof(SRS_UA_DEGREE_CONV)); - - oSRS.CopyGeogCSFrom( &oGeogCS ); + + oSRS.CopyGeogCSFrom( &oGeogCS ); } else if(projType == "ossimSinusoidalProjection") { @@ -315,7 +317,7 @@ ossimString ossimOgcWktTranslator::fromOssimKwl(const ossimKeywordlist &kwl, falseEastingNorthing.x, falseEastingNorthing.y); } - else + else { cerr << "ossimOgcWktTranslator::fromOssimKwl:\n" << "Projection translation for " @@ -323,24 +325,24 @@ ossimString ossimOgcWktTranslator::fromOssimKwl(const ossimKeywordlist &kwl, << " not supported " << endl; } - + datumType = datumType.upcase(); - + if(datumType == "WGE") { oSRS.SetWellKnownGeogCS("WGS84"); } else if(datumType == "WGD") { - oSRS.SetWellKnownGeogCS("WGS72"); + oSRS.SetWellKnownGeogCS("WGS72"); } else if(datumType == "NAS-C") //1927 { - oSRS.SetWellKnownGeogCS("NAD27"); + oSRS.SetWellKnownGeogCS("NAD27"); } else if(datumType == "NAS") //1927 { - oSRS.SetWellKnownGeogCS("NAD27"); + oSRS.SetWellKnownGeogCS("NAD27"); } else if(datumType == "NAR-C") // 1983 { @@ -361,18 +363,18 @@ ossimString ossimOgcWktTranslator::fromOssimKwl(const ossimKeywordlist &kwl, <<" not supported" << endl; } - + char* exportString = NULL; oSRS.exportToWkt(&exportString); - + if(exportString) { wktString = exportString; OGRFree(exportString); } - + return wktString; - + } bool ossimOgcWktTranslator::toOssimKwl( const ossimString& wktString, @@ -381,26 +383,20 @@ bool ossimOgcWktTranslator::toOssimKwl( const ossimString& wktString, { static const char MODULE[] = "ossimOgcWktTranslator::toOssimKwl"; - + const char* wkt = wktString.c_str(); - + OGRSpatialReferenceH hSRS = NULL; ossimDpt falseEastingNorthing; - - // Translate the WKT into an OGRSpatialReference. + + // Translate the WKT into an OGRSpatialReference. hSRS = OSRNewSpatialReference(NULL); if( OSRImportFromWkt( hSRS, (char **) &wkt ) != OGRERR_NONE ) { OSRDestroySpatialReference( hSRS ); return false; } - - if (static_cast<OGRSpatialReference *>(hSRS)->IsGeographic()) - { - OSRDestroySpatialReference( hSRS ); - return false; - } - + // Determine if State Plane Coordinate System ossimString ossimProj = ""; const ossimStatePlaneProjectionInfo* spi = NULL; @@ -410,33 +406,44 @@ bool ossimOgcWktTranslator::toOssimKwl( const ossimString& wktString, ossimStatePlaneProjectionFactory* spf = ossimStatePlaneProjectionFactory::instance(); spi = spf->getInfo(ossimString::toInt(epsg_code)); - + if(spi) { ossimProj = "ossimStatePlaneProjection"; } } - - // Extract Units - // + //--- + // Extract Units + // ESH 11/2008: Check for geographic system when setting default units. + // If geographic, use degrees. + //--- const char* units = OSRGetAttrValue( hSRS, "UNIT", 0 ); - ossimString ossim_units = "meters"; - - if(units) + ossimString ossim_units; + bool bGeog = OSRIsGeographic(hSRS); + if ( bGeog == false ) { - if(ossimString(units) == ossimString("U.S. Foot")) - ossim_units = "us_survey_feet"; - else if(ossimString(units) == ossimString("US survey foot")) - ossim_units = "us_survey_feet"; - else if(ossimString(units) == ossimString("degree")) - ossim_units = "degrees"; - else if(ossimString(units) == ossimString("Meter")) - ossim_units = "meters"; - else if(ossimString(units) == ossimString("metre")) - ossim_units = "meters"; + ossim_units = "meters"; + if ( units != NULL ) + { + if(ossimString(units) == ossimString("U.S. Foot")) + ossim_units = "us_survey_feet"; + else if(ossimString(units) == ossimString("US survey foot")) + ossim_units = "us_survey_feet"; + else if(ossimString(units) == ossimString("degree")) + ossim_units = "degrees"; + else if(ossimString(units) == ossimString("Meter")) + ossim_units = "meters"; + else if(ossimString(units) == ossimString("metre")) + ossim_units = "meters"; + } } - kwl.add(prefix, ossimKeywordNames::UNITS_KW, ossim_units, true); + else + { + ossim_units = "degrees"; + } + + bool bModified = false; if(ossimProj == "") // Not State Plane Projection { // Determine which other Projection System is represented. @@ -449,10 +456,9 @@ bool ossimOgcWktTranslator::toOssimKwl( const ossimString& wktString, { ossimString localCs = OSRGetAttrValue( hSRS, "LOCAL_CS", 0 ); localCs = localCs.upcase(); - // std::cout << "localCs ========== " << localCs << std::endl; if(localCs == "GREATBRITAIN_GRID") { - ossimProj = "ossimBngProjection"; + ossimProj = "ossimBngProjection"; } else if (ossim_units.contains("degree")) { @@ -460,18 +466,32 @@ bool ossimOgcWktTranslator::toOssimKwl( const ossimString& wktString, ossimProj = "ossimEquDistCylProjection"; } } + + if ( ossimProj != "" ) + { + bModified = true; + } + } + + // ESH 11/2008: Ticket #479, if we've got a geographic coordsys + // make sure the units are set to degrees. + if( bModified == true && ossimProj == "ossimEquDistCylProjection" ) + { + ossim_units = "degrees"; } + // ESH 11/2008: Ticket #479, don't set units until we've checked + // whether or not the projection was updated. + kwl.add(prefix, ossimKeywordNames::UNITS_KW, ossim_units, true); + if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << "DEBUG:" << "\nossimProj = " << ossimProj << endl; } - kwl.add(prefix, - ossimKeywordNames::TYPE_KW, - ossimProj.c_str(), - true); + + kwl.add(prefix, ossimKeywordNames::TYPE_KW, ossimProj.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); @@ -492,30 +512,28 @@ bool ossimOgcWktTranslator::toOssimKwl( const ossimString& wktString, ossimKeywordNames::STD_PARALLEL_1_KW, OSRGetProjParm(hSRS, SRS_PP_STANDARD_PARALLEL_1, 0.0, NULL), true); - + kwl.add(prefix, ossimKeywordNames::ORIGIN_LATITUDE_KW, OSRGetProjParm(hSRS, SRS_PP_STANDARD_PARALLEL_1, 0.0, NULL), true); - kwl.add(prefix, - ossimKeywordNames::FALSE_EASTING_NORTHING_KW, - falseEastingNorthing.toString(), - true); - kwl.add(prefix, - ossimKeywordNames::FALSE_EASTING_NORTHING_UNITS_KW, - ossim_units, - true); - -// kwl.add(prefix, -// ossimKeywordNames::FALSE_EASTING_KW, -// OSRGetProjParm(hSRS, SRS_PP_FALSE_EASTING, 0.0, NULL), -// true); - -// kwl.add(prefix, -// ossimKeywordNames::FALSE_NORTHING_KW, -// OSRGetProjParm(hSRS, SRS_PP_FALSE_NORTHING, 0.0, NULL), -// true); + ossimUnitType units = + static_cast<ossimUnitType>(ossimUnitTypeLut::instance()-> + getEntryNumber(ossim_units.c_str())); + if ( units == OSSIM_METERS || + units == OSSIM_FEET || + units == OSSIM_US_SURVEY_FEET ) + { + kwl.add(prefix, + ossimKeywordNames::FALSE_EASTING_NORTHING_KW, + falseEastingNorthing.toString(), + true); + kwl.add(prefix, + ossimKeywordNames::FALSE_EASTING_NORTHING_UNITS_KW, + ossim_units, + true); + } } else if(ossimProj == "ossimEquDistCylProjection") { @@ -523,14 +541,24 @@ bool ossimOgcWktTranslator::toOssimKwl( const ossimString& wktString, ossimKeywordNames::TYPE_KW, "ossimEquDistCylProjection", true); - kwl.add(prefix, - ossimKeywordNames::FALSE_EASTING_NORTHING_KW, - falseEastingNorthing.toString(), - true); - kwl.add(prefix, - ossimKeywordNames::FALSE_EASTING_NORTHING_UNITS_KW, - ossim_units, - true); + + ossimUnitType units = + static_cast<ossimUnitType>(ossimUnitTypeLut::instance()-> + getEntryNumber(ossim_units.c_str())); + if ( units == OSSIM_METERS || + units == OSSIM_FEET || + units == OSSIM_US_SURVEY_FEET ) + { + kwl.add(prefix, + ossimKeywordNames::FALSE_EASTING_NORTHING_KW, + falseEastingNorthing.toString(), + true); + kwl.add(prefix, + ossimKeywordNames::FALSE_EASTING_NORTHING_UNITS_KW, + ossim_units, + true); + } + kwl.add(prefix, ossimKeywordNames::ORIGIN_LATITUDE_KW, OSRGetProjParm(hSRS, SRS_PP_LATITUDE_OF_ORIGIN, 0.0, NULL), @@ -618,14 +646,13 @@ bool ossimOgcWktTranslator::toOssimKwl( const ossimString& wktString, { int bNorth; int nZone = OSRGetUTMZone( hSRS, &bNorth ); - OGRErr err = OGRERR_NONE; if( nZone != 0 ) { kwl.add(prefix, ossimKeywordNames::TYPE_KW, "ossimUtmProjection", true); - + kwl.add(prefix, ossimKeywordNames::ZONE_KW, nZone, @@ -638,7 +665,7 @@ bool ossimOgcWktTranslator::toOssimKwl( const ossimString& wktString, { kwl.add(prefix, ossimKeywordNames::HEMISPHERE_KW, "S", true); } - } + } else { kwl.add(prefix, @@ -649,7 +676,7 @@ bool ossimOgcWktTranslator::toOssimKwl( const ossimString& wktString, ossimKeywordNames::SCALE_FACTOR_KW, OSRGetProjParm(hSRS, SRS_PP_SCALE_FACTOR, 1.0, NULL), true); - + kwl.add(prefix, ossimKeywordNames::ORIGIN_LATITUDE_KW, OSRGetProjParm(hSRS, SRS_PP_LATITUDE_OF_ORIGIN, 0.0, NULL), @@ -675,7 +702,7 @@ bool ossimOgcWktTranslator::toOssimKwl( const ossimString& wktString, ossimNotify(ossimNotifyLevel_DEBUG) << "ossimOgcWktTranslator::toOssimKwl DEBUG:\n" << "Projection conversion to OSSIM not supported !!!!!!!!!\n" - << "Please send the following string to the development staff\n" + << "Please send the following string to the development staff\n" << "to be added to the transaltion to OSSIM\n" << wkt << endl; } @@ -685,7 +712,7 @@ bool ossimOgcWktTranslator::toOssimKwl( const ossimString& wktString, // const char *datum = OSRGetAttrValue( hSRS, "DATUM", 0 ); ossimString oDatum = "WGE"; - + if( datum ) { oDatum = wktToOssimDatum(datum); @@ -694,13 +721,13 @@ bool ossimOgcWktTranslator::toOssimKwl( const ossimString& wktString, oDatum = "WGE"; } } - + kwl.add(prefix, ossimKeywordNames::DATUM_KW, oDatum, true); - + // std::cout << "KWL ======= " << kwl << std::endl; OSRDestroySpatialReference( hSRS ); - + return true; } @@ -709,14 +736,14 @@ void ossimOgcWktTranslator::initializeDatumTable() { // theWktToOssimDatumTranslation.insert(make_pair(ossimString("North_American_Datum_1927"), // ossimString("NAS-C"))); - + // theWktToOssimDatumTranslation.insert(make_pair(ossimString("North_American_Datum_1983"), // ossimString("NAR-C"))); // theWktToOssimDatumTranslation.insert(make_pair(ossimString("WGS_1984"), // ossimString("WGE"))); // theWktToOssimDatumTranslation.insert(make_pair(ossimString("OSGB_1936"), // ossimString("OSGB_1936"))); - + theOssimToWktDatumTranslation.insert(make_pair(ossimString("NAS-C"), ossimString("North_American_Datum_1927"))); theOssimToWktDatumTranslation.insert(make_pair(ossimString("NAR-C"), @@ -728,7 +755,7 @@ void ossimOgcWktTranslator::initializeDatumTable() theOssimToWktDatumTranslation.insert(make_pair(ossimString("WGE"), ossimString("WGS_1984"))); theWktToOssimDatumTranslation.insert(make_pair(ossimString("OSGB_1936"), - ossimString("OGB-B"))); + ossimString("OGB-B"))); } void ossimOgcWktTranslator::initializeProjectionTable() @@ -757,7 +784,7 @@ void ossimOgcWktTranslator::initializeProjectionTable() ossimString(SRS_PT_SINUSOIDAL))); theOssimToWktProjectionTranslation.insert(make_pair(ossimString("ossimMercatorProjection"), ossimString(SRS_PT_MERCATOR_1SP))); - + } ossimString ossimOgcWktTranslator::wktToOssimDatum(const ossimString& datum)const @@ -790,7 +817,7 @@ ossimString ossimOgcWktTranslator::wktToOssimDatum(const ossimString& datum)cons { return "OGB-D"; } - + return ""; }