private org.locationtech.spatial4j.shape.Point getSpatial4jPoint() { return getShapeFactory().pointXY(longitude, latitude); }
/** * Constructs a circle from a given center point and a radius in kilometer * @param latitude * @param longitude * @param radiusInKM * @return */ public static Geoshape circle(final double latitude, final double longitude, final double radiusInKM) { Preconditions.checkArgument(isValidCoordinate(latitude, longitude), "Invalid coordinate provided"); Preconditions.checkArgument(radiusInKM > 0, "Invalid radius provided [%s]", radiusInKM); return new Geoshape(getShapeFactory().circle(longitude, latitude, DistanceUtils.dist2Degrees(radiusInKM, DistanceUtils.EARTH_MEAN_RADIUS_KM))); }
/** * Constructs a line from list of coordinates * @param coordinates Coordinate (lon,lat) pairs * @return */ public static Geoshape line(List<double[]> coordinates) { Preconditions.checkArgument(coordinates.size() >= 2, "Too few coordinate pairs provided"); final LineStringBuilder builder = getShapeFactory().lineString(); for (double[] coordinate : coordinates) { Preconditions.checkArgument(isValidCoordinate(coordinate[1], coordinate[0]), "Invalid coordinate provided"); builder.pointXY(coordinate[0], coordinate[1]); } return new Geoshape(builder.build()); }
lastShape = shpFactory.pointXY(shpFactory.normX(reader.readLat()), shpFactory.normY(reader.readLng())); break; ShapeFactory.LineStringBuilder lineBuilder = shpFactory.lineString(); reader.readPoints(lineBuilder); lineBuilder.buffer(shpFactory.normDist(arg)); double lat1 = shpFactory.normX(reader.readLat()); double lon1 = shpFactory.normY(reader.readLng()); lastShape = shpFactory.rect(lat1, shpFactory.normX(reader.readLat()), lon1, shpFactory.normY(reader.readLng())); break; lastShape = reader.readPoints(shpFactory.multiPoint()).build(); break; throw new IllegalArgumentException("the input should have a radius argument"); lastShape = shpFactory.circle(shpFactory.normX(reader.readLat()), shpFactory.normY(reader.readLng()), shpFactory.normDist(arg.doubleValue())); break; ShapeFactory.MultiShapeBuilder<Shape> multiBuilder = shpFactory.multiShape(Shape.class); for (Shape shp : shapes) { multiBuilder.add(shp);
remove(store, "doc1", ImmutableMultimap.of(TIME, 1001), false); add(store, "doc1", ImmutableMultimap.of(TIME, 1005, WEIGHT, 11.1, LOCATION, Geoshape.point(-48.0, 0.0), BOUNDARY, Geoshape.circle(-48.0, 0.0, 1.0)), false); final Geoshape multiPoint = Geoshape.geoshape(Geoshape.getShapeFactory().multiPoint().pointXY(60.0, 60.0).pointXY(120.0, 60.0).build()); add(store, "doc5", getDocument("A Full Yes", -100, -11.2, Geoshape.point(48.0, 8.0), multiPoint, Arrays.asList("10", "11", "12"), Sets.newHashSet("10", "11"), Instant.ofEpochSecond(400)), true); final Geoshape multiLine = Geoshape.geoshape(Geoshape.getShapeFactory().multiLineString().add(Geoshape.getShapeFactory().lineString().pointXY(59.0, 60.0).pointXY(61.0, 60.0)) .add(Geoshape.getShapeFactory().lineString().pointXY(119.0, 60.0).pointXY(121.0, 60.0)).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)) .add(Geoshape.getShapeFactory().lineString().pointXY(119.0, 60.0).pointXY(121.0, 60.0).build()).build()); add(store, "doc8", getDocument("A Full Yes", -100, -11.2, Geoshape.point(48.0, 8.0), geometryCollection, Arrays.asList("10", "11", "12"), Sets.newHashSet("10", "11"), Instant.ofEpochSecond(400)), true);
ShapeFactory.MultiShapeBuilder<Shape> b = factory.multiShape(Shape.class); ArrayNode arr = (ArrayNode)node.get("geometries"); for(int i=0; i<arr.size(); i++) { ShapeFactory.MultiPointBuilder b = factory.multiPoint(); fillPoints(b, arr); return b.build(); ShapeFactory.MultiLineStringBuilder builder = factory.multiLineString(); for(int i=0; i<arr.size(); i++) { ShapeFactory.LineStringBuilder b = builder.lineString(); ShapeFactory.LineStringBuilder builder = factory.lineString(); fillPoints(builder, arr); builder.buffer(buffer); ShapeFactory.PolygonBuilder b = factory.polygon(); fillPolygon(b, arr); return b.buildOrRect(); ShapeFactory.MultiPolygonBuilder buildier = factory.multiPolygon(); for(int i=0; i<arr.size(); i++) { ShapeFactory.PolygonBuilder b = buildier.polygon(); return factory.circle(readPoint(arr, factory), radius);
ShapeFactory.MultiPointBuilder shapeBuilder = sf.multiPoint(); Collection<ShapePoint> shapePoints = gtfsData.getAllShapePoints(); if (shapePoints != null && !ignoreShapes && shapePoints.size() > 3) { List<ShapePoint> tripShape = mShapePoints.get(shapeAgencyAndId.getId()); if (tripShape != null) { ShapeFactory.LineStringBuilder lineBuilder = sf.lineString(); for (ShapePoint p : tripShape) { lineBuilder.pointXY(p.getLon(), p.getLat()); ShapeFactory.MultiPointBuilder stopBuilder = sf.multiPoint(); Collection<Stop> stops = gtfsData.getAllStops(); for (Stop stop : stops) {
/** * Constructs a new box shape which is identified by its south-west and north-east corner points * @param southWestLatitude * @param southWestLongitude * @param northEastLatitude * @param northEastLongitude * @return */ public static Geoshape box(final double southWestLatitude, final double southWestLongitude, final double northEastLatitude, final double northEastLongitude) { Preconditions.checkArgument(isValidCoordinate(southWestLatitude, southWestLongitude), "Invalid south-west coordinate provided"); Preconditions.checkArgument(isValidCoordinate(northEastLatitude, northEastLongitude), "Invalid north-east coordinate provided"); return new Geoshape(getShapeFactory().rect(southWestLongitude, northEastLongitude, southWestLatitude, northEastLatitude)); }
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()); }
/** * Parses an ENVELOPE (aka Rectangle) shape from the raw string. The values are normalized. * <p> * Source: OGC "Catalogue Services Specification", the "CQL" (Common Query Language) sub-spec. * <em>Note the inconsistent order of the min & max values between x & y!</em> * * <pre> * '(' x1 ',' x2 ',' y2 ',' y1 ')' * </pre> */ protected Shape parseEnvelopeShape(State state) throws ParseException { // FYI no dimension or EMPTY state.nextExpect('('); double x1 = state.nextDouble(); state.nextExpect(','); double x2 = state.nextDouble(); state.nextExpect(','); double y2 = state.nextDouble(); state.nextExpect(','); double y1 = state.nextDouble(); state.nextExpect(')'); return shapeFactory.rect(shapeFactory.normX(x1), shapeFactory.normX(x2), shapeFactory.normY(y1), shapeFactory.normY(y2)); }
protected Shape readMultiPoint(JSONParser parser) throws IOException, ParseException { assert (parser.lastEvent() == JSONParser.ARRAY_START); ShapeFactory.MultiPointBuilder builder = shapeFactory.multiPoint(); readCoordListXYZ(parser, builder); return builder.build(); }
public static MultiShapeBuilder<Shape> getGeometryCollectionBuilder() { return getShapeFactory().multiShape(Shape.class); }
protected Shape readMultiPolygon(JSONParser parser) throws IOException, ParseException { assert (parser.lastEvent() == JSONParser.ARRAY_START); // TODO need Spatial4j Polygon interface ShapeFactory.MultiPolygonBuilder builder = shapeFactory.multiPolygon(); int evt = parser.nextEvent(); while (true) { switch (evt) { case JSONParser.ARRAY_START: ShapeFactory.PolygonBuilder polygonBuilder = readPolygon(parser, builder.polygon()); builder.add(polygonBuilder); break; case JSONParser.ARRAY_END: return builder.build(); default: throw new ParseException("Unexpected " + JSONParser.getEventString(evt), (int) parser.getPosition()); } evt = parser.nextEvent(); } } }
protected Shape readMultiLineString(JSONParser parser) throws IOException, ParseException { assert (parser.lastEvent() == JSONParser.ARRAY_START); // TODO need Spatial4j LineString interface ShapeFactory.MultiLineStringBuilder builder = shapeFactory.multiLineString(); int evt = parser.nextEvent(); while (true) { switch (evt) { case JSONParser.ARRAY_START: ShapeFactory.LineStringBuilder lineStringBuilder = builder.lineString(); readCoordListXYZ(parser, lineStringBuilder); builder.add(lineStringBuilder); break; case JSONParser.ARRAY_END: return builder.build(); default: throw new ParseException("Unexpected " + JSONParser.getEventString(evt), (int) parser.getPosition()); } evt = parser.nextEvent(); } }
/** Construct a rectangle. */ @Deprecated public Rectangle makeRectangle(Point lowerLeft, Point upperRight) { return shapeFactory.rect(lowerLeft, upperRight); }
/** * 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(); }
/** * Parses a MULTIPOINT shape from the raw string -- a collection of points. * * <pre> * '(' coordinate (',' coordinate )* ')' * </pre> * * Furthermore, coordinate can optionally be wrapped in parenthesis. * * @see #point(State, ShapeFactory.PointsBuilder) */ protected Shape parseMultiPointShape(State state) throws ParseException { ShapeFactory.MultiPointBuilder builder = shapeFactory.multiPoint(); if (state.nextIfEmptyAndSkipZM()) return builder.build(); state.nextExpect('('); do { boolean openParen = state.nextIf('('); point(state, builder); if (openParen) state.nextExpect(')'); } while (state.nextIf(',')); state.nextExpect(')'); return builder.build(); }
/** Construct a ShapeCollection, analogous to an OGC GeometryCollection. */ @Deprecated public <S extends Shape> ShapeCollection<S> makeCollection(List<S> coll) { return shapeFactory.multiShape(coll); }
/** * Parses a MULTIPOLYGON shape from the raw string. * * <pre> * '(' polygon (',' polygon )* ')' * </pre> */ protected Shape parseMulitPolygonShape(WKTReader.State state) throws ParseException { ShapeFactory.MultiPolygonBuilder multiPolygonBuilder = shapeFactory.multiPolygon(); if (!state.nextIfEmptyAndSkipZM()) { state.nextExpect('('); do { multiPolygonBuilder.add(polygon(state, multiPolygonBuilder.polygon())); } while (state.nextIf(',')); state.nextExpect(')'); } return multiPolygonBuilder.build(); }