/** * Cast to a {@link LiteCoordinateSequence} * * <p>This method first checks if <tt>cs</tt> is an instanceof {@link LiteCoordinateSequence}, * if it is, itself is returned. If not, <tt>cs</tt> is cloned into a new {@link * LiteCoordinateSequence} * * <p>If cs is null, null is returned. * * @param cs The source {@link CoordinateSequence}. Can be null. * @return A LiteCoordinateSequence, or null if <tt>cs</tt> was null. */ public static LiteCoordinateSequence lite(CoordinateSequence cs) { if (cs instanceof LiteCoordinateSequence) { return (LiteCoordinateSequence) cs; } else if (cs == null) { return null; } else { return new LiteCoordinateSequence(cs.toCoordinateArray()); } } }
public CoordinateSequence create(CoordinateSequence coordSeq) { /** * If copying a LiteCoordinateSequence, use the copy constructor to preserve dimensionality * information. */ if (coordSeq instanceof LiteCoordinateSequence) return new LiteCoordinateSequence((LiteCoordinateSequence) coordSeq); return new LiteCoordinateSequence(coordSeq.toCoordinateArray()); }
static void encodeCoords(Element e, CoordinateSequence coords, PrintHandler output) throws IOException { if ((coords == null) || (coords.size() == 0)) { return; } encodeCoords(e, coords.toCoordinateArray(), output); }
/** * Ensure Ring of Coordinates are in a counter Orientationwise order. * * <p>If the Coordinate need to be reversed a copy will be returned. * * @param factory Factory to used to reverse CoordinateSequence * @param ring Ring of Coordinates * @return coords in a CCW order */ public static CoordinateSequence counterClockWise( CoordinateSequenceFactory factory, CoordinateSequence ring) { if (Orientation.isCCW(ring.toCoordinateArray())) { return ring; } return Coordinates.reverse(factory, ring); }
/** * Ensure Ring of Coordinates are in a Orientationwise order. * * <p>If the Coordinate need to be reversed a copy will be returned. * * @param factory Factory used to reverse CoordinateSequence * @param ring Ring of Coordinates * @return coords in a CW order */ private static CoordinateSequence clockWise( CoordinateSequenceFactory factory, CoordinateSequence ring) { if (!Orientation.isCCW(ring.toCoordinateArray())) { return ring; } return Coordinates.reverse(factory, ring); }
@Override public void filter(CoordinateSequence seq, int i) { // we do all the collecting when called for the first ordinate if (i > 0) { return; } // collects only points with a Z if (hasElevations(seq)) { Coordinate[] coords = seq.toCoordinateArray(); for (int j = 0; j < coords.length; j++) { Coordinate c = coords[j]; // avoid adding the last element of a ring to avoid // un-balancing the // weights (the fist/last coordinate would be counted twice) if ((j < coords.length - 1 || !c.equals(coords[0])) && !Double.isNaN(c.z)) { results.add(new PointDistance(c)); } } } } });
/** Helper method that converts an array of coordinates to an array of ordinates. */ private List<Double> getOrdinates(CoordinateSequence coordinateSequence) { List<Double> ordinates = new ArrayList<>(); for (Coordinate coordinate : coordinateSequence.toCoordinateArray()) { // let's get all the coordinates ordinates for (int i = 0; i < coordinateSequence.getDimension(); i++) { ordinates.add(coordinate.getOrdinate(i)); } } return ordinates; }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { CoordinateSequence coordinates = (CoordinateSequence) node.getChildValue(KML.coordinates.getLocalPart()); // If the last point is not the same as the first point jts will throw an error // where as other KML readers like google earth just auto close the polygon so // here we manually fix it even though it's invalid so KMls that work elsewhere work here Coordinate firstCoord = coordinates.getCoordinate(0); Coordinate lastCoord = coordinates.getCoordinate(coordinates.size() - 1); if (!firstCoord.equals3D(lastCoord)) { List<Coordinate> updateCoords = new ArrayList<>(Arrays.asList(coordinates.toCoordinateArray())); updateCoords.add((Coordinate) firstCoord.clone()); coordinates = csFactory.create(updateCoords.toArray(new Coordinate[0])); } return geometryFactory.createLinearRing(coordinates); }
/** The following is basically a copy-and-paste of a previous implementation by Andrea Aime. */ private CoordinateSequence transform(final CoordinateSequence cs, final MathTransform transform) throws TransformException { double[] coords = new double[100]; final Coordinate[] scs = cs.toCoordinateArray(); final Coordinate[] tcs = new Coordinate[scs.length]; if (coords.length < (scs.length * 2)) { coords = new double[scs.length * 2]; } for (int i = 0; i < scs.length; i++) { coords[i * 2] = scs[i].x; coords[i * 2 + 1] = scs[i].y; } transform.transform(coords, 0, coords, 0, scs.length); for (int i = 0; i < tcs.length; i++) { tcs[i] = new Coordinate(coords[i * 2], coords[i * 2 + 1]); } return csFactory.create(tcs); } }
public Coordinate[] getCoordinates() { return points.toCoordinateArray(); }
@Override public CoordinateSequence create(final CoordinateSequence coordSeq) { return new LiteCoordinateSequence(coordSeq.toCoordinateArray()); }
/** * @see org.locationtech.jts.geom.CoordinateSequenceFactory#create(org.locationtech.jts.geom.CoordinateSequence) */ public CoordinateSequence create(CoordinateSequence coordSeq) { int dimension = coordSeq.getDimension(); int measures = coordSeq.getMeasures(); if (type == DOUBLE) { return new PackedCoordinateSequence.Double(coordSeq.toCoordinateArray(), dimension, measures); } else { return new PackedCoordinateSequence.Float(coordSeq.toCoordinateArray(), dimension, measures); } }
@Override public CoordinateSequence transform(final CoordinateSequence cs, final int minpoints) { final Coordinate[] coords = cs.toCoordinateArray(); final Coordinate[] deci = decimate(coords,minpoints); if(deci.length == coords.length){ //nothing to decimate return cs; }else{ return csf.create(deci); } }
protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geometry parent) { Coordinate[] inputPts = coords.toCoordinateArray(); Coordinate[] newPts = null; if (inputPts.length == 0) { newPts = new Coordinate[0]; } else { newPts = VWLineSimplifier.simplify(inputPts, distanceTolerance); } return factory.getCoordinateSequenceFactory().create(newPts); }
protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geometry parent) { Coordinate[] srcPts = coords.toCoordinateArray(); Coordinate[] newPts = snapLine(srcPts, snapPts); return factory.getCoordinateSequenceFactory().create(newPts); }
protected CoordinateSequence transformCoordinates( CoordinateSequence coords, Geometry parent) { Coordinate[] inputPts = coords.toCoordinateArray(); Coordinate[] newPts = Densifier .densifyPoints(inputPts, distanceTolerance, parent.getPrecisionModel()); // prevent creation of invalid linestrings if (parent instanceof LineString && newPts.length == 1) { newPts = new Coordinate[0]; } return factory.getCoordinateSequenceFactory().create(newPts); }
protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geometry parent) { Coordinate[] inputPts = coords.toCoordinateArray(); Coordinate[] newPts = null; if (inputPts.length == 0) { newPts = new Coordinate[0]; } else { newPts = DouglasPeuckerLineSimplifier.simplify(inputPts, distanceTolerance); } return factory.getCoordinateSequenceFactory().create(newPts); }
private static void doTestIndexOf(CoordinateSequenceFactory factory, int dimension) { // arrange CoordinateSequence sequence = createSequenceFromOrdinates(factory, dimension); // act & assert Coordinate[] coordinates = sequence.toCoordinateArray(); for (int i = 0; i < sequence.size(); i++) assertEquals(i, CoordinateSequences.indexOf(coordinates[i], sequence)); }
assertEquals( 4.0, coord.getX()); assertEquals( 4.0, coord.getY()); array = seq.toCoordinateArray(); assertEquals(coord, array[4]); assertTrue(isEqual(seq,array)); assertEquals( 4.0, coord.getY()); assertEquals( 4.0, coord.getZ()); array = seq.toCoordinateArray(); assertEquals(coord, array[4]); assertTrue(isEqual(seq,array)); assertEquals( 4.0, coord.getY()); assertEquals( 4.0, coord.getM()); array = seq.toCoordinateArray(); assertEquals(coord, array[4]); assertTrue(isEqual(seq,array)); assertEquals( 4.0, coord.getZ()); assertEquals( 4.0, coord.getM()); array = seq.toCoordinateArray(); assertEquals(coord, array[4]); assertTrue(isEqual(seq,array));
assertEquals( 4.0, coord.getX()); assertEquals( 4.0, coord.getY()); array = seq.toCoordinateArray(); assertEquals(coord, array[4]); assertTrue(coord != array[4]); assertEquals( 4.0, coord.getY()); assertEquals( 4.0, coord.getZ()); array = seq.toCoordinateArray(); assertEquals(coord, array[4]); assertTrue(coord != array[4]); assertEquals( 4.0, coord.getY()); assertEquals( 4.0, coord.getM()); array = seq.toCoordinateArray(); assertEquals(coord, array[4]); assertTrue(coord != array[4]); assertEquals( 4.0, coord.getZ()); assertEquals( 4.0, coord.getM()); array = seq.toCoordinateArray(); assertEquals(coord, array[4]); assertTrue(coord != array[4]);