Geometry
# 简介
几何图形(Geometry)是PIE-Engine中的几何图形对象,包括点、线和面等对象,表示一个几何形体对象。PIE-Engine Studio提供构建Geometry算子及Geometry相关算法,包括但不限于坐标点提取、中心点计算、图形几何运算、空间位置判断及计算、格式转换。
# Geometry (opens new window)
函数 | 返回值 |
---|---|
Geometry(geoJson,proj,geodesic,evenOdd) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
geoJson | String|PIEGeometry|PIEFeature|Array | 几何形体的GeoJSON对象 |
proj | Projection | 坐标系对象,null表示4326 |
geodesic | Boolean | 未启用 |
evenOdd | Boolean | 未启用 |
# area (opens new window)
计算几何图形的面积,只对面有效。
函数 | 返回值 |
---|---|
area(proj) | Number |
参数 | 类型 | 说明 |
---|---|---|
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式 |
var geometry = pie.Geometry.Polygon([[[119, 39], [121, 39], [121, 41], [119, 41],[119, 39]]]);
print(geometry.area());
# bounds
获得几何图形的最小外接矩形范围。
函数 | 返回值 |
---|---|
bounds(maxError,proj) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
maxError | MaxError | 未启用 |
proj | Projection | 坐标系对象,null表示4326 |
var polyline = pie.Geometry.LineString([[118, 31.1],[119, 32.1]], null);
var geometry = polyline.bounds();
var roi = pie.FeatureCollection(pie.Feature(geometry));
Map.addLayer(roi, {color: "00ff00ff", fillColor: "00000000"}, "roi", true);
Map.centerObject(geometry, 6);
# buffer
获得几何图形缓冲区。
函数 | 返回值 |
---|---|
buffer(distance,proj) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
distance | Number | 缓冲距离,默认单位是米,如果是度,需要设置proj为地理坐标系 |
proj | Projection | 坐标系,指定distance的单位;可以WKT串也可以是EPSG编码表示方式 |
var point = pie.Geometry.Point([120,40]);
// var geometry = point.buffer(1,"EPSG:4326"); // 1度的缓冲区
var geometry = point.buffer(100); // 100米的缓冲区
var feature = pie.Feature(geometry);
var featureCollection = pie.FeatureCollection(feature);
Map.addLayer(featureCollection);
Map.setCenter(120,40,10);
# centroid
获得几何图形的中心点。
函数 | 返回值 |
---|---|
centroid(maxError,proj) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
maxError | MaxError | 未启用 |
proj | Projection | 坐标系对象,null表示4326 |
var polyline = pie.Geometry.LineString([[118, 31.1],[119, 32.1]], null);
var geometry = polyline.centroid();
var roi = pie.FeatureCollection(pie.Feature(geometry));
Map.addLayer(roi, {color: "00ff00ff", fillColor: "00000000"}, "roi", true);
Map.centerObject(geometry, 7);
# containedIn
判断左边的Geometry是否包含在右边的Geometry中,若包含返回true,不包含返回false。
函数 | 返回值 |
---|---|
containedIn(right,proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Geometry | 右边的Geometry |
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式; |
//加载点,绿色
var point = pie.Geometry.Point([120,40]);
Map.addLayer(pie.FeatureCollection(pie.Feature(point)), {color:"00ff0000"}, "point");
Map.centerObject(point,6)
// 100米的缓冲区,红色
var geometry2 = point.buffer(10000);
Map.addLayer(pie.FeatureCollection(pie.Feature(geometry2)), {color:"ff0000ff",fillColor:"ff0000ff"}, "geometry2");
// 1度的缓冲区
var geometry1 = point.buffer(1,"EPSG:4326");
Map.addLayer(pie.FeatureCollection(pie.Feature(geometry1)), {color:"0000ffff",fillColor:"0000ffff"}, "geometry1");
//判断geometry2是否包含在geometry1中
print(geometry2.containedIn(geometry1));
# contains
判断左边的Geometry是否包含右边的Geometry,若包含返回true,不包含返回false。
函数 | 返回值 |
---|---|
contains(right,proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Geometry | 右边的Geometry |
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式; |
var point = pie.Geometry.Point([120,40]);
var geometry1 = point.buffer(1,"EPSG:4326"); // 1度的缓冲区
var geometry2 = point.buffer(10000); // 100米的缓冲区
print(geometry1.contains(geometry2));
# coordinates
获得几何图形折点信息。
函数 | 返回值 |
---|---|
coordinates() | Array |
var polyline = pie.Geometry.LineString([[118, 31.1],[119, 32.1]], null);
var cords = polyline.coordinates();
# difference
计算左边的Geometry和右边的Geometry差集。
函数 | 返回值 |
---|---|
difference(right,proj) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
right | Geometry | 右边的Geometry |
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式 |
var polygon = pie.Geometry.Polygon([[[119, 39], [121, 39], [121, 41], [119, 41],[119, 39]]]);
var polygon1 = pie.Geometry.Polygon([[[120, 38], [122, 38], [122, 40], [120, 40],[120, 38]]]);
var geometry = polygon.difference(polygon1)
var feature = pie.Feature(geometry);
var featureCollection = pie.FeatureCollection(feature);
Map.addLayer(featureCollection);
Map.setCenter(120,40,6);
# disjoint
判断左边的Geometry是否和右边的Geometry相离,若相离则是返回true,相交返回false。
函数 | 返回值 |
---|---|
disjoint(right,proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Geometry | 右边的Geometry |
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式 |
// 加载并显示polygon1,红色
var polygon1 = pie.Geometry.Polygon([[[119, 39], [121, 39], [121, 41], [119, 41],[119, 39]]]);
Map.centerObject(polygon1,6);
var visgeometry1 = {color: "ff0000ff", fillColor: "00000000"};
Map.addLayer(pie.FeatureCollection(pie.Feature(polygon1)), visgeometry1, "geometry1");
//加载并显示polygon2,绿色
var polygon2 = pie.Geometry.Polygon([[[122, 38], [123, 38], [123, 40], [122, 40],[122, 38]]]);
var visgeometry2 = {color: "00ff0000", fillColor: "00000000"};
Map.addLayer(pie.FeatureCollection(pie.Feature(polygon2)), visgeometry2, "geometry2");
//加载并显示polygon3,蓝色
var polygon3 = pie.Geometry.Polygon([[[117.46, 40.22],[119.80,40.22],[119.76,38.12],[117.32,38.17],[117.46,40.22]]]);
var visgeometry3 = {color: "0000ffff", fillColor: "00000000"};
Map.addLayer(pie.FeatureCollection(pie.Feature(polygon3)), visgeometry3, "geometry3");
//判断两图形是否相离,相离返回true,相交返回false
print(polygon1.disjoint(polygon2));
print(polygon1.disjoint(polygon3));
# intersection
计算左边的Geometry和右边的Geometry交集。
函数 | 返回值 |
---|---|
intersection(right,proj) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
right | Geometry | 右边的Geometry |
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式 |
var polygon = pie.Geometry.Polygon([[[119, 39], [121, 39], [121, 41], [119, 41],[119, 39]]]);
var polygon1 = pie.Geometry.Polygon([[[120, 38], [122, 38], [122, 40], [120, 40],[120, 38]]]);
var geometry = polygon.intersection(polygon1)
var feature = pie.Feature(geometry);
var featureCollection = pie.FeatureCollection(feature);
Map.addLayer(featureCollection);
Map.setCenter(120,40,5);
# intersects
判断左边的Geometry是否和右边的Geometry相交,若相交返回true,不相交返回false。
函数 | 返回值 |
---|---|
intersects(right,proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Geometry | 右边的Geometry |
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式 |
// 加载并显示polygon1,红色
var polygon1 = pie.Geometry.Polygon([[[119, 39], [121, 39], [121, 41], [119, 41],[119, 39]]]);
Map.centerObject(polygon1,6);
var visgeometry1 = {color: "ff0000ff", fillColor: "00000000"};
Map.addLayer(pie.FeatureCollection(pie.Feature(polygon1)), visgeometry1, "geometry1");
//加载并显示polygon2,绿色
var polygon2 = pie.Geometry.Polygon([[[122, 38], [123, 38], [123, 40], [122, 40],[122, 38]]]);
var visgeometry2 = {color: "00ff0000", fillColor: "00000000"};
Map.addLayer(pie.FeatureCollection(pie.Feature(polygon2)), visgeometry2, "geometry2");
//加载并显示polygon3,蓝色
var polygon3 = pie.Geometry.Polygon([[[117.46, 40.22],[119.80,40.22],[119.76,38.12],[117.32,38.17],[117.46,40.22]]]);
var visgeometry3 = {color: "0000ffff", fillColor: "00000000"};
Map.addLayer(pie.FeatureCollection(pie.Feature(polygon3)), visgeometry3, "geometry3");
//判断两图形是否相交,相交返回true,相离返回false
print(polygon1.intersects(polygon2));
print(polygon1.intersects(polygon3));
# length
计算几何图形的长度或周长,只对线面有效。
函数 | 返回值 |
---|---|
length(proj) | Number |
参数 | 类型 | 说明 |
---|---|---|
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式 |
var geometry = pie.Geometry.Polygon([[[119, 39], [121, 39], [121, 41], [119, 41],[119, 39]]]);
print(geometry.length());
# LineRing
构建一个环形线对象。如果最后一个点不等于第一个点,则会在末尾添加第一个点的副本。
函数 | 返回值 |
---|---|
LinearRing(coords,proj,geodesic,maxError) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
coords | Array | 多个坐标点序列的集合 |
proj | Projection | 坐标系对象,null表示4326 |
geodesic | Boolean | 未启用 |
maxError | MaxError | 未启用 |
var geometry = pie.Geometry.LinearRing([[117.2,31.8],[117.9,31.8],[117.9,31.4],[117.2,31.4]], null);
var roi = pie.FeatureCollection(pie.Feature(geometry));
Map.addLayer(roi, {color: "ff0000ff", fillColor: "00000000"}, "roi", true);
Map.centerObject(geometry, 8);
# LineString
构建一个单线对象。
函数 | 返回值 |
---|---|
LineString(coords,proj,geodesic,maxError) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
coords | Array | 多个坐标点序列的集合 |
proj | Projection | 坐标系对象,null表示4326 |
geodesic | Boolean | 未启用 |
maxError | MaxError | 未启用 |
var polyline = pie.Geometry.LineString([[118, 31.1], [119, 31.1], [119, 32.1]], null);
var roi = pie.FeatureCollection(pie.Feature(polyline));
Map.addLayer(roi, {color: "ff0000ff", fillColor: "00000000"}, "roi", true);
Map.centerObject(polyline, 5);
# MultiLineString
构建一个多线对象。
函数 | 返回值 |
---|---|
MultiLineString(coords,proj,geodesic,maxError) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
coords | Array | 多个线坐标点序列的集合 |
proj | Projection | 坐标系对象,null表示4326 |
geodesic | Boolean | 未启用 |
maxError | MaxError | 未启用 |
var mulPolyline = pie.Geometry.MultiLineString([[[118, 31.1], [119, 31.1], [119, 32.1]],[[118.5, 31.6],[120, 35],[130, 40]]], null);
var roi = pie.FeatureCollection(pie.Feature(mulPolyline));
Map.addLayer(roi, {color: "ff0000ff", fillColor: "00000000"}, "roi", true);
Map.centerObject(mulPolyline, 3);
# MultiPoint
构建一个多点对象。
函数 | 返回值 |
---|---|
MultiPoint (coords,proj) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
coords | Array | 多个坐标点序列的集合 |
proj | Projection | 坐标系对象,null表示4326 |
var mulPoint = pie.Geometry.MultiPoint([[118.5, 31.6],[120, 35],[130, 40]] , null);
var roi = pie.FeatureCollection(pie.Feature(mulPoint));
Map.addLayer(roi, {color: "ff0000ff", fillColor: "00000000"}, "roi", true);
Map.centerObject(mulPoint, 5);
# MultiPolygon
构建一个多面对象。
函数 | 返回值 |
---|---|
MultiPolygon(coords,proj,geodesic,maxError,evenOdd) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
coords | Array | 多个面坐标序列的集合 |
proj | Projection | 坐标系对象,null表示4326 |
geodesic | Boolean | 未启用 |
maxError | MaxError | 未启用 |
evenOdd | Boolean | 未启用 |
var mulPolygon = pie.Geometry.MultiPolygon(
[[[[118, 31.1], [119, 31.1], [119, 32.1], [118, 32.1],[118, 31.1]]],
[[[120, 35], [120, 36], [130, 36], [130, 35],[120, 35]]]],
null);
var roi = pie.FeatureCollection(pie.Feature(mulPolygon));
Map.addLayer(roi, {color: "ff0000ff", fillColor: "00000000"}, "roi", true);
Map.centerObject(mulPolygon, 4);
# Point
构建一个单点对象。
函数 | 返回值 |
---|---|
Point(coords,proj) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
coords | Array | 坐标点序列 |
proj | Projection | 坐标系对象,null表示4326 |
var point = pie.Geometry.Point([118.5, 31.6] , null);
var roi = pie.FeatureCollection(pie.Feature(point));
Map.addLayer(roi, {color: "00ff00ff", fillColor: "00000000"}, "roi", true);
Map.centerObject(point, 5);
# Polygon
构建一个单面对象。
函数 | 返回值 |
---|---|
Polygon(coords,proj,geodesic,maxError,evenOdd) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
coords | Array | 多个坐标点序列的集合 |
proj | Projection | 坐标系对象,null表示4326 |
geodesic | Boolean | 未启用 |
maxError | MaxError | 未启用 |
evenOdd | Boolean | 未启用 |
var polygon = pie.Geometry.Polygon([[[118, 31.1], [119, 31.1], [119, 32.1], [118, 32.1],[118, 31.1]]], null);
var roi = pie.FeatureCollection(pie.Feature(polygon));
Map.addLayer(roi, {color: "ff0000ff", fillColor: "00000000"}, "roi", true);
Map.centerObject(polygon, 6);
# Rectangle
构建一个矩形对象。
函数 | 返回值 |
---|---|
Rectangle(coords,proj,geodesic,maxError,evenOdd) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
coords | Array | 矩形两个角点的坐标点序列的集合 |
proj | Projection | 坐标系对象,null表示4326 |
geodesic | Boolean | 未启用 |
maxError | MaxError | 未启用 |
evenOdd | Boolean | 未启用 |
var rectangle = pie.Geometry.Rectangle([[118, 31.1], [119, 32.1]], null);
var roi = pie.FeatureCollection(pie.Feature(rectangle));
Map.addLayer(roi, {color: "ff0000ff", fillColor: "00000000"}, "roi", true);
Map.centerObject(rectangle, 6);
# simplify
Geometry简化。
函数 | 返回值 |
---|---|
simplify(proj) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式; |
var geometry = pie.Geometry.Polygon([[[119, 39], [121, 39], [121, 41], [119, 41],[119, 39]]]);
geometry = geometry.simplify();
var feature = pie.Feature(geometry);
var featureCollection = pie.FeatureCollection(feature);
Map.addLayer(featureCollection);
Map.setCenter(120,40,5);
# toGeoJSON
转换成GeoJSON对象。
函数 | 返回值 |
---|---|
toGeoJSON() | Json |
var polyline = pie.Geometry.LineString([[118, 31.1],[119, 32.1]], null);
var json = polyline.toGeoJSON();
# toGeoJSONString
转换成GeoJSON字符串。
函数 | 返回值 |
---|---|
toGeoJSONString() | Json |
var polyline = pie.Geometry.LineString([[118, 31.1],[119, 32.1]], null);
var json = polyline.toGeoJSONString();
# union
计算左边的Geometry和右边的Geometry并集。
函数 | 返回值 |
---|---|
union(right,proj) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
right | Geometry | 右边的Geometry |
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式 |
var polygon = pie.Geometry.Polygon([[[119, 39], [121, 39], [121, 41], [119, 41],[119, 39]]]);
var polygon1 = pie.Geometry.Polygon([[[120, 38], [122, 38], [122, 40], [120, 40],[120, 38]]]);
var geometry = polygon.union(polygon1)
var feature = pie.Feature(geometry);
var featureCollection = pie.FeatureCollection(feature);
Map.addLayer(featureCollection);
Map.setCenter(120,40,5);
# withinDistance
判断左边的Geometry是否包含在右边Geometry的范围内,若包含返回true,不包含返回false。
函数 | 返回值 |
---|---|
withinDistance(right,distance,proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Geometry | 右边的Geometry |
distance | Number | 缓冲距离,默认单位是米,如果是度,需要设置proj为地理坐标系 |
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式; |
var point = pie.Geometry.Point([120,40]);
var geometry1 = point.buffer(1,"EPSG:4326"); // 1度的缓冲区
var geometry2 = point.buffer(10000); // 100米的缓冲区
print(geometry1.withinDistance(geometry2,1,"EPSG:4326"));