获取Mapbox中geogson功能的坐标

问题描述 投票:4回答:2

GeoJson功能如下所示:

{
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [
      43.59375,
      59.17592824927136
    ]
  }
}

在使用Java / JVM的Mapbox中,我们可以构建如下的功能:

val testFeature = Feature.fromGeometry(Point.fromLngLat(2.0,3.0))

但我似乎没有找到一种方法来获取坐标/指向功能。

有一个Feature#getGeometry()但我不能从那里获得坐标,因为它只是GeoJson界面本身的糖。

java android mapbox geojson mapbox-android
2个回答
1
投票

每个特征都有一个.coordinates()方法返回一个List<Point>List<List<Point>对象(除非你在Point特征上调用它,在这种情况下它将返回一个List<Double>

[来源:core API's geojson documentation]


1
投票

我刚刚发现每个特征公开了我们可以投射到任何类型(Point,Line,polygon,Multipoit等等)的方法.geometry()。从那里我们可以得到PointList<Point>

示例:

val position1 = feature1.geometry() as Point
val longitude = position1.longitude()

val area1 = feature2.geometry() as MultiPoint
val firstPointLatitude = area1.coordinates()!![0].latitude()
© www.soinside.com 2019 - 2024. All rights reserved.