Feature
# 简介
要素(Feature)是PIE-Engine中的矢量要素对象,对应矢量数据中的一条记录,包括几何图形信息和属性信息。PIE-Engine Studio提供构建要素算子及要素相关算法,包括但不限于获取要素属性信息、几何信息,判断要素间位置关系,要素间空间分析计算。
# Feature
函数 | 返回值 |
---|---|
Feature(geometry,properties) | Feature |
参数 | 类型 | 说明 |
---|---|---|
geometry | Geometry | 几何形体对象 |
properties | Json | 属性信息JSON对象 |
var polyline = pie.Geometry.LineString([[118, 31.1],[119, 32.1]], null);
var feature = pie.Feature(polyline.bounds());
var featureCollection = pie.FeatureCollection(feature);
Map.addLayer(featureCollection);
Map.setCenter(118.5,31.6,9);
# area
计算矢量要素的面积,只对面有效。
函数 | 返回值 |
---|---|
area(proj) | Number |
参数 | 类型 | 说明 |
---|---|---|
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式 |
var geometry = pie.Geometry.Polygon([[[119, 39], [121, 39], [121, 41], [119, 41],[119, 39]]]);
var feature = pie.Feature(geometry);
print(feature.area());
# buffer
矢量要素的几何图形缓冲。
函数 | 返回值 |
---|---|
buffer(distance,proj) | Feature |
参数 | 类型 | 说明 |
---|---|---|
distance | Number | 缓冲距离,默认单位是米,如果是度,需要设置proj为地理坐标系 |
proj | Projection | 坐标系,指定distance的单位;可以WKT串也可以是EPSG编码表示方式 |
var point = pie.Geometry.Point([120,40]);
var feature = pie.Feature(point);
// feature = feature.buffer(1,"EPSG:4326"); // 1度的缓冲区
feature = feature.buffer(100); // 100米的缓冲区
var featureCollection = pie.FeatureCollection(feature);
Map.addLayer(featureCollection);
Map.setCenter(120,40,10);
# containedIn
判断左边矢量要素的Geometry是否包含在右边矢量要素的Geometry中,若包含返回true,不包含返回false。
函数 | 返回值 |
---|---|
containedIn(right,proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 右边的Feature |
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米的缓冲区
var feature1 = pie.Feature(geometry1);
var feature2 = pie.Feature(geometry2);
print(feature2.containedIn(feature1));
# contains
判断左边矢量要素的Geometry是否包含右边矢量要素的Geometry,若包含返回true,不包含返回false。
函数 | 返回值 |
---|---|
contains(right,proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 右边的Feature |
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米的缓冲区
var feature1 = pie.Feature(geometry1);
var feature2 = pie.Feature(geometry2);
print(feature1.contains(feature2));
# difference
计算左边矢量要素的Geometry和右边矢量要素的Geometry差集。
函数 | 返回值 |
---|---|
difference(right,proj) | Feature |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 右边的Feature |
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式 |
var polygon1 = pie.Geometry.Polygon([[[119, 39], [121, 39], [121, 41], [119, 41],[119, 39]]]);
var polygon2 = pie.Geometry.Polygon([[[120, 38], [122, 38], [122, 40], [120, 40],[120, 38]]]);
var feature1 = pie.Feature(polygon1);
var feature2 = pie.Feature(polygon2);
var feature = feature1.difference(feature2);
var featureCollection = pie.FeatureCollection(feature);
Map.addLayer(featureCollection);
Map.setCenter(120,40,6);
# disjoint
判断左边矢量要素的Geometry是否和右边矢量要素的Geometry相离,若相交返回true,不相交返回false。
函数 | 返回值 |
---|---|
disjoint(right,proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 右边的Feature |
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式; |
var polygon1 = pie.Geometry.Polygon([[[119, 39], [121, 39], [121, 41], [119, 41],[119, 39]]]);
var polygon2 = pie.Geometry.Polygon([[[122, 38], [123, 38], [123, 40], [122, 40],[122, 38]]]);
var feature1 = pie.Feature(polygon1);
var feature2 = pie.Feature(polygon2);
print(feature1.disjoint(feature2));
# geometry
获得矢量要素的几何形体。
函数 | 返回值 |
---|---|
geometry(maxError,proj,geodesic) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
maxError | MaxError | 未启用 |
proj | Projection | 坐标系对象,默认为WGS84 |
geodesic | Boolean | 未启用 |
var polyline = pie.Geometry.LineString([[118, 31.1],[119, 32.1]], null);
var feature = pie.Feature();
feature = feature.setGeometry(polyline.bounds());
var featureCollection = pie.FeatureCollection(feature);
var feature = featureCollection.getAt(0);
var geometry = feature.geometry();
# get
根据属性名获得Feature下的属性值信息。
函数 | 返回值 |
---|---|
get(key) | String|Number|Boolean|Object|List |
参数 | 类型 | 说明 |
---|---|---|
key | String | 属性名 |
var featureCollection0 = pie.FeatureCollection('NGCC/CHINA_CITY_BOUNDARY');
var feature = featureCollection0.first();
feature = feature.set("key1","keyValue1");
var value = feature.get("key1");
print(value);
# getArray
根据属性名获得Feature下的属性值信息,并且将其转换为数组类型。
函数 | 返回值 |
---|---|
getArray(property) | Array |
参数 | 类型 | 说明 |
---|---|---|
property | String | 属性名 |
var featureCollection = pie.FeatureCollection('TYPHOON/CMABST');
var feature = featureCollection.first();
var dict = {key1: "123", key2: 12.34, key3: [1, 2, 3, 4, 5, 6]};
feature = feature.setMulti(dict);
var value3 = feature.getArray("key3");
print(value3);
# getNumber
根据属性名获得Feature下的属性值信息,并且将其转换为数值类型。
函数 | 返回值 |
---|---|
getNumber(property) | Number |
参数 | 类型 | 说明 |
---|---|---|
property | String | 属性名 |
var featureCollection = pie.FeatureCollection('TYPHOON/CMABST');
var feature = featureCollection.first();
var dict = {key1: "123", key2: 12.34, key3: [1, 2, 3, 4, 5, 6]};
feature = feature.setMulti(dict);
var value = feature.getNumber("key1");
print(value);
# getString
根据属性名获得Feature下的属性值信息,并且将其转换为字符串类型。
函数 | 返回值 |
---|---|
getString(property) | String |
参数 | 类型 | 说明 |
---|---|---|
property | String | 属性名 |
var featureCollection = pie.FeatureCollection('TYPHOON/CMABST');
var feature = featureCollection.first();
var dict = {key1: "123", key2: 12.34, key3: [1, 2, 3, 4, 5, 6]};
feature = feature.setMulti(dict);
var value = feature.getString("key2").getInfo();
print(value);
# id
返回Feature对象的id。
函数 | 返回值 |
---|---|
id() | String |
var featureCollection = pie.FeatureCollection('NGCC/CHINA_PROVINCE_BOUNDARY');
var feature = featureCollection.first();
var id = feature.id().getInfo();
# intersection
计算左边矢量要素的Geometry和右边矢量要素的Geometry交集。
函数 | 返回值 |
---|---|
intersection(right,proj) | Feature |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 右边的Feature |
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式 |
var polygon1 = pie.Geometry.Polygon([[[119, 39], [121, 39], [121, 41], [119, 41],[119, 39]]]);
var polygon2 = pie.Geometry.Polygon([[[120, 38], [122, 38], [122, 40], [120, 40],[120, 38]]]);
var feature1 = pie.Feature(polygon1);
var feature2 = pie.Feature(polygon2);
var feature = feature1.intersection(feature2);
var featureCollection = pie.FeatureCollection(feature);
Map.addLayer(featureCollection);
Map.setCenter(120,40,6);
# intersects
判断左边矢量要素的Geometry是否和右边矢量要素的Geometry相交,若相交返回true,不相交返回false。
函数 | 返回值 |
---|---|
intersects(right,proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 右边的Feature |
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 feature1 = pie.Feature(polygon);
var feature2 = pie.Feature(polygon1);
print(feature1.intersects(feature2));
# length
计算几何图形的长度或周长,只对线面有效。
函数 | 返回值 |
---|---|
length(proj) | Number |
参数 | 类型 | 说明 |
---|---|---|
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式 |
var geometry = pie.Geometry.Polygon([[[119, 39], [121, 39], [121, 41], [119, 41],[119, 39]]]);
var feature = pie.Feature(geometry);
print(feature.length());
# propertyNames
返回Feature对象的属性名列表。
函数 | 返回值 |
---|---|
propertyNames() | List |
var featureCollection = pie.FeatureCollection('TYPHOON/CMABST');
var feature = featureCollection.first();
var propertyNames = feature.propertyNames().getInfo();
print(propertyNames);
# set
设置属性值,将覆盖一个或多个元数据属性。
方法参数:
- feature(Feature)
Feature实例
- key(String)
属性名称
- value(String|Number|Object|List)
属性值
返回值:Feature
# setGeometry
设置矢量要素的几何形体对象。
函数 | 返回值 |
---|---|
setGeometry(geometry) | Feature |
参数 | 类型 | 说明 |
---|---|---|
geometry | Geometry | 几何形体对象 |
var polyline = pie.Geometry.LineString([[118, 31.1],[119, 32.1]], null);
var feature = pie.Feature();
feature = feature.setGeometry(polyline.bounds());
var featureCollection = pie.FeatureCollection(feature);
Map.addLayer(featureCollection);
Map.setCenter(118.5,31.6,9);
# setMulti
批量设置Feature下的属性信息,如果存在就覆盖更新,如果不存在则直接创建。
函数 | 返回值 |
---|---|
setMulti(properties) | Void |
参数 | 类型 | 说明 |
---|---|---|
properties | Dictionary | 属性键值对,以字典形式传入 |
var featureCollection = pie.FeatureCollection('TYPHOON/CMABST');
var feature = featureCollection.first();
var dict = {key1: "123", key2: 12.34, key3: [1, 2, 3, 4, 5, 6]};
feature = feature.setMulti(dict);
print(feature);
# simplify
矢量要素的Geometry简化。
函数 | 返回值 |
---|---|
simplify(proj) | Feature |
参数 | 类型 | 说明 |
---|---|---|
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式; |
var geometry = pie.Geometry.Polygon([[[119, 39], [121, 39], [121, 41], [119, 41],[119, 39]]]);
var feature = pie.Feature(geometry);
feature = feature.simplify();
var featureCollection = pie.FeatureCollection(feature);
Map.addLayer(featureCollection);
Map.setCenter(120,40,6);
# union
计算左边矢量要素的Geometry和右边矢量要素的Geometry并集。
函数 | 返回值 |
---|---|
union(right,proj) | Feature |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 右边的Feature |
proj | Projection | 坐标系,可以WKT串也可以是EPSG编码表示方式 |
var polygon1 = pie.Geometry.Polygon([[[119, 39], [121, 39], [121, 41], [119, 41],[119, 39]]]);
var polygon2 = pie.Geometry.Polygon([[[120, 38], [122, 38], [122, 40], [120, 40],[120, 38]]]);
var feature1 = pie.Feature(polygon1);
var feature2 = pie.Feature(polygon2);
var feature = feature1.union(feature2);
var featureCollection = pie.FeatureCollection(feature);
Map.addLayer(featureCollection);
Map.setCenter(120,40,6);
# withinDistance
判断左边矢量要素的Geometry是否包含在右边矢量要素的Geometry的范围内,若包含返回true,不包含返回false。
函数 | 返回值 |
---|---|
withinDistance(right,distance,proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 右边的Feature |
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米的缓冲区
var feature1 = pie.Feature(geometry1);
var feature2 = pie.Feature(geometry2);
print(feature1.withinDistance(feature2,1,"EPSG:4326"));