private LinearRing fromRing( double[][] points ) { LinkedList<Point> ps = new LinkedList<Point>(); for ( double[] p : points ) { ps.add( fac.createPoint( null, p, crs ) ); } // may be expensive if ( ps.getFirst() != ps.getLast() ) { LOG.debug( "Ring was not closed as required by the shape file spec!" ); LOG.debug( "Trying to recover anyway." ); ps.add( ps.getFirst() ); } return fac.createLinearRing( null, crs, new PointsList( ps ) ); }
private LinkedList<Polygon> fromTriangleStrip( double[][] points ) { LinkedList<Point> ps = new LinkedList<Point>(); for ( double[] p : points ) { ps.add( fac.createPoint( null, p, crs ) ); } LinkedList<Polygon> ss = new LinkedList<Polygon>(); while ( ps.size() > 2 ) { LinkedList<Point> ring = new LinkedList<Point>(); ring.add( ps.get( 0 ) ); ring.add( ps.get( 1 ) ); ring.add( ps.get( 2 ) ); ring.add( ring.getFirst() ); ps.poll(); LinearRing r = fac.createLinearRing( null, crs, new PointsList( ring ) ); ss.add( fac.createPolygon( null, crs, r, null ) ); } return ss; }
private LinkedList<Polygon> fromTriangleFan( double[][] points ) { LinkedList<Point> ps = new LinkedList<Point>(); for ( double[] p : points ) { ps.add( fac.createPoint( null, p, crs ) ); } LinkedList<Polygon> ss = new LinkedList<Polygon>(); Point center = ps.poll(); while ( ps.size() > 1 ) { LinkedList<Point> ringps = new LinkedList<Point>(); ringps.add( center ); ringps.add( ps.get( 0 ) ); ringps.add( ps.get( 1 ) ); ringps.add( center ); ps.poll(); LinearRing ring = fac.createLinearRing( null, crs, new PointsList( ringps ) ); ss.add( fac.createPolygon( null, crs, ring, null ) ); } return ss; }
private Polygon getLegendRect( int xpos, int ypos, int xsize, int ysize ) { Point p1 = geofac.createPoint( null, xpos, ypos, mapcs ); Point p2 = geofac.createPoint( null, xpos + xsize, ypos, mapcs ); Point p3 = geofac.createPoint( null, xpos + xsize, ypos - ysize, mapcs ); Point p4 = geofac.createPoint( null, xpos, ypos - ysize, mapcs ); List<Point> ps = new ArrayList<Point>( 5 ); ps.add( p1 ); ps.add( p2 ); ps.add( p3 ); ps.add( p4 ); ps.add( p1 ); return geofac.createPolygon( null, mapcs, geofac.createLinearRing( null, null, geofac.createPoints( ps ) ), null ); }
private LinearRing transform( Ring ring, Transformation trans ) throws TransformationException { if ( ring != null ) { // TODO DefaultRing.getAsLineString currently returns an UnsupportedOpertionException // interior.getAsLineString().getControlPoints(), Points cP = ring.getControlPoints(); Points tcP = transform( cP, trans ); return geomFactory.createLinearRing( ring.getId(), getTargetCRS(), tcP ); } return null; }
outer = fac.createLinearRing( null, crs, p ); } else { LinearRing ring = fac.createLinearRing( null, crs, p ); Polygon outerP = fac.createPolygon( null, crs, outer, null ); Polygon innerP = fac.createPolygon( null, crs, ring, null );
LinearRing linearRing = geomFac.createLinearRing( gid, crs, points ); linearRing.setType( type );
LinearRing movedExteriorRing = null; if ( exterior != null ) { movedExteriorRing = fac.createLinearRing( exterior.getId(), exterior.getCoordinateSystem(), move( exterior.getAsLineString().getControlPoints(), List<Ring> movedInteriorRings = new ArrayList<Ring>( interiorRings.size() ); for ( Ring interior : interiorRings ) { movedInteriorRings.add( fac.createLinearRing( interior.getId(), interior.getCoordinateSystem(), move( interior.getAsLineString().getControlPoints(),
/** * @param xmlStream * @param defaultCRS * @return * @throws XMLStreamException */ public Ring parseLinearRing( XMLStreamReaderWrapper xmlStream, ICRS defaultCRS ) throws XMLStreamException { String gid = parseGeometryId( xmlStream ); ICRS crs = determineActiveCRS( xmlStream, defaultCRS ); xmlStream.nextTag(); Points points = parseControlPoints( xmlStream, crs ); if ( points.size() < 4 ) { String msg = "Error in 'gml:LinearRing' element. Must specify at least four points."; throw new XMLParsingException( xmlStream, msg ); } xmlStream.require( END_ELEMENT, GML21NS, "LinearRing" ); LinearRing linearRing = geomFac.createLinearRing( gid, crs, points ); idContext.addObject( linearRing ); return linearRing; }
/** * @param env * @return a polygon */ public static Polygon envelopeToPolygon( Envelope env ) { GeometryFactory fac = new GeometryFactory(); Point a = env.getMin(); Point b = fac.createPoint( null, a.get0() + env.getSpan0(), a.get1(), env.getCoordinateSystem() ); Point c = env.getMax(); Point d = fac.createPoint( null, a.get0(), a.get1() + env.getSpan1(), env.getCoordinateSystem() ); LinearRing ring = fac.createLinearRing( null, env.getCoordinateSystem(), new PointsArray( a, b, c, d, a ) ); return fac.createPolygon( null, env.getCoordinateSystem(), ring, null ); }
/** * Return the bounding geometry of a raster as a polygon (but is actually a rectangle). * * @param raster * @return bounding polygon */ public static Polygon createPolygonGeometry( AbstractRaster raster ) { ICRS crs = raster.getCoordinateSystem(); GeometryFactory fac = new GeometryFactory(); Envelope env = raster.getEnvelope(); env = raster.getRasterReference().relocateEnvelope( OriginLocation.OUTER, env ); Point pmin = env.getMin(); Point pmax = env.getMax(); Point p1 = fac.createPoint( null, pmin.get0(), pmin.get1(), crs ); Point p3 = fac.createPoint( null, pmax.get0(), pmax.get1(), crs ); Point p2 = fac.createPoint( null, p1.get0(), p3.get1(), crs ); Point p4 = fac.createPoint( null, p3.get0(), p1.get1(), crs ); Point p5 = fac.createPoint( null, p1.get0(), p1.get1(), crs ); Point[] points = { p1, p2, p3, p4, p5 }; // (asList(points)); LinearRing ring = fac.createLinearRing( null, crs, new PointsList( asList( points ) ) ); Polygon poly = fac.createPolygon( null, crs, ring, null ); return poly; }