spatial
spatial copied to clipboard
unable to see nodes created layer.add()
Hello,
Why is that when we add nodes using the layer.add(layer.getGeometryFactory...) method, it doesn't create the actual nodes in the layer? If we add a node using the following:
Node temp = graph.createNode(Road.Label1),
Below is my code,, I;m adding these linestrings in my layer, and I want to see them as nodes in the Neo4j browser but they are not coming.
public static void ReadAndCreateNodes_Road() throws JsonParseException, JsonMappingException, IOException {
File storeDir = new File("20170508_line");
GraphDatabaseService graph = new GraphDatabaseFactory().newEmbeddedDatabase(storeDir);
SpatialDatabaseService db = new SpatialDatabaseService(graph);
EditableLayer layer = db.getOrCreateEditableLayer("line");
// read geojson
File fin = new File(
"sample_roads.geojson");
FileInputStream fis = new FileInputStream(fin);
// Construct BufferedReader from InputStreamReader
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String line = null;
int counter = 0;
while ((line = br.readLine()) != null) {
System.out.println(counter++);
GeoJsonObject object = new ObjectMapper().readValue(line, GeoJsonObject.class);
if (object instanceof Feature) {
LineString geometry = (LineString) ((Feature) object).getGeometry();
List<LngLatAlt> x = geometry.getCoordinates();
try (Transaction tx = graph.beginTx()) {
CoordinateList coordinates = new CoordinateList();
for(int i=0;i<x.size();i++) {
coordinates.add( new Coordinate( x.get(i).getLatitude(), x.get(i).getLongitude() ), false );
}
SpatialDatabaseRecord record = layer.add(layer.getGeometryFactory().createLineString(coordinates.toCoordinateArray()));
tx.success();
}
}
}
br.close();
}
What could have gone wrong? Thank you.