/** * Add the given line to the graph * * @param wrappedLine is MasonGeometry wrapping a JTS line * @note Some code copied from JTS PolygonizeGraph.addEdge() and hacked to fit */ private void addLineString(MasonGeometry wrappedLine) { LineString line = (LineString) wrappedLine.geometry; if (line.isEmpty()) { return; } Coordinate[] linePts = CoordinateArrays.removeRepeatedPoints(line.getCoordinates()); if (linePts.length < 2) { return; } Coordinate startPt = linePts[0]; Coordinate endPt = linePts[linePts.length - 1]; Node nStart = getNode(startPt); // nodes added as necessary side-effect Node nEnd = getNode(endPt); GeomPlanarGraphEdge edge = new GeomPlanarGraphEdge(line); GeomPlanarGraphDirectedEdge de0 = new GeomPlanarGraphDirectedEdge(nStart, nEnd, linePts[1], true); GeomPlanarGraphDirectedEdge de1 = new GeomPlanarGraphDirectedEdge(nEnd, nStart, linePts[linePts.length - 2], false); edge.setDirectedEdges(de0, de1); edge.setAttributes(wrappedLine.getAttributes()); add(edge); }
/** * Adds an Edge, DirectedEdges, and Nodes for the given LineString representation of an edge. * Snaps all vertices according to GraphParams.GLOBAL_SNAP_DIST * * @param lineString * @param id : the id coming out of OSM */ public void addLineString( LineString lineString, int id, short envType, short cykType, double groenM) { distancesCalculated = false; if (lineString.isEmpty()) { return; } if (lineString.getCoordinates().length < 2) { System.exit(1); } Coordinate[] coordinates = lineString.getCoordinates(); modifyEnvelope(coordinates); if (GraphParams.getInstance().getSnap()) { double sd = GraphParams.getInstance().getSnapDistance(); for (Coordinate c : coordinates) { c.x = c.x - (c.x % sd); c.y = c.y - (c.y % sd); } } Edge edge = getLineMergeGraphH4cked().addEdge(lineString); edgeId__edge.put(id, edge); if (edge != null) { // edge might not have been added because of coinciding coordinates if (lineString.getUserData() == null) lineString.setUserData(new HashMap<String, Object>(3)); @SuppressWarnings("unchecked") HashMap<String, Object> userdata = (HashMap<String, Object>) lineString.getUserData(); // HashMap<String, Object> hm = new HashMap<String, Object>(); userdata.put("id", id); userdata.put("et", envType); userdata.put("ct", cykType); userdata.put("gm", groenM); // groenM userdata.put("geom", lineString); edge.setData(userdata); // add edge data to the spatial index } }