/** @see org.geotools.geometry.coordinatesequence.CSBuilder#getCoordinateSequence() */ public CoordinateSequence end() { CoordinateSequence cs = factory.create(coordinateArray); coordinateArray = null; return cs; }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(InstanceComponent instance, Object value) throws Exception { List list = (List) value; Coordinate[] coordinates = new Coordinate[list.size()]; int i = 0; for (Iterator l = list.iterator(); l.hasNext(); i++) { StringTokenizer st = new StringTokenizer((String) l.next(), ","); Coordinate c = new Coordinate(); c.x = Double.parseDouble(st.nextToken()); c.y = Double.parseDouble(st.nextToken()); if (st.hasMoreTokens()) { c.z = Double.parseDouble(st.nextToken()); } coordinates[i] = c; } return csFactory.create(coordinates); }
cs = csFactory.create(size, dimension, measures);
/** * * <!-- 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); }
private void readCoordinateSequences() { Figure[] figures = binary.getFigures(); CoordinateSequence[] sequences = new CoordinateSequence[figures.length]; for (int i = 0; i < figures.length; i++) { int figurePointOffset = figures[i].getPointOffset(); int nextPointOffset = figures.length >= i + 2 ? figures[i + 1].getPointOffset() : binary.getCoordinates().length; Coordinate[] coordinates = Arrays.copyOfRange(binary.getCoordinates(), figurePointOffset, nextPointOffset); int attribute = figures[i].getAttribute(); if ((attribute == 0 || attribute == 2) && !coordinates[0].equals(coordinates[coordinates.length - 1])) { coordinates = Arrays.copyOf(coordinates, coordinates.length + 1); coordinates[coordinates.length - 1] = coordinates[0]; } sequences[i] = gf.getCoordinateSequenceFactory().create(coordinates); } binary.setSequences(sequences); }
/** 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); } }
/** * Construct CoordinateSequence with no LRS measures. * * <p>To produce two dimension Coordinates pass in <code>null</code> for z * * @param f DOCUMENT ME! * @param x DOCUMENT ME! * @param y DOCUMENT ME! * @param z DOCUMENT ME! * @return DOCUMENT ME! */ public static CoordinateSequence coordiantes( CoordinateSequenceFactory f, AttributeList x, AttributeList y, AttributeList z) { final int LENGTH = x.size(); Coordinate[] array = new Coordinate[LENGTH]; if (z != null) { for (int i = 0; i < LENGTH; i++) { array[i] = new Coordinate(x.getDouble(i), y.getDouble(i), z.getDouble(i)); } } else { for (int i = 0; i < LENGTH; i++) { array[i] = new Coordinate(x.getDouble(i), y.getDouble(i)); } } return f.create(array); }
CoordinateSequenceFactory f, final int GTYPE, double[] ordinates) { if ((ordinates == null) || (ordinates.length == 0)) { return f.create(new Coordinate[0]);
CoordinateSequence revSeq = factory.create(sequence); CoordinateSequences.reverse(revSeq); return revSeq;
/** * Creates a Point using the given Coordinate. * A null Coordinate creates an empty Geometry. * * @param coordinate a Coordinate, or null * @return the created Point */ public Point createPoint(Coordinate coordinate) { return createPoint(coordinate != null ? getCoordinateSequenceFactory().create(new Coordinate[]{coordinate}) : null); }
/** * Creates a {@link LinearRing} using the given {@link Coordinate}s. * A null or empty array creates an empty LinearRing. * The points must form a closed and simple linestring. * @param coordinates an array without null elements, or an empty array, or null * @return the created LinearRing * @throws IllegalArgumentException if the ring is not closed, or has too few points */ public LinearRing createLinearRing(Coordinate[] coordinates) { return createLinearRing(coordinates != null ? getCoordinateSequenceFactory().create(coordinates) : null); }
500 * random.nextDouble()); final CoordinateSequence sourceCS = csFactory.create(source); final CoordinateSequence targetCS = transform(sourceCS, t); assertNotSame(sourceCS, targetCS);
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 CoordinateSequence createClosedRing(CoordinateSequenceFactory fact, CoordinateSequence seq, int size) { CoordinateSequence newseq = fact.create(size, seq.getDimension()); int n = seq.size(); copy(seq, 0, newseq, 0, n); // fill remaining coordinates with start point for (int i = n; i < size; i++) copy(seq, 0, newseq, i, 1); return newseq; }
/** @deprecated Use GeometryFactory instead */ public LineString(Coordinate points[], PrecisionModel precisionModel, int SRID) { super(new GeometryFactory(precisionModel, SRID)); init(getFactory().getCoordinateSequenceFactory().create(points)); }
public static CoordinateSequence extend(CoordinateSequenceFactory fact, CoordinateSequence seq, int size) { CoordinateSequence newseq = fact.create(size, seq.getDimension()); int n = seq.size(); copy(seq, 0, newseq, 0, n); // fill remaining coordinates with end point, if it exists if (n > 0) { for (int i = n; i < size; i++) copy(seq, n-1, newseq, i, 1); } return newseq; }
private void init(CoordinateSequence coordinates) { if (coordinates == null) { coordinates = getFactory().getCoordinateSequenceFactory().create(new Coordinate[]{}); } Assert.isTrue(coordinates.size() <= 1); this.coordinates = coordinates; }
public LinearRing createLinearRing(CoordinateSequence cs) { if (cs.getCoordinate(0).equals(cs.getCoordinate(cs.size() - 1))) return super.createLinearRing(cs); // add a new coordinate to close the ring CoordinateSequenceFactory csFact = getCoordinateSequenceFactory(); CoordinateSequence csNew = csFact.create(cs.size() + 1, cs.getDimension()); CoordinateSequences.copy(cs, 0, csNew, 0, cs.size()); CoordinateSequences.copyCoord(csNew, 0, csNew, csNew.size() - 1); return super.createLinearRing(csNew); }
public void testSerializable() throws IOException, ClassNotFoundException { Coordinate[] coords = createArray(SIZE); CoordinateSequence seq = getCSFactory().create(coords); // throws exception if not serializable byte[] data = serialize(seq); // check round-trip gives same data CoordinateSequence seq2 = deserialize(data); assertTrue(isEqual(seq2, coords)); }