Skip to content

Commit 7812fd3

Browse files
authored
Don't return null buffer polygon (#243)
1 parent 48b9cbb commit 7812fd3

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/main/java/com/esri/core/geometry/Bufferer.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ private Geometry bufferPolygon_() {
576576
generateCircleTemplate_();
577577
m_geometry = simplify.execute(m_geometry, null, false,
578578
m_progress_tracker);
579+
if(m_geometry.isEmpty()) {
580+
return m_geometry;
581+
}
579582

580583
if (m_distance < 0) {
581584
Polygon poly = (Polygon) (m_geometry);
@@ -600,7 +603,12 @@ private Geometry bufferPolygon_() {
600603
.getInstance().getOperator(Operator.Type.Union)).execute(
601604
cursor, m_spatialReference, m_progress_tracker);
602605
Geometry result = union_cursor.next();
603-
return result;
606+
if (result != null) {
607+
return result;
608+
} else {
609+
//never return empty.
610+
return new Polygon(m_geometry.getDescription());
611+
}
604612
}
605613
}
606614

src/test/java/com/esri/core/geometry/TestBuffer.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import junit.framework.TestCase;
2828
import org.junit.Test;
2929

30+
import com.esri.core.geometry.ogc.OGCGeometry;
31+
3032
public class TestBuffer extends TestCase {
3133
@Override
3234
protected void setUp() throws Exception {
@@ -389,4 +391,27 @@ public void testBufferPolygon() {
389391
assertTrue(simplify.isSimpleAsFeature(result, sr, null));
390392
}
391393
}
394+
395+
@Test
396+
public static void testTinyBufferOfPoint() {
397+
{
398+
Geometry result1 = OperatorBuffer.local().execute(new Point(0, 0), SpatialReference.create(4326), 1e-9, null);
399+
assertTrue(result1 != null);
400+
assertTrue(result1.isEmpty());
401+
Geometry geom1 = OperatorImportFromWkt.local().execute(0, Geometry.Type.Unknown, "POLYGON ((177.0 64.0, 177.0000000001 64.0, 177.0000000001 64.0000000001, 177.0 64.0000000001, 177.0 64.0))", null);
402+
Geometry result2 = OperatorBuffer.local().execute(geom1, SpatialReference.create(4326), 0.01, null);
403+
assertTrue(result2 != null);
404+
assertTrue(result2.isEmpty());
405+
406+
}
407+
408+
{
409+
OGCGeometry p = OGCGeometry.fromText(
410+
"POLYGON ((177.0 64.0, 177.0000000001 64.0, 177.0000000001 64.0000000001, 177.0 64.0000000001, 177.0 64.0))");
411+
OGCGeometry buffered = p.buffer(0.01);
412+
assertTrue(buffered != null);
413+
}
414+
415+
416+
}
392417
}

0 commit comments

Comments
 (0)