Skip to content

Commit 23d0c4c

Browse files
committed
Merge branch 'master' of github.com:gwaldron/osgearth
2 parents 45a2ca9 + adaf439 commit 23d0c4c

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

src/osgEarthFeatures/BuildGeometryFilter.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ BuildGeometryFilter::tileAndBuildPolygon(Geometry* ring,
515515

516516
#define MAX_POINTS_PER_CROP_TILE 1024
517517

518+
bool built = false;
518519
unsigned count = ring->getTotalPointCount();
519520
if ( count > MAX_POINTS_PER_CROP_TILE )
520521
{
@@ -530,6 +531,7 @@ BuildGeometryFilter::tileAndBuildPolygon(Geometry* ring,
530531
osg::ref_ptr<Polygon> poly = new Polygon;
531532
poly->resize( 4 );
532533

534+
built = true;
533535
for(int x=0; x<(int)tx; ++x)
534536
{
535537
for(int y=0; y<(int)ty; ++y)
@@ -552,13 +554,30 @@ BuildGeometryFilter::tileAndBuildPolygon(Geometry* ring,
552554
}
553555
else
554556
{
555-
// This just means the crop resulted in empty geometry, which is legal.
556-
//OE_WARN << LC << "Crop failed; tile skipped!" << std::endl;
557+
// If crop resulted in empty geometry (valid case) ringTile will still be valid,
558+
// otherwise we need to process the entire polygon without tiling.
559+
if (!ringTile.valid())
560+
{
561+
//clean up geometry
562+
osgGeom->setVertexArray(0L);
563+
if (osgGeom->getNumPrimitiveSets())
564+
osgGeom->removePrimitiveSet(0, osgGeom->getNumPrimitiveSets());
565+
566+
OE_NOTICE << LC << "GEOS crop failed, tessellating feature without tiling." << std::endl;
567+
568+
built = false;
569+
break;
570+
}
557571
}
558572
}
573+
574+
// GEOS failed
575+
if (!built)
576+
break;
559577
}
560578
}
561-
else
579+
580+
if ( !built )
562581
{
563582
buildPolygon(ring, featureSRS, mapSRS, makeECEF, tessellate, osgGeom, world2local);
564583
}

src/osgEarthSymbology/Geometry.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ bool
230230
Geometry::crop( const Polygon* cropPoly, osg::ref_ptr<Geometry>& output ) const
231231
{
232232
#ifdef OSGEARTH_HAVE_GEOS
233+
bool success = false;
234+
output = 0L;
233235

234236
GEOSContext gc;
235237

@@ -256,20 +258,38 @@ Geometry::crop( const Polygon* cropPoly, osg::ref_ptr<Geometry>& output ) const
256258
if ( outGeom )
257259
{
258260
output = gc.exportGeometry( outGeom );
259-
gc.disposeGeometry( outGeom );
260261

261-
if ( output.valid() && !output->isValid() )
262+
if ( output.valid())
262263
{
263-
output = 0L;
264+
if ( output->isValid() )
265+
{
266+
success = true;
267+
}
268+
else
269+
{
270+
// GEOS result is invalid
271+
output = 0L;
272+
}
264273
}
274+
else
275+
{
276+
// set output to empty geometry to indicate the (valid) empty case,
277+
// still returning false but allows for check.
278+
if (outGeom->getNumPoints() == 0)
279+
{
280+
output = new osgEarth::Symbology::Geometry();
281+
}
282+
}
283+
284+
gc.disposeGeometry( outGeom );
265285
}
266286
}
267287

268288
//Destroy the geometry
269289
gc.disposeGeometry( cropGeom );
270290
gc.disposeGeometry( inGeom );
271291

272-
return output.valid();
292+
return success;
273293

274294
#else // OSGEARTH_HAVE_GEOS
275295

0 commit comments

Comments
 (0)