/** * 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); }
/** * Creates a LineString using the given CoordinateSequence; a null or empty CoordinateSequence will * create an empty LineString. Consecutive points must not be equal. * @param coordinates a CoordinateSequence possibly empty, or null */ public LineString createLineString(CoordinateSequence coordinates) { return new LineString(coordinates, this); }
/** * Creates a LineString using the given CoordinateSequence. * A null or empty CoordinateSequence creates an empty LineString. * * @param coordinates a CoordinateSequence (possibly empty), or null */ public LineString createLineString(CoordinateSequence coordinates) { return new LineString(coordinates, this); }
@Override public LineString convert(final PolyLine polyLine) { return new LineString(COORDINATE_ARRAY_CONVERTER.convert(polyLine), FACTORY); } }
public static LineString buildLineString(final Coordinate[] coordinates) { final CoordinateArraySequence sequence = new CoordinateArraySequence(coordinates); return new LineString(sequence, GEOMETRY_FACTORY); }
public static LineString createLineString(Coordinate[] aCoordinates) { CoordinateSequence cSeq = csFactory.create(aCoordinates); return new LineString(cSeq, gFactory); }
public static LineString addPoint2LineString(LineString aPoly, Point point2Add) { Coordinate[] oldCoordinates = aPoly.getCoordinates(); Coordinate[] newCoordinates = new Coordinate[oldCoordinates.length + 1]; System.arraycopy(oldCoordinates, 0, newCoordinates, 0, oldCoordinates.length); newCoordinates[newCoordinates.length - 1] = point2Add.getCoordinate(); CoordinateSequence cSeq = csFactory.create(newCoordinates); return new LineString(cSeq, gFactory); }
public static LineString createLineString(Point begPoint, Point endPoint) { Coordinate[] coordinates = new Coordinate[2]; coordinates[0] = new Coordinate(begPoint.getX(), begPoint.getY()); coordinates[1] = new Coordinate(endPoint.getX(), endPoint.getY()); CoordinateSequence cSeq = csFactory.create(coordinates); return new LineString(cSeq, gFactory); }
private Geometry buildGeometry() { Coordinate[] coordinates = new Coordinate[locations.size()]; for (int i = 0; i < locations.size(); i++) { coordinates[i] = new Coordinate( locations.get(i).getLongitude(), locations.get(i).getLatitude()); } GeometryFactory factory = SPATIAL_CONTEXT.getGeometryFactory(); CoordinateSequence sequence = factory.getCoordinateSequenceFactory().create(coordinates); switch (getShapeType()) { case POINT: return new Point(sequence, factory); case LINESTRING: return new LineString(sequence, factory); case POLYGON: LinearRing shell = new LinearRing(sequence, factory); return new Polygon(shell, null, factory); default: throw new IllegalStateException("Unrecognized geometry"); } }
/** * Checks to see if the literal is a geometry, and encodes it if it is, if * not just sends to the parent class. * * @param expression * the expression to visit and encode. * * @throws IOException * for IO exception (need a better error) */ public void visitLiteralGeometry(LiteralExpression expression) throws IOException { Geometry bbox = (Geometry) expression.evaluate( null, Geometry.class ); String geomText = null; if ( bbox instanceof LinearRing ) { //postgis does not handle linear rings, convert to just a line string LineString lineString = new LineString( ((LinearRing)bbox).getCoordinateSequence(), bbox.getFactory() ); geomText = wkt.write( lineString ); } else { geomText = wkt.write(bbox); } out.write("GeometryFromText('" + geomText + "', " + srid + ")"); }
LineString line = new LineString(subList( gf.getCoordinateSequenceFactory(), coords, GTYPE, elemInfo, triplet), gf);
@ProcessMethod @OutputParameter( // id = "bboxPoint", // title = "Point to calculate BBox", // description = "Point to calculate BBox") public Geometry bboxPolygon(@InputParameter( // id = "echo", // title = "input point in JS form", // description = "Description of the input point in JS form") Point input) { //create a 1000x1000 bounding box around the point Coordinate[] coordinates = new Coordinate[] { new Coordinate(input.getX() - 500, input.getY() - 500, 0), new Coordinate(input.getX() + 500, input.getY() + 500, 0) }; CoordinateSequence coordinateSequence = new CoordinateArraySequence(coordinates); LineString boxLineString = new LineString(coordinateSequence, input.getFactory()); return boxLineString.getEnvelope(); }