public Geoshape polygon(List<double[]> coordinates) { Preconditions.checkArgument(coordinates.size() >= 4, "Too few coordinate pairs provided"); Preconditions.checkArgument(Arrays.equals(coordinates.get(0), coordinates.get(coordinates.size()-1)), "Polygon is not closed"); final PolygonBuilder builder = this.getContext().getShapeFactory().polygon(); for (double[] coordinate : coordinates) { Preconditions.checkArgument(coordinate.length==2 && Geoshape.isValidCoordinate(coordinate[1], coordinate[0]), "Invalid coordinate provided"); builder.pointXY(coordinate[0], coordinate[1]); } return new Geoshape(builder.build()); }
add(store, "doc6", getDocument("A Full Yes", -100, -11.2, Geoshape.point(48.0, 8.0), multiLine, Arrays.asList("10", "11", "12"), Sets.newHashSet("10", "11"), Instant.ofEpochSecond(400)), true); final Geoshape multiPolygon = Geoshape.geoshape(Geoshape.getShapeFactory().multiPolygon() .add(Geoshape.getShapeFactory().polygon().pointXY(59.0, 59.0).pointXY(61.0, 59.0).pointXY(61.0, 61.0).pointXY(59.0, 61.0).pointXY(59.0, 59.0)) .add(Geoshape.getShapeFactory().polygon().pointXY(119.0, 59.0).pointXY(121.0, 59.0).pointXY(121.0, 61.0).pointXY(119.0, 61.0).pointXY(119.0, 59.0)).build()); add(store, "doc7", getDocument("A Full Yes", -100, -11.2, Geoshape.point(48.0, 8.0), multiPolygon, Arrays.asList("10", "11", "12"), Sets.newHashSet("10", "11"), Instant.ofEpochSecond(400)), true); final Geoshape geometryCollection = Geoshape.geoshape(Geoshape.getGeometryCollectionBuilder().add(Geoshape.getShapeFactory().pointXY(60.0, 60.0))
/** * Parses a POLYGON shape from the raw string. It might return a * {@link org.locationtech.spatial4j.shape.Rectangle} if the polygon is one. * * <pre> * coordinateSequenceList * </pre> */ protected Shape parsePolygonShape(WKTReader.State state) throws ParseException { ShapeFactory.PolygonBuilder polygonBuilder = shapeFactory.polygon(); if (!state.nextIfEmptyAndSkipZM()) { polygonBuilder = polygon(state, polygonBuilder); } return polygonBuilder.buildOrRect(); }
ShapeFactory.PolygonBuilder b = factory.polygon(); fillPolygon(b, arr); return b.buildOrRect();
protected Shape readPolygon(XReader reader) throws IOException { ShapeFactory.PolygonBuilder polyBuilder = shpFactory.polygon(); reader.readPoints(polyBuilder); if(!reader.isDone() && reader.peek()==PolyshapeWriter.KEY_ARG_START) { List<LinearRing> list = new ArrayList<LinearRing>(); while(reader.isEvent() && reader.peek()==PolyshapeWriter.KEY_ARG_START) { reader.readKey(); // eat the event; reader.readPoints(polyBuilder.hole()).endHole(); } } return polyBuilder.build(); }
protected Shape readShapeFromCoordinates(String type, JSONParser parser) throws IOException, ParseException { switch(type) { case "Point": return readPoint(parser); case "LineString": return readLineString(parser); case "Circle": return readCircle(parser); case "Polygon": return readPolygon(parser, shapeFactory.polygon()).buildOrRect(); case "MultiPoint": return readMultiPoint(parser); case "MultiLineString": return readMultiLineString(parser); case "MultiPolygon": return readMultiPolygon(parser); default: throw new ParseException("Unable to make shape type: " + type, (int) parser.getPosition()); } }