- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在查找两个多边形是否与草皮相交时遇到一些问题。
我的代码的目的是什么?
代码:
function calculateFOV(origin,fov,distance) {
let turf = require('@turf/turf');
var pontoOrigem = turf.point([origin.long, origin.lat]); //setup the origin
var pontosDestino = []; //prepare the array that contains the making of the polygon I want to intersect
if (campo.length == 2) {
var bearing = 90; //always 90 for now
var options = {units: 'kilometers'};
for(var bearing=fov[0]; bearing<=fov[1]; bearing+=10) {
pontosDestino.push(turf.getCoord(turf.destination(pontoOrigem, distance/1000, bearing, options)));
}
//if (pontosDestino.length > 0) pontosDestino.push(pontosDestino[0]); //equal the to the first element so that turf does not complain about the last element not being equal to the first
}
return pontosDestino;
}
var poly1 = calculateFOV({'long' :-7.9554464, 'lat':37.0100746},[-180,180],1);
var poly2 = calculateFOV({'long' :-7.9322, 'lat':37.0194},[-180,180],1);
poly1 返回:
[
[ -7.955446399999999, 37.01006560679637 ],
[ -7.955448355660866, 37.010065743423326 ],
[ -7.955450251899985, 37.01006614915285 ],
[ -7.955452031101114, 37.01006681165707 ],
[ -7.955453639204135, 37.010067710806105 ],
[ -7.9554550273476625, 37.01006881927983 ],
[ -7.955456153353656, 37.01007010339779 ],
[ -7.955456983008984, 37.01007152414274 ],
[ -7.95545749110498, 37.010073038346064 ],
[ -7.955457662203383, 37.01007459999947 ],
[ -7.9554574911054345, 37.01007616165291 ],
[ -7.955456983009841, 37.01007767585633 ],
[ -7.955456153354809, 37.01007909660142 ],
[ -7.955455027348974, 37.01008038071956 ],
[ -7.955453639205447, 37.01008148919346 ],
[ -7.9554520311022685, 37.01008238834268 ],
[ -7.955450251900842, 37.01008305084704 ],
[ -7.9554483556613205, 37.01008345657665 ],
[ -7.955446399999999, 37.010083593203646 ],
[ -7.955444444338677, 37.01008345657665 ],
[ -7.955442548099154, 37.01008305084704 ],
[ -7.95544076889773, 37.01008238834268 ],
[ -7.95543916079455, 37.01008148919346 ],
[ -7.955437772651024, 37.01008038071956 ],
[ -7.95543664664519, 37.01007909660142 ],
[ -7.955435816990157, 37.01007767585633 ],
[ -7.955435308894563, 37.01007616165291 ],
[ -7.955435137796615, 37.01007459999947 ],
[ -7.955435308895018, 37.010073038346064 ],
[ -7.955435816991014, 37.01007152414274 ],
[ -7.9554366466463415, 37.01007010339779 ],
[ -7.955437772652336, 37.01006881927983 ],
[ -7.955439160795862, 37.010067710806105 ],
[ -7.955440768898884, 37.01006681165707 ],
[ -7.955442548100012, 37.01006614915285 ],
[ -7.955444444339133, 37.010065743423326 ],
[ -7.955446399999999, 37.01006560679637 ]
]
poly2 返回:
[
[ -7.9322, 37.01939100679636 ],
[ -7.932201955900867, 37.01939114342331 ],
[ -7.9322038523726945, 37.019391549152836 ],
[ -7.9322056317921685, 37.01939221165705 ],
[ -7.932207240092537, 37.0193931108061 ],
[ -7.9322086284064195, 37.01939421927982 ],
[ -7.932209754550595, 37.019395503397774 ],
[ -7.932210584307741, 37.019396924142725 ],
[ -7.93221109246609, 37.01939843834605 ],
[ -7.932211263585491, 37.019399999999465 ],
[ -7.932211092466545, 37.0194015616529 ],
[ -7.932210584308598, 37.019403075856324 ],
[ -7.932209754551749, 37.01940449660141 ],
[ -7.932208628407731, 37.01940578071955 ],
[ -7.932207240093851, 37.01940688919345 ],
[ -7.932205631793323, 37.019407788342676 ],
[ -7.932203852373552, 37.01940845084703 ],
[ -7.932201955901323, 37.019408856576646 ],
[ -7.9322, 37.01940899320363 ],
[ -7.932198044098676, 37.019408856576646 ],
[ -7.932196147626447, 37.01940845084703 ],
[ -7.932194368206678, 37.019407788342676 ],
[ -7.932192759906149, 37.01940688919345 ],
[ -7.9321913715922685, 37.01940578071955 ],
[ -7.9321902454482505, 37.01940449660141 ],
[ -7.932189415691402, 37.019403075856324 ],
[ -7.932188907533454, 37.0194015616529 ],
[ -7.932188736414509, 37.019399999999465 ],
[ -7.93218890753391, 37.01939843834605 ],
[ -7.932189415692259, 37.019396924142725 ],
[ -7.932190245449405, 37.019395503397774 ],
[ -7.93219137159358, 37.01939421927982 ],
[ -7.932192759907462, 37.0193931108061 ],
[ -7.932194368207832, 37.01939221165705 ],
[ -7.932196147627304, 37.019391549152836 ],
[ -7.932198044099133, 37.01939114342331 ],
[ -7.9322, 37.01939100679636 ]
]
节点上的 turf.intersect(poly1,poly2),退出时显示以下消息:
错误:geojson 必须是有效的要素或几何对象 在 getGeom (/home/pedroh/Documentos/Faro/node_modules/@turf/turf/turf.js:1909:11) 在 Object.intersect$2 [相交] (/home/pedroh/Documentos/Faro/node_modules/@turf/turf/turf.js:43369:17) 在对象。 (/home/pedroh/Documentos/Faro/_test_turf.js:11:6)
然后使用该函数的第二个版本,
function calculateFOV(origin,fov,distance) {
let turf = require('@turf/turf');
var pontoOrigem = turf.point([origin.long, origin.lat]); //setup the origin
var pontosDestino = []; //prepare the array that contains the making of the polygon I want to intersect
if (campo.length == 2) {
var bearing = 90; //always 90 for now
var options = {units: 'kilometers'};
for(var bearing=fov[0]; bearing<=fov[1]; bearing+=10) {
pontosDestino.push(turf.destination(pontoOrigem, distance/1000, bearing, options));
}
//if (pontosDestino.length > 0) pontosDestino.push(pontosDestino[0]); //equal the to the first element so that turf does not complain about the last element not being equal to the first
}
return pontosDestino;
}
var poly1 = calculateFOV({'long' :-7.9554464, 'lat':37.0100746},[-180,180],1);
var poly2 = calculateFOV({'long' :-7.9322, 'lat':37.0194},[-180,180],1);
poly1 和 poly2 返回如下内容:
[
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
},
{
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [Array] }
}
]
节点退出时出现相同的错误。
是我遗漏了什么,还是代码有问题?
已更新功能接受答案后
function calculateFOV(origem,campo,distancia_focal,bearing) {
let turf = require('@turf/turf');
var pontoOrigem = turf.point([origem.long, origem.lat]);
var pontosDestino = [];
pontosDestino.push([]);
if (campo.length == 2) {
var options = {units: 'kilometers'};
for(var bearing=campo[0]; bearing<=campo[1]; bearing+=10) {
//esta linha é comentada porque o resultado final tem um tipo manhoso
//pontosDestino.push(turf.destination(pontoOrigem, distancia_focal/1000, bearing, options));
pontosDestino[0].push(turf.getCoord(turf.destination(pontoOrigem, distancia_focal/1000, bearing, options)));
}
//igualar o último ponto para que o turf não bitcha sobre pontos equivalentes. faz sentido porque os polígonos têm de ser fechados
if (JSON.stringify(pontosDestino[0][0]) != JSON.stringify(pontosDestino[0][pontosDestino[0].length-1])) {
pontosDestino[0].push(pontosDestino[0][0]);
}
}
return pontosDestino;
}
//testing function
function testIntersection(poly1,poly2) {
if (typeof poly1 !== 'undefined' && typeof poly2 !== 'undefined') {
console.log("intersection");
//test intersection with two turf features
let turf = require('@turf/turf');
let polygon1 = turf.polygon(poly1);
let polygon2 = turf.polygon(poly2);
/* test intersection */
return turf.intersect(polygon1, polygon2);
}
else {
return -1; //error code given if I don't have both asset's positions at time of check
}
}
最佳答案
不确定这是否有帮助(以前从未使用过Turf JS),但是如果我将你的poly1和poly2放在一个最小的脚本中,则交集的结果为空。根据 https://turfjs.org/docs/#intersect ,这表明“他们没有任何共同点”。
<html><head>
<script src='https://npmcdn.com/@turf/turf/turf.min.js'></script>
<script>
var poly1 = turf.polygon([[
[ -7.955446399999999, 37.01006560679637 ],
[ -7.955448355660866, 37.010065743423326 ],
[ -7.955450251899985, 37.01006614915285 ],
[ -7.955452031101114, 37.01006681165707 ],
[ -7.955453639204135, 37.010067710806105 ],
[ -7.9554550273476625, 37.01006881927983 ],
[ -7.955456153353656, 37.01007010339779 ],
[ -7.955456983008984, 37.01007152414274 ],
[ -7.95545749110498, 37.010073038346064 ],
[ -7.955457662203383, 37.01007459999947 ],
[ -7.9554574911054345, 37.01007616165291 ],
[ -7.955456983009841, 37.01007767585633 ],
[ -7.955456153354809, 37.01007909660142 ],
[ -7.955455027348974, 37.01008038071956 ],
[ -7.955453639205447, 37.01008148919346 ],
[ -7.9554520311022685, 37.01008238834268 ],
[ -7.955450251900842, 37.01008305084704 ],
[ -7.9554483556613205, 37.01008345657665 ],
[ -7.955446399999999, 37.010083593203646 ],
[ -7.955444444338677, 37.01008345657665 ],
[ -7.955442548099154, 37.01008305084704 ],
[ -7.95544076889773, 37.01008238834268 ],
[ -7.95543916079455, 37.01008148919346 ],
[ -7.955437772651024, 37.01008038071956 ],
[ -7.95543664664519, 37.01007909660142 ],
[ -7.955435816990157, 37.01007767585633 ],
[ -7.955435308894563, 37.01007616165291 ],
[ -7.955435137796615, 37.01007459999947 ],
[ -7.955435308895018, 37.010073038346064 ],
[ -7.955435816991014, 37.01007152414274 ],
[ -7.9554366466463415, 37.01007010339779 ],
[ -7.955437772652336, 37.01006881927983 ],
[ -7.955439160795862, 37.010067710806105 ],
[ -7.955440768898884, 37.01006681165707 ],
[ -7.955442548100012, 37.01006614915285 ],
[ -7.955444444339133, 37.010065743423326 ],
[ -7.955446399999999, 37.01006560679637 ]
]]);
var poly2 = turf.polygon([[
[ -7.9322, 37.01939100679636 ],
[ -7.932201955900867, 37.01939114342331 ],
[ -7.9322038523726945, 37.019391549152836 ],
[ -7.9322056317921685, 37.01939221165705 ],
[ -7.932207240092537, 37.0193931108061 ],
[ -7.9322086284064195, 37.01939421927982 ],
[ -7.932209754550595, 37.019395503397774 ],
[ -7.932210584307741, 37.019396924142725 ],
[ -7.93221109246609, 37.01939843834605 ],
[ -7.932211263585491, 37.019399999999465 ],
[ -7.932211092466545, 37.0194015616529 ],
[ -7.932210584308598, 37.019403075856324 ],
[ -7.932209754551749, 37.01940449660141 ],
[ -7.932208628407731, 37.01940578071955 ],
[ -7.932207240093851, 37.01940688919345 ],
[ -7.932205631793323, 37.019407788342676 ],
[ -7.932203852373552, 37.01940845084703 ],
[ -7.932201955901323, 37.019408856576646 ],
[ -7.9322, 37.01940899320363 ],
[ -7.932198044098676, 37.019408856576646 ],
[ -7.932196147626447, 37.01940845084703 ],
[ -7.932194368206678, 37.019407788342676 ],
[ -7.932192759906149, 37.01940688919345 ],
[ -7.9321913715922685, 37.01940578071955 ],
[ -7.9321902454482505, 37.01940449660141 ],
[ -7.932189415691402, 37.019403075856324 ],
[ -7.932188907533454, 37.0194015616529 ],
[ -7.932188736414509, 37.019399999999465 ],
[ -7.93218890753391, 37.01939843834605 ],
[ -7.932189415692259, 37.019396924142725 ],
[ -7.932190245449405, 37.019395503397774 ],
[ -7.93219137159358, 37.01939421927982 ],
[ -7.932192759907462, 37.0193931108061 ],
[ -7.932194368207832, 37.01939221165705 ],
[ -7.932196147627304, 37.019391549152836 ],
[ -7.932198044099133, 37.01939114342331 ],
[ -7.9322, 37.01939100679636 ]
]]);
var intersection = turf.intersect( poly1, poly2 );
console.log( intersection );
</script>
</head><body>
</body></html>
更重要的是,https://turfjs.org/docs/#intersect 文档中的示例显示了多边形的三重嵌套数组。我所做的唯一调整是确保 Poly1 和 Poly2 是三重嵌套数组,而您上面的问题显示 Poly1 和 Poly2 是双重嵌套数组。
希望这有帮助。
关于javascript - Turf JS 交叉口问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59231038/
我有这个多边形: const polygon = JSON.parse('{"type":"Feature","properties":{},"geometry":{"type":"Polygon",
我想使用 booleanCrosses和 booleanContains我在客户端的应用程序中使用 Turf.js 库中的方法,但我失败了。我首先尝试只下载 turf.min.js ,但是当我在我的代
我正在制作传单 map 。我正在加载一些 geoJSON 数据。我有 map 的点击功能。当我单击时,我只想提醒离加载的 geoJSON 最近的点。问题是无论我在城市的哪个地方点击,都只返回一个点(下
我在查找两个多边形是否与草皮相交时遇到一些问题。 我的代码的目的是什么? 给定 Assets 的位置(坐标)、视野(-180 到 180 之间,当然是模拟的)和距离(我称之为视野范围;假设为 1 公里
图书馆:http://turfjs.org/ 使用平台:Node.js v8.9.4 Turf 版本:来自 npm 的最新版本 - @turf/turf 代码: var center = [20.65
利用Turf.js版本 3.0.12。下面的函数应该返回两个多边形之间的交点,如果它们不相交则返回 null。多边形确实相交。我尝试了几种不同的多边形并收到相同的错误: “错误:第一个和最后一个位置不
我正在使用 Turf.js在我的应用程序中进行高级地理空间分析,但找不到检查两个多边形是否相互交叉的方法。 Intersect方法不是我想要的,因为如果我有一个小多边形并且想要找到穿过这个小多边形的多
可以使用 turfjs 计算直线路径上两点之间的距离吗?怎么办? 最佳答案 使用 turf.lineSlice 使用您的两个点对线进行切片。这将返回一条新线,其中仅包含两点之间线上的部分。接下来,您可
可以使用 turfjs 计算直线路径上两点之间的距离吗?怎么办? 最佳答案 使用 turf.lineSlice 使用您的两个点对线进行切片。这将返回一条新线,其中仅包含两点之间线上的部分。接下来,您可
我正在使用 OpenLayers3 ol.interaction.Draw让用户在 map 上绘制形状,可以通过单击顶点或通过 Shift+拖动来绘制自由多边形(这对我的应用程序很重要)。绘制形状后,
我有一个featureCollection。每个元素都有 properties,其中又包含条目 arr。 arr 要么包含 [],要么包含 ["a",.... n]。我想从 featureCollec
将 turf.intersect 与特定多边形一起使用时,出现以下错误:“TopologyException”“发现 LINESTRING(-0.140733 51.505327、-0.141097
将 turf.intersect 与特定多边形一起使用时,出现以下错误:“TopologyException”“发现 LINESTRING(-0.140733 51.505327、-0.141097
我正在尝试编写一个脚本,使用 Turf.js 的 inside 方法获取用户提交的坐标并将其与相应的人口普查区相匹配。下面的代码,作为测试,我相信应该返回 true。它没有。 那些坐标肯定是瑞格利球场
如何将坐标的JSON数据传给turf.polygon? 示例: turf.polygon(); var polygon = turf.polygon([[ [-2.275543, 53.464547
我正在尝试构建 turf-buffer 的最新副本这是 turf.js 的模块。我运行了npm install turf-buffer,然后运行browserify turf-buffer/index
方法:我目前使用 turf.js 作为 broader mapping project 的一部分进行地理处理;我的工作流程是这样的: 拉取整个县的人口普查区域的 geojson 从 OSM 中为县域拉
我正在尝试在同一个 map 容器中的标记之间添加多条大圆线。我设法用 greatCircle 展示了一个在 turf.js 中。 for(var i = 0; i < 2 ;i++) { va
我有一个使用 NAD-83 UTM 投影的 GeoJSON 要素集合,因此坐标以米为单位。我想将此特征集合与 Turf.JS 库一起使用来进行一些轮廓绘制。 问题是 Turf.JS 只采用 WGS84
我正在使用 Node.js 构建一个 map 应用程序。我们在 map 上显示了大约 40,000 个多边形,因此我尝试通过尽可能合并它们来提高性能。 Turf.js 有一个看起来像票证的合并功能。但
我是一名优秀的程序员,十分优秀!