Skip to content

Commit

Permalink
EMPTY points in JTS are now convertible to a Shape instead of throwin…
Browse files Browse the repository at this point in the history
…g an exception.

Fixes #163
  • Loading branch information
dsmiley committed Mar 12, 2020
1 parent d97b565 commit 5d8bac2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
7 changes: 4 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
## VERSION 0.8

DATE: March 8 2020
DATE: unreleased

* \#177: Improve conversion of a Circle to Shape. JtsShapeFactory allows converting from a Shape
object to a JTS Geometry object. Geodetic circles now translate to a polygon that has points
equidistant from the center. Before the change, there was potentially a large inaccuracy.
(Hrishi Bakshi)

---------------------------------------

* \#163: EMPTY points in JTS are now convertible to a Spatial4j Shape instead of throwing an exception.
(David Smiley)

## VERSION 0.7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,11 @@ public Shape makeShapeFromGeometry(Geometry geom) {
}
} else if (geom instanceof org.locationtech.jts.geom.Point) {
org.locationtech.jts.geom.Point pt = (org.locationtech.jts.geom.Point) geom;
return pointXY(pt.getX(), pt.getY());
if (pt.isEmpty()) {
return pointXY(Double.NaN, Double.NaN);
} else {
return pointXY(pt.getX(), pt.getY());
}
} else if (geom instanceof LineString) {
if (!useJtsLineString()) {
LineString lineString = (LineString) geom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
package org.locationtech.spatial4j.shape.jts;

import org.junit.Assert;
import org.junit.Test;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.junit.Test;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.Polygon;
import org.locationtech.spatial4j.context.SpatialContext;
import org.locationtech.spatial4j.context.jts.JtsSpatialContext;
import org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory;
import org.locationtech.spatial4j.distance.DistanceUtils;
import org.locationtech.spatial4j.distance.GeodesicSphereDistCalc;
import org.locationtech.spatial4j.shape.Point;
import org.locationtech.spatial4j.shape.Shape;
import org.locationtech.spatial4j.shape.impl.GeoCircle;
import org.locationtech.spatial4j.shape.impl.PointImpl;

Expand All @@ -52,6 +54,16 @@ public void testIndex() {
assertTrue(jtsGeom2.isIndexed());
}

@Test
public void testEmptyPoint() {
JtsSpatialContextFactory jtsCtxFactory = new JtsSpatialContextFactory();
JtsSpatialContext jtsCtx = jtsCtxFactory.newSpatialContext();
GeometryFactory geometryFactory = jtsCtxFactory.getGeometryFactory();
final org.locationtech.jts.geom.Point point = geometryFactory.createPoint();//empty
final Shape shape = jtsCtx.getShapeFactory().makeShapeFromGeometry(point); // don't throw
assertTrue(shape.isEmpty());
}

@Test
public void testCircleGeometryConversions() {
// Hawaii (Far West)
Expand Down

0 comments on commit 5d8bac2

Please sign in to comment.