本文整理汇总了C++中FilterContext::profile方法的典型用法代码示例。如果您正苦于以下问题:C++ FilterContext::profile方法的具体用法?C++ FilterContext::profile怎么用?C++ FilterContext::profile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilterContext
的用法示例。
在下文中一共展示了FilterContext::profile方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xform
osg::Node*
GeomCompiler::compile(FeatureCursor* cursor,
const Style& style,
const FilterContext& context)
{
if ( !context.profile() ) {
OE_WARN << LC << "Valid feature profile required" << std::endl;
return 0L;
}
if ( style.empty() ) {
OE_WARN << LC << "Non-empty style required" << std::endl;
return 0L;
}
osg::ref_ptr<osg::Group> resultGroup = new osg::Group();
// start by making a working copy of the feature set
FeatureList workingSet;
cursor->fill( workingSet );
// create a filter context that will track feature data through the process
FilterContext cx = context;
if ( !cx.extent().isSet() )
cx.extent() = cx.profile()->getExtent();
// only localize coordinates if the map if geocentric AND the extent is
// less than 180 degrees.
const MapInfo& mi = cx.getSession()->getMapInfo();
GeoExtent workingExtent = cx.extent()->transform( cx.profile()->getSRS()->getGeographicSRS() );
bool localize = mi.isGeocentric() && workingExtent.width() < 180.0;
// go through the Style and figure out which filters to use.
const MarkerSymbol* marker = style.get<MarkerSymbol>();
const PointSymbol* point = style.get<PointSymbol>();
const LineSymbol* line = style.get<LineSymbol>();
const PolygonSymbol* polygon = style.get<PolygonSymbol>();
const ExtrusionSymbol* extrusion = style.get<ExtrusionSymbol>();
const AltitudeSymbol* altitude = style.get<AltitudeSymbol>();
const TextSymbol* text = style.get<TextSymbol>();
// transform the features into the map profile
TransformFilter xform( mi.getProfile()->getSRS(), mi.isGeocentric() );
xform.setLocalizeCoordinates( localize );
if ( altitude && altitude->verticalOffset().isSet() )
xform.setMatrix( osg::Matrixd::translate(0, 0, *altitude->verticalOffset()) );
cx = xform.push( workingSet, cx );
bool clampRequired =
altitude && altitude->clamping() != AltitudeSymbol::CLAMP_NONE;
// model substitution
if ( marker )
{
if ( marker->placement() == MarkerSymbol::PLACEMENT_RANDOM ||
marker->placement() == MarkerSymbol::PLACEMENT_INTERVAL )
{
ScatterFilter scatter;
scatter.setDensity( *marker->density() );
scatter.setRandom( marker->placement() == MarkerSymbol::PLACEMENT_RANDOM );
scatter.setRandomSeed( *marker->randomSeed() );
cx = scatter.push( workingSet, cx );
}
if ( clampRequired )
{
ClampFilter clamp;
clamp.setIgnoreZ( altitude->clamping() == AltitudeSymbol::CLAMP_TO_TERRAIN );
cx = clamp.push( workingSet, cx );
clampRequired = false;
}
SubstituteModelFilter sub( style );
sub.setClustering( *_options.clustering() );
if ( marker->scale().isSet() )
sub.setModelMatrix( osg::Matrixd::scale( *marker->scale() ) );
cx = sub.push( workingSet, cx );
osg::Node* node = sub.getNode();
if ( node )
resultGroup->addChild( node );
}
// extruded geometry
if ( extrusion && ( line || polygon ) )
{
if ( clampRequired )
{
ClampFilter clamp;
clamp.setIgnoreZ( altitude->clamping() == AltitudeSymbol::CLAMP_TO_TERRAIN );
if ( extrusion->heightReference() == ExtrusionSymbol::HEIGHT_REFERENCE_MSL )
clamp.setMaxZAttributeName( "__max_z");
cx = clamp.push( workingSet, cx );
clampRequired = false;
}
ExtrudeGeometryFilter extrude;
if ( extrusion )
//.........这里部分代码省略.........
示例2: eq
void
AltitudeFilter::pushAndClamp( FeatureList& features, FilterContext& cx )
{
const Session* session = cx.getSession();
// the map against which we'll be doing elevation clamping
//MapFrame mapf = session->createMapFrame( Map::ELEVATION_LAYERS );
MapFrame mapf = session->createMapFrame( Map::TERRAIN_LAYERS );
const SpatialReference* mapSRS = mapf.getProfile()->getSRS();
osg::ref_ptr<const SpatialReference> featureSRS = cx.profile()->getSRS();
// establish an elevation query interface based on the features' SRS.
ElevationQuery eq( mapf );
NumericExpression scaleExpr;
if ( _altitude->verticalScale().isSet() )
scaleExpr = *_altitude->verticalScale();
NumericExpression offsetExpr;
if ( _altitude->verticalOffset().isSet() )
offsetExpr = *_altitude->verticalOffset();
// whether to record the min/max height-above-terrain values.
bool collectHATs =
_altitude->clamping() == AltitudeSymbol::CLAMP_RELATIVE_TO_TERRAIN ||
_altitude->clamping() == AltitudeSymbol::CLAMP_ABSOLUTE;
// whether to clamp every vertex (or just the centroid)
bool perVertex =
_altitude->binding() == AltitudeSymbol::BINDING_VERTEX;
// whether the SRS's have a compatible vertical datum.
bool vertEquiv =
featureSRS->isVertEquivalentTo( mapSRS );
for( FeatureList::iterator i = features.begin(); i != features.end(); ++i )
{
Feature* feature = i->get();
double maxTerrainZ = -DBL_MAX;
double minTerrainZ = DBL_MAX;
double minHAT = DBL_MAX;
double maxHAT = -DBL_MAX;
double scaleZ = 1.0;
if ( _altitude.valid() && _altitude->verticalScale().isSet() )
scaleZ = feature->eval( scaleExpr, &cx );
double offsetZ = 0.0;
if ( _altitude.valid() && _altitude->verticalOffset().isSet() )
offsetZ = feature->eval( offsetExpr, &cx );
GeometryIterator gi( feature->getGeometry() );
while( gi.hasMore() )
{
Geometry* geom = gi.next();
// Absolute heights in Z. Only need to collect the HATs; the geometry
// remains unchanged.
if ( _altitude->clamping() == AltitudeSymbol::CLAMP_ABSOLUTE )
{
if ( perVertex )
{
std::vector<double> elevations;
elevations.reserve( geom->size() );
if ( eq.getElevations( geom->asVector(), featureSRS, elevations, _maxRes ) )
{
for( unsigned i=0; i<geom->size(); ++i )
{
osg::Vec3d& p = (*geom)[i];
p.z() *= scaleZ;
p.z() += offsetZ;
double z = p.z();
if ( !vertEquiv )
{
osg::Vec3d tempgeo;
if ( !featureSRS->transform(p, mapSRS->getGeographicSRS(), tempgeo) )
z = tempgeo.z();
}
double hat = z - elevations[i];
if ( hat > maxHAT )
maxHAT = hat;
if ( hat < minHAT )
minHAT = hat;
if ( elevations[i] > maxTerrainZ )
maxTerrainZ = elevations[i];
if ( elevations[i] < minTerrainZ )
minTerrainZ = elevations[i];
}
}
}
else // per centroid
{
//.........这里部分代码省略.........
示例3: iter
void
ScatterFilter::polyScatter(const Geometry* input,
const SpatialReference* inputSRS,
const FilterContext& context,
PointSet* output )
{
Bounds bounds;
double areaSqKm = 0.0;
ConstGeometryIterator iter( input, false );
while( iter.hasMore() )
{
const Polygon* polygon = dynamic_cast<const Polygon*>( iter.next() );
if ( !polygon )
continue;
if ( /*context.isGeocentric() ||*/ context.profile()->getSRS()->isGeographic() )
{
bounds = polygon->getBounds();
double avglat = bounds.yMin() + 0.5*bounds.height();
double h = bounds.height() * 111.32;
double w = bounds.width() * 111.32 * sin( 1.57079633 + osg::DegreesToRadians(avglat) );
areaSqKm = w * h;
}
else if ( context.profile()->getSRS()->isProjected() )
{
bounds = polygon->getBounds();
areaSqKm = (0.001*bounds.width()) * (0.001*bounds.height());
}
double zMin = 0.0;
unsigned numInstancesInBoundingRect = (unsigned)(areaSqKm * (double)osg::clampAbove( 0.1f, _density ));
if ( numInstancesInBoundingRect == 0 )
continue;
if ( _random )
{
// Random scattering. Note, we try to place as many instances as would
// fit in the bounding rectangle; The real placed number will be less since
// we only place models inside the actual polygon. But the density will
// be correct.
for( unsigned j=0; j<numInstancesInBoundingRect; ++j )
{
double x = bounds.xMin() + _prng.next() * bounds.width();
double y = bounds.yMin() + _prng.next() * bounds.height();
bool include = true;
if ( include && polygon->contains2D( x, y ) )
output->push_back( osg::Vec3d(x, y, zMin) );
}
}
else
{
// regular interval scattering:
double numInst1D = sqrt((double)numInstancesInBoundingRect);
double ar = bounds.width() / bounds.height();
unsigned cols = (unsigned)( numInst1D * ar );
unsigned rows = (unsigned)( numInst1D / ar );
double colInterval = bounds.width() / (double)(cols-1);
double rowInterval = bounds.height() / (double)(rows-1);
double interval = 0.5*(colInterval+rowInterval);
for( double cy=bounds.yMin(); cy<=bounds.yMax(); cy += interval )
{
for( double cx = bounds.xMin(); cx <= bounds.xMax(); cx += interval )
{
bool include = true;
if ( include && polygon->contains2D( cx, cy ) )
output->push_back( osg::Vec3d(cx, cy, zMin) );
}
}
}
}
}
示例4: 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 );
//.........这里部分代码省略.........
示例5: scriptExpr
//.........这里部分代码省略.........
osg::ref_ptr<osg::Node>& model = uniqueModels[key];
if ( !model.valid() )
{
// Always clone the cached instance so we're not processing data that's
// already in the scene graph. -gw
context.resourceCache()->cloneOrCreateInstanceNode(instance.get(), model);
// if icon decluttering is off, install an AutoTransform.
if ( iconSymbol )
{
if ( iconSymbol->declutter() == true )
{
Decluttering::setEnabled( model->getOrCreateStateSet(), true );
}
else if ( dynamic_cast<osg::AutoTransform*>(model.get()) == 0L )
{
osg::AutoTransform* at = new osg::AutoTransform();
at->setAutoRotateMode( osg::AutoTransform::ROTATE_TO_SCREEN );
at->setAutoScaleToScreen( true );
at->addChild( model );
model = at;
}
}
}
if ( model.valid() )
{
GeometryIterator gi( input->getGeometry(), false );
while( gi.hasMore() )
{
Geometry* geom = gi.next();
// if necessary, transform the points to the target SRS:
if ( !makeECEF && !targetSRS->isEquivalentTo(context.profile()->getSRS()) )
{
context.profile()->getSRS()->transform( geom->asVector(), targetSRS );
}
for( unsigned i=0; i<geom->size(); ++i )
{
osg::Matrixd mat;
// need to recalcluate expression-based data per-point, not just per-feature!
if ( symbol->scale().isSet() )
{
scale = input->eval(scaleEx, &context);
if ( scale == 0.0 )
scale = 1.0;
if ( scale != 1.0 )
_normalScalingRequired = true;
scaleMatrix = osg::Matrix::scale( scale, scale, scale );
}
if ( modelSymbol->heading().isSet() )
{
float heading = input->eval(headingEx, &context);
rotationMatrix.makeRotate( osg::Quat(osg::DegreesToRadians(heading), osg::Vec3(0,0,1)) );
}
osg::Vec3d point = (*geom)[i];
if ( makeECEF )
{
// the "rotation" element lets us re-orient the instance to ensure it's pointing up. We
// could take a shortcut and just use the current extent's local2world matrix for this,
// but if the tile is big enough the up vectors won't be quite right.
osg::Matrixd rotation;
示例6: if
osg::Node*
GeometryCompiler::compile(FeatureList& workingSet,
const Style& style,
const FilterContext& context)
{
#ifdef PROFILING
osg::Timer_t p_start = osg::Timer::instance()->tick();
unsigned p_features = workingSet.size();
#endif
osg::ref_ptr<osg::Group> resultGroup = new osg::Group();
// create a filter context that will track feature data through the process
FilterContext sharedCX = context;
if ( !sharedCX.extent().isSet() && sharedCX.profile() )
{
sharedCX.extent() = sharedCX.profile()->getExtent();
}
// ref_ptr's to hold defaults in case we need them.
osg::ref_ptr<PointSymbol> defaultPoint;
osg::ref_ptr<LineSymbol> defaultLine;
osg::ref_ptr<PolygonSymbol> defaultPolygon;
// go through the Style and figure out which filters to use.
const PointSymbol* point = style.get<PointSymbol>();
const LineSymbol* line = style.get<LineSymbol>();
const PolygonSymbol* polygon = style.get<PolygonSymbol>();
const ExtrusionSymbol* extrusion = style.get<ExtrusionSymbol>();
const AltitudeSymbol* altitude = style.get<AltitudeSymbol>();
const TextSymbol* text = style.get<TextSymbol>();
const MarkerSymbol* marker = style.get<MarkerSymbol>(); // to be deprecated
const IconSymbol* icon = style.get<IconSymbol>();
const ModelSymbol* model = style.get<ModelSymbol>();
// check whether we need tessellation:
if ( line && line->tessellation().isSet() )
{
TemplateFeatureFilter<TessellateOperator> filter;
filter.setNumPartitions( *line->tessellation() );
sharedCX = filter.push( workingSet, sharedCX );
}
// if the style was empty, use some defaults based on the geometry type of the
// first feature.
if ( !point && !line && !polygon && !marker && !extrusion && !text && !model && !icon && workingSet.size() > 0 )
{
Feature* first = workingSet.begin()->get();
Geometry* geom = first->getGeometry();
if ( geom )
{
switch( geom->getComponentType() )
{
case Geometry::TYPE_LINESTRING:
case Geometry::TYPE_RING:
defaultLine = new LineSymbol();
line = defaultLine.get();
break;
case Geometry::TYPE_POINTSET:
defaultPoint = new PointSymbol();
point = defaultPoint.get();
break;
case Geometry::TYPE_POLYGON:
defaultPolygon = new PolygonSymbol();
polygon = defaultPolygon.get();
break;
case Geometry::TYPE_MULTI:
case Geometry::TYPE_UNKNOWN:
break;
}
}
}
// resample the geometry if necessary:
if (_options.resampleMode().isSet())
{
ResampleFilter resample;
resample.resampleMode() = *_options.resampleMode();
if (_options.resampleMaxLength().isSet())
{
resample.maxLength() = *_options.resampleMaxLength();
}
sharedCX = resample.push( workingSet, sharedCX );
}
// check whether we need to do elevation clamping:
bool altRequired =
_options.ignoreAltitudeSymbol() != true &&
altitude && (
altitude->clamping() != AltitudeSymbol::CLAMP_NONE ||
altitude->verticalOffset().isSet() ||
altitude->verticalScale().isSet() ||
altitude->script().isSet() );
// marker substitution -- to be deprecated in favor of model/icon
if ( marker )
{
// use a separate filter context since we'll be munging the data
FilterContext markerCX = sharedCX;
//.........这里部分代码省略.........
示例7: tex
osg::Node*
Graticule::createGridLevel( unsigned int levelNum ) const
{
if ( !_map->isGeocentric() )
{
OE_WARN << "Graticule: only supports geocentric maps" << std::endl;
return 0L;
}
Graticule::Level level;
if ( !getLevel( levelNum, level ) )
return 0L;
OE_DEBUG << "Graticule: creating grid level " << levelNum << std::endl;
osg::Group* group = new osg::Group();
const Profile* mapProfile = _map->getProfile();
const GeoExtent& pex = mapProfile->getExtent();
double tw = pex.width() / (double)level._cellsX;
double th = pex.height() / (double)level._cellsY;
for( unsigned int x=0; x<level._cellsX; ++x )
{
for( unsigned int y=0; y<level._cellsY; ++y )
{
GeoExtent tex(
mapProfile->getSRS(),
pex.xMin() + tw * (double)x,
pex.yMin() + th * (double)y,
pex.xMin() + tw * (double)(x+1),
pex.yMin() + th * (double)(y+1) );
Geometry* geom = createCellGeometry( tex, level._lineWidth, pex, _map->isGeocentric() );
Feature* feature = new Feature();
feature->setGeometry( geom );
FeatureList features;
features.push_back( feature );
FilterContext cx;
cx.profile() = new FeatureProfile( tex );
cx.isGeocentric() = _map->isGeocentric();
if ( _map->isGeocentric() )
{
// We need to make sure that on a round globe, the points are sampled such that
// long segments follow the curvature of the earth.
ResampleFilter resample;
resample.maxLength() = tex.width() / 10.0;
cx = resample.push( features, cx );
}
TransformFilter xform( mapProfile->getSRS() );
xform.setMakeGeocentric( _map->isGeocentric() );
xform.setLocalizeCoordinates( true );
cx = xform.push( features, cx );
osg::ref_ptr<osg::Node> output;
BuildGeometryFilter bg;
bg.setStyle( _lineStyle );
cx = bg.push( features, cx );
output = bg.getNode();
if ( cx.isGeocentric() )
{
// get the geocentric control point:
double cplon, cplat, cpx, cpy, cpz;
tex.getCentroid( cplon, cplat );
tex.getSRS()->getEllipsoid()->convertLatLongHeightToXYZ(
osg::DegreesToRadians( cplat ), osg::DegreesToRadians( cplon ), 0.0, cpx, cpy, cpz );
osg::Vec3 controlPoint(cpx, cpy, cpz);
// get the horizon point:
tex.getSRS()->getEllipsoid()->convertLatLongHeightToXYZ(
osg::DegreesToRadians( tex.yMin() ), osg::DegreesToRadians( tex.xMin() ), 0.0,
cpx, cpy, cpz );
osg::Vec3 horizonPoint(cpx, cpy, cpz);
// the deviation is the dot product of the control vector and the vector from the
// control point to the horizon point.
osg::Vec3 controlPointNorm = controlPoint; controlPointNorm.normalize();
osg::Vec3 horizonVecNorm = horizonPoint - controlPoint; horizonVecNorm.normalize();
float deviation = controlPointNorm * horizonVecNorm;
// construct the culling callback using the deviation.
osg::ClusterCullingCallback* ccc = new osg::ClusterCullingCallback();
ccc->set( controlPoint, controlPointNorm, deviation, (controlPoint-horizonPoint).length() );
// need a new group, because never put a cluster culler on a matrixtransform (doesn't work)
osg::Group* me = new osg::Group();
me->setCullCallback( ccc );
me->addChild( output.get() );
output = me;
}
group->addChild( output.get() );
}
}
//.........这里部分代码省略.........
示例8: push
FilterContext push(FeatureList& input, FilterContext& context)
{
if (_featureSource.valid())
{
// Get any features that intersect this query.
FeatureList boundaries;
getFeatures(context.extent().get(), boundaries );
// The list of output features
FeatureList output;
if (boundaries.empty())
{
// No intersecting features. If contains is false, then just the output to the input.
if (contains() == false)
{
output = input;
}
}
else
{
// Transform the boundaries into the coordinate system of the features
for (FeatureList::iterator itr = boundaries.begin(); itr != boundaries.end(); ++itr)
{
itr->get()->transform( context.profile()->getSRS() );
}
for(FeatureList::const_iterator f = input.begin(); f != input.end(); ++f)
{
Feature* feature = f->get();
if ( feature && feature->getGeometry() )
{
osg::Vec2d c = feature->getGeometry()->getBounds().center2d();
if ( contains() == true )
{
// coarsest:
if (_featureSource->getFeatureProfile()->getExtent().contains(GeoPoint(feature->getSRS(), c.x(), c.y())))
{
for (FeatureList::iterator itr = boundaries.begin(); itr != boundaries.end(); ++itr)
{
Ring* ring = dynamic_cast< Ring*>(itr->get()->getGeometry());
if (ring && ring->contains2D(c.x(), c.y()))
{
output.push_back( feature );
}
}
}
}
else
{
bool contained = false;
// coarsest:
if (_featureSource->getFeatureProfile()->getExtent().contains(GeoPoint(feature->getSRS(), c.x(), c.y())))
{
for (FeatureList::iterator itr = boundaries.begin(); itr != boundaries.end(); ++itr)
{
Ring* ring = dynamic_cast< Ring*>(itr->get()->getGeometry());
if (ring && ring->contains2D(c.x(), c.y()))
{
contained = true;
break;
}
}
}
if ( !contained )
{
output.push_back( feature );
}
}
}
}
}
OE_INFO << LC << "Allowed " << output.size() << " out of " << input.size() << " features\n";
input = output;
}
return context;
}
示例9: createFeatureCursor
FeatureCursor* createFeatureCursor( const Symbology::Query& query )
{
FeatureCursor* result = 0L;
std::string url = createURL( query );
if (url.empty()) return 0;
// check the blacklist:
if ( Registry::instance()->isBlacklisted(url) )
return 0L;
OE_DEBUG << LC << url << std::endl;
URI uri(url);
// read the data:
ReadResult r = uri.readString( _dbOptions.get() );
const std::string& buffer = r.getString();
const Config& meta = r.metadata();
bool dataOK = false;
FeatureList features;
if ( !buffer.empty() )
{
// Get the mime-type from the metadata record if possible
std::string mimeType = r.metadata().value( IOMetadata::CONTENT_TYPE );
//If the mimetype is empty then try to set it from the format specification
if (mimeType.empty())
{
if (_options.format().value() == "json") mimeType = "json";
else if (_options.format().value().compare("gml") == 0) mimeType = "text/xml";
}
dataOK = getFeatures( buffer, mimeType, features );
}
if ( dataOK )
{
OE_DEBUG << LC << "Read " << features.size() << " features" << std::endl;
}
//If we have any filters, process them here before the cursor is created
if (!_options.filters().empty())
{
// preprocess the features using the filter list:
if ( features.size() > 0 )
{
FilterContext cx;
cx.profile() = getFeatureProfile();
for( FeatureFilterList::const_iterator i = _options.filters().begin(); i != _options.filters().end(); ++i )
{
FeatureFilter* filter = i->get();
cx = filter->push( features, cx );
}
}
}
//result = new FeatureListCursor(features);
result = dataOK ? new FeatureListCursor( features ) : 0L;
if ( !result )
Registry::instance()->blacklist( url );
return result;
}
示例10: 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;
//.........这里部分代码省略.........
示例11: gi
bool
SubstituteModelFilter::process(const FeatureList& features,
const MarkerSymbol* symbol,
Session* session,
osg::Group* attachPoint,
FilterContext& context )
{
bool makeECEF = context.getSession()->getMapInfo().isGeocentric();
for( FeatureList::const_iterator f = features.begin(); f != features.end(); ++f )
{
Feature* input = f->get();
GeometryIterator gi( input->getGeometry(), false );
while( gi.hasMore() )
{
Geometry* geom = gi.next();
for( unsigned i=0; i<geom->size(); ++i )
{
osg::Matrixd mat;
osg::Vec3d point = (*geom)[i];
if ( makeECEF )
{
// the "rotation" element lets us re-orient the instance to ensure it's pointing up. We
// could take a shortcut and just use the current extent's local2world matrix for this,
// but it the tile is big enough the up vectors won't be quite right.
osg::Matrixd rotation;
ECEF::transformAndGetRotationMatrix( context.profile()->getSRS(), point, point, rotation );
mat = rotation * _modelMatrix * osg::Matrixd::translate( point ) * _world2local;
}
else
{
mat = _modelMatrix * osg::Matrixd::translate( point ) * _world2local;
}
osg::MatrixTransform* xform = new osg::MatrixTransform();
xform->setMatrix( mat );
xform->setDataVariance( osg::Object::STATIC );
MarkerFactory factory( session);
osg::ref_ptr< osg::Node > model = factory.getOrCreateNode( input, symbol );
if (model.get())
{
xform->addChild( model.get() );
}
attachPoint->addChild( xform );
// name the feature if necessary
if ( !_featureNameExpr.empty() )
{
const std::string& name = input->eval( _featureNameExpr );
if ( !name.empty() )
xform->setName( name );
}
}
}
}
return true;
}
示例12: gi
FilterContext
ScatterFilter::push(FeatureList& features, const FilterContext& context )
{
if ( !isSupported() ) {
OE_WARN << LC << "support for this filter is not enabled" << std::endl;
return context;
}
// seed the random number generator so the randomness is the same each time
// todo: control this seeding based on the feature source name, perhaps?
::srand( _randomSeed );
for( FeatureList::iterator i = features.begin(); i != features.end(); ++i )
{
Feature* f = i->get();
Geometry* geom = f->getGeometry();
if ( !geom )
continue;
const SpatialReference* geomSRS = context.profile()->getSRS();
// first, undo the localization frame if there is one.
context.toWorld( geom );
// convert to geodetic if necessary, and compute the approximate area in sq km
if ( context.isGeocentric() )
{
GeometryIterator gi( geom );
while( gi.hasMore() )
geomSRS->getGeographicSRS()->transformFromECEF( gi.next(), true );
geomSRS = geomSRS->getGeographicSRS();
}
PointSet* points = new PointSet();
if ( geom->getComponentType() == Geometry::TYPE_POLYGON )
{
polyScatter( geom, geomSRS, context, points );
}
else if (
geom->getComponentType() == Geometry::TYPE_LINESTRING ||
geom->getComponentType() == Geometry::TYPE_RING )
{
lineScatter( geom, geomSRS, context, points );
}
else {
OE_WARN << LC << "Sorry, don't know how to scatter a PointSet yet" << std::endl;
}
// convert back to geocentric if necessary.
if ( context.isGeocentric() )
context.profile()->getSRS()->getGeographicSRS()->transformToECEF( points, true );
// re-apply the localization frame.
context.toLocal( points );
// replace the source geometry with the scattered points.
f->setGeometry( points );
}
return context;
}