void ossimTiledElevationDatabase::getBoundingRect( ossimRefPtr<ossimImageGeometry> geom, ossimGrect& boundingRect) const { if ( geom.valid() ) { std::vector<ossimGpt> corner(4); if ( geom->getCornerGpts(corner[0], corner[1], corner[2], corner[3]) ) { ossimGpt ulGpt(corner[0]); ossimGpt lrGpt(corner[0]); for ( ossim_uint32 i = 1; i < 4; ++i ) { if ( corner[i].lon < ulGpt.lon ) ulGpt.lon = corner[i].lon; if ( corner[i].lat > ulGpt.lat ) ulGpt.lat = corner[i].lat; if ( corner[i].lon > lrGpt.lon ) lrGpt.lon = corner[i].lon; if ( corner[i].lat < lrGpt.lat ) lrGpt.lat = corner[i].lat; } boundingRect = ossimGrect(ulGpt, lrGpt); } else { boundingRect.makeNan(); } } }
bool ossimGeneralRasterElevHandler::setFilename(const ossimFilename& file) { if(file.trim() == "") { return false; } theFilename = file; ossimFilename hdrFile = file; ossimFilename geomFile = file; theGeneralRasterInfo.theFilename = file; theGeneralRasterInfo.theWidth = 0; theGeneralRasterInfo.theHeight = 0; theNullHeightValue = ossim::nan(); hdrFile = hdrFile.setExtension("omd"); geomFile = geomFile.setExtension("geom"); if(!hdrFile.exists()|| !geomFile.exists()) { return false; } ossimKeywordlist kwl(hdrFile); if (kwl.getErrorStatus() == ossimErrorCodes::OSSIM_ERROR) { return false; } kwl.add(ossimKeywordNames::FILENAME_KW, file.c_str(), true); ossimGeneralRasterInfo generalInfo; if(!generalInfo.loadState(kwl)) { return false; } if(generalInfo.numberOfBands() != 1) { ossimNotify(ossimNotifyLevel_WARN) << "ossimGeneralRasterElevHandler::initializeInfo WARNING:The number of bands are not specified in the header file" << std::endl; return false; } kwl.clear(); if(kwl.addFile(geomFile)) { theGeneralRasterInfo.theNullHeightValue = generalInfo.getNullPixelValue(0); theGeneralRasterInfo.theImageRect = generalInfo.imageRect(); theGeneralRasterInfo.theUl = theGeneralRasterInfo.theImageRect.ul(); theGeneralRasterInfo.theLr = theGeneralRasterInfo.theImageRect.lr(); theGeneralRasterInfo.theWidth = theGeneralRasterInfo.theImageRect.width(); theGeneralRasterInfo.theHeight = theGeneralRasterInfo.theImageRect.height(); theGeneralRasterInfo.theImageRect = generalInfo.imageRect(); theGeneralRasterInfo.theByteOrder = generalInfo.getImageDataByteOrder(); theGeneralRasterInfo.theScalarType = generalInfo.getScalarType(); theGeneralRasterInfo.theBytesPerRawLine = generalInfo.bytesPerRawLine(); //add by simbla theGeneralRasterInfo.theGeometry = new ossimImageGeometry; if(!theGeneralRasterInfo.theGeometry->loadState(kwl)) { theGeneralRasterInfo.theGeometry = 0; } if(!theGeneralRasterInfo.theGeometry.valid()) { return false; } ossimGpt defaultDatum; ossimGpt ulGpt; ossimGpt urGpt; ossimGpt lrGpt; ossimGpt llGpt; theGeneralRasterInfo.theDatum = defaultDatum.datum(); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.ul(), ulGpt); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.ur(), urGpt); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.lr(), lrGpt); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.ll(), llGpt); ulGpt.changeDatum(theGeneralRasterInfo.theDatum); urGpt.changeDatum(theGeneralRasterInfo.theDatum); lrGpt.changeDatum(theGeneralRasterInfo.theDatum); llGpt.changeDatum(theGeneralRasterInfo.theDatum); theMeanSpacing = theGeneralRasterInfo.theGeometry->getMetersPerPixel().y; theGroundRect = ossimGrect(ulGpt, urGpt, lrGpt, llGpt); theGeneralRasterInfo.theWgs84GroundRect = ossimDrect(ulGpt, urGpt, lrGpt, llGpt, OSSIM_RIGHT_HANDED); theNullHeightValue = theGeneralRasterInfo.theNullHeightValue; } else { return false; } return true; }
bool ossimDtedHandler::open(const ossimFilename& file, bool memoryMapFlag) { static const char* MODULE = "ossimDtedHandler::open"; close(); theFilename = file; m_fileStr.clear(); m_fileStr.open(file.c_str(), std::ios::in | std::ios::binary); if(!m_fileStr.good()) { return false; } m_numLonLines = 0; m_numLatPoints = 0; m_dtedRecordSizeInBytes = 0; // Attempt to parse. m_vol.parse(m_fileStr); m_hdr.parse(m_fileStr); m_uhl.parse(m_fileStr); m_dsi.parse(m_fileStr); m_acc.parse(m_fileStr); //*** // Check for errors. Must have uhl, dsi and acc records. vol and hdr // are for magnetic tape only; hence, may or may not be there. //*** if (m_uhl.getErrorStatus() == ossimErrorCodes::OSSIM_ERROR || m_dsi.getErrorStatus() == ossimErrorCodes::OSSIM_ERROR || m_acc.getErrorStatus() == ossimErrorCodes::OSSIM_ERROR) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG " << MODULE << ": " << "\nError parsing file: " << file.c_str() << "\nPossibly not a dted file." << std::endl; } theErrorStatus = ossimErrorCodes::OSSIM_ERROR; close(); return false; } if(memoryMapFlag) { m_fileStr.seekg(0); m_fileStr.clear(); m_memoryMap.resize(theFilename.fileSize()); m_fileStr.read((char*)(&m_memoryMap.front()), (std::streamsize)m_memoryMap.size()); m_fileStr.close(); } m_numLonLines = m_uhl.numLonLines(); m_numLatPoints = m_uhl.numLatPoints(); m_latSpacing = m_uhl.latInterval(); m_lonSpacing = m_uhl.lonInterval(); m_dtedRecordSizeInBytes = m_numLatPoints*2+ossimDtedRecord::DATA_LENGTH; m_edition = m_dsi.edition(); m_productLevel = m_dsi.productLevel(); m_compilationDate = m_dsi.compilationDate(); m_offsetToFirstDataRecord = m_acc.stopOffset(); #if 0 /* Serious debug only... */ std::cout << m_numLonLines << "\t" << m_numLatPoints << "\t" << m_lonSpacing << "\t" << m_latSpacing << "\t" << m_dtedRecordSizeInBytes << "\t" << theFilename.fileSize() << "\t" << file << "\t" << m_offsetToFirstDataRecord << std::endl; #endif //*** // initialize the bounding rectangle: //*** double south_boundary = m_uhl.latOrigin(); double west_boundary = m_uhl.lonOrigin(); double north_boundary = south_boundary + m_latSpacing*(m_numLatPoints-1); double east_boundary = west_boundary + m_lonSpacing*(m_numLonLines-1); // For ossimElevCellHandler::pointHasCoverage method. theGroundRect = ossimGrect(ossimGpt(north_boundary, west_boundary, 0.0), ossimGpt(south_boundary, east_boundary, 0.0)); m_swCornerPost.lat = south_boundary; m_swCornerPost.lon = west_boundary; //*** // Determine the mean spacing: //*** double center_lat = (south_boundary + north_boundary)/2.0; theMeanSpacing = (m_latSpacing + m_lonSpacing*ossim::cosd(center_lat)) * ossimGpt().metersPerDegree().x / 2.0; // Initialize the accuracy values: theAbsLE90 = m_acc.absLE(); theAbsCE90 = m_acc.absCE(); // Set the base class null height value. theNullHeightValue = -32767.0; //--- // Commented out as this writes an un-needed file. (drb 20100611) // Get the statistics. // gatherStatistics(); //--- return true; }
void ossimTiledElevationDatabase::mapRegion() { static const char M[] = "ossimTiledElevationDatabase::mapRegion"; if ( m_entries.size() && ( m_requestedRect.isLonLatNan() == false ) ) { ossimRefPtr<ossimOrthoImageMosaic> mosaic = new ossimOrthoImageMosaic(); std::vector<ossimTiledElevationEntry>::iterator i = m_entries.begin(); while ( i != m_entries.end() ) { mosaic->connectMyInputTo( (*i).m_sic.get() ); ++i; } // Compute the requested rectangle in view space. ossimRefPtr<ossimImageGeometry> geom = mosaic->getImageGeometry(); if ( geom.valid() ) { ossimDpt ulDpt; ossimDpt lrDpt; geom->worldToLocal(m_requestedRect.ul(), ulDpt); geom->worldToLocal(m_requestedRect.lr(), lrDpt); // Expand out to fall on even view coordinates. ulDpt.x = std::floor(ulDpt.x); ulDpt.y = std::floor(ulDpt.y); lrDpt.x = std::ceil(lrDpt.x); lrDpt.y = std::floor(lrDpt.y); // Get new(expanded) corners in ground space. ossimGpt ulGpt; ossimGpt lrGpt; geom->localToWorld(ulDpt, ulGpt); geom->localToWorld(lrDpt, lrGpt); theGroundRect = ossimGrect(ulGpt, lrGpt); // Expanded requested rect in view space. ossimIpt ulIpt = ulDpt; ossimIpt lrIpt = lrDpt; const ossimIrect VIEW_RECT(ulIpt, lrIpt); // Get the data. ossimRefPtr<ossimImageData> data = mosaic->getTile(VIEW_RECT, 0); if ( data.valid() ) { // Initialize the grid: const ossimIpt SIZE( data->getWidth(), data->getHeight() ); const ossimDpt ORIGIN(ulGpt.lon, lrGpt.lat); // SouthWest corner const ossimDpt SPACING( (lrGpt.lon-ulGpt.lon)/(SIZE.x-1), (ulGpt.lat-lrGpt.lat)/(SIZE.y-1) ); if ( !m_grid ) m_grid = new ossimDblGrid(); m_grid->initialize(SIZE, ORIGIN, SPACING, ossim::nan()); if ( traceDebug() ) { ossimNotify(ossimNotifyLevel_DEBUG) << M << "\nrequested view rect: " << VIEW_RECT << "\nexpanded ground rect: " << theGroundRect << "\norigin: " << ORIGIN << "\nsize: " << SIZE << "\nspacing: " << SPACING << std::endl; } // Fill the grid: switch( data->getScalarType() ) { case OSSIM_SINT16: { fillGrid(ossim_sint16(0), data); break; } case OSSIM_SINT32: { fillGrid(ossim_sint32(0), data); break; } case OSSIM_FLOAT32: { fillGrid(ossim_float32(0), data); break; } case OSSIM_FLOAT64: { fillGrid(ossim_float64(0), data); break; } case OSSIM_UINT8: case OSSIM_SINT8: case OSSIM_USHORT11: case OSSIM_UINT16: case OSSIM_UINT32: case OSSIM_NORMALIZED_DOUBLE: case OSSIM_NORMALIZED_FLOAT: case OSSIM_SCALAR_UNKNOWN: default: { std::string errMsg = M; errMsg += " ERROR:\nUnhandled scalar type: "; errMsg += data->getScalarTypeAsString().string(); throw ossimException(errMsg); } } } // if ( data.valid() ) } // if ( geom.valid() ) } // if ( m_entries.size() && ... }
void ossimGeographicAnnotationGrid::setViewProjectionInformation(ossimMapProjection* projection, const ossimGrect& boundingGroundRect) { static const char* MODULE = "ossimGeographicAnnotationGrid::setViewProjectionInformation"; theViewProjection = projection; // set the ground and then stretch it // to cover which even degree grid we are currently // in. theGroundRect = boundingGroundRect; // find the even degree grid. ossimGrect rect(ossimGpt(90, -180), ossimGpt(-90, 180)); // make sure that it is within the range of the // geographic grid. ossimGrect clipRect = rect.clipToRect(boundingGroundRect); // for easier math we will shift the points so they // are between 0..360Lon and 0..180Lat. This way // we are working with just positive numbers double upperLeftLonShift = clipRect.ul().lond() + 180; double upperLeftLatShift = clipRect.ul().latd() + 90; double lowerRightLonShift = clipRect.lr().lond() + 180; double lowerRightLatShift = clipRect.lr().latd() + 90; // now find the even boundaries double upperLeftLonCell = floor(upperLeftLonShift/theDeltaLonSpacing)* theDeltaLonSpacing; double upperLeftLatCell = floor(upperLeftLatShift/theDeltaLatSpacing)* theDeltaLatSpacing; double lowerRightLonCell = floor(lowerRightLonShift/theDeltaLonSpacing)* theDeltaLonSpacing; double lowerRightLatCell = floor(lowerRightLatShift/theDeltaLatSpacing)* theDeltaLatSpacing; // now adjust them by 1 boundary distance. upperLeftLonCell -= theDeltaLonSpacing; upperLeftLatCell += theDeltaLatSpacing; lowerRightLonCell += theDeltaLonSpacing; lowerRightLatCell -= theDeltaLatSpacing; // now clamp to the range of the lat and lon upperLeftLonCell = (upperLeftLonCell<0?0:upperLeftLonCell); upperLeftLatCell = (upperLeftLatCell>180?180:upperLeftLatCell); lowerRightLonCell = (lowerRightLonCell>360?360:lowerRightLonCell); lowerRightLatCell = (lowerRightLatCell<0?0:lowerRightLatCell); // now shift them back into range upperLeftLonCell -= 180; upperLeftLatCell -= 90; lowerRightLonCell -= 180; lowerRightLatCell -= 90; const ossimDatum* datum = theGroundRect.ul().datum(); theGroundRect = ossimGrect(upperLeftLatCell, upperLeftLonCell, lowerRightLatCell, lowerRightLonCell, datum); if(traceDebug()) { CLOG << "Ground Rect: " << theGroundRect << endl; } computeBoundingRect(); }