基础类型方法
类名 | 含义 |
ee.Geometry.LineString | 线段:由一系列点组成的直线 |
ee.Geometry.LineRing | 环:线段首尾相连接 |
ee.Geometry.MultiLineString | 复合线段:多个线段组合在一起 |
ee.Geometry.Point | 点 |
ee.Geometry.MultiPoint | 复合点:多个点组合在一起 |
ee.Geometry.Polygon | 多边形 |
ee.Geometry.Rectangle | 矩形 |
ee.Geometry.MultiPolygon | 复合矩形:多个矩形组合在一起 |
代码
var line = /* color: #d63000 */ee.Geometry.LineString(
[[-103.28593749999999, 38.46623315614578],
[-94.98027343749999, 40.534424706292405]]),
multiLine = /* color: #28db3e */ee.Geometry.MultiLineString(
[[[-101.70316271563797, 37.737101081855215],
[-96.46658167152503, 38.017322136064934]],
[[-105.74687499999999, 35.73286699047012],
[-100.34160156249999, 36.584391288158706]]]),
point = /* color: #0b4a8b */ee.Geometry.Point([-89.09160156249999, 39.7956206925268]),
multiPoint = /* color: #ffc82d */ee.Geometry.MultiPoint(
[[-92.65117187499999, 37.42662495543974],
[-93.79374999999999, 37.28690130733523]]),
polygon = /* color: #00ffff */ee.Geometry.Polygon(
[[[-96.86992187499999, 34.438354866968545],
[-95.55156249999999, 36.90132207718713],
[-97.74882812499999, 35.44697585969926]]]),
rectangle = ee.Geometry.Polygon(
[[[-93.70585937499999, 36.44311350012563],
[-93.70585937499999, 33.63721310743895],
[-89.57499999999999, 33.63721310743895],
[-89.57499999999999, 36.44311350012563]]], null, false),
multiPolygon = /* color: #ff0000 */ee.Geometry.MultiPolygon(
[[[[-84.29587208507718, 39.96117602741789],
[-84.20893110596711, 38.095486162792234],
[-81.32717506033146, 40.59421005772966]]],
[[[-83.68632812499999, 34.7277971009936],
[-81.97246093749999, 37.8095219161184],
[-85.00468749999999, 37.63572230181635]]]]);
Map.addLayer(line, {color: "d63000"}, "line");
Map.addLayer(multiLine, {color: "28db3e"}, "multiLine");
Map.addLayer(point, {color: "0b4a8b"}, "point");
Map.addLayer(multiPoint, {color: "ffc82d"}, "multiPoint");
Map.addLayer(polygon, {color: "00ffff"}, "polygon");
Map.addLayer(rectangle, {color: "bf04c2"}, "rectangle");
Map.addLayer(multiPolygon, {color: "ff0000"}, "multiPolygon");
Map.centerObject(point, 4);
空间计算方法
(1)计算Geometry的面积使用area( ),返回值单位为平方米;
(2)提取Geometry的中心点使用centroid( ),返回值是对应Geometry的中心坐标;
(3)提取Geometry对应的外接矩形使用bounds( );
(4)对Geometry做缓冲区域使用buffer( ),如果传入的距离是正整数则对Geometry做向外的扩大缓冲区域,如果传入的距离是负数则可以对Geometry做向内缩小的缓冲区域;
(5)判断两个Geometry是否相交使用intersects( ),返回两个Geometry是否相交的结果,如果两个Geometry相交则返回true,否则返回false;
(6)取得两个Geometry的相交部分内容使用intersection( ),,返回值是两个Geometry相交的新的Geometry;
(7)两个Geometry取得不同的部分使用difference( ),简单来说就是在第一个Geometry但不是不在第二个Geometry的部分。
代码
var polygon1 = /* color: #d63000 */ee.Geometry.Polygon(
[[[116.18363255709164, 39.73608336682765],
[116.62857884615414, 39.75297820506206],
[116.60660618990414, 40.08580181855619],
[116.15067357271664, 40.077395868796174]]]);
var polygon2 = /* color: #ffc82d */ee.Geometry.Polygon(
[[[116.45728060961198, 40.23636657920226],
[116.42981478929948, 39.97166693527704],
[116.82806918383073, 39.95903650847623],
[116.88849398851823, 40.20700637790917]]]);
Map.centerObject(polygon1, 9);
Map.addLayer(polygon1, {color: "red"}, "polygon1");
Map.addLayer(polygon2, {color: "blue"}, "polygon2");
//polygon area
print("polygon area is: ", polygon1.area());
//polygon bounds
print("polygon bounds is: ", polygon1.bounds());
//polygon center point
print("polygon centroid is: ", polygon1.centroid());
//polygon coordinates
print("polygon coordinates is: ", polygon1.coordinates());
//check intersects
print("polygon1 and polygon2 is intersects ?", polygon1.intersects(polygon2));
var intersec = polygon1.intersection(polygon2);
Map.addLayer(intersec, {}, "intersec");
//outer 2000m
var bufferPolygon1 = polygon1.buffer(2000);
Map.addLayer(bufferPolygon1, {color:"ff00ff"}, "bufferPolygon1");
//innner 2000m
var bufferPolygon2 = polygon1.buffer(-2000);
Map.addLayer(bufferPolygon2, {color:"00ffff"}, "bufferPolygon2");
//difference
var differ = bufferPolygon1.difference(bufferPolygon2);
Map.addLayer(differ, {color:"green"}, "differ");