标签: turfjs

mapbox-gl-js:对于给定的音高,调整可见区域和轴承到给定的线

我正在尝试优化长途远足径的Mapbox视图,例如Appalachian Trail或Pacific Crest Trail.这是一个例子,我手工定向,展示了西班牙的SendaPirenáica:

屏幕截图

给出了感兴趣的区域,视口和音高.我需要找到正确的中心,方位和缩放.

这个map.fitBounds方法对我没有帮助,因为它假设pitch = 0且bearing = 0.

我做了一些戳,这似乎是最小的周围矩形问题的变化,但我仍然坚持一些额外的复杂性:

  1. 我如何解释音高的扭曲效果?
  2. 如何优化视口的宽高比?请注意,将视口缩小或更宽会改变最佳解决方案的方位:

草图

FWIW我也使用turf-js,这可以帮助我获得线的凸包.

javascript mapbox turfjs mapbox-gl-js

17
推荐指数
1
解决办法
1237
查看次数

草皮中质心和 centerOfMass 之间的差异

我需要找到点的地理空间坐标,这是我的 GeoJSON 数据集中所有要素之间距离的平均值。在 turf.js 中,centroid 和 centerOfMass 都出现了。centerOfMass 的解释是它“采用任何 Feature 或 FeatureCollection 并使用此公式返回其质心:多边形质心。” 但是应用于我的功能的 centroid 和 centerOfMass 给出了不同的结果。它们之间有什么区别?那应该用什么?

javascript turfjs

7
推荐指数
1
解决办法
762
查看次数

Geojson/ turf :将多个多边形合并到一个保留洞的多边形中

所以我想在 javascript 中合并相邻的多边形,这就是我在代码中实际拥有的:

地图

我想删除内部描边但保留边框描边。

所以我想从这里开始:

地图2

对此:

地图3

我想保留巴黎的洞 - 我可以定义哪些多边形必须分组,但我无法将它们与以下代码合并:

var map = L.map('map', {
    center: [46.52863469527167, 2.43896484375],
    zoom: 6,
    maxZoom: 18,
    minZoom: 7
});
$http.get("france.json").then(function (response) {
    $scope.communeFr = response.data.features
    $http.get(apiult).then(function (response) {
        $scope.showCommune = response.data.Liste
        $scope.communeFr.map(x => {
            x.show = false
            for (let i = 0; i < $scope.showCommune .length; i++) {
                if (x.properties.insee == $scope.showCommune[i].insee) {
                    x.show = true
                    return
                }
            }                
        })
        L.geoJson($scope.communeFr, {
            filter: function (feature, latlng) {
                return feature.show 
            }
        }).addTo(map);
    });
    
});
Run Code Online (Sandbox Code Playgroud)

更新 - …

polygon geojson leaflet turfjs

7
推荐指数
1
解决办法
7553
查看次数

如何在单击时更改 mapbox gl 中的图标大小?

我想根据最近的草皮更改地图点击时的图标大小。我如何做到这一点?nearestBuilding.properties['icon-size'] = 0.2;不起作用。

var retail = {
        type: 'FeatureCollection',
        features: [
            { 
                type: 'Feature',
                properties: {
                    title: 'TEST',
                    description: 'TEST'
                },
                geometry: {
                    type: 'Point',
                    coordinates: [121.051779, 14.550224]
                }
            },
            { 
                type: 'Feature',
                properties: {
                    title: 'TEST',
                    description: 'TEST'
                },
                geometry: {
                    type: 'Point',
                    coordinates: [121.04568958282472, 14.552170837008527]
                } 
            }
        ]
    };

    map.on('load', function() {
        map.loadImage('https://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Wiki_Loves_Earth_map_marker.svg/600px-Wiki_Loves_Earth_map_marker.svg.png', function(error, image) {
            if (error) throw error;
            map.addImage('marker', image);

            map.addLayer({
                id: 'retail',
                type: 'symbol',
                source: {
                  type: 'geojson',
                  data: retail
                },
                layout: { …
Run Code Online (Sandbox Code Playgroud)

turfjs mapbox-gl-js

6
推荐指数
1
解决办法
6420
查看次数

未捕获的错误:坐标只能包含数字(Turf和Mapbox)

当我在地图框上使用草皮时,特别是以下行,它会产生错误var nearestBuilding = turf.nearest(currentLocation, geoJson);。我使用mapbox-gl和草皮来获取最近的建筑物。当我手动输入数据而无需object.push()但我需要数据库中的信息时,它会起作用。

var object = [];

for (var x = 0; x < json.length; x++) {
  var 
    image = json[x].image == '' ? '' : "<div style='text-align:center;'><img src='" + json[x].image + "' width='100' height='75' /></div>",
    number = json[x].contact == '' ? '' : "<br/>" + json[x].contact,
    details = json[x].details == '' ? '' : '<br/>' + '<a href="{{ url('restaurants-and - cafe') }}/' + json[x].details + '">More Details</a>';

  object.push({
    type: 'Feature',
    properties: {
      title: …
Run Code Online (Sandbox Code Playgroud)

javascript turfjs mapbox-gl-js

6
推荐指数
0
解决办法
1214
查看次数

检查 Turf.js 中一个多边形是否与另一个多边形相交

我在应用程序中使用Turf.js进行高级地理空间分析,但找不到一种检查两个多边形是否相互交叉的方法。Intersect方法不是我想要的,因为如果我有一个小多边形并且想要找到穿过这个小多边形的多边形,则此方法将返回包含这个较小多边形的大重叠多边形。

让我直观地解释一下。所以,这就是我所拥有的多边形:

在此输入图像描述

在这种情况下,多边形彼此相交:

在此输入图像描述

在这种情况下,我认为它们不相交:

在此输入图像描述

在最后一种情况下,绿色多边形的边界不与较小的多边形相交,因此它们不相交。

我的问题是,是否可以在 Turf.js 中实现这种交集功能?

javascript geospatial turfjs

5
推荐指数
1
解决办法
3051
查看次数

如何将坐标的 JSON 数据提供给 turf.polygon?

如何将坐标的 JSON 数据提供给 turf.polygon?

示例: turf.polygon();

var polygon = turf.polygon([[
 [-2.275543, 53.464547],
 [-2.275543, 53.489271],
 [-2.215118, 53.489271],
 [-2.215118, 53.464547],
 [-2.275543, 53.464547]
]], { name: 'poly1', population: 400});
Run Code Online (Sandbox Code Playgroud)

示例: JSON 形式

var json = 
{
    "type": "geojson",
    "data": 
        {
         "type": "FeatureCollection",
         "features": [{
               "type": "Feature",
               "geometry": {
                   "type": "Polygon",
                   "coordinates": [[
                         [1.275543, 54.464547], // I want to feed these coordinates
                         [1.275543, 54.489271],
                         [1.215118, 54.489271],
                         [1.215118, 54.464547],
                         [1.275543, 54.464547]  
                    ]]
                }
            }]
       }
 }
Run Code Online (Sandbox Code Playgroud)

我的伪代码:这不起作用并返回错误消息"LinearRing of a Polygon must have 4 …

javascript json turfjs

5
推荐指数
1
解决办法
6156
查看次数

尝试在 angular 5 (noob) 中使用 turf js

我是一个 angular 5(和 turfjs)菜鸟,试图使用 turfjs()。

我有一个非常简单的 angular 5 项目(用 angular-cli 构建)。

要添加草皮,我跑了:

npm install @turf/along --save
Run Code Online (Sandbox Code Playgroud)

我在我的节点模块目录中看到 @turf/along。我尝试添加到我的 js 文件中:

declare var along: any;
Run Code Online (Sandbox Code Playgroud)

但这没有用。我也尝试添加

"../node_modules/@turf/along/index.js"
Run Code Online (Sandbox Code Playgroud)

到我的 angular-cli.json 文件,但没有运气。

导入此方法以便我可以使用它的正确方法是什么?

turfjs angular-cli angular

5
推荐指数
1
解决办法
3107
查看次数

基于本地geojson文件的mapbox 3D挤压

我在网上看到过这个例子,它进行数据驱动的建筑挤压,但根本不提供代码。

我非常想实现同样的目标。我有一个 geojson 文件,其中包含某种属性,我想将其映射到建筑物的高度。你知道这怎么可能吗?

我已经考虑了推荐的替代方案:对已经根据我的数据生成的圆进行 3D 挤压。未提供此博客文章中的代码,因此我起诉了此帖子中的代码。

代码如下:

<html>
<head>
    <meta charset='utf-8' />
    <title>Display buildings in 3D</title>
    <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
    <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.48.0/mapbox-gl.js'></script>
    <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.48.0/mapbox-gl.css' rel='stylesheet' />
    <script src='https://npmcdn.com/@turf/turf/turf.min.js'></script> 
    <style>
        body {
          margin: 0;
          padding: 0;
        }

        #map {
          position: absolute;
          top: 0;
          bottom: 0;
          width: 100%;
        }
    </style>
</head>
<body>

<div id='map'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoicXVlMzIxNiIsImEiOiJjaWhxZmMxMDUwMDBzdXhsdWh0ZDkyMzVqIn0.sz3lHuX9erctIPE2ya6eCw';

var map = new mapboxgl.Map({
  container: 'map',
  style: 'mapbox://styles/mapbox/light-v9',
  center: [8.538961, 47.372476],
  zoom: 16,
  pitch: 40, …
Run Code Online (Sandbox Code Playgroud)

javascript maps mapbox turfjs mapbox-gl-js

5
推荐指数
1
解决办法
2822
查看次数

无法删除多边形之间的区域交点

我有两个多边形,它们的交叉点不可见且不可移动。我试图通过从第一个中删除第二个区域来找到它们之间的差异,然后再次找到交叉点 - 结果交叉点仍然存在并且具有公共区域。为什么会发生这种情况?如何去除两个多边形之间的交点并使它们的边界接触?

const turf = require("@turf/turf");

const poly1 = [
    [
        [37.367249, 55.615589],
        [37.372462, 55.612478],
        [37.372463, 55.61248],
        [37.453365, 55.564205],
        [37.45336, 55.564206],
        [37.459431, 55.560583],
        [37.558005, 55.682037],
        [37.367249, 55.615589]
    ]
];
const poly2 = [
    [
        [37.336522, 55.603857],
        [37.360725, 55.57621],
        [37.408614, 55.591334],
        [37.371557, 55.613064],
        [37.336522, 55.603857]
    ]
];

const difference = turf.difference(turf.polygon(poly1), turf.polygon(poly2)); // removed poly2 from poly1, difference now is Feature<Polygon>
const intersection = turf.intersect(turf.polygon(difference.geometry.coordinates), turf.polygon(poly2));

if (intersection) { //intersection is geometry collection with polygons
    // why???
}
Run Code Online (Sandbox Code Playgroud)

geometry polygon geospatial node.js turfjs

5
推荐指数
1
解决办法
314
查看次数