Permalink
Browse files

fixed issue #21

  • Loading branch information...
1 parent 95c9a15 commit dc033590d71f4e5f083935121fab0c309a66dd01 @svzdvd svzdvd committed Oct 17, 2011
@@ -71,8 +71,11 @@ public LayerIndexReader getIndex() {
* Add the geometry encoded in the given Node. This causes the geometry to appear in the index.
*/
public SpatialDatabaseRecord add(Node geomNode) {
- Geometry geometry = getGeometryEncoder().decodeGeometry(geomNode);
-
+ Geometry geometry = getGeometryEncoder().decodeGeometry(geomNode);
+
+ // add BBOX to Node if it's missing
+ getGeometryEncoder().encodeGeometry(geometry, geomNode);
+
index.add(geomNode);
return new SpatialDatabaseRecord(this, geomNode, geometry);
}
@@ -31,6 +31,9 @@
import org.neo4j.collections.rtree.Envelope;
import org.neo4j.gis.spatial.pipes.GeoPipeFlow;
import org.neo4j.gis.spatial.pipes.GeoPipeline;
+import org.neo4j.graphdb.GraphDatabaseService;
+import org.neo4j.graphdb.Node;
+import org.neo4j.graphdb.Transaction;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.CoordinateList;
@@ -93,6 +96,31 @@ public void testNeoTextLayer() {
checkPointOrder(results);
}
+ @Test
+ public void testIndexingExistingPointNodes() {
+ GraphDatabaseService db = graphDb();
+ SpatialDatabaseService sdb = new SpatialDatabaseService(db);
+ SimplePointLayer layer = sdb.createSimplePointLayer("my-points", "x", "y");
+
+ Coordinate[] coords = makeCoordinateDataFromTextFile("NEO4J-SPATIAL.txt");
+ for (Coordinate coordinate : coords) {
+ Transaction tx = db.beginTx();
+ try {
+ Node n = db.createNode();
+ n.setProperty("x", coordinate.x);
+ n.setProperty("y", coordinate.y);
+
+ layer.add(n);
+
+ tx.success();
+ } finally {
+ tx.finish();
+ }
+ }
+
+ assertEquals(coords.length, layer.getIndex().count());
+ }
+
private void checkPointOrder(List<GeoPipeFlow> results) {
for (int i = 0; i < results.size() - 1; i++) {
GeoPipeFlow first = results.get(i);

0 comments on commit dc03359

Please sign in to comment.