/** * Returns the number of positions in the <code>PositionSequence</code> of this <code>Geometry</code>. * * @return the number of positions in the <code>PositionSequence</code> of this <code>Geometry</code>. */ public int getNumPositions() { return getPositions().size(); }
private static CoordinateSequence sequenceOf(org.geolatte.geom.Geometry geometry) { if (geometry == null) { throw new JTSConversionException("Can't convert null geometries."); } else { return (CoordinateSequence) geometry.getPositions(); } } }
/** * Returns the coordinate dimension of this <code>Geometry</code> * <p/> * <p>The coordinate dimension is the number of components in the coordinates of the points in * this <code>Geometry</code>. </p> * * @return the coordinate dimension */ public int getCoordinateDimension() { return getPositions().getCoordinateDimension(); }
/** * Tests whether this <code>Geometry</code> corresponds to the empty set. * * @return true if this <code>Geometry</code> corresponds to the empty set, false otherwise. */ public boolean isEmpty() { return this.getPositions().isEmpty(); }
public Class<P> getPositionClass() { return !getPositions().isEmpty() ? getPositions().getPositionClass() : this.crs.getPositionClass(); }
@Override public int hashCode() { int result = getGeometryType().hashCode(); result = 31 * result + this.getPositions().hashCode(); return result; }
@SuppressWarnings("unchecked") protected static <T extends Position> PositionSequence<T> nestPositionSequences(Geometry<T>[] geometries) { if (geometries == null || geometries.length == 0) { return new NestedPositionSequence<T>((PositionSequence<T>[])new PositionSequence[0]); } PositionSequence<T>[] sequences = (PositionSequence<T>[]) (new PositionSequence[geometries.length]); int i = 0; for (Geometry<T> g : geometries) { sequences[i++] = g.getPositions(); } return new NestedPositionSequence<T>(sequences); }
@Override public Double execute() { if (geometry == null) { throw new IllegalArgumentException("Operation expects a non-empty geometry"); } if (geometry.isEmpty()) { return Double.NaN; } FindExtremumMeasureVisitor<P> visitor = new FindExtremumMeasureVisitor<P>(min); geometry.getPositions().accept(visitor); return visitor.extremum; } };
/** * Returns the position at the specified index in the <code>PositionSequence</code> of this <code>Geometry</code>. * * @param index the position in the <code>PositionSequence</code> (first point is at index 0). * @return the position at the specified index in the <code>PositionSequence</code> of this <code>Geometry</code>. */ public P getPositionN(int index) { if (index >= getPositions().size()) { throw new IndexOutOfBoundsException(); } double[] coords = new double[getCoordinateDimension()]; getPositions().getCoordinates(index, coords); return Positions.mkPosition(getCoordinateReferenceSystem(), coords); }
@Override protected void encode(Geometry<?> geom, int parentShapeIndex, CountingPositionSequenceBuilder<?> coordinates, List<Figure> figures, List<Shape> shapes) { if ( !( geom instanceof LineString ) ) { throw new IllegalArgumentException( "Require LineString geometry" ); } if ( geom.isEmpty() ) { shapes.add( new Shape( parentShapeIndex, -1, OpenGisType.LINESTRING ) ); return; } int figureOffset = figures.size(); int pointOffset = coordinates.getNumAdded(); double[] c = new double[coordinates.getCoordinateDimension()]; for ( Position pos : geom.getPositions() ) { coordinates.add( pos.toArray(c) ); } figures.add( new Figure( FigureAttribute.Stroke, pointOffset ) ); shapes.add( new Shape( parentShapeIndex, figureOffset, OpenGisType.LINESTRING ) ); }
/** * Creates a <code>Geometry</code> having as coordinates the coordinates of the input <code>Geometry</code> in reverse order. * * @param geometry the <code>Geometry</code> to reverse * @return a <code>Geometry</code> with the same coordinates as the specified input <code>Geometry</code> but in reverse order */ @Override public <P extends C2D, G extends Geometry<P>> G reverse(G geometry) { PositionSequence<P> pos = geometry.getPositions().reverse(); if (geometry instanceof Simple) { return (G)Geometries.mkGeometry((Class<? extends Simple>)geometry.getClass(), pos, geometry.getCoordinateReferenceSystem()); } else { Complex<P, ?> complex = (Complex<P, ?>) geometry; Geometry<P>[] geoms = complex.components(); reverseOrder(reverseAll(geoms)); return (G)Geometries.mkGeometry((Class<? extends Complex>)geometry.getClass(), geoms); } }
if (geometry instanceof Simple) { Simple simple = (Simple) geometry; PositionSequence<Q> positions = Positions.copy(geometry.getPositions(), crs.getPositionClass()); return Geometries.mkGeometry(simple.getClass(), positions, crs); } else {
/** * Returns the {@code Envelope} of this instance. * @return the {@code Envelope} of this instance. */ public Envelope<P> getEnvelope() { if (isEmpty()) return new Envelope<P>(getCoordinateReferenceSystem()); PositionSequence<P> positions = getPositions(); EnvelopeVisitor<P> visitor = new EnvelopeVisitor<P>(getCoordinateReferenceSystem()); positions.accept(visitor); return visitor.result(); }
/** * {@inheritDoc} */ @Override public <P extends Position> boolean equals(Geometry<P> first, Geometry<P> second) { if (first == second) return true; if (first == null || second == null) return false; if (first.isEmpty() && second.isEmpty()) return true; if (first.isEmpty() || second.isEmpty()) return false; if (! first.getCoordinateReferenceSystem().equals(second.getCoordinateReferenceSystem())) return false; if (first.getGeometryType() != second.getGeometryType()) return false; if (first instanceof GeometryCollection) { assert(second instanceof GeometryCollection); return equals((GeometryCollection<?,?>)first, (GeometryCollection<?,?>)second); } if (first instanceof Polygon) { assert(second instanceof Polygon); return equals((Polygon<P>)first, (Polygon<P>)second); } return pointSeqEq.equals(first.getPositions(), second.getPositions()); }
@Override public <P extends Position, G extends Geometry<P>> SDOGeometry encode(G geom) { final int dim = geom.getCoordinateDimension(); final int lrsPos = getLRSDim(geom); final boolean isLrs = lrsPos > 0; final Double[] ordinates = convertPositionSequence(geom.getPositions()); final ElemInfo info = new ElemInfo(1); info.setElement(0, 1, ElementType.LINE_STRAITH_SEGMENTS, 0); return new SDOGeometry( new SDOGType(dim, lrsPos, TypeGeometry.LINE), geom.getSRID(), null, info, new Ordinates(ordinates)); }
case LINESTRING: case LINEARRING: addPointList(geometry.getPositions()); break; case POLYGON:
@Override public <P extends Position, G extends Geometry<P>> SDOGeometry encode(G geom) { final int dim = geom.getCoordinateDimension(); final int lrsDim = getLRSDim(geom); final boolean isLrs = (lrsDim != 0); final Double[] coord = convertPositionSequence(geom.getPositions()); if (Settings.useSdoPointType() && !isLrs && !geom.isEmpty()) { return new SDOGeometry( new SDOGType(dim, lrsDim, TypeGeometry.POINT), geom.getSRID(), new SDOPoint(coord), null, null ); } final ElemInfo info = new ElemInfo(1); info.setElement(0, 1, ElementType.POINT, 1); return new SDOGeometry( new SDOGType(dim, lrsDim, TypeGeometry.POINT), geom.getSRID(), null, info, new Ordinates(coord) ); }
sqlServerGeom.allocateMValueArray(); sqlServerGeom.setCoordinate(0, geom.getPositions()); return sqlServerGeom;