public static boolean isEqual(Coordinate[] c1, Coordinate c2[], boolean reverse) { if (c1.length != c2.length) return (false); if (!reverse) { for (int i = 0; i < c1.length; i++) { if (!c1[i].equals(c2[i])) return (false); } return (true); } for (int i = 0; i < c1.length; i++) { if (!c1[i].equals(c2[c1.length - i - 1])) return (false); } return (true); }
/** * Tests whether this edge has the given orig and dest vertices. * * @param p0 the origin vertex to test * @param p1 the destination vertex to test * @return true if the vertices are equal to the ones of this edge */ public boolean equals(Coordinate p0, Coordinate p1) { return orig.equals2D(p0) && sym.orig.equals(p1); }
protected void setNext(Edge next) { // don't bother setting next if its null if (next != null) { // self-loop throws an invalid shape if (this.coordinate.equals(next.coordinate)) { throw new InvalidShapeException("Provided shape has duplicate consecutive coordinates at: " + this.coordinate); } this.next = next; } }
private static void validateLinearRing(LineStringBuilder lineString) { /** * Per GeoJSON spec (http://geojson.org/geojson-spec.html#linestring) * A LinearRing is closed LineString with 4 or more positions. The first and last positions * are equivalent (they represent equivalent points). Though a LinearRing is not explicitly * represented as a GeoJSON geometry type, it is referred to in the Polygon geometry type definition. */ List<Coordinate> points = lineString.coordinates; if (points.size() < 4) { throw new IllegalArgumentException( "invalid number of points in LinearRing (found [" + points.size() + "] - must be >= 4)"); } if (!points.get(0).equals(points.get(points.size() - 1))) { throw new IllegalArgumentException("invalid LinearRing found (coordinates are not closed)"); } }
public LineString toLineString(List<?> list) { List<Coordinate> coordList = new ArrayList<Coordinate>(list.size()); for (Object o : list) { coordList.add(toCoordinate((List<?>) o)); } Coordinate[] coords = coordList.toArray(new Coordinate[coordList.size()]); if (coords.length > 3 && coords[0].equals(coords[coords.length - 1])) { return geometryFactory.createLinearRing(coords); } return geometryFactory.createLineString(coords); }
void validateLinearRing(CoordinateNode coordinates, boolean coerce) { if (coordinates.children == null || coordinates.children.isEmpty()) { String error = "Invalid LinearRing found."; error += (coordinates.coordinate == null) ? " No coordinate array provided" : " Found a single coordinate when expecting a coordinate array"; throw new ElasticsearchParseException(error); } int numValidPts = coerce ? 3 : 4; if (coordinates.children.size() < numValidPts) { throw new ElasticsearchParseException("invalid number of points in LinearRing (found [{}] - must be >= [{}])", coordinates.children.size(), numValidPts); } // close linear ring iff coerce is set and ring is open, otherwise throw parse exception if (!coordinates.children.get(0).coordinate.equals( coordinates.children.get(coordinates.children.size() - 1).coordinate)) { if (coerce == true) { coordinates.children.add(coordinates.children.get(0)); } else { throw new ElasticsearchParseException("invalid LinearRing found (coordinates are not closed)"); } } }
public CompoundCurve(List<LineString> components, GeometryFactory factory, double tolerance) { super(CircularString.FAKE_STRING_2D, factory); this.tolerance = tolerance; // sanity check, we don't want compound curves containing other compound curves this.components = new ArrayList<>(); for (LineString ls : components) { if (ls instanceof CompoundCurve) { CompoundCurve cc = (CompoundCurve) ls; this.components.addAll(cc.components); } else { this.components.add(ls); } } // check connectedness if (components.size() > 1) { LineString prev = components.get(0); for (int i = 1; i < components.size(); i++) { LineString curr = components.get(i); Coordinate endPoint = prev.getCoordinateN(prev.getNumPoints() - 1); Coordinate startPoint = curr.getCoordinateN(0); if (!endPoint.equals(startPoint)) { throw new IllegalArgumentException( "Found two elements that are not connected, " + prev + " and " + curr); } prev = curr; } } }
private static LineStringBuilder parseLinearRing(StreamTokenizer stream, final boolean ignoreZValue, final boolean coerce) throws IOException, ElasticsearchParseException { String token = nextEmptyOrOpen(stream); if (token.equals(EMPTY)) { return null; } List<Coordinate> coordinates = parseCoordinateList(stream, ignoreZValue, coerce); int coordinatesNeeded = coerce ? 3 : 4; if (coordinates.size() >= coordinatesNeeded) { if (!coordinates.get(0).equals(coordinates.get(coordinates.size() - 1))) { if (coerce == true) { coordinates.add(coordinates.get(0)); } else { throw new ElasticsearchParseException("invalid LinearRing found (coordinates are not closed)"); } } } if (coordinates.size() < 4) { throw new ElasticsearchParseException("invalid number of points in LinearRing (found [{}] - must be >= 4)", coordinates.size()); } return new LineStringBuilder(coordinates); }
/** * Gets a set of coordinates valid to create a polygon: - at least 4 coordinates - * closed path * * @param coordinates * @return */ private Coordinate[] getPolygonCoordinates(Coordinate[] coordinates) { // at least 4 points coordinates = growCoordinatesNum(coordinates, 4); if (!coordinates[coordinates.length - 1].equals(coordinates[0])) { Coordinate[] newCoordinates = arrayCopy(coordinates, coordinates.length + 1); newCoordinates[newCoordinates.length - 1] = newCoordinates[0]; coordinates = newCoordinates; } return coordinates; } };
@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)); } } } } });
protected LineSegment alterLine(LineSegment line, Node n1, Node n2) { Point c1added = ((Point) n1.getObject()); Point c2added = ((Point) n2.getObject()); if (!c1added.getCoordinate().equals(line.p0) || c2added.getCoordinate().equals(line.p1)) { line = new LineSegment(c1added.getCoordinate(), c2added.getCoordinate()); } return line; }
prev = visitedEdge.get(prev.coordinate).v1(); ++splitIndex; } while (!current.coordinate.equals(prev.coordinate)); ++connectedComponents; } else {
public void filter(Geometry geom) { // this filter will receive either points, which we don't consider, // or lines, that we need to wrap if (geom instanceof LineString) { LineString ls = (LineString) geom; CoordinateSequence cs = ls.getCoordinateSequence(); int direction = getDisconinuityDirection(cs); if (direction == NOWRAP) return; boolean ring = geom instanceof LinearRing || cs.getCoordinate(0).equals(cs.getCoordinate(cs.size() - 1)); applyOffset(cs, direction == EAST_TO_WEST ? 0 : wrapLimit * 2, ring); } }
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); }
assert cseq.getCoordinate(0).equals(cseq.getCoordinate(size-1)); assert shiftXPage == 0;//starts and ends at 0
edges[edgeOffset + i] = new Edge(points[pointOffset + i], edges[edgeOffset + i - 1]); edges[edgeOffset + i].component = component; } else if(!edges[edgeOffset + i - 1].coordinate.equals(points[pointOffset + i])) { edges[edgeOffset + i - 1].next = edges[edgeOffset + i] = new Edge(points[pointOffset + i], null); edges[edgeOffset + i - 1].component = component;
if (l1.getCoordinateN(l1.getNumPoints() - 1).equals(l2.getCoordinateN(0))) { merged[i + l1.getNumPoints()] = l2.getCoordinateN(i + 1); } else if (l2.getCoordinateN(l2.getNumPoints() - 1).equals(l1.getCoordinateN(0))) { .equals(l2.getCoordinateN(l2.getNumPoints() - 1))) { merged[i + l1.getNumPoints()] = l2.getCoordinateN(l2.getNumPoints() - 2 - i); } else if (l1.getCoordinateN(0).equals(l2.getCoordinateN(0))) {
public void testReadPoint() throws Exception { SimpleFeatureCollection fc = dataStore.getFeatureSource(tname(getPoint3d())).getFeatures(); try (SimpleFeatureIterator fr = fc.features()) { assertTrue(fr.hasNext()); Point p = (Point) fr.next().getDefaultGeometry(); assertTrue(new Coordinate(1, 1, 1).equals(p.getCoordinate())); } }
assertEquals(sourceCS.size(), targetCS.size()); for (int i = sourceCS.size(); --i >= 0; ) { assertFalse(sourceCS.getCoordinate(i).equals(targetCS.getCoordinate(i)));