/** * Create a Point from the given coordinates. * * @param lon The x axis value. Longitude in a geographic projection. * @param lat The y axis value. Latitude in a geographic projection. * @return Point instance. */ public static Point from(double lon, double lat) { return from(lon, lat, Double.NaN); }
/** * Create a Point from the given coordinates. * * @param lon The x axis value. Longitude in a geographic projection. * @param lat The y axis value. Latitude in a geographic projection. * @return Point instance. */ public static Point from(double lon, double lat) { return from(lon, lat, Double.NaN); }
protected static Point fromJtsPoint(com.vividsolutions.jts.geom.Point src) { Coordinate coordinate = src.getCoordinate(); return Point.from(coordinate.x, coordinate.y, coordinate.z); }
/** * Returns a new Point instance with the given x-axis value. * * @param lat The new latitude value. * @return A Point instance with this instance longitude and the given latitude. */ public Point withLat(double lat) { return from(lon(), lat, alt()); }
/** * Returns a new Point instance with the given z-axis value. * * @param alt The new latitude value. * @return A Point instance with this instance longitude and the given latitude. */ public Point withAlt(double alt) { return from(lon(), lat(), alt); }
/** * Returns a new Point instance with the given x-axis value. * * @param lat The new latitude value. * @return A Point instance with this instance longitude and the given latitude. */ public Point withLat(double lat) { return from(lon(), lat, alt()); }
/** * Returns a new Point instance with the given x-axis value. * * @param lon The new longitude value. * @return A Point instance with this instance latitude and the given longitude */ public Point withLon(double lon) { return from(lon, lat(), alt()); }
/** * Returns a new Point instance with the given z-axis value. * * @param alt The new latitude value. * @return A Point instance with this instance longitude and the given latitude. */ public Point withAlt(double alt) { return from(lon(), lat(), alt); }
@Test public void shouldHandleMultiPolygonWithSinglePolygonWithHoles() { MultiPolygon source = MultiPolygon.of( Polygon.of( LinearRing.of(Point.from(120.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(120.3, 45.3)), LinearRing.of(Point.from(150.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(150.3, 45.3)), LinearRing.of(Point.from(140.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(140.3, 45.3)) ) ); MultiPolygon parsed = this.toTest.fromJson(this.toTest.toJson(source), MultiPolygon.class); assertThat(parsed, equalTo(source)); }
@Test public void shouldHandlePolygon() { Polygon source = Polygon.of( LinearRing.of(Point.from(120.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(120.3, 45.3)), LinearRing.of(Point.from(120.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(120.3, 45.3)) ); Polygon parsed = toTest.fromJson(toTest.toJson(source), Polygon.class); assertThat(parsed, equalTo(source)); }
@Test public void shouldHandleMultiPolygonWithPolygonsWithoutHoles() { MultiPolygon source = MultiPolygon.of( Polygon.of(LinearRing.of(Point.from(120.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(120.3, 45.3))), Polygon.of(LinearRing.of(Point.from(150.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(150.3, 45.3))) ); MultiPolygon parsed = this.toTest.fromJson(this.toTest.toJson(source), MultiPolygon.class); assertThat(parsed, equalTo(source)); }
@Test public void shouldHandlePolygonWithoutHoles() { Polygon source = Polygon.of( LinearRing.of(Point.from(120.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(120.3, 45.3)) ); Polygon parsed = this.toTest.fromJson(this.toTest.toJson(source), Polygon.class); assertThat(parsed, equalTo(source)); }
@Test public void shouldHandleMultiLineString() { MultiLineString source = MultiLineString.of( LineString.of(Point.from(14.5, 47.3), Point.from(42.19, 3.8)), LineString.of(Point.from(11.3, 44.3), Point.from(42.9, 2.8), Point.from(10.1, 46.1)) ); MultiLineString parsed = this.toTest.fromJson(this.toTest.toJson(source), MultiLineString.class); assertThat(parsed, equalTo(source)); }
@Test public void shouldHandlePoint() { Point point = Point.from(56.7, 83.6); Point parsed = toTest.fromJson(toTest.toJson(point), Point.class); assertThat(parsed, equalTo(point)); }
@Test public void shouldHandleMultiPolygonWithSinglePolygonWithoutHoles() { MultiPolygon source = MultiPolygon.of( Polygon.of(LinearRing.of(Point.from(120.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(120.3, 45.3))) ); MultiPolygon parsed = this.toTest.fromJson(this.toTest.toJson(source), MultiPolygon.class); assertThat(parsed, equalTo(source)); }
@Test public void shouldHandleMultiLineStringWithSingleLineString() { MultiLineString source = MultiLineString.of( LineString.of(Point.from(14.5, 47.3), Point.from(42.19, 3.8)) ); MultiLineString parsed = this.toTest.fromJson(this.toTest.toJson(source), MultiLineString.class); assertThat(parsed, equalTo(source)); }
@Test public void shouldHandleFeaturesWithoutId() { Feature feature = FeatureUtils.featureWithGeometry(Point.from(12.3, 45.3)); Feature parsed = toTest.fromJson(toTest.toJson(feature), Feature.class); assertThat(parsed, is(feature)); }