语句语法:
面积:$area/1000000
,$area表示平方米,除以1000000,结果就是平方公里
多条件语法:
设置 Layer → Properties → Symbol → Rule-based → Filter,根据条件设置图层显示样式。(比Categorized更高级、灵活的样式)
"name" = '香洲区' AND "type" = 'sub'
这个polygon的feature有2个字段,name和type。type有2种,main(主区域)和sub(附属岛屿)
可能的问题
1、mutiString 执行 polygonize 前,务必确保每一段独立的线段至少包含3小段(含端点顶点至少4个顶点),否则可能会被忽略,结果就缺一块。
polygonize.png
2、QIGS貌似对MutiPolygon的兼容性有点问题,显示没毛病,但是往往执行各种操作(如Centroids、GCJ02 to WGS等)就会报错。
错误信息类似于
2024-02-03T09:42:26 CRITICAL Feature (0) from “黄埔各街道DIY” has invalid geometry.
Please fix the geometry or change the “Invalid features filtering” option for this input or globally in Processing settings.
用Processing Toolbox的Check Validity工具检查,在输出的Error ouput的attriubte table里可以看到错误信息
'Self-intersection'
QGIS创建图层的Geometry type里也没有MutiPolygon选项。(ScratchLayer则有MutiPolygon选项)
关于Polygon和MutiPolygon的区别自行查阅资料,我也不肾了解。我的解决办法就用js代码把MutiPolygon转换成Polygon。
转换代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
</style>
</head>
<body>
<p>
请打开控制台(chrome浏览器 按F12打开 或 ctrl+shift+i 或在菜单中找到开发者工具),在控制台(console)菜单栏中查看输出结果。
</p>
</body>
<script type="module">
window.onload = function() {
mutiPolygon2Polygon()
} // onload end.........................................................................................................
function mutiPolygon2Polygon() {
var mutiPolygon = getMutiPolygon()
// console.log(mutiPolygon)
if (mutiPolygon && mutiPolygon.features && mutiPolygon.features.length > 0) {
var layerName = '珠海' //在 gis 左侧 Layers 窗口展示的名称
var thePolygon = {
"type": "FeatureCollection",
"name": layerName,
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
features: [
]
}
for (var i = mutiPolygon.features.length - 1; i >= 0; i--) {
var featureMlti = mutiPolygon.features[i]
if (featureMlti.geometry) {
var polygonArr = featureMlti.geometry.coordinates
if (polygonArr && polygonArr.length > 0) {
for (var j = 0; j < polygonArr.length; j++) {
var polygon = polygonArr[j]
var feature = genFeatrue()
feature.geometry.coordinates = polygon // 给 Feature 的 geometry.coordinates 添加坐标数组
// 属性拷贝,可能有多个属性,看你需要保留哪一些。手动修改。
feature.properties.name = featureMlti.properties.name
// feature.properties.filedName2 = featureMlti.properties.xxx2
// feature.properties.filedName3 = featureMlti.properties.xxx3
thePolygon.features.push(feature)
}
} else {
console.log('featureMlti index = ' + i + '. mutiPolygon.features.geometry.coordinates empty')
}
}
}
var string = JSON.stringify(thePolygon)
console.log(string)
} else {
console.log('mutiPolygon.features.geometry null')
}
}
// Polygon 的 Feature
function genFeatrue() {
return {
"type": "Feature",
"properties": {
// name: ''
},
geometry: {
type: 'Polygon',
"coordinates": []
}
}
}
// 执行操作会出错的mutiPolygon贴 return 后面,(下面是删减大部分内容后的一个示例)
// 粘贴后,保存文本,浏览器上刷新即可。
function getMutiPolygon() {
return {"type":"FeatureCollection","features":[{"type":"Feature","properties":{"adcode":440402,"name":"香洲区","center":[113.55027,22.271249],"centroid":[113.534744,22.257259],"childrenNum":0,"level":"district","parent":{"adcode":440400},"subFeatureIndex":0,"acroutes":[100000,440000,440400]},"geometry":{"type":"MultiPolygon","coordinates":[[[[113.430563,22.201289],[113.426009,22.194849],[113.418899,22.190714],[113.413314,22.186605],[113.41463,22.184083],[113.426927,22.160445], [113.430563,22.201289]]]]}}]}
}
</script>
</html
网友评论