/** * Returns the length of the geometry in meters. * * @param geometry * @return */ private double getGeometryLengthMeters(Geometry geometry) { Coordinate[] coordinates = geometry.getCoordinates(); double d = 0; for (int i = 1; i < coordinates.length; ++i) { d += SphericalDistanceLibrary.distance(coordinates[i - 1], coordinates[i]); } return d; }
@Override public void serialize(Geometry arg, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { if (arg == null) { jgen.writeNull(); } Coordinate[] lineCoords = arg.getCoordinates(); List<Coordinate> coords = Arrays.asList(lineCoords); jgen.writeObject(PolylineEncoder.createEncodings(coords).getPoints()); }
@JsonSerialize(using = EncodedPolylineJSONSerializer.class) @XmlJavaTypeAdapter(LineStringAdapter.class) public LineString getGeometry() { if (geometry == null) { List<Coordinate> coords = new ArrayList<Coordinate>(); for (RouteSegment segment : exemplarSegments) { if (segment.hopOut != null) { Geometry segGeometry = segment.getGeometry(); coords.addAll(Arrays.asList(segGeometry.getCoordinates())); } } Coordinate[] coordArray = new Coordinate[coords.size()]; geometry = GeometryUtils.getGeometryFactory().createLineString( coords.toArray(coordArray)); } return geometry; }
private Geometry removeDuplicatePoints(Geometry routeGeometry) { List<Coordinate> coords = new ArrayList<Coordinate>(); Coordinate last = null; for (Coordinate c : routeGeometry.getCoordinates()) { if (!c.equals(last)) { last = c; coords.add(c); } } if (coords.size() < 2) { return null; } Coordinate[] coordArray = new Coordinate[coords.size()]; return routeGeometry.getFactory().createLineString(coords.toArray(coordArray)); }
/** * @param index The index of the segment in the list * @return The partial geometry between this segment's stop and the next one. */ public LineString getGeometrySegment(int index) { RouteSegment segment = exemplarSegments.get(index); if (segment.hopOut != null) { return GeometryUtils.getGeometryFactory().createLineString( segment.getGeometry().getCoordinates()); } return null; }
final Coordinate[] geomCoords = geom.getCoordinates(); if(geomCoords.length <= 0) { Collections.emptyList();
private boolean isValid(Geometry geometry, Stop s0, Stop s1) { Coordinate[] coordinates = geometry.getCoordinates(); if (coordinates.length < 2) { return false; } if (geometry.getLength() == 0) { return false; } for (Coordinate coordinate : coordinates) { if (Double.isNaN(coordinate.x) || Double.isNaN(coordinate.y)) { return false; } } Coordinate geometryStartCoord = coordinates[0]; Coordinate geometryEndCoord = coordinates[coordinates.length - 1]; Coordinate startCoord = new Coordinate(s0.getLon(), s0.getLat()); Coordinate endCoord = new Coordinate(s1.getLon(), s1.getLat()); if (SphericalDistanceLibrary.fastDistance(startCoord, geometryStartCoord) > maxStopToShapeSnapDistance) { return false; } else if (SphericalDistanceLibrary.fastDistance(endCoord, geometryEndCoord) > maxStopToShapeSnapDistance) { return false; } return true; }
Coordinate[] coords = g.getCoordinates();
final int minLineToLen) { final Coordinate[] geomCoords = geom.getCoordinates();
continue; for (Coordinate c : g.getCoordinates()) { if (Double.isNaN(c.x) || Double.isNaN(c.y)) { LOG.warn(graph.addBuilderAnnotation(new BogusEdgeGeometry(e))); Coordinate edgeStartCoord = e.getFromVertex().getCoordinate(); Coordinate edgeEndCoord = e.getToVertex().getCoordinate(); Coordinate[] geometryCoordinates = g.getCoordinates(); if (geometryCoordinates.length < 2) { LOG.warn(graph.addBuilderAnnotation(new BogusEdgeGeometry(e)));
Geometry geometry = s1.getBackEdge().getGeometry(); if (geometry != null) { List<Coordinate> coordinates = new ArrayList<Coordinate>(Arrays.asList(geometry.getCoordinates())); for (int i = 0; i < coordinates.size(); ++i) { Coordinate coordinate = new Coordinate(coordinates.get(i));
OffsetCurveBuilder offsetBuilder = new OffsetCurveBuilder(new PrecisionModel(), bufParams); Coordinate[] coords = offsetBuilder.getOffsetCurve(midLineGeom.getCoordinates(), lineWidth * 0.4); if (coords.length < 2)
coords = circleShape.getCoordinates();
public Coordinate[] extractTargetCoordinates(Geometry g) { // TODO: should do this more efficiently. Use CoordSeq filter to get points, KDTree for uniqueness & queries Set ptSet = new TreeSet(); Coordinate[] pts = g.getCoordinates(); for (int i = 0; i < pts.length; i++) { ptSet.add(pts[i]); } return (Coordinate[]) ptSet.toArray(new Coordinate[0]); }
/** * Splits the input geometry into two LineStrings at a fraction of the distance covered. */ public static P2<LineString> splitGeometryAtFraction(Geometry geometry, double fraction) { LineString empty = new LineString(null, gf); Coordinate[] coordinates = geometry.getCoordinates(); CoordinateSequence sequence = gf.getCoordinateSequenceFactory().create(coordinates); LineString total = new LineString(sequence, gf); if (coordinates.length < 2) return new P2<LineString>(empty, empty); if (fraction <= 0) return new P2<LineString>(empty, total); if (fraction >= 1) return new P2<LineString>(total, empty); double totalDistance = total.getLength(); double requestedDistance = totalDistance * fraction; // An index in JTS can actually refer to any point along the line. It is NOT an array index. LocationIndexedLine line = new LocationIndexedLine(geometry); LinearLocation l = LengthLocationMap.getLocation(geometry, requestedDistance); LineString beginning = (LineString) line.extractLine(line.getStartIndex(), l); LineString ending = (LineString) line.extractLine(l, line.getEndIndex()); return new P2<LineString>(beginning, ending); }
private void createVertices(Geometry geom) { Coordinate[] coords = geom.getCoordinates(); for (int i = 0; i < coords.length; i++) { Vertex v = new ConstraintVertex(coords[i]); constraintVertexMap.put(coords[i], v); } }
public void loadSourceGeometries(Collection geoms) { for (Iterator i = geoms.iterator(); i.hasNext(); ) { Geometry geom = (Geometry) i.next(); loadVertices(geom.getCoordinates(), geom.getUserData()); } }
/** * Extracts the unique {@link Coordinate}s from the given {@link Geometry}. * @param geom the geometry to extract from * @return a List of the unique Coordinates */ public static CoordinateList extractUniqueCoordinates(Geometry geom) { if (geom == null) return new CoordinateList(); Coordinate[] coords = geom.getCoordinates(); return unique(coords); }
public final Geometry edit(Geometry geometry, GeometryFactory factory) { if (geometry instanceof LinearRing) { return factory.createLinearRing(edit(geometry.getCoordinates(), geometry)); } if (geometry instanceof LineString) { return factory.createLineString(edit(geometry.getCoordinates(), geometry)); } if (geometry instanceof Point) { Coordinate[] newCoordinates = edit(geometry.getCoordinates(), geometry); return factory.createPoint((newCoordinates.length > 0) ? newCoordinates[0] : null); } return geometry; }
public void loadSourceGeometries(Geometry geomColl) { for (int i = 0; i < geomColl.getNumGeometries(); i++) { Geometry geom = geomColl.getGeometryN(i); loadVertices(geom.getCoordinates(), geom.getUserData()); } }