private static Geometry<C2D> toPolygon(Envelope env) { final PositionSequence<C2D> ps = PositionSequenceBuilders.fixedSized( 4, C2D.class ) .add( env.lowerLeft().getCoordinate( 0 ), env.lowerLeft().getCoordinate( 1 ) ) .add( env.lowerLeft().getCoordinate( 0 ), env.upperRight().getCoordinate( 1 ) ) .add( env.upperRight().getCoordinate( 0 ), env.upperRight().getCoordinate( 1 ) ) .add( env.lowerLeft().getCoordinate( 0 ), env.lowerLeft().getCoordinate( 1 ) ) .toPositionSequence(); return new Polygon<C2D>( ps, CoordinateReferenceSystems.PROJECTED_2D_METER ); }
/** * Creates an empty {@code Polygon} for a coordinate reference system * * @param crs the coordinate reference system for the created {@code Polygon} * @param <P> the type of {@code Position} * @return an empty {@code Polygon} with the specified coordinate reference system */ public static <P extends Position> Polygon<P> mkEmptyPolygon(CoordinateReferenceSystem<P> crs) { return new Polygon<P>(crs); }
public static <P extends Position> Polygon<P> mkPolygon(LinearRing<P>... rings) { return new Polygon<P>(rings); }
protected Polygon<?> createNullGeometry(CoordinateReferenceSystem<?> crs) { return new Polygon(crs); }
public static <P extends Position> Polygon<P> mkPolygon(List<LinearRing<P>> rings) { LinearRing<P>[] ringArr = (LinearRing<P>[]) new LinearRing[rings.size()]; return new Polygon<P>(rings.toArray(ringArr)); }
@Override @SuppressWarnings("unchecked") Polygon<P> toGeometry(CoordinateReferenceSystem<P> crs) { LinearRing<P>[] rings = new LinearRing[ringTokens.length]; for (int i = 0; i < rings.length; i++) { rings[i] = ringTokens[i].toGeometry(crs); } return new Polygon(rings); } }
/** * Creates a {@code Polygon} from the specified ring tokens and {@code CoordinateReferenceSystem} * * @param crs the {@code CoordinateReferenceSystem} for the returned {@code Polygon} * @param tokens the {@code GeometryTokens} representing (in order) the outer and any inner rings * @param <P> the {@code Position} type * @return the {@code Polygon} defined by the specified coordinate reference system and ring tokens */ @SuppressWarnings("unchecked") @SafeVarargs public static <P extends Position> Polygon<P> polygon(CoordinateReferenceSystem<P> crs, LinearRingToken<P>... tokens) { if (tokens.length == 0) { return new Polygon<P>(crs); } LinearRing<P>[] rings = new LinearRing[tokens.length]; int idx = 0; for (LinearRingToken t : tokens) { rings[idx++] = t.toGeometry(crs); } return new Polygon<P>(rings); }
/** * Creates a {@code Polygon} from the specified outer ring (or hull) and inner rings (if any) * * @param hull the outer ring of the returned {@code Polygon} * @param rings the inner rings of the returned {@code Polygon} * @param <P> the {@code Position} type * @return the {@code Polygon} defined by the specified outer and inner rings. */ @SuppressWarnings("unchecked") @SafeVarargs public static <P extends Position> Polygon<P> polygon(LinearRing<P> hull, LinearRing<P>... rings) { LinearRing<P>[] combined = combine(LinearRing.class, hull, rings); return new Polygon<P>(combined); }
private Polygon decodePolygon(int shapeIdx) { Shape shape = shapes[shapeIdx]; int figureOffset = shape.figureOffset; if (figureOffset <= -1) { return Polygon.createEmpty(); } int figureStopIdx = figures.length - 1; if (shapeIdx < (shapes.length - 1)) { figureStopIdx = shapes[shapeIdx + 1].figureOffset - 1; } List<LinearRing> linearRings = Lists.newArrayList(); for (int i = figureOffset; i <= figureStopIdx; i++) { linearRings.add(new LinearRing(createPoints(i))); } return new Polygon(linearRings.toArray(new LinearRing[0])); }
private Polygon decodePolygon(int shapeIdx) { Shape shape = shapes[shapeIdx]; int figureOffset = shape.figureOffset; if (figureOffset <= -1) { return Polygon.createEmpty(); } int figureStopIdx = figures.length - 1; if (shapeIdx < (shapes.length - 1)) { figureStopIdx = shapes[shapeIdx + 1].figureOffset - 1; } List<LinearRing> linearRings = Lists.newArrayList(); for (int i = figureOffset; i <= figureStopIdx; i++) { linearRings.add(new LinearRing(createPoints(i))); } return new Polygon(linearRings.toArray(new LinearRing[0])); }
public static <Q extends Position> Geometry<Q> mkGeometry(Class<? extends Complex> geometryClass, CoordinateReferenceSystem<Q> crs) { if (Polygon.class.isAssignableFrom(geometryClass)) { return new Polygon<Q>(crs); } if (MultiLineString.class.isAssignableFrom(geometryClass)) { return new MultiLineString<Q>(crs); } if (MultiPoint.class.isAssignableFrom(geometryClass)) { return new MultiPoint<Q>(crs); } if (MultiPolygon.class.isAssignableFrom(geometryClass)) { return new MultiPolygon<Q>(crs); } if (GeometryCollection.class.isAssignableFrom(geometryClass)) { return new GeometryCollection<Q, Geometry<Q>>(crs); } throw new IllegalStateException("Unknown Geometry class"); }
@SuppressWarnings("unchecked") public static <P extends Position> Geometry<P> mkGeometry(Class<? extends Complex> geometryClass, Geometry<P>... parts) { if (Polygon.class.isAssignableFrom(geometryClass)) { return new Polygon((LinearRing<P>[]) parts); } if (MultiLineString.class.isAssignableFrom(geometryClass)) { return new MultiLineString<P>((LineString<P>[]) parts); } if (MultiPoint.class.isAssignableFrom(geometryClass)) { return new MultiPoint<P>((Point<P>[]) parts); } if (MultiPolygon.class.isAssignableFrom(geometryClass)) { return new MultiPolygon<P>((Polygon<P>[]) parts); } if (GeometryCollection.class.isAssignableFrom(geometryClass)) { return new GeometryCollection<P, Geometry<P>>((Geometry<P>[]) parts); } throw new IllegalStateException("Unknown Geometry class"); }
private static Polygon convert(org.postgis.Polygon geometry) { LinearRing[] rings = new LinearRing[geometry.numRings()]; for (int i = 0; i < rings.length; i++) { rings[i] = convert(geometry.getRing(i)); } return new Polygon(rings); }
private static Polygon convert(org.postgis.Polygon geometry) { LinearRing[] rings = new LinearRing[geometry.numRings()]; for (int i = 0; i < rings.length; i++) { rings[i] = convert(geometry.getRing(i)); } return new Polygon(rings); }
protected Polygon<?> createGeometry(SqlServerGeometry nativeGeom, int shapeIndex) { if ( nativeGeom.isEmptyShape( shapeIndex ) ) { return (Polygon<?>)createNullGeometry(nativeGeom.getCoordinateReferenceSystem()); } //polygons consist of one exterior ring figure, and several interior ones. IndexRange figureRange = nativeGeom.getFiguresForShape( shapeIndex ); List<LinearRing<?>> rings = new ArrayList<LinearRing<?>>(figureRange.length()); //the rings should contain all inner rings from index 1 to index length - 1 // index = 0 should be reserved for the shell. for ( int figureIdx = figureRange.start, i = 1; figureIdx < figureRange.end; figureIdx++ ) { IndexRange pntIndexRange = nativeGeom.getPointsForFigure( figureIdx ); if ( nativeGeom.isFigureInteriorRing( figureIdx ) ) { rings.add(i++,toLinearRing( nativeGeom, pntIndexRange)); } else { rings.add(0, toLinearRing( nativeGeom, pntIndexRange)); } } LinearRing<?>[] ringArr = (LinearRing<?>[])new LinearRing[rings.size()]; return new Polygon(rings.toArray(ringArr)); }
@SuppressWarnings("unchecked") private static <P extends Position> org.geolatte.geom.Polygon<P> from(Polygon jtsGeometry, CoordinateReferenceSystem<P> crs) { if (jtsGeometry.isEmpty()) { return new org.geolatte.geom.Polygon<P>(crs); } org.geolatte.geom.LinearRing<P>[] rings = new org.geolatte.geom.LinearRing[jtsGeometry.getNumInteriorRing() + 1]; org.geolatte.geom.LineString<P> extRing = from(jtsGeometry.getExteriorRing(), crs); rings[0] = new org.geolatte.geom.LinearRing(extRing.getPositions(), extRing.getCoordinateReferenceSystem()); for (int i = 1; i < rings.length; i++) { org.geolatte.geom.LineString intRing = from(jtsGeometry.getInteriorRingN(i - 1), crs); rings[i] = new org.geolatte.geom.LinearRing(intRing); } return new org.geolatte.geom.Polygon(rings); }
private <P extends Position> Polygon<P> decodePolygonText(CoordinateReferenceSystem<P> crs) { if (matchesOpenList()) { List<LinearRing<P>> rings = new ArrayList<LinearRing<P>>(); while (!matchesCloseList()) { LinearRing ring = decodeLinearRingText(crs); if (ring.isEmpty()) { throw new WktDecodeException("Empty ring found in polygon" + "Wkt: " + wktString); } rings.add(ring); matchesElementSeparator(); } return mkPolygon(rings); } if (matchesEmptyToken()) { return new Polygon<P>(crs); } throw new WktDecodeException(buildWrongSymbolAtPositionMsg()); }
private static Polygon convertPolygon(JGeometry geometry) { CrsId crs = CrsId.valueOf(geometry.getSRID()); int dimensions = geometry.getDimensions(); boolean measured = geometry.isLRSGeometry(); DimensionalFlag flag = DimensionalFlag.valueOf(dimensions > (measured ? 3 : 2), measured); Object[] elements = geometry.getOrdinatesOfElements(); LinearRing[] rings = new LinearRing[elements.length]; for (int i = 0; i < elements.length; i++) { PointSequence points = PointCollectionFactory.create((double[]) elements[i], flag, crs); rings[i] = new LinearRing(points); } return new Polygon(rings); }
private static Polygon convertPolygon(JGeometry geometry) { CrsId crs = CrsId.valueOf(geometry.getSRID()); int dimensions = geometry.getDimensions(); boolean measured = geometry.isLRSGeometry(); DimensionalFlag flag = DimensionalFlag.valueOf(dimensions > (measured ? 3 : 2), measured); Object[] elements = geometry.getOrdinatesOfElements(); LinearRing[] rings = new LinearRing[elements.length]; for (int i = 0; i < elements.length; i++) { PointSequence points = PointCollectionFactory.create((double[]) elements[i], flag, crs); rings[i] = new LinearRing(points); } return new Polygon(rings); }
@Override @SuppressWarnings("unchecked") Geometry<?> internalDecode(SDOGeometry sdoGeom) { CoordinateReferenceSystem crs = getCoordinateReferenceSystem(sdoGeom); LinearRing shell = null; final LinearRing[] rings = new LinearRing[sdoGeom.getNumElements()]; final ElemInfo info = sdoGeom.getInfo(); int i = 0; int idxInteriorRings = 1; while (i < info.getSize()) { PositionSequence cs = null; int numCompounds = 0; if (info.getElementType(i).isCompound()) { numCompounds = info.getNumCompounds(i); cs = add(cs, getCompoundCSeq(i + 1, i + numCompounds, sdoGeom)); } else { cs = add(cs, getElementCSeq(i, sdoGeom, false, crs)); } if (info.getElementType(i).isInteriorRing()) { rings[idxInteriorRings] = new LinearRing(cs, crs); idxInteriorRings++; } else { rings[0] = new LinearRing(cs, crs); } i += 1 + numCompounds; } return new Polygon(rings); } }