Java Code Examples for com.vividsolutions.jts.geom.LineString#getCoordinates()
The following examples show how to use
com.vividsolutions.jts.geom.LineString#getCoordinates() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VariableWidthBuffer.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * Computes a list of values for the points along a line by * interpolating between values for the start and end point. * The interpolation is * based on the distance of each point along the line * relative to the total line length. * * @param line the line to interpolate along * @param start the start value * @param end the end value * @return the array of interpolated values */ public static double[] interpolate(LineString line, double start, double end) { start = Math.abs(start); end = Math.abs(end); double[] widths = new double[line.getNumPoints()]; widths[0] = start; widths[widths.length - 1] = end; double totalLen = line.getLength(); Coordinate[] pts = line.getCoordinates(); double currLen = 0; for (int i = 1; i < widths.length; i++) { double segLen = pts[i].distance(pts[i - 1]); currLen += segLen; double lenFrac = currLen / totalLen; double delta = lenFrac * (end - start); widths[i] = start + delta; } return widths; }
Example 2
Source File: Distance3DOp.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
private void computeMinDistanceLineLine(LineString line0, LineString line1, boolean flip) { Coordinate[] coord0 = line0.getCoordinates(); Coordinate[] coord1 = line1.getCoordinates(); // brute force approach! for (int i = 0; i < coord0.length - 1; i++) { for (int j = 0; j < coord1.length - 1; j++) { double dist = CGAlgorithms3D.distanceSegmentSegment(coord0[i], coord0[i + 1], coord1[j], coord1[j + 1]); if (dist < minDistance) { minDistance = dist; // TODO: compute closest pts in 3D LineSegment seg0 = new LineSegment(coord0[i], coord0[i + 1]); LineSegment seg1 = new LineSegment(coord1[j], coord1[j + 1]); Coordinate[] closestPt = seg0.closestPoints(seg1); updateDistance(dist, new GeometryLocation(line0, i, closestPt[0]), new GeometryLocation(line1, j, closestPt[1]), flip ); } if (isDone) return; } } }
Example 3
Source File: Distance3DOp.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
private void computeMinDistanceLinePoint(LineString line,Point point, boolean flip) { Coordinate[] lineCoord = line.getCoordinates(); Coordinate coord = point.getCoordinate(); // brute force approach! for (int i = 0; i < lineCoord.length - 1; i++) { double dist = CGAlgorithms3D.distancePointSegment(coord, lineCoord[i], lineCoord[i + 1]); if (dist < minDistance) { LineSegment seg = new LineSegment(lineCoord[i], lineCoord[i + 1]); Coordinate segClosestPoint = seg.closestPoint(coord); updateDistance(dist, new GeometryLocation(line, i, segClosestPoint), new GeometryLocation(point, 0, coord), flip); } if (isDone) return; } }
Example 4
Source File: GeometrySmoother.java From coordination_oru with GNU General Public License v3.0 | 5 votes |
/** * Creates a new {@code LineString} which is a smoothed version of * the input {@code LineString}. * * @param ls the input {@code LineString} * * @param alpha a value between 0 and 1 (inclusive) specifying the tightness * of fit of the smoothed boundary (0 is loose) * * @return the smoothed {@code LineString} */ LineString smooth(LineString ls, double alpha) { Coordinate[] coords = ls.getCoordinates(); Coordinate[][] controlPoints = getLineControlPoints(coords, alpha); final int N = coords.length; List<Coordinate> smoothCoords = new ArrayList<Coordinate>(); double dist; for (int i = 0; i < N - 1; i++) { dist = coords[i].distance(coords[i+1]); if (dist < control.getMinLength()) { // segment too short - just copy input coordinate smoothCoords.add(new Coordinate(coords[i])); } else { int smoothN = control.getNumVertices(dist); Coordinate[] segment = cubicBezier( coords[i], coords[i+1], controlPoints[i][1], controlPoints[i+1][0], smoothN); int copyN = i < N - 1 ? segment.length - 1 : segment.length; for (int k = 0; k < copyN; k++) { smoothCoords.add(segment[k]); } } } smoothCoords.add(coords[N - 1]); return geomFactory.createLineString(smoothCoords.toArray(new Coordinate[0])); }
Example 5
Source File: GeoWaveIndexerSfTest.java From rya with Apache License 2.0 | 5 votes |
/** * convert a lineString geometry to GML * @param line * @return String that is XML that is a GMLLiteral of line */ private static String geoToGml(final LineString line) { final StringBuilder coordString = new StringBuilder() ; for (final Coordinate coor : line.getCoordinates()) { coordString.append(" ").append(coor.x).append(" ").append(coor.y); //ESPG:4326 lat/long } return " <gml:LineString srsName=\"http://www.opengis.net/def/crs/EPSG/0/4326\" xmlns:gml='http://www.opengis.net/gml'>\n" + "<gml:posList srsDimension=\"2\">"// + coordString // + "</gml:posList></gml:LineString >"; }
Example 6
Source File: GeoIndexerSfTest.java From rya with Apache License 2.0 | 5 votes |
/** * convert a lineString geometry to GML * @param line * @return String that is XML that is a GMLLiteral of line */ private static String geoToGml(final LineString line) { final StringBuilder coordString = new StringBuilder() ; for (final Coordinate coor : line.getCoordinates()) { coordString.append(" ").append(coor.x).append(" ").append(coor.y); //ESPG:4326 lat/long } return " <gml:LineString srsName=\"http://www.opengis.net/def/crs/EPSG/0/4326\" xmlns:gml='http://www.opengis.net/gml'>\n" + "<gml:posList srsDimension=\"2\">"// + coordString // + "</gml:posList></gml:LineString >"; }
Example 7
Source File: DataSourcePolylineOverlay.java From geoar-app with Apache License 2.0 | 5 votes |
protected void createPath(final Path path, final Point drawPosition, final LineString lineString) { path.reset(); boolean start = true; for (Coordinate coordinate : lineString.getCoordinates()) { if (start) { path.moveTo((float) coordinate.x - drawPosition.x, (float) coordinate.y - drawPosition.y); start = false; } else { path.lineTo((float) coordinate.x - drawPosition.x, (float) coordinate.y - drawPosition.y); } } }
Example 8
Source File: BufferFunctions.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private static Geometry buildBufferLineSimplifiedSet(Geometry g, double distance) { List simpLines = new ArrayList(); List lines = new ArrayList(); LinearComponentExtracter.getLines(g, lines); for (Iterator i = lines.iterator(); i.hasNext(); ) { LineString line = (LineString) i.next(); Coordinate[] pts = line.getCoordinates(); simpLines.add(g.getFactory().createLineString(BufferInputLineSimplifier.simplify(pts, distance))); } Geometry simpGeom = g.getFactory().buildGeometry(simpLines); return simpGeom; }
Example 9
Source File: SegmentStringUtil.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
/** * Extracts all linear components from a given {@link Geometry} * to {@link SegmentString}s. * The SegmentString data item is set to be the source Geometry. * * @param geom the geometry to extract from * @return a List of SegmentStrings */ public static List extractNodedSegmentStrings(Geometry geom) { List segStr = new ArrayList(); List lines = LinearComponentExtracter.getLines(geom); for (Iterator i = lines.iterator(); i.hasNext(); ) { LineString line = (LineString) i.next(); Coordinate[] pts = line.getCoordinates(); segStr.add(new NodedSegmentString(pts, geom)); } return segStr; }