我在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.
更多推荐
发布评论