GEE----Geometry related functions introduction (1)

1. Create a point

1.1point() creates a single point

var point =ee.Geometry.Point(-101.8775,35.2463)
Map.addLayer(point)
Map.centerObject(point)

 1.2 MultiPoint() creates multiple points

var point =ee.Geometry.MultiPoint([[-101.8775,35.2463],
                                  [-101.7621,35.2007],
                                  [-101.7604,35.2386]])
Map.addLayer(point)

2 LineString()/MultiLineString() creates single or multi-line segments

//创建单线
/*var line =ee.Geometry.LineString([[-101.8775,35.2463],
                                  [-101.7621,35.2007]])*/
//创建多线
var multiline=ee.Geometry.MultiLineString([[-101.8775,35.2463],
                                           [-101.7621,35.2007],
                                           [-101.8761,35.2036],
                                            [-101.76044,35.2386]])
Map.addLayer(multiline)

Note: When creating a closed line, the last point is the starting point coordinates, and LinearRing() is used

3 Create polygons

3.1 Polygon() creates a single polygon


var multiline=ee.Geometry.Polygon([[[-102.00057948108831,35.11716328220111],
                                  [-101.65451014515081,35.11716328220111],
                                  [-101.65451014515081,35.268670400291384],
                                  [-102.00057948108831,35.268670400291384],
                                  [-102.00057948108831,35.11716328220111]]])
Map.addLayer(multiline)

3.2MultiPolygon() creates multiple polygons

var Forbidden_City = ee.Geometry.MultiPolygon(
        [[[[116.39393637477303, 39.921260179361866],
           [116.39350722133065, 39.91882457850439],
           [116.39676878749276, 39.918791664386056],
           [116.39711211024667, 39.920963962263336]]],
         [[[116.39887163936044, 39.91810046424626],
           [116.39595339595223, 39.91698136351405],
           [116.40080282985116, 39.91652055201477]]]]);

Map.centerObject(Forbidden_City)
print(Forbidden_City)
Map.addLayer(Forbidden_City)

3.3rectangle() creates a rectangle

var rectangle=ee.Geometry.Rectangle(-102.00057948108831,35.11716328220111,
                                 -101.65451014515081,35.268670400291384)//输入四边形的对角线
Map.addLayer(rectangle)

4. transform() projection transformation

var rectangle=ee.Geometry.Rectangle(-102.00057948108831,35.11716328220111,
                                 -101.65451014515081,35.268670400291384)
var tran_rectangle=rectangle.transform('EPSG:4326',ee.ErrorMargin(100))//将rectangle转换为WGS84

Map.addLayer(tran_rectangle,{color:'000000'})

Map.addLayer(rectangle,{color:'FF0000'})

transform(proj,maxerror):

        proj is the projection to be transformed, and the projection must be in EPSG format. For details, please refer to the URL

        EPSG.io: Coordinate Systems Worldwide

        maxerror is the maximum projection error that can be tolerated.

5. centroid() calculates the centroid/mass center of the geometry

var rectangle=ee.Geometry.Rectangle(-102.00057948108831,35.11716328220111,
                                 -101.65451014515081,35.268670400291384)
var centroid_rectangle=rectangle.centroid()

Map.addLayer(rectangle,{color:'FF0000'})
Map.addLayer(centroid_rectangle,{color:'000000'})

6. simplify() simplifies graphics

var simple_pol1=pol_1.simplify(1000)//接受的最大误差值


Map.addLayer(simple_pol1,{color:'000000'})

 7. bounds()/convexHull() obtains the circumscribed matrix or convex hull of the aggregate

var bound_pol1=pol_1.bounds()
var convexHull=pol_1.convexHull()
Map.addLayer(bound_pol1,{color:'000000'})//黑色显示
Map.addLayer(convexHull,{color:"FF0000"})//凸包红色显示

        The convex hull of a point is the point itself, the convex hull of collinear points is the line, and the convex hull of everything else is a polygon.

 8. buffer() returns a buffer with a given distance

var pol_1_buffer=pol_1.buffer(1000)
Map.addLayer(pol_1_buffer,{color:"FF0000"})

Guess you like

Origin blog.csdn.net/weixin_51775350/article/details/128007261