本文整理汇总了C++中GeoExtent::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ GeoExtent::isValid方法的具体用法?C++ GeoExtent::isValid怎么用?C++ GeoExtent::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeoExtent
的用法示例。
在下文中一共展示了GeoExtent::isValid方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clampAndTransformExtent
void
Profile::getIntersectingTiles(const GeoExtent& extent, unsigned localLOD, std::vector<TileKey>& out_intersectingKeys) const
{
GeoExtent ext = extent;
// reproject into the profile's SRS if necessary:
if ( !getSRS()->isHorizEquivalentTo( extent.getSRS() ) )
{
// localize the extents and clamp them to legal values
ext = clampAndTransformExtent( extent );
if ( !ext.isValid() )
return;
}
if ( ext.crossesAntimeridian() )
{
GeoExtent first, second;
if (ext.splitAcrossAntimeridian( first, second ))
{
addIntersectingTiles( first, localLOD, out_intersectingKeys );
addIntersectingTiles( second, localLOD, out_intersectingKeys );
}
}
else
{
addIntersectingTiles( ext, localLOD, out_intersectingKeys );
}
}
示例2: BoundingSphered
osg::BoundingSphered
FeatureModelGraph::getBoundInWorldCoords(const GeoExtent& extent,
const MapFrame* mapf ) const
{
osg::Vec3d center, corner;
GeoExtent workingExtent;
if ( !extent.isValid() )
{
return osg::BoundingSphered();
}
if ( extent.getSRS()->isEquivalentTo( _usableMapExtent.getSRS() ) )
{
workingExtent = extent;
}
else
{
workingExtent = extent.transform( _usableMapExtent.getSRS() ); // safe.
}
workingExtent.getCentroid( center.x(), center.y() );
double centerZ = 0.0;
if ( mapf )
{
// Use an appropriate resolution for this extents width
double resolution = workingExtent.width();
ElevationQuery query( *mapf );
GeoPoint p( mapf->getProfile()->getSRS(), center, ALTMODE_ABSOLUTE );
query.getElevation( p, center.z(), resolution );
centerZ = center.z();
}
corner.x() = workingExtent.xMin();
corner.y() = workingExtent.yMin();
corner.z() = 0;
if ( _session->getMapInfo().isGeocentric() )
{
const SpatialReference* ecefSRS = workingExtent.getSRS()->getECEF();
workingExtent.getSRS()->transform( center, ecefSRS, center );
workingExtent.getSRS()->transform( corner, ecefSRS, corner );
//workingExtent.getSRS()->transformToECEF( center, center );
//workingExtent.getSRS()->transformToECEF( corner, corner );
}
if (workingExtent.getSRS()->isGeographic() &&
( workingExtent.width() >= 90 || workingExtent.height() >= 90 ) )
{
return osg::BoundingSphered( osg::Vec3d(0,0,0), 2*center.length() );
}
return osg::BoundingSphered( center, (center-corner).length() );
}
示例3: getSRS
GeoExtent
Profile::clampAndTransformExtent( const GeoExtent& input, bool* out_clamped ) const
{
if ( out_clamped )
*out_clamped = false;
// do the clamping in LAT/LONG.
const SpatialReference* geo_srs = getSRS()->getGeographicSRS();
// get the input in lat/long:
GeoExtent gcs_input =
input.getSRS()->isGeographic()?
input :
input.transform( geo_srs );
// bail out on a bad transform:
if ( !gcs_input.isValid() )
return GeoExtent::INVALID;
// bail out if the extent's do not intersect at all:
if ( !gcs_input.intersects(_latlong_extent, false) )
return GeoExtent::INVALID;
// clamp it to the profile's extents:
GeoExtent clamped_gcs_input = GeoExtent(
gcs_input.getSRS(),
osg::clampBetween( gcs_input.xMin(), _latlong_extent.xMin(), _latlong_extent.xMax() ),
osg::clampBetween( gcs_input.yMin(), _latlong_extent.yMin(), _latlong_extent.yMax() ),
osg::clampBetween( gcs_input.xMax(), _latlong_extent.xMin(), _latlong_extent.xMax() ),
osg::clampBetween( gcs_input.yMax(), _latlong_extent.yMin(), _latlong_extent.yMax() ) );
if ( out_clamped )
*out_clamped = (clamped_gcs_input != gcs_input);
// finally, transform the clamped extent into this profile's SRS and return it.
GeoExtent result =
clamped_gcs_input.getSRS()->isEquivalentTo( this->getSRS() )?
clamped_gcs_input :
clamped_gcs_input.transform( this->getSRS() );
if (result.isValid())
{
OE_DEBUG << LC << "clamp&xform: input=" << input.toString() << ", output=" << result.toString() << std::endl;
}
return result;
}
示例4: getDataExtents
bool
TerrainLayer::mayHaveDataInExtent(const GeoExtent& ex) const
{
if (!ex.isValid())
{
// bad extent; no data
return false;
}
const DataExtentList& de = getDataExtents();
if (de.empty())
{
// not enough info, assume yes
return true;
}
// Get extent in local profile:
GeoExtent localExtent = ex;
if (getProfile() && getProfile()->getSRS()->isHorizEquivalentTo(ex.getSRS()))
{
localExtent = getProfile()->clampAndTransformExtent(ex);
}
// Check union:
if (getDataExtentsUnion().intersects(localExtent))
{
// possible yes
return true;
}
// Check each extent in turn:
for (DataExtentList::const_iterator i = de.begin(); i != de.end(); ++i)
{
if (i->intersects(localExtent))
{
// possible yes
return true;
}
}
// definite no.
return false;
}
示例5: execute
void execute()
{
GeoImage geoImage;
bool isFallbackData = false;
bool useMercatorFastPath =
_opt->enableMercatorFastPath() != false &&
_mapInfo->isGeocentric() &&
_layer->getProfile() &&
_layer->getProfile()->getSRS()->isSphericalMercator();
// fetch the image from the layer, falling back on parent keys utils we are
// able to find one that works.
bool autoFallback = _key.getLevelOfDetail() <= 1;
TileKey imageKey( _key );
TileSource* tileSource = _layer->getTileSource();
const Profile* layerProfile = _layer->getProfile();
//Only try to get data from the source if it actually intersects the key extent
bool hasDataInExtent = true;
if (tileSource && layerProfile)
{
GeoExtent ext = _key.getExtent();
if (!layerProfile->getSRS()->isEquivalentTo( ext.getSRS()))
{
ext = layerProfile->clampAndTransformExtent( ext );
}
hasDataInExtent = ext.isValid() && tileSource->hasDataInExtent( ext );
}
if (hasDataInExtent)
{
while( !geoImage.valid() && imageKey.valid() && _layer->isKeyValid(imageKey) )
{
if ( useMercatorFastPath )
{
bool mercFallbackData = false;
geoImage = _layer->createImageInNativeProfile( imageKey, 0L, autoFallback, mercFallbackData );
if ( geoImage.valid() && mercFallbackData )
{
isFallbackData = true;
}
}
else
{
geoImage = _layer->createImage( imageKey, 0L, autoFallback );
}
if ( !geoImage.valid() )
{
imageKey = imageKey.createParentKey();
isFallbackData = true;
}
}
}
GeoLocator* locator = 0L;
if ( !geoImage.valid() )
{
// no image found, so make an empty one (one pixel alpha).
geoImage = GeoImage( ImageUtils::createEmptyImage(), _key.getExtent() );
locator = GeoLocator::createForKey( _key, *_mapInfo );
isFallbackData = true;
}
else
{
if ( useMercatorFastPath )
locator = new MercatorLocator(geoImage.getExtent());
else
locator = GeoLocator::createForExtent(geoImage.getExtent(), *_mapInfo);
}
bool isStreaming = _opt->loadingPolicy()->mode() == LoadingPolicy::MODE_PREEMPTIVE || _opt->loadingPolicy()->mode() == LoadingPolicy::MODE_SEQUENTIAL;
if (geoImage.getImage() && isStreaming)
{
// protected against multi threaded access. This is a requirement in sequential/preemptive mode,
// for example. This used to be in TextureCompositorTexArray::prepareImage.
// TODO: review whether this affects performance.
geoImage.getImage()->setDataVariance( osg::Object::DYNAMIC );
}
// add the color layer to the repo.
_repo->add( CustomColorLayer(
_layer,
geoImage.getImage(),
locator,
_key.getLevelOfDetail(),
_key,
isFallbackData ) );
}
示例6: createFeatureProfile
/** Called once at startup to create the profile for this feature set. Successful profile
creation implies that the datasource opened succesfully. */
const FeatureProfile* createFeatureProfile()
{
FeatureProfile* result = 0L;
// see if we have a custom profile.
osg::ref_ptr<const Profile> profile;
if ( _options.profile().isSet() )
{
profile = Profile::create( *_options.profile() );
}
if ( _geometry.valid() )
{
// if the user specified explicit geometry/profile, use that:
GeoExtent ex;
if ( profile.valid() )
{
ex = profile->getExtent();
}
if ( !ex.isValid() )
{
// default to WGS84 Lat/Long
ex = osgEarth::Registry::instance()->getGlobalGeodeticProfile()->getExtent();
}
result = new FeatureProfile( ex );
}
else if ( !_source.empty() )
{
// otherwise, assume we're loading from the URL:
OGR_SCOPED_LOCK;
// load up the driver, defaulting to shapefile if unspecified.
std::string driverName = _options.ogrDriver().value();
if ( driverName.empty() )
driverName = "ESRI Shapefile";
_ogrDriverHandle = OGRGetDriverByName( driverName.c_str() );
// attempt to open the dataset:
int openMode = _options.openWrite().isSet() && _options.openWrite().value() ? 1 : 0;
_dsHandle = OGROpen( _source.c_str(), openMode, &_ogrDriverHandle );
if ( _dsHandle )
{
if (openMode == 1) _writable = true;
if ( _options.layer().isSet() )
{
_layerIndex = _options.layer().value();
}
_layerHandle = OGR_DS_GetLayer( _dsHandle, _layerIndex );
if ( _layerHandle )
{
GeoExtent extent;
// if the user provided a profile, user that:
if ( profile.valid() )
{
result = new FeatureProfile( profile->getExtent() );
}
else
{
// extract the SRS and Extent:
OGRSpatialReferenceH srHandle = OGR_L_GetSpatialRef( _layerHandle );
if ( srHandle )
{
osg::ref_ptr<SpatialReference> srs = SpatialReference::createFromHandle( srHandle, false );
if ( srs.valid() )
{
// extract the full extent of the layer:
OGREnvelope env;
if ( OGR_L_GetExtent( _layerHandle, &env, 1 ) == OGRERR_NONE )
{
GeoExtent extent( srs.get(), env.MinX, env.MinY, env.MaxX, env.MaxY );
// got enough info to make the profile!
result = new FeatureProfile( extent );
}
}
}
}
// assuming we successfully opened the layer, build a spatial index if requested.
if ( _options.buildSpatialIndex() == true )
{
OE_INFO << LC << "Building spatial index for " << getName() << std::endl;
std::stringstream buf;
const char* name = OGR_FD_GetName( OGR_L_GetLayerDefn( _layerHandle ) );
buf << "CREATE SPATIAL INDEX ON " << name;
std::string bufStr;
bufStr = buf.str();
OE_DEBUG << LC << "SQL: " << bufStr << std::endl;
OGR_DS_ExecuteSQL( _dsHandle, bufStr.c_str(), 0L, 0L );
}
//.........这里部分代码省略.........
示例7: v
void
TFSPackager::package( FeatureSource* features, const std::string& destination, const std::string& layername, const std::string& description )
{
if (!_destSRSString.empty())
{
_srs = SpatialReference::create( _destSRSString );
}
//Get the destination SRS from the feature source if it's not already set
if (!_srs.valid())
{
_srs = features->getFeatureProfile()->getSRS();
}
//Get the extent of the dataset, or use the custom extent value
GeoExtent srsExtent = _customExtent;
if (!srsExtent.isValid())
srsExtent = features->getFeatureProfile()->getExtent();
//Transform to lat/lon extents
GeoExtent extent = srsExtent.transform( _srs.get() );
osg::ref_ptr< const osgEarth::Profile > profile = osgEarth::Profile::create(extent.getSRS(), extent.xMin(), extent.yMin(), extent.xMax(), extent.yMax(), 1, 1);
TileKey rootKey = TileKey(0, 0, 0, profile );
osg::ref_ptr< FeatureTile > root = new FeatureTile( rootKey );
//Loop through all the features and try to insert them into the quadtree
osg::ref_ptr< FeatureCursor > cursor = features->createFeatureCursor( _query );
int added = 0;
int failed = 0;
int skipped = 0;
int highestLevel = 0;
while (cursor.valid() && cursor->hasMore())
{
osg::ref_ptr< Feature > feature = cursor->nextFeature();
//Reproject the feature to the dest SRS if it's not already
if (!feature->getSRS()->isEquivalentTo( _srs ) )
{
feature->transform( _srs );
}
if (feature->getGeometry() && feature->getGeometry()->getBounds().valid() && feature->getGeometry()->isValid())
{
AddFeatureVisitor v(feature.get(), _maxFeatures, _firstLevel, _maxLevel, _method);
root->accept( &v );
if (!v._added)
{
OE_NOTICE << "Failed to add feature " << feature->getFID() << std::endl;
failed++;
}
else
{
if (highestLevel < v._levelAdded)
{
highestLevel = v._levelAdded;
}
added++;
OE_DEBUG << "Added " << added << std::endl;
}
}
else
{
OE_NOTICE << "Skipping feature " << feature->getFID() << " with null or invalid geometry" << std::endl;
skipped++;
}
}
OE_NOTICE << "Added=" << added << " Skipped=" << skipped << " Failed=" << failed << std::endl;
#if 1
// Print the width of tiles at each level
for (int i = 0; i <= highestLevel; ++i)
{
TileKey tileKey(i, 0, 0, profile);
GeoExtent tileExtent = tileKey.getExtent();
OE_NOTICE << "Level " << i << " tile size: " << tileExtent.width() << std::endl;
}
#endif
WriteFeaturesVisitor write(features, destination, _method, _srs);
root->accept( &write );
//Write out the meta doc
TFSLayer layer;
layer.setTitle( layername );
layer.setAbstract( description );
layer.setFirstLevel( _firstLevel );
layer.setMaxLevel( highestLevel );
layer.setExtent( profile->getExtent() );
layer.setSRS( _srs.get() );
TFSReaderWriter::write( layer, osgDB::concatPaths( destination, "tfs.xml"));
}
示例8: seed
//.........这里部分代码省略.........
}
else
{
for (std::vector< GeoExtent >::const_iterator itr = _extents.begin(); itr != _extents.end(); itr++)
{
const GeoExtent& extent = *itr;
double boundsArea = extent.area();
TileKey ll = map->getProfile()->createTileKey(extent.xMin(), extent.yMin(), level);
TileKey ur = map->getProfile()->createTileKey(extent.xMax(), extent.yMax(), level);
int tilesWide = ur.getTileX() - ll.getTileX() + 1;
int tilesHigh = ll.getTileY() - ur.getTileY() + 1;
int tilesAtLevel = tilesWide * tilesHigh;
//OE_NOTICE << "Tiles at level " << level << "=" << tilesAtLevel << std::endl;
bool hasData = false;
for (ImageLayerVector::const_iterator itr = mapf.imageLayers().begin(); itr != mapf.imageLayers().end(); itr++)
{
TileSource* src = itr->get()->getTileSource();
if (src)
{
if (src->hasDataAtLOD( level ))
{
//Compute the percent coverage of this dataset on the current extent
if (src->getDataExtents().size() > 0)
{
double cov = 0.0;
for (unsigned int j = 0; j < src->getDataExtents().size(); j++)
{
GeoExtent b = src->getDataExtents()[j].transform( extent.getSRS());
GeoExtent intersection = b.intersectionSameSRS( extent );
if (intersection.isValid())
{
double coverage = intersection.area() / boundsArea;
cov += coverage; //Assumes the extents aren't overlapping
}
}
if (coverageRatio < cov) coverageRatio = cov;
}
else
{
//We have no way of knowing how much coverage we have
coverageRatio = 1.0;
}
hasData = true;
break;
}
}
}
for (ElevationLayerVector::const_iterator itr = mapf.elevationLayers().begin(); itr != mapf.elevationLayers().end(); itr++)
{
TileSource* src = itr->get()->getTileSource();
if (src)
{
if (src->hasDataAtLOD( level ))
{
//Compute the percent coverage of this dataset on the current extent
if (src->getDataExtents().size() > 0)
{
double cov = 0.0;
for (unsigned int j = 0; j < src->getDataExtents().size(); j++)
{
GeoExtent b = src->getDataExtents()[j].transform( extent.getSRS());
示例9: createFeatureProfile
/** Called once at startup to create the profile for this feature set. Successful profile
creation implies that the datasource opened succesfully. */
const FeatureProfile* createFeatureProfile()
{
FeatureProfile* result = 0L;
if ( _geometry.valid() )
{
// if the user specified explicit geometry/profile, use that:
GeoExtent ex;
if ( _options.geometryProfileOptions().isSet() )
{
osg::ref_ptr<const Profile> _profile = Profile::create(
ProfileOptions(_options.geometryProfileOptions().value()) );
if ( _profile.valid() )
ex = _profile->getExtent();
}
if ( !ex.isValid() )
{
// default to WGS84 Lat/Long
ex = osgEarth::Registry::instance()->getGlobalGeodeticProfile()->getExtent();
}
result = new FeatureProfile( ex );
}
else if ( !_absUrl.empty() )
{
// otherwise, assume we're loading from the URL:
OGR_SCOPED_LOCK;
// load up the driver, defaulting to shapefile if unspecified.
std::string driverName = _options.ogrDriver().value();
if ( driverName.empty() )
driverName = "ESRI Shapefile";
_ogrDriverHandle = OGRGetDriverByName( driverName.c_str() );
// attempt to open the dataset:
_dsHandle = OGROpenShared( _absUrl.c_str(), 0, &_ogrDriverHandle );
if ( _dsHandle )
{
_layerHandle = OGR_DS_GetLayer( _dsHandle, 0 ); // default to layer 0 for now
if ( _layerHandle )
{
GeoExtent extent;
// extract the SRS and Extent:
OGRSpatialReferenceH srHandle = OGR_L_GetSpatialRef( _layerHandle );
if ( srHandle )
{
osg::ref_ptr<SpatialReference> srs = SpatialReference::createFromHandle( srHandle, false );
if ( srs.valid() )
{
// extract the full extent of the layer:
OGREnvelope env;
if ( OGR_L_GetExtent( _layerHandle, &env, 1 ) == OGRERR_NONE )
{
GeoExtent extent( srs.get(), env.MinX, env.MinY, env.MaxX, env.MaxY );
// got enough info to make the profile!
result = new FeatureProfile( extent );
}
}
}
// assuming we successfully opened the layer, build a spatial index if requested.
if ( _options.buildSpatialIndex() == true )
{
OE_INFO << LC << "Building spatial index for " << getName() << " ..." << std::flush;
std::stringstream buf;
const char* name = OGR_FD_GetName( OGR_L_GetLayerDefn( _layerHandle ) );
buf << "CREATE SPATIAL INDEX ON " << name;
std::string bufStr;
bufStr = buf.str();
OGR_DS_ExecuteSQL( _dsHandle, bufStr.c_str(), 0L, 0L );
OE_INFO << LC << "...done." << std::endl;
}
}
}
else
{
OE_INFO << LC << "failed to open dataset at " << _absUrl << std::endl;
}
}
else
{
OE_INFO << LC
<< "Feature Source: no valid source data available" << std::endl;
}
return result;
}