Skip to content

Commit

Permalink
Push missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Mar 8, 2024
1 parent 166fd55 commit 0e49ae0
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 74 deletions.
18 changes: 8 additions & 10 deletions src/osgEarth/AttributesFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,26 @@ AttributesFilter::push(FeatureList& input, FilterContext& context)
return context;
}

FeatureList output;
output.reserve(input.size());

bool ok = true;
for (FeatureList::iterator i = input.begin(); i != input.end(); )
for(auto& feature : input)
{
bool passed = false;
if (i->valid())
if (feature.valid())
{
for (auto& a : _attributes)
{
if (i->get()->hasAttr(a))
if (feature->hasAttr(a))
{
++i;
passed = true;
output.emplace_back(feature);
break;
}
}
}

if (!passed)
{
i = input.erase(i);
}
}
output.swap(input);

return context;
}
19 changes: 11 additions & 8 deletions src/osgEarth/BufferFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ BufferFilter::push( FeatureList& input, FilterContext& context )
return context;
}

FeatureList output;
output.reserve(input.size());

//OE_NOTICE << "Buffer: input = " << input.size() << " features" << std::endl;
for( FeatureList::iterator i = input.begin(); i != input.end(); )
for(auto& feature : input)
{
Feature* feature = i->get();
if ( !feature || !feature->getGeometry() )
if ( !feature.valid() || !feature->getGeometry() )
continue;

osg::ref_ptr<Geometry> output;
osg::ref_ptr<Geometry> geom;

BufferParameters params;

Expand All @@ -104,17 +106,18 @@ BufferFilter::push( FeatureList& input, FilterContext& context )

params._cornerSegs = _numQuadSegs;

if ( feature->getGeometry()->buffer( _distance.value(), output, params ) )
if (feature->getGeometry()->buffer(_distance.value(), geom, params))
{
feature->setGeometry( output.get() );
++i;
feature->setGeometry(geom.get());
output.emplace_back(feature);
}
else
{
i = input.erase( i );
OE_DEBUG << LC << "feature " << feature->getFID() << " yielded no geometry" << std::endl;
}
}

output.swap(input);

return context;
}
115 changes: 60 additions & 55 deletions src/osgEarth/CropFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,33 @@ CropFilter::push( FeatureList& input, FilterContext& context )

if ( _method == METHOD_CENTROID )
{
for( FeatureList::iterator i = input.begin(); i != input.end(); )
for(auto& feature : input)
{
bool keepFeature = false;

Feature* feature = i->get();
Geometry* featureGeom = feature->getGeometry();

if ( featureGeom && featureGeom->isValid() )
if (feature.valid())
{
Bounds bounds = featureGeom->getBounds();
if ( bounds.valid() )
bool keepFeature = false;
Geometry* featureGeom = feature->getGeometry();

if (featureGeom && featureGeom->isValid())
{
osg::Vec3d centroid = bounds.center();
if ( extent.contains( centroid.x(), centroid.y() ) )
Bounds bounds = featureGeom->getBounds();
if (bounds.valid())
{
keepFeature = true;
newExtent.expandToInclude( bounds.xMin(), bounds.yMin() );
newExtent.expandToInclude( bounds.xMax(), bounds.yMax() );
osg::Vec3d centroid = bounds.center();
if (extent.contains(centroid.x(), centroid.y()))
{
keepFeature = true;
newExtent.expandToInclude(bounds.xMin(), bounds.yMin());
newExtent.expandToInclude(bounds.xMax(), bounds.yMax());
}
}
}
}

if ( keepFeature )
++i;
else
i = input.erase( i );
if (!keepFeature)
{
feature = nullptr;
}
}
}
}

Expand All @@ -78,60 +79,64 @@ CropFilter::push( FeatureList& input, FilterContext& context )

// create the intersection polygon:
osg::ref_ptr<Polygon> poly;
FeatureList output;
output.reserve(input.size());

for( FeatureList::iterator i = input.begin(); i != input.end(); )
for(auto& feature : input)
{
bool keepFeature = false;

Feature* feature = i->get();

Geometry* featureGeom = feature->getGeometry();
if ( featureGeom && featureGeom->isValid() )
if (feature.valid())
{
// test for trivial acceptance:
GeoExtent featureExtent = feature->getExtent();
if (featureExtent.isInvalid())
Geometry* featureGeom = feature->getGeometry();
if (featureGeom && featureGeom->isValid())
{
//nop
}

else if ( extent.contains(featureExtent) )
{
keepFeature = true;
newExtent.expandToInclude(featureExtent);
}
// test for trivial acceptance:
GeoExtent featureExtent = feature->getExtent();
if (featureExtent.isInvalid())
{
//nop
}

// then move on to the cropping operation:
else
{
if ( !poly.valid() )
else if (extent.contains(featureExtent))
{
poly = new Polygon();
poly->push_back( osg::Vec3d( extent.xMin(), extent.yMin(), 0 ));
poly->push_back( osg::Vec3d( extent.xMax(), extent.yMin(), 0 ));
poly->push_back( osg::Vec3d( extent.xMax(), extent.yMax(), 0 ));
poly->push_back( osg::Vec3d( extent.xMin(), extent.yMax(), 0 ));
keepFeature = true;
newExtent.expandToInclude(featureExtent);
}

osg::ref_ptr<Geometry> croppedGeometry;
if ( featureGeom->crop( poly.get(), croppedGeometry ) )
// then move on to the cropping operation:
else
{
if ( croppedGeometry->isValid() )
if (!poly.valid())
{
feature->setGeometry( croppedGeometry.get() );
keepFeature = true;
newExtent.expandToInclude(GeoExtent(newExtent.getSRS(), croppedGeometry->getBounds()));
poly = new Polygon();
poly->push_back(osg::Vec3d(extent.xMin(), extent.yMin(), 0));
poly->push_back(osg::Vec3d(extent.xMax(), extent.yMin(), 0));
poly->push_back(osg::Vec3d(extent.xMax(), extent.yMax(), 0));
poly->push_back(osg::Vec3d(extent.xMin(), extent.yMax(), 0));
}

osg::ref_ptr<Geometry> croppedGeometry;
if (featureGeom->crop(poly.get(), croppedGeometry))
{
if (croppedGeometry->isValid())
{
feature->setGeometry(croppedGeometry.get());
keepFeature = true;
newExtent.expandToInclude(GeoExtent(newExtent.getSRS(), croppedGeometry->getBounds()));
}
}
}
}
}

if ( keepFeature )
++i;
else
i = input.erase( i );
if (keepFeature)
{
output.emplace_back(feature);
}
}

output.swap(input);

#else // OSGEARTH_HAVE_GEOS

OE_WARN << "CropFilter - METHOD_CROPPING not available - please compile osgEarth with GEOS" << std::endl;
Expand Down
4 changes: 3 additions & 1 deletion src/osgEarthDrivers/script_engine_duktape/DuktapeEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,14 @@ namespace
const AttributeTable& attrs = feature->getAttrs();
for(AttributeTable::const_iterator a = attrs.begin(); a != attrs.end(); ++a)
{
AttributeType type = a->second.first;
AttributeType type = a->second.type;
switch(type) {
case ATTRTYPE_DOUBLE: duk_push_number (ctx, a->second.getDouble()); break; // [global] [feature] [properties] [name]
case ATTRTYPE_INT: duk_push_number(ctx, (double)a->second.getInt()); break; // [global] [feature] [properties] [name]
case ATTRTYPE_BOOL: duk_push_boolean(ctx, a->second.getBool()?1:0); break; // [global] [feature] [properties] [name]
#if 0
case ATTRTYPE_DOUBLEARRAY: break;
#endif
case ATTRTYPE_STRING:
default: duk_push_string (ctx, a->second.getString().c_str()); break; // [global] [feature] [properties] [name]
}
Expand Down

0 comments on commit 0e49ae0

Please sign in to comment.