android - How to "round" GeoJSON coordinates using mapbox
问题描述
I am developing a react-native-mapbox-gl app on Windows 10. I need to "round" GeoJSON points uploaded to the app so that they appear in the center of a house block. For example:
Figure 1: A marker is added on the northeaster corner of a block
Figure 2: The marker is "rounded" / "moved" to the geographical center of the block
Since it's unfeasible to manually create a GeoJSON geometry for every street there is, is there a way to achieve this?
解决方案
If you encode the boundaries of a particular block as a Polygon
feature, you can then use Turf.js's centroid
method to calculate the center of said polygon. This will return a coordinate that can be used for the location of the marker.
If you don't have the geographic bounds of these features, one option would be to use the Mapbox Tilequery API to query for all building features within a particular radius, and then create a LatLngBounds
object containing these buildings to use as the Polygon
defining the boundaries of the block.
推荐阅读
- django - 如何在 django 中获取 webpack 文件?
- c# - 我可以在 ASP.NET 和 C# 的 Web 应用程序中嵌入程序的输出吗
- octave - 如何防止 Octave 对行向量和列向量求和?
- css - 在 Angular 7 中使用 PrimeNG 的 flexgrid 没有任何效果
- python - 为什么我列出素数的简单程序告诉我“builtin_function_or_method”对象不可下标?
- python - AttributeError:“datetime.timezone”对象没有属性“_utcoffset”
- php - Laravel 组计数
- mongodb - 如何在graphql和mongodb的一个突变中保存多行?
- mysql - 具有非计数的 Mysql 数据透视表
- php - 从数据中删除某些字符以使其成为有效的 json