@Override public Polygon getTestPolygon() { WKTReader reader = new WKTReader(); try { Polygon polygon = (Polygon) reader.read( "POLYGON((0 0, 50 0, 90 90, 100 0, 0 0))" ); polygon.setSRID( getTestSrid() ); return polygon; } catch (ParseException e) { throw new RuntimeException( e ); } }
/** * Return a testsuite-suite polygon (filter, ...) * * @return a testsuite-suite polygon */ public Polygon getTestPolygon() { WKTReader reader = new WKTReader(); try { Polygon polygon = (Polygon) reader.read( TEST_POLYGON_WKT ); polygon.setSRID( getTestSrid() ); return polygon; } catch (ParseException e) { throw new RuntimeException( e ); } }
public void setSRID(int SRID) { polygon.setSRID(SRID); }
/** * Converts the specified {@code Envelope} to a {@code Polygon} having the specified srid. * * @param env The envelope to convert * @param srid The srid for the polygon * * @return The Polygon */ public static Polygon toPolygon(Envelope env, int srid) { final Coordinate[] coords = new Coordinate[5]; coords[0] = new Coordinate( env.getMinX(), env.getMinY() ); coords[1] = new Coordinate( env.getMinX(), env.getMaxY() ); coords[2] = new Coordinate( env.getMaxX(), env.getMaxY() ); coords[3] = new Coordinate( env.getMaxX(), env.getMinY() ); coords[4] = new Coordinate( env.getMinX(), env.getMinY() ); final LinearRing shell = geomFactory.createLinearRing( coords ); final Polygon pg = geomFactory.createPolygon( shell, null ); pg.setSRID( srid ); return pg; }
/** * Returns the completed OGC Polygon. * * @param geometryFactory Geometry factory to be used in Polygon creation. * @return Completed OGC Polygon. */ public Geometry create(GeometryFactory geometryFactory) { for (int i = 0; i < innerBoundaries.size(); i++) { LinearRing hole = (LinearRing) innerBoundaries.get(i); if (hole.crosses(outerBoundary)) { LOGGER.warning("Topology Error building polygon"); return null; } } LinearRing[] rings = (LinearRing[]) innerBoundaries.toArray(new LinearRing[innerBoundaries.size()]); Polygon polygon = geometryFactory.createPolygon(outerBoundary, rings); polygon.setUserData(getSRS()); polygon.setSRID(getSRID()); return polygon; } }
poly.setSRID(SRID);
LOGGER.exiting("SubHandlerBox", "create", polygon); polygon.setUserData(getSRS()); polygon.setSRID(getSRID());
/** * Creates a rectangular Polygon formed from the minima and maxima by the * given shell. * The user can set a srid. * @param xmin X min * @param ymin Y min * @param xmax X max * @param ymax Y max * @param srid SRID * @return Envelope as a POLYGON */ public static Polygon makeEnvelope(double xmin, double ymin, double xmax, double ymax, int srid) { Polygon geom = makeEnvelope(xmin, ymin, xmax, ymax); geom.setSRID(srid); return geom; } }
public Object parse(Handler arg, GeometryFactory gf) throws SAXException { // one child, either a coord // or a coordinate sequence if(arg.children.size()<1) throw new SAXException("Cannot create a polygon without atleast one linear ring"); int srid = getSrid(arg.attrs,gf.getSRID()); LinearRing outer = (LinearRing) arg.children.get(0); // will be the first List t = arg.children.size()>1?arg.children.subList(1,arg.children.size()):null; LinearRing[] inner = t==null?null:(LinearRing[]) t.toArray(new LinearRing[t.size()]); Polygon p = gf.createPolygon(outer,inner); if(p.getSRID()!=srid) p.setSRID(srid); return p; } });
/** * Creates the polygon. * * @param wkt * the wkt * @return the polygon * @throws ParseException * the parse exception */ public Polygon createPolygon(String wkt) throws ParseException { Polygon poly = polAdapter.unmarshal(wkt); if (poly.getSRID() == 0) { poly.setSRID(4326); } return poly; }
@Override public String marshal(Polygon the_geom) throws ParseException { if (the_geom != null) { WKTWriter wktWriter = new WKTWriter(); if (the_geom.getSRID() == 0) the_geom.setSRID(4326); return wktWriter.write(the_geom); } else { throw new ParseException("Polygon obj is null."); } } }
@Override public String marshal(Polygon the_geom) throws ParseException { if (the_geom != null) { WKTWriter wktWriter = new WKTWriter(); if (the_geom.getSRID() == 0) the_geom.setSRID(4326); return wktWriter.write(the_geom); } else { throw new ParseException("Polygon obj is null."); } } }
@Override public String marshal(Polygon the_geom) throws ParseException { if (the_geom != null) { WKTWriter wktWriter = new WKTWriter(); if (the_geom.getSRID() == 0) the_geom.setSRID(4326); return wktWriter.write(the_geom); } else { throw new ParseException("Polygon obj is null."); } } }
@Override public String marshal(Polygon the_geom) throws ParseException { if (the_geom != null) { WKTWriter wktWriter = new WKTWriter(); if (the_geom.getSRID() == 0) the_geom.setSRID(4326); return wktWriter.write(the_geom); } else { throw new ParseException("Polygon obj is null."); } } }
/** * {@inheritDoc } */ @Override public org.locationtech.jts.geom.Geometry computeJTSPeer() { final SurfaceBoundary boundary = getBoundary(); final Ring exterior = boundary.getExterior(); final List interiors = boundary.getInteriors(); if (exterior != null) { final org.locationtech.jts.geom.Geometry g = ((JTSGeometry) exterior).getJTSGeometry(); final int numHoles = (interiors != null) ? interiors.size() : 0; final org.locationtech.jts.geom.LinearRing jtsExterior = JTSUtils.GEOMETRY_FACTORY.createLinearRing(g.getCoordinates()); final org.locationtech.jts.geom.LinearRing [] jtsInterior = new org.locationtech.jts.geom.LinearRing[numHoles]; for (int i=0; i<numHoles; i++) { final org.locationtech.jts.geom.Geometry g2 = ((JTSGeometry) interiors.get(i)).getJTSGeometry(); jtsInterior[i] = JTSUtils.GEOMETRY_FACTORY.createLinearRing(g2.getCoordinates()); } final org.locationtech.jts.geom.Polygon result = JTSUtils.GEOMETRY_FACTORY.createPolygon(jtsExterior, jtsInterior); final CoordinateReferenceSystem crs = getCoordinateReferenceSystem(); if (crs != null) { final int srid = SRIDGenerator.toSRID(crs, Version.V1); result.setSRID(srid); } return result; } return null; }