如何获取Google地球引擎中LinearRing中每个元素的长度(How can I get the length of each element in a LinearRing in Google

编程入门 行业动态 更新时间:2024-10-28 06:34:09
如何获取Google地球引擎中LinearRing中每个元素的长度(How can I get the length of each element in a LinearRing in Google Earth Engine)

我在Google地球引擎中使用JavaScript(对这两者都很新),以获取建筑物每一侧的长度(从地图视图中往下看)

首先,我在建筑的周边绘制了一个LinearRing,它存储在可变的rectangle 。 我想提取rectangle中每一行的长度并打印所有这些长度。

我到目前为止的代码是:

var rectangle = /* color: ffffff */ee.Geometry.LinearRing( [[coord_1], [coord_2], [coord_3], [coord_4], [coord_1]]); var geometries = rectangle.geometries(); var line1 = geometries.get(0); var line2 = geometries.get(1); print(line2)

这给了我一个错误:

ComputedObject (Error) List.get: List index must be between -1 and 0. Found 1.

在GEE中为var rectangle转换的JS代码如下所示,以供参考:

var rectangle: LinearRing, 5 vertices type: LinearRing coordinates: List (5 elements) 0: [coord_1] 1: [coord_2] 2: [coord_3] 3: [coord_4] 4: [coord_1]

谢谢!

I am using JavaScript in Google Earth Engine (very new to both of these) to get the lengths of each side of a building (looking down from map view)

First, I drew a LinearRing around the perimeter of the building, which is stored in the variable rectangle. I would like to extract the lengths of each of the lines in rectangle and print all of them.

The code I have below so far:

var rectangle = /* color: ffffff */ee.Geometry.LinearRing( [[coord_1], [coord_2], [coord_3], [coord_4], [coord_1]]); var geometries = rectangle.geometries(); var line1 = geometries.get(0); var line2 = geometries.get(1); print(line2)

This gives me an error of:

ComputedObject (Error) List.get: List index must be between -1 and 0. Found 1.

The converted JS code in GEE for var rectangle looks like this for reference:

var rectangle: LinearRing, 5 vertices type: LinearRing coordinates: List (5 elements) 0: [coord_1] 1: [coord_2] 2: [coord_3] 3: [coord_4] 4: [coord_1]

Thanks!

最满意答案

尝试在你的矩形上调用.coordinates()而不是.geometries() 。

如果您有一个FeatureCollection,则.geometries()将为您提供该集合中所有.geometries()的几何图形,而.coordinates()将返回单个几何图形的坐标。

Try calling .coordinates() rather than .geometries() on your rectangle.

If you had a FeatureCollection, .geometries() would get you the geometries of all the features in that collection, while .coordinates() returns the coordinates of a single Geometry.

更多推荐

本文发布于:2023-08-04 12:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1416146.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:长度   元素   地球   引擎   LinearRing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!