com.mapbox.geojson.Point类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(291)

本文整理了Java中com.mapbox.geojson.Point类的一些代码示例,展示了Point类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Point类的具体详情如下:
包路径:com.mapbox.geojson.Point
类名称:Point

Point介绍

[英]A point represents a single geographic position and is one of the seven Geometries found in the GeoJson spec.

This adheres to the RFC 7946 internet standard when serialized into JSON. When deserialized, this class becomes an immutable object which should be initiated using its static factory methods.

Coordinates are in x, y order (easting, northing for projected coordinates), longitude, and latitude for geographic coordinates), precisely in that order and using double values. Altitude or elevation MAY be included as an optional third parameter while creating this object.

The size of a GeoJson text in bytes is a major interoperability consideration, and precision of coordinate values has a large impact on the size of texts when serialized. For geographic coordinates with units of degrees, 6 decimal places (a default common in, e.g., sprintf) amounts to about 10 centimeters, a precision well within that of current GPS systems. Implementations should consider the cost of using a greater precision than necessary.

Furthermore, pertaining to altitude, the WGS 84 datum is a relatively coarse approximation of the geoid, with the height varying by up to 5 m (but generally between 2 and 3 meters) higher or lower relative to a surface parallel to Earth's mean sea level.

A sample GeoJson Point's provided below (in its serialized state).

{ 
"type": "Point", 
"coordinates": [100.0, 0.0] 
}

[中]一个点代表一个地理位置,是GeoJson规范中七种几何图形之一。
当序列化为JSON时,它遵守RFC 7946互联网标准。反序列化时,该类将成为一个不可变对象,应使用其静态工厂方法启动该对象。
坐标按x、y顺序(投影坐标为东、北)、地理坐标为经度和纬度),精确地按该顺序并使用双值。创建此对象时,可以将高度或高程作为可选的第三个参数。
GeoJson文本的大小(以字节为单位)是一个主要的互操作性考虑因素,而坐标值的精度在序列化时对文本的大小有很大影响。对于以度为单位的地理坐标,小数点后6位(例如sprintf中常见的默认值)相当于约10厘米,这一精度与当前GPS系统相当。实现应该考虑使用比需要的精度更高的成本。
此外,关于高度,WGS 84基准面是大地水准面的一个相对粗略的近似值,相对于平行于地球平均海平面的表面,其高度可高或低5米(但通常在2到3米之间)。
下面提供了一个示例GeoJson点(处于序列化状态)。

{ 
"type": "Point", 
"coordinates": [100.0, 0.0] 
}

代码示例

代码示例来源:origin: mapbox/mapbox-java

private static List<Point> formatCoordinates(String coordinates) {
 String[] coordPairs = coordinates.split(";", -1);
 List<Point> coordinatesFormatted = new ArrayList<>();
 for (String coordPair : coordPairs) {
  String[] coords = coordPair.split(",", -1);
  coordinatesFormatted.add(
   Point.fromLngLat(Double.valueOf(coords[0]), Double.valueOf(coords[1])));
 }
 return coordinatesFormatted;
}

代码示例来源:origin: mapbox/mapbox-java

/**
 * Square distance between 2 points.
 *
 * @param p1 first {@link Point}
 * @param p2 second Point
 * @return square of the distance between two input points
 */
private static double getSqDist(Point p1, Point p2) {
 double dx = p1.longitude() - p2.longitude();
 double dy = p1.latitude() - p2.latitude();
 return dx * dx + dy * dy;
}

代码示例来源:origin: com.mapbox.mapboxsdk/mapbox-sdk-geojson

/**
 * This returns a double value ranging from -180 to 180 representing the x or easting position of
 * this point. ideally, this value would be restricted to 6 decimal places to correctly follow the
 * GeoJson spec.
 *
 * @return a double value ranging from -180 to 180 representing the x or easting position of this
 *   point
 * @since 3.0.0
 */
public double longitude() {
 return coordinates().get(0);
}

代码示例来源:origin: mapbox/mapbox-java

@Override
public List<Double> unshiftPoint(Point shiftedPoint) {
 return Arrays.asList(shiftedPoint.longitude() - 3,
     shiftedPoint.latitude() - 5,
     shiftedPoint.altitude() - 8);
}

代码示例来源:origin: mapbox/mapbox-java

@Test
public void fromJson() throws IOException {
 final String json = loadJsonFixture(SAMPLE_MULTIPOLYGON);
 MultiPolygon geo = MultiPolygon.fromJson(json);
 assertEquals(geo.type(), "MultiPolygon");
 assertEquals(geo.coordinates().get(0).get(0).get(0).longitude(), 102.0, DELTA);
 assertEquals(geo.coordinates().get(0).get(0).get(0).latitude(), 2.0, DELTA);
 assertFalse(geo.coordinates().get(0).get(0).get(0).hasAltitude());
}

代码示例来源:origin: mapbox/mapbox-java

@Test
public void turfAlong_returnsZeroWhenRouteIsPoint() throws Exception {
 List<Point> coords = new ArrayList<>();
 coords.add(Point.fromLngLat(1.0, 1.0));
 LineString lineString = LineString.fromLngLats(coords);
 Point point = TurfMeasurement.along(lineString, 0, TurfConstants.UNIT_METERS);
 assertEquals(1.0, point.latitude(), DELTA);
 assertEquals(1.0, point.longitude(), DELTA);
}

代码示例来源:origin: mapbox/mapbox-java

@Test
public void latitude_doesReturnCorrectValue() throws Exception {
 Point point = Point.fromLngLat(1.0, 2.0, 5.0);
 assertEquals(2, point.latitude(), DELTA);
}

代码示例来源:origin: mapbox/mapbox-java

@Test
public void longitude_doesReturnCorrectValue() throws Exception {
 Point point = Point.fromLngLat(1.0, 2.0, 5.0);
 assertEquals(1, point.longitude(), DELTA);
}

代码示例来源:origin: mapbox/mapbox-java

@Test
public void fromJson() throws IOException {
 final String json = loadJsonFixture(SAMPLE_MULTIPOINT);
 MultiPoint geo = MultiPoint.fromJson(json);
 assertEquals(geo.type(), "MultiPoint");
 assertEquals(geo.coordinates().get(0).longitude(), 100.0, DELTA);
 assertEquals(geo.coordinates().get(0).latitude(), 0.0, DELTA);
 assertEquals(geo.coordinates().get(1).longitude(), 101.0, DELTA);
 assertEquals(geo.coordinates().get(1).latitude(), 1.0, DELTA);
 assertFalse(geo.coordinates().get(0).hasAltitude());
 assertEquals(Double.NaN, geo.coordinates().get(0).altitude(), DELTA);
}

代码示例来源:origin: mapbox/mapbox-java

@Test
public void point_hasAltitudeValueNoBoundingBox() throws Exception {
 Point point = Point.fromLngLat(100, 0, 200);
 compareJson(loadJsonFixture(POINT_WITH_ALTITUDE_NO_BBOX_FIXTURE), point.toJson());
}

代码示例来源:origin: mapbox/mapbox-java

/**
 * Convenience method for getting the bounding box most westerly point (longitude) as a double
 * coordinate.
 *
 * @return the most westerly coordinate inside this bounding box
 * @since 3.0.0
 */
public final double west() {
 return southwest().longitude();
}

代码示例来源:origin: com.mapbox.mapboxsdk/mapbox-sdk-geojson

/**
 * Convenience method for getting the bounding box most westerly point (longitude) as a double
 * coordinate.
 *
 * @return the most westerly coordinate inside this bounding box
 * @since 3.0.0
 */
public final double north() {
 return northeast().latitude();
}

代码示例来源:origin: mapbox/mapbox-java

@Test
public void altitude_doesReturnCorrectValueFromDoubleArray() throws Exception {
 double[] coords = new double[] {1.0, 2.0, 5.0};
 Point point = Point.fromLngLat(coords);
 assertEquals(5, point.altitude(), DELTA);
}

代码示例来源:origin: mapbox/mapbox-java

@Test
public void bbox_nullWhenNotSet() throws Exception {
 Point point = Point.fromLngLat(1.0, 2.0);
 assertNull(point.bbox());
}

代码示例来源:origin: mapbox/mapbox-java

@Test
public void passingInSingleFeature_doesHandleCorrectly() throws Exception {
 Point geometry = Point.fromLngLat(1.0, 2.0);
 Feature feature = Feature.fromGeometry(geometry);
 FeatureCollection geo = FeatureCollection.fromFeature(feature);
 assertNotNull(geo.features());
 assertEquals(1, geo.features().size());
 assertEquals(2.0, ((Point) geo.features().get(0).geometry()).coordinates().get(1), DELTA);
}

代码示例来源:origin: com.mapbox.mapboxsdk/mapbox-sdk-geojson

/**
 * Optionally, the coordinate spec in GeoJson allows for altitude values to be placed inside the
 * coordinate array. If an altitude value was provided while initializing this instance, this will
 * return true.
 *
 * @return true if this instance of point contains an altitude value
 * @since 3.0.0
 */
public boolean hasAltitude() {
 return !Double.isNaN(altitude());
}

代码示例来源:origin: mapbox/mapbox-java

@Test
public void fromJsonHoles() throws IOException {
 final String json = loadJsonFixture(SAMPLE_POLYGON_HOLES);
 Polygon geo = Polygon.fromJson(json);
 assertEquals("Polygon", geo.type());
 assertEquals(100.0, geo.coordinates().get(0).get(0).longitude(), DELTA);
 assertEquals(0.0, geo.coordinates().get(0).get(0).latitude(), DELTA);
 assertEquals(2, geo.coordinates().size());
 assertEquals(100.8, geo.coordinates().get(1).get(0).longitude(), DELTA);
 assertEquals(0.8, geo.coordinates().get(1).get(0).latitude(), DELTA);
 assertFalse(geo.coordinates().get(0).get(0).hasAltitude());
}

代码示例来源:origin: mapbox/mapbox-java

@Test
public void passingInSingleLineString_doesHandleCorrectly() throws Exception {
 List<Point> points = new ArrayList<>();
 points.add(Point.fromLngLat(1.0, 2.0));
 points.add(Point.fromLngLat(3.0, 4.0));
 LineString geometry = LineString.fromLngLats(points);
 MultiLineString multiLineString = MultiLineString.fromLineString(geometry);
 assertNotNull(multiLineString);
 assertEquals(1, multiLineString.lineStrings().size());
 assertEquals(2.0, multiLineString.lineStrings().get(0).coordinates().get(0).latitude(), DELTA);
}

代码示例来源:origin: mapbox/mapbox-java

@Test
public void point_deserializeArray() throws Exception {
 String jsonString = "[100.0, 0.0, 200.0]";
 GsonBuilder gsonBuilder = new GsonBuilder()
  .registerTypeAdapter(Point.class, new PointDeserializer());
 Point point = gsonBuilder.create().fromJson(jsonString, Point.class);
 assertEquals(100, point.longitude(), DELTA);
 assertEquals(0, point.latitude(), DELTA);
 assertEquals(200, point.altitude(), DELTA);
}

代码示例来源:origin: mapbox/mapbox-java

@Test
public void point_hasAltitudeValueWithBoundingBox() throws Exception {
 Point point = Point.fromLngLat(100, 0, 200,
  BoundingBox.fromLngLats(-100, -10, 100, 100, 10, 200));
 compareJson(loadJsonFixture(POINT_WITH_ALTITUDE_AND_BBOX_FIXTURE), point.toJson());
}

相关文章