27 #include <gdal_priv.h> 28 #include <cpl_string.h> 33 static ossimTrace traceDebug(
"ossimGdalProjectionFactory:debug");
55 GDALDriverH driverH = 0;
60 h = GDALOpen(filename.
c_str(), GA_ReadOnly);
63 driverH = GDALGetDatasetDriver( h );
64 ossimString driverName( driverH ? GDALGetDriverShortName( driverH ) :
"" );
67 if(driverName ==
"NITF")
74 char** papszMetadata = GDALGetMetadata( h,
"SUBDATASETS" );
80 if( papszMetadata&&(CSLCount(papszMetadata) < static_cast<ossim_int32>(entryIdx)) )
82 ossimNotify(
ossimNotifyLevel_WARN) <<
"ossimGdalProjectionFactory::createProjection: We don't support multi entry handlers through the factory yet, only through the handler!";
94 double geoTransform[6];
95 bool transOk = GDALGetGeoTransform( h, geoTransform ) == CE_None;
96 bool wktTranslatorOk = wkt.
empty()?
false:wktTranslator.
toOssimKwl(wkt, kwl);
103 const GDAL_GCP* gcpList = GDALGetGCPs(h);
107 for(idx = 0; idx < gcpCount; ++idx)
109 ossimDpt dpt(gcpList[idx].dfGCPPixel,
110 gcpList[idx].dfGCPLine);
113 gcpList[idx].dfGCPZ);
125 if ( transOk && proj==0 )
130 if ( proj_type.trim().empty() &&
131 (driverName ==
"MrSID" || driverName ==
"JP2MrSID") )
135 if( geoTransform[2] == 0.0 && geoTransform[4] == 0.0 )
137 ossimString projTag( GDALGetMetadataItem( h,
"IMG__PROJECTION_NAME",
"" ) );
138 if ( projTag.
contains(
"Geographic") )
143 "ossimEquDistCylProjection",
true);
147 ossimString unitTag( GDALGetMetadataItem( h,
"IMG__HORIZONTAL_UNITS",
"" ) );
163 if ( bClose ==
true )
179 bool pixelTypeIsArea =
true;
189 const char* areaOrPoint = GDALGetMetadataItem(h,
"AREA_OR_POINT",
"");
192 if (
ossimString( areaOrPoint ).downcase().contains(
"point") )
194 pixelTypeIsArea =
false;
200 const char* rasterTypeStr = GDALGetMetadataItem(
201 h,
"GEOTIFF_CHAR__GTRasterTypeGeoKey",
"");
204 if (
ossimString( rasterTypeStr ).downcase().contains(
"point") )
206 pixelTypeIsArea =
false;
213 if( (driverName ==
"MrSID") || (driverName ==
"JP2MrSID") ||
214 (driverName ==
"AIG") || (driverName ==
"VRT") )
216 const char* rasterTypeStr = GDALGetMetadataItem( h,
"GEOTIFF_CHAR__GTRasterTypeGeoKey",
"" );
221 if ( (driverName ==
"AIG") ||
222 (driverName ==
"VRT") ||
223 (rasterTypeTag.
contains(
"RasterPixelIsArea")) )
225 geoTransform[0] += fabs(geoTransform[1]) / 2.0;
226 geoTransform[3] -= fabs(geoTransform[5]) / 2.0;
233 GDALRasterBandH bBand = GDALGetRasterBand( h, 1 );
234 char** papszMetadata = GDALGetMetadata( bBand, NULL );
235 if (CSLCount(papszMetadata) > 0)
237 for(
int i = 0; papszMetadata[i] != NULL; i++ )
241 if (metaStr.
contains(
"AREA_OR_POINT"))
244 pixel_is_point_or_area.
upcase();
245 if (pixel_is_point_or_area.
contains(
"AREA"))
248 geoTransform[0] += fabs(geoTransform[1]) / 2.0;
249 geoTransform[3] -= fabs(geoTransform[5]) / 2.0;
259 ossimDpt gsd(fabs(geoTransform[1]), fabs(geoTransform[5]));
260 ossimDpt tie(geoTransform[0], geoTransform[3]);
268 if((proj_type ==
"ossimLlxyProjection") || (proj_type ==
"ossimEquDistCylProjection"))
276 if ( (tie.
x-halfGsd.
x) < -180.0 )
278 tie.
x = -180.0 + halfGsd.
x;
279 geoTransform[0] = tie.
x;
281 if ( (tie.
y+halfGsd.
y) > 90.0 )
283 tie.
y = 90.0 - halfGsd.
y;
284 geoTransform[3] = tie.
y;
287 int samples = GDALGetRasterXSize(h);
289 if ( degrees > 360.0 )
295 if ( fabs(degrees - 360.0) <= gsd.
x )
297 gsd.
x = 360.0 / samples;
298 geoTransform[1] = gsd.
x;
303 tie.
x = -180 + gsd.
x / 2.0;
304 geoTransform[0] = tie.
x;
308 int lines = GDALGetRasterYSize(h);
309 degrees = lines * gsd.
y;
310 if ( degrees > 180.0 )
316 if ( fabs(degrees - 180.0) <= gsd.
y )
318 gsd.
y = 180.0 / lines;
319 geoTransform[5] = gsd.
y;
324 tie.
y = 90.0 - gsd.
y / 2.0;
325 geoTransform[3] = tie.
y;
338 int nPixelsLon = GDALGetRasterXSize(h)/2.0;
339 int nPixelsLat = GDALGetRasterYSize(h)/2.0;
342 double shiftLon = nPixelsLon * fabs(gsd.
x);
343 double shiftLat = -nPixelsLat * fabs(gsd.
y);
346 double centerLon = (tie.
x - halfGsd.
x) + shiftLon;
347 double centerLat = (tie.
y + halfGsd.
y) + shiftLat;
369 (pixelTypeIsArea?
"area":
"point"),
391 if ( (geoTransform[2] != 0.0) || (geoTransform[4] != 0.0) )
394 if ( pixelTypeIsArea ==
true )
397 geoTransform[0] += fabs(geoTransform[1]) / 2.0;
398 geoTransform[3] -= fabs(geoTransform[5]) / 2.0;
412 <<
" " << 0 <<
" " << 0 <<
" " << 1 <<
" " << 0
413 <<
" " << 0 <<
" " << 0 <<
" " << 0 <<
" " << 1;
416 matrixString.str().c_str(),
true);
418 units.string().c_str(),
true);
424 if(driverName ==
"AIG" && datum_type ==
"OSGB_1936")
440 "ossimBngProjection",
true);
448 else if(datum ==
"OGB_B")
450 else if(datum ==
"OGB_C")
452 else if(datum ==
"OGB_D")
454 else if(datum ==
"OGB_M")
456 else if(datum ==
"OGB_7")
480 const char *prefix)
const 492 tempKwl2.
add(keywordList, prefix,
true);
493 tempKwl.
add(prefix, tempKwl2,
true);
519 tempName = tempName.
trim();
521 if ( tempName.
size() >= 6 )
525 testName = testName.
upcase();
526 if((testName ==
"PROJCS")||
527 (testName ==
"GEOGCS"))
550 const char* prefix)
const 561 std::list<ossimString> result;
static ossimString upcase(const ossimString &aString)
std::basic_stringstream< char > stringstream
Class for char mixed input and output memory streams.
static const char * DATUM_KW
static const char * CENTRAL_MERIDIAN_KW
Represents serializable keyword/value map.
bool addFile(const char *file)
const char * find(const char *key) const
virtual void getTypeNameList(std::vector< ossimString > &typeList) const
bool almostEqual(T x, T y, T tolerance=FLT_EPSILON)
static const char * IMAGE_MODEL_TRANSFORM_MATRIX_KW
bool contains(char aChar) const
virtual std::list< ossimString > getList() const
static ossimString toString(bool aValue)
Numeric to string methods.
ossimOgcWktTranslator theWktTranslator
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
virtual ossim_int32 getEntryNumber(const char *entry_string, bool case_insensitive=true) const
virtual ossimString getClassName() const
static const char * TYPE_KW
virtual ossimObject * createObject(const ossimString &typeName) const
virtual double optimizeFit(const ossimTieGptSet &tieSet, double *targetVariance=0)
static const char * PIXEL_SCALE_XY_KW
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
ossimProjection * createProjection(const ossimFilename &filename, ossim_uint32 entryIdx) const
static const char * TIE_POINT_XY_KW
std::string::size_type size() const
std::string::iterator begin()
unsigned int ossim_uint32
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
static const char * IMAGE_MODEL_TRANSFORM_UNIT_KW
static ossimGdalProjectionFactory * theInstance
storage class for tie point between ground and image based on ossimGpt
static ossimProjectionFactoryRegistry * instance()
static const char * ORIGIN_LATITUDE_KW
static const char * UNITS_KW
void addTiePoint(ossimRefPtr< ossimTieGpt > aTiePt)
operations
ossimString toString(ossim_uint32 precision=15) const
static ossimGdalProjectionFactory * instance()
storage class for a set of geographic tie points, between master and slave images ...
static const char * PIXEL_TYPE_KW
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
ossimGdalProjectionFactory()
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
bool toOssimKwl(const ossimString &wktString, ossimKeywordlist &kwl, const char *prefix=NULL) const
static ossimUnitTypeLut * instance()
Returns the static instance of an ossimUnitTypeLut object.
ossimFilename path() const
void remove(const char *key)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
static const char * PIXEL_SCALE_UNITS_KW
virtual ossimProjection * createProjection(const ossimFilename &filename, ossim_uint32 entryIdx) const
takes a filename.
static const char * TIE_POINT_UNITS_KW