本文整理汇总了C++中GeoExtent::transform方法的典型用法代码示例。如果您正苦于以下问题:C++ GeoExtent::transform方法的具体用法?C++ GeoExtent::transform怎么用?C++ GeoExtent::transform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GeoExtent
的用法示例。
在下文中一共展示了GeoExtent::transform方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
MPTerrainEngineNode::invalidateRegion(const GeoExtent& extent,
unsigned minLevel,
unsigned maxLevel)
{
if (_terrainOptions.incrementalUpdate() == true && _liveTiles.valid())
{
GeoExtent extentLocal = extent;
if ( !extent.getSRS()->isEquivalentTo(this->getMap()->getSRS()) )
{
extent.transform(this->getMap()->getSRS(), extentLocal);
}
_liveTiles->setDirty(extentLocal, minLevel, maxLevel);
}
}
示例2: 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;
}
示例3: 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() )
{
workingExtent.getSRS()->transformToECEF( center, center );
workingExtent.getSRS()->transformToECEF( corner, corner );
}
return osg::BoundingSphered( center, (center-corner).length() );
}
示例4:
void
HeightFieldUtils::resolveInvalidHeights(osg::HeightField* grid,
const GeoExtent& ex,
float invalidValue,
const Geoid* geoid)
{
if ( geoid )
{
// need the lat/long extent for geoid queries:
unsigned numRows = grid->getNumRows();
unsigned numCols = grid->getNumColumns();
GeoExtent geodeticExtent = ex.getSRS()->isGeographic() ? ex : ex.transform( ex.getSRS()->getGeographicSRS() );
double latMin = geodeticExtent.yMin();
double lonMin = geodeticExtent.xMin();
double lonInterval = geodeticExtent.width() / (double)(numCols-1);
double latInterval = geodeticExtent.height() / (double)(numRows-1);
for( unsigned r=0; r<numRows; ++r )
{
double lat = latMin + latInterval*(double)r;
for( unsigned c=0; c<numCols; ++c )
{
double lon = lonMin + lonInterval*(double)c;
if ( grid->getHeight(c, r) == invalidValue )
{
grid->setHeight( c, r, geoid->getHeight(lat, lon) );
}
}
}
}
else
{
for(unsigned int i=0; i<grid->getHeightList().size(); i++ )
{
if ( grid->getHeightList()[i] == invalidValue )
{
grid->getHeightList()[i] = 0.0;
}
}
}
}
示例5: 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"));
}
示例6: renderFeaturesForStyle
bool
FeatureTileSource::queryAndRenderFeaturesForStyle(const Style& style,
const Query& query,
osg::Referenced* data,
const GeoExtent& imageExtent,
osg::Image* out_image)
{
// first we need the overall extent of the layer:
const GeoExtent& featuresExtent = getFeatureSource()->getFeatureProfile()->getExtent();
// convert them both to WGS84, intersect the extents, and convert back.
GeoExtent featuresExtentWGS84 = featuresExtent.transform( featuresExtent.getSRS()->getGeographicSRS() );
GeoExtent imageExtentWGS84 = imageExtent.transform( featuresExtent.getSRS()->getGeographicSRS() );
GeoExtent queryExtentWGS84 = featuresExtentWGS84.intersectionSameSRS( imageExtentWGS84 );
if ( queryExtentWGS84.isValid() )
{
GeoExtent queryExtent = queryExtentWGS84.transform( featuresExtent.getSRS() );
// incorporate the image extent into the feature query for this style:
Query localQuery = query;
localQuery.bounds() =
query.bounds().isSet() ? query.bounds()->unionWith( queryExtent.bounds() ) :
queryExtent.bounds();
// query the feature source:
osg::ref_ptr<FeatureCursor> cursor = _features->createFeatureCursor( localQuery );
// now copy the resulting feature set into a list, converting the data
// types along the way if a geometry override is in place:
FeatureList cellFeatures;
while( cursor.valid() && cursor->hasMore() )
{
Feature* feature = cursor->nextFeature();
Geometry* geom = feature->getGeometry();
if ( geom )
{
// apply a type override if requested:
if (_options.geometryTypeOverride().isSet() &&
_options.geometryTypeOverride() != geom->getComponentType() )
{
geom = geom->cloneAs( _options.geometryTypeOverride().value() );
if ( geom )
feature->setGeometry( geom );
}
}
if ( geom )
{
cellFeatures.push_back( feature );
}
}
//OE_NOTICE
// << "Rendering "
// << cellFeatures.size()
// << " features in ("
// << queryExtent.toString() << ")"
// << std::endl;
return renderFeaturesForStyle( style, cellFeatures, data, imageExtent, out_image );
}
else
{
return false;
}
}
示例7: renderFeaturesForStyle
//override
bool renderFeaturesForStyle(
const Style& style,
const FeatureList& features,
osg::Referenced* buildData,
const GeoExtent& imageExtent,
osg::Image* image )
{
// A processing context to use with the filters:
FilterContext context;
context.setProfile( getFeatureSource()->getFeatureProfile() );
const LineSymbol* masterLine = style.getSymbol<LineSymbol>();
const PolygonSymbol* masterPoly = style.getSymbol<PolygonSymbol>();
// sort into bins, making a copy for lines that require buffering.
FeatureList polygons;
FeatureList lines;
for(FeatureList::const_iterator f = features.begin(); f != features.end(); ++f)
{
if ( f->get()->getGeometry() )
{
if ( masterPoly || f->get()->style()->has<PolygonSymbol>() )
{
polygons.push_back( f->get() );
}
if ( masterLine || f->get()->style()->has<LineSymbol>() )
{
Feature* newFeature = new Feature( *f->get() );
if ( !newFeature->getGeometry()->isLinear() )
{
newFeature->setGeometry( newFeature->getGeometry()->cloneAs(Geometry::TYPE_RING) );
}
lines.push_back( newFeature );
}
}
}
// initialize:
RenderFrame frame;
frame.xmin = imageExtent.xMin();
frame.ymin = imageExtent.yMin();
frame.xf = (double)image->s() / imageExtent.width();
frame.yf = (double)image->t() / imageExtent.height();
if ( lines.size() > 0 )
{
// We are buffering in the features native extent, so we need to use the
// transformed extent to get the proper "resolution" for the image
const SpatialReference* featureSRS = context.profile()->getSRS();
GeoExtent transformedExtent = imageExtent.transform(featureSRS);
double trans_xf = (double)image->s() / transformedExtent.width();
double trans_yf = (double)image->t() / transformedExtent.height();
// resolution of the image (pixel extents):
double xres = 1.0/trans_xf;
double yres = 1.0/trans_yf;
// downsample the line data so that it is no higher resolution than to image to which
// we intend to rasterize it. If you don't do this, you run the risk of the buffer
// operation taking forever on very high-res input data.
if ( _options.optimizeLineSampling() == true )
{
ResampleFilter resample;
resample.minLength() = osg::minimum( xres, yres );
context = resample.push( lines, context );
}
// now run the buffer operation on all lines:
BufferFilter buffer;
double lineWidth = 1.0;
if ( masterLine )
{
buffer.capStyle() = masterLine->stroke()->lineCap().value();
if ( masterLine->stroke()->width().isSet() )
{
lineWidth = masterLine->stroke()->width().value();
GeoExtent imageExtentInFeatureSRS = imageExtent.transform(featureSRS);
double pixelWidth = imageExtentInFeatureSRS.width() / (double)image->s();
// if the width units are specified, process them:
if (masterLine->stroke()->widthUnits().isSet() &&
masterLine->stroke()->widthUnits().get() != Units::PIXELS)
{
const Units& featureUnits = featureSRS->getUnits();
const Units& strokeUnits = masterLine->stroke()->widthUnits().value();
// if the units are different than those of the feature data, we need to
// do a units conversion.
if ( featureUnits != strokeUnits )
{
if ( Units::canConvert(strokeUnits, featureUnits) )
{
// linear to linear, no problem
lineWidth = strokeUnits.convertTo( featureUnits, lineWidth );
//.........这里部分代码省略.........
示例8: initialize
//.........这里部分代码省略.........
result = osgEarth::Registry::instance()->getGlobalGeodeticProfile();
}
// Next, try to glean the extents from the layer list
if ( capabilities.valid() )
{
StringTokenizer tok(",");
StringVector tized;
tok.tokenize(_options.layers().value(), tized);
for (StringVector::const_iterator itr = tized.begin(); itr != tized.end(); ++itr)
{
std::string layerName = *itr;
WMSLayer* layer = capabilities->getLayerByName(layerName);
if (layer)
{
// Get the lat/lon extents
double minLon, minLat, maxLon, maxLat;
layer->getLatLonExtents(minLon, minLat, maxLon, maxLat);
GeoExtent wgs84Extent(SpatialReference::create("wgs84"), minLon, minLat, maxLon, maxLat);
getDataExtents().push_back(DataExtent(wgs84Extent, 0));
}
}
// If we don't have a profile yet, transform the lat/lon extents to the requested srs and use it as the extents of the profile.
if (!result.valid())
{
const SpatialReference* srs = SpatialReference::create(_srsToUse);
GeoExtent totalExtent(srs);
for (DataExtentList::const_iterator itr = getDataExtents().begin(); itr != getDataExtents().end(); ++itr)
{
GeoExtent dataExtent = *itr;
GeoExtent nativeExtent;
dataExtent.transform(srs, nativeExtent);
totalExtent.expandToInclude(nativeExtent);
}
result = Profile::create(srs, totalExtent.xMin(), totalExtent.yMin(), totalExtent.xMax(), totalExtent.yMax());
}
}
// Last resort: create a global extent profile (only valid for global maps)
if ( !result.valid() && wms_srs->isGeographic())
{
result = osgEarth::Registry::instance()->getGlobalGeodeticProfile();
}
#ifdef SUPPORT_JPL_TILESERVICE
// JPL uses an experimental interface called TileService -- ping to see if that's what
// we are trying to read:
URI tsUrl = _options.tileServiceUrl().value();
if ( tsUrl.empty() )
{
tsUrl = URI(_options.url()->full() + sep + std::string("request=GetTileService"), tsUrl.context());
}
OE_INFO << LC << "Testing for JPL/TileService at " << tsUrl.full() << std::endl;
osg::ref_ptr<TileService> tileService = TileServiceReader::read(tsUrl.full(), dbOptions);
if (tileService.valid())
{
OE_INFO << LC << "Found JPL/TileService spec" << std::endl;
TileService::TilePatternList patterns;
tileService->getMatchingPatterns(
_options.layers().value(),
_formatToUse,
_options.style().value(),
_srsToUse,
示例9: renderFeaturesForStyle
//override
bool renderFeaturesForStyle(
const Style& style,
const FeatureList& inFeatures,
osg::Referenced* buildData,
const GeoExtent& imageExtent,
osg::Image* image )
{
// local copy of the features that we can process
FeatureList features = inFeatures;
BuildData* bd = static_cast<BuildData*>( buildData );
// A processing context to use with the filters:
FilterContext context;
context.profile() = getFeatureSource()->getFeatureProfile();
const LineSymbol* masterLine = style.getSymbol<LineSymbol>();
const PolygonSymbol* masterPoly = style.getSymbol<PolygonSymbol>();
//bool embeddedStyles = getFeatureSource()->hasEmbeddedStyles();
// if only a line symbol exists, and there are polygons in the mix, draw them
// as outlines (line rings).
//OE_INFO << LC << "Line Symbol = " << (masterLine == 0L ? "null" : masterLine->getConfig().toString()) << std::endl;
//OE_INFO << LC << "Poly SYmbol = " << (masterPoly == 0L ? "null" : masterPoly->getConfig().toString()) << std::endl;
//bool convertPolysToRings = poly == 0L && line != 0L;
//if ( convertPolysToRings )
// OE_INFO << LC << "No PolygonSymbol; will draw polygons to rings" << std::endl;
// initialize:
double xmin = imageExtent.xMin();
double ymin = imageExtent.yMin();
//double s = (double)image->s();
//double t = (double)image->t();
double xf = (double)image->s() / imageExtent.width();
double yf = (double)image->t() / imageExtent.height();
// strictly speaking we should iterate over the features and buffer each one that's a line,
// rather then checking for the existence of a LineSymbol.
FeatureList linesToBuffer;
for(FeatureList::iterator i = features.begin(); i != features.end(); i++)
{
Feature* feature = i->get();
Geometry* geom = feature->getGeometry();
if ( geom )
{
// check for an embedded style:
const LineSymbol* line = feature->style().isSet() ?
feature->style()->getSymbol<LineSymbol>() : masterLine;
const PolygonSymbol* poly =
feature->style().isSet() ? feature->style()->getSymbol<PolygonSymbol>() : masterPoly;
// if we have polygons but only a LineSymbol, draw the poly as a line.
if ( geom->getComponentType() == Geometry::TYPE_POLYGON )
{
if ( !poly && line )
{
Feature* outline = new Feature( *feature );
geom = geom->cloneAs( Geometry::TYPE_RING );
outline->setGeometry( geom );
*i = outline;
feature = outline;
}
//TODO: fix to enable outlined polys. doesn't work, not sure why -gw
//else if ( poly && line )
//{
// Feature* outline = new Feature();
// geom = geom->cloneAs( Geometry::TYPE_LINESTRING );
// outline->setGeometry( geom );
// features.push_back( outline );
//}
}
bool needsBuffering =
geom->getComponentType() == Geometry::TYPE_LINESTRING ||
geom->getComponentType() == Geometry::TYPE_RING;
if ( needsBuffering )
{
linesToBuffer.push_back( feature );
}
}
}
if ( linesToBuffer.size() > 0 )
{
//We are buffering in the features native extent, so we need to use the transform extent to get the proper "resolution" for the image
GeoExtent transformedExtent = imageExtent.transform(context.profile()->getSRS());
double trans_xf = (double)image->s() / transformedExtent.width();
double trans_yf = (double)image->t() / transformedExtent.height();
// resolution of the image (pixel extents):
double xres = 1.0/trans_xf;
double yres = 1.0/trans_yf;
//.........这里部分代码省略.........