Feature
# 简介
要素(Feature)是PIE-Engine中的矢量要素对象,对应矢量数据中的一条记录,包括几何图形信息和属性信息。PIE-Engine Studio提供构建要素算子及要素相关算法,包括但不限于获取要素属性信息、几何信息,判断要素间位置关系,要素间空间分析计算。
# Feature
函数 | 返回值 |
---|---|
Feature(geometry,properties) | Feature |
参数 | 类型 | 说明 |
---|---|---|
geometry | Geometry | 几何形体对象 |
properties | Json | 属性信息JSON对象 |
# 示例
polyline = pie.Geometry.LineString([[118, 31.1],[119, 32.1]], None)
feature = pie.Feature(polyline.bounds(0,None))
Map = pie.Map()
Map.addLayer(feature,{'color':'red'},'feature')
Map.setCenter(118.5,31.6,8)
Map
# area
计算矢量图形对象的面积,只对面有效。
函数 | 返回值 |
---|---|
area(self,proj) | Number |
参数 | 类型 | 说明 |
---|---|---|
proj | Dictionary | 设置投影方式 |
# 示例
polygon = pie.Geometry.Polygon([[
[
76.0641376209303,
44.11876326018208
],
[
80.83964695953506,
49.800143138994855
],
[
89.95652842415888,
48.14753031988744
],
[
82.74985069498081,
41.50791700751361
],
[
76.0641376209303,
44.11876326018208
]
]], None)
p_feature = pie.Feature(polygon)
print(p_feature.area(None).getInfo())
# buffer
返回矢量要素的几何图形在给定距离生成的缓冲区。
函数 | 返回值 |
---|---|
buffer(self, distance, proj) | Feature |
参数 | 类型 | 说明 |
---|---|---|
distance | Int | 缓冲距离 |
proj | Dictionary | 设置投影方式 |
# 示例
polygon = pie.Geometry.Polygon([[
[
76.0641376209303,
44.11876326018208
],
[
80.83964695953506,
49.800143138994855
],
[
89.95652842415888,
48.14753031988744
],
[
82.74985069498081,
41.50791700751361
],
[
76.0641376209303,
44.11876326018208
]
]], None)
p_feature = pie.Feature(polygon)
p_buffer = p_feature.buffer(100000, None)
Map = pie.Map()
Map.addLayer(p_feature, {'color': 'blue'}, 'p_feature')
Map.addLayer(p_buffer, {'color': 'red'}, 'p_buffer')
Map.setCenter(84,46,5)
Map
# containedIn
判断左边矢量要素的Geometry是否包含在右边矢量要素的Geometry中,若包含返回True,不包含返回False。
函数 | 返回值 |
---|---|
containedIn(self,right,proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 矢量对象 |
proj | Dictionary | 设置投影方式 |
# 示例
a = pie.Geometry.Polygon([[
[
86.80129479936647,
47.42899226581099
],
[
82.87305373501061,
47.53413332597603
],
[
79.52821480892538,
44.62131637232005
],
[
95.12449863869472,
40.29107652773166
],
[
96.56355724642901,
43.390491195479
],
[
86.80129479936647,
47.42899226581099
]
]], None)
b = pie.Geometry.Polygon([[
[
76.0641376209303,
44.11876326018208
],
[
80.83964695953506,
49.800143138994855
],
[
89.95652842415888,
48.14753031988744
],
[
82.74985069498081,
41.50791700751361
],
[
76.0641376209303,
44.11876326018208
]
]], None)
af = pie.Feature(a)
bf = pie.Feature(b)
print(af.containedIn(bf, None).getInfo())
# contains
判断左边矢量要素的Geometry是否包含右边矢量要素的Geometry,若包含返回True,不包含返回False。
函数 | 返回值 |
---|---|
contains(self,right,proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 矢量对象 |
proj | Dictionary | 设置投影方式 |
# 示例
a = pie.Geometry.Polygon([[
[
86.80129479936647,
47.42899226581099
],
[
82.87305373501061,
47.53413332597603
],
[
79.52821480892538,
44.62131637232005
],
[
95.12449863869472,
40.29107652773166
],
[
96.56355724642901,
43.390491195479
],
[
86.80129479936647,
47.42899226581099
]
]], None)
b = pie.Geometry.Polygon([[
[
76.0641376209303,
44.11876326018208
],
[
80.83964695953506,
49.800143138994855
],
[
89.95652842415888,
48.14753031988744
],
[
82.74985069498081,
41.50791700751361
],
[
76.0641376209303,
44.11876326018208
]
]], None)
af = pie.Feature(a)
bf = pie.Feature(b)
print(af.contains(bf, None).getInfo())
# difference
计算左边矢量要素的Geometry和右边矢量要素的Geometry差集。
函数 | 返回值 |
---|---|
difference(self, right, proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 矢量对象 |
proj | Dictionary | 设置投影方式 |
# 示例
a = pie.Geometry.Polygon([[
[
86.80129479936647,
47.42899226581099
],
[
82.87305373501061,
47.53413332597603
],
[
79.52821480892538,
44.62131637232005
],
[
95.12449863869472,
40.29107652773166
],
[
96.56355724642901,
43.390491195479
],
[
86.80129479936647,
47.42899226581099
]
]], None)
b = pie.Geometry.Polygon([[
[
76.0641376209303,
44.11876326018208
],
[
80.83964695953506,
49.800143138994855
],
[
89.95652842415888,
48.14753031988744
],
[
82.74985069498081,
41.50791700751361
],
[
76.0641376209303,
44.11876326018208
]
]], None)
af = pie.Feature(a)
bf = pie.Feature(b)
cf = af.difference(bf, None)
print(cf.geometry().getInfo())
Map = pie.Map()
Map.addLayer(af, {'color': 'red'}, 'af')
Map.addLayer(bf, {'color':'blue'}, 'bf')
Map.addLayer(cf, {'color':'yellow'}, 'cf')
Map.setCenter(84,45,5)
Map
# disjoint
判断左边矢量要素的Geometry是否和右边矢量要素的Geometry相离,若相离返回True,不相离返回False。
函数 | 返回值 |
---|---|
disjoint(self,right,proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 矢量对象 |
proj | Dictionary | 设置投影方式 |
# 示例
a = pie.Geometry.Polygon([[
[
86.80129479936647,
47.42899226581099
],
[
82.87305373501061,
47.53413332597603
],
[
79.52821480892538,
44.62131637232005
],
[
95.12449863869472,
40.29107652773166
],
[
96.56355724642901,
43.390491195479
],
[
86.80129479936647,
47.42899226581099
]
]], None)
b = pie.Geometry.Polygon([[
[
76.0641376209303,
44.11876326018208
],
[
80.83964695953506,
49.800143138994855
],
[
89.95652842415888,
48.14753031988744
],
[
82.74985069498081,
41.50791700751361
],
[
76.0641376209303,
44.11876326018208
]
]], None)
af = pie.Feature(a)
bf = pie.Feature(b)
print(af.disjoint(bf, None).getInfo())
# geometry
获得矢量要素的几何形体。
函数 | 返回值 |
---|---|
geometry(maxError,proj,geodesic) | Geometry |
参数 | 类型 | 说明 |
---|---|---|
maxError | MaxError | 未启用 |
proj | Project | 坐标系,默认为WGS84 |
geodesic | Boolean | 未启用 |
# 示例
featureCollection = pie.FeatureCollection("NGCC/CHINA_PROVINCE_BOUNDARY")
f0 = featureCollection.getAt(0).geometry()
print(f0.getInfo())
# get
根据属性名获得Feature下该属性值信息。
函数 | 返回值 |
---|---|
get(self,key) | Value |
参数 | 类型 | 说明 |
---|---|---|
key | String | 属性名 |
# 示例
geometry = pie.Geometry.LineString([
[
116.47239746093555,
39.90895451343508
],
[
115.61247314452947,
40.701053532910964
]
], None)
f = pie.Feature(geometry)
f = f.set("key1",1)
value = f.get("key1")
print(value.getInfo())
# getArray
根据属性名获得Feature下的属性值信息,并且将其转换为数组类型。
函数 | 返回值 |
---|---|
getArray(property) | Array |
参数 | 类型 | 说明 |
---|---|---|
property | String | 属性名 |
# 示例
featureCollection = pie.FeatureCollection("user/101/public/shape/Shi_HeBei")
value = featureCollection.first().getArray("Bianma").getInfo()
print(value)
# getNumber
根据属性名获得Feature下的属性值信息,并且将其转换为数值类型。
函数 | 返回值 |
---|---|
getNumber(property) | Number |
参数 | 类型 | 说明 |
---|---|---|
property | String | 属性名 |
# 示例
featureCollection = pie.FeatureCollection("user/101/public/shape/Shi_HeBei")
value = featureCollection.first().getNumber("Bianma").getInfo()
print(value)
# getString
根据属性名获得Feature下的属性值信息,并且将其转换为字符串类型。
函数 | 返回值 |
---|---|
getString(property) | String |
参数 | 类型 | 说明 |
---|---|---|
property | String | 属性名 |
# 示例
featureCollection = pie.FeatureCollection("user/101/public/shape/Shi_HeBei")
value = featureCollection.first().getString("NAME").getInfo()
print(value)
# id
返回Feature对象的id。
函数 | 返回值 |
---|---|
id() | String |
# 示例
featureCollection = pie.FeatureCollection("user/101/public/shape/Shi_HeBei")
feature = featureCollection.first()
id = feature.id().getInfo()
print(id)
# intersection
计算左边矢量要素的Geometry和右边矢量要素的Geometry交集。
函数 | 返回值 |
---|---|
intersection(self, right, proj) | Feature |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 矢量对象 |
proj | Dictionary | 设置投影方式 |
# 示例
a = pie.Geometry.Polygon([[
[
86.80129479936647,
47.42899226581099
],
[
82.87305373501061,
47.53413332597603
],
[
79.52821480892538,
44.62131637232005
],
[
95.12449863869472,
40.29107652773166
],
[
96.56355724642901,
43.390491195479
],
[
86.80129479936647,
47.42899226581099
]
]], None)
b = pie.Geometry.Polygon([[
[
76.0641376209303,
44.11876326018208
],
[
80.83964695953506,
49.800143138994855
],
[
89.95652842415888,
48.14753031988744
],
[
82.74985069498081,
41.50791700751361
],
[
76.0641376209303,
44.11876326018208
]
]], None)
af = pie.Feature(a)
bf = pie.Feature(b)
cf = af.intersection(bf, None)
print(cf.geometry().getInfo())
Map = pie.Map()
Map.addLayer(af, {'color': 'red'}, 'af')
Map.addLayer(bf, {'color': 'blue'}, 'bf')
Map.addLayer(cf, {'color': 'yellow'}, 'cf')
Map.setCenter(84,46,5)
Map
# intersects
判断左边矢量要素的Geometry是否和右边矢量要素的Geometry相交,若相交返回True,不相交返回False。
函数 | 返回值 |
---|---|
intersects(self,right,proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 矢量对象 |
proj | Dictionary | 设置投影方式 |
# 示例
a = pie.Geometry.Polygon([[
[
86.80129479936647,
47.42899226581099
],
[
82.87305373501061,
47.53413332597603
],
[
79.52821480892538,
44.62131637232005
],
[
95.12449863869472,
40.29107652773166
],
[
96.56355724642901,
43.390491195479
],
[
86.80129479936647,
47.42899226581099
]
]], None)
b = pie.Geometry.Polygon([[
[
76.0641376209303,
44.11876326018208
],
[
80.83964695953506,
49.800143138994855
],
[
89.95652842415888,
48.14753031988744
],
[
82.74985069498081,
41.50791700751361
],
[
76.0641376209303,
44.11876326018208
]
]], None)
af = pie.Feature(a)
bf = pie.Feature(b)
print(af.intersects(bf, None).getInfo())
# length
计算矢量图形对象的长度或周长,只对线面有效。
函数 | 返回值 |
---|---|
length(self,proj) | Number |
参数 | 类型 | 说明 |
---|---|---|
proj | Dictionary | 设置投影方式 |
# 示例
line = pie.Geometry.LineString([
[
86.21755088013333,
42.173683155554215
],
[
95.75003820467464,
45.90600966211181
],
],None)
l_feature = pie.Feature(line)
print(l_feature.length(None).getInfo())
# propertyNames
返回Feature对象的属性名列表。
函数 | 返回值 |
---|---|
propertyNames() | List |
# 示例
featureCollection = pie.FeatureCollection("user/101/public/shape/Shi_HeBei")
feature = featureCollection.first()
feature = feature.set("key1", 123)
propertyNames = feature.propertyNames().getInfo()
print(propertyNames)
# set
设置Feature下的指定属性的属性值,如果存在就覆盖更新,如果不存在则直接创建。
函数 | 返回值 |
---|---|
Set(self,key,value) | Void |
参数 | 类型 | 说明 |
---|---|---|
key | String | 属性名 |
value | String|Number|Boolean|Object|List | 属性值 |
# 示例
geometry = pie.Geometry.LineString([
[
116.47239746093555,
39.90895451343508
],
[
115.61247314452947,
40.701053532910964
]
], None)
f = pie.Feature(geometry)
f_set = f.set("key1", [1,2,3])
f_set2 = f.set('properties', 'feature')
print(f_set.getInfo())
print(f_set2.getInfo())
# setGeometry
设置矢量要素的几何形体对象。
函数 | 返回值 |
---|---|
setGeometry(geometry) | Feature |
参数 | 类型 | 说明 |
---|---|---|
geometry | Geometry | 几何形体对象 |
# 示例
polyline = pie.Geometry.LineString([[118, 31.1],[119, 32.1]], None)
feature = pie.Feature().setGeometry(polyline.bounds(0,None))
Map = pie.Map()
Map.addLayer(feature,{'color':'red'},'feature')
Map.addLayer(pie.Feature(polyline),{'color':'blue'},'polyline')
Map.setCenter(118.5,31.5,8)
Map
# setMulti
批量设置Feature下的属性信息,如果存在就覆盖更新,如果不存在则直接创建。
函数 | 返回值 |
---|---|
setMulti(properties) | Void |
参数 | 类型 | 说明 |
---|---|---|
properties | Dictionary | 属性键值对,以字典形式传入 |
# 示例
featureCollection = pie.FeatureCollection("user/101/public/shape/Shi_HeBei")
feature = featureCollection.first()
dict = {'key1': "123", 'key2': 12.34, 'key3': [1, 2, 3, 4, 5, 6]}
feature = feature.setMulti(dict)
print(feature.getInfo())
# simplify
简化矢量图形对象。
函数 | 返回值 |
---|---|
simplify(self,proj) | Feature |
参数 | 类型 | 说明 |
---|---|---|
proj | Dictionary | 设置投影方式 |
# 示例
featureCollection = pie.FeatureCollection("NGCC/CHINA_PROVINCE_BOUNDARY")
f0 = featureCollection.getAt(0)
print(f0.simplify(None).getInfo())
# union
计算左边矢量要素的Geometry和右边矢量要素的Geometry并集。
函数 | 返回值 |
---|---|
union(self, right, proj) | Feature |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 矢量对象 |
proj | Dictionary | 设置投影方式 |
# 示例
a = pie.Geometry.Polygon([[
[
86.80129479936647,
47.42899226581099
],
[
82.87305373501061,
47.53413332597603
],
[
79.52821480892538,
44.62131637232005
],
[
95.12449863869472,
40.29107652773166
],
[
96.56355724642901,
43.390491195479
],
[
86.80129479936647,
47.42899226581099
]
]], None)
b = pie.Geometry.Polygon([[
[
76.0641376209303,
44.11876326018208
],
[
80.83964695953506,
49.800143138994855
],
[
89.95652842415888,
48.14753031988744
],
[
82.74985069498081,
41.50791700751361
],
[
76.0641376209303,
44.11876326018208
]
]], None)
af = pie.Feature(a)
bf = pie.Feature(b)
cf = af.union(bf, None)
print(cf.geometry().getInfo())
Map = pie.Map()
Map.addLayer(af, {'color': 'red'}, 'af')
Map.addLayer(bf, {'color': 'blue'}, 'bf')
Map.addLayer(cf, {'color': 'yellow'}, 'cf')
Map.setCenter(84,46,5)
Map
# withinDistance
判断左边矢量要素的Geometry与右边矢量要素的Geometry相隔距离是否在给定的范围内,若是返回Ttrue,不是返回False。
函数 | 返回值 |
---|---|
withinDistance(self,right,distance,proj) | Boolean |
参数 | 类型 | 说明 |
---|---|---|
right | Feature | 矢量对象 |
proj | Dictionary | 设置投影方式 |
distance | int | 缓冲距离 |
# 示例
featureCollection = pie.FeatureCollection("NGCC/CHINA_PROVINCE_BOUNDARY")
f0 = featureCollection.getAt(0)
f1 = featureCollection.getAt(1)
print(f0.withinDistance(f1,1000000,None).getInf