geojson转wkt
时间: 2024-02-05 21:03:16 浏览: 143
wkt与geojson互相转换所需的依赖包.rar
5星 · 资源好评率100%
可以使用许多不同的工具和库来将GeoJSON转换为WKT格式,下面是一些常用的方法:
方法一:使用Python中的`shapely`库
```python
import json
from shapely.geometry import shape
# 将GeoJSON读入Python字典
with open('data.geojson') as f:
geojson_data = json.load(f)
# 将每个要素转换为WKT格式
for feature in geojson_data['features']:
geom = shape(feature['geometry'])
wkt = geom.wkt
print(wkt)
```
方法二:使用在线转换工具,如MyGeodata Converter
1. 打开 https://mygeodata.cloud/converter/geojson-to-wkt
2. 上传要转换的GeoJSON文件
3. 点击“转换”按钮
4. 下载WKT文件或将结果复制到剪贴板
方法三:使用在线代码编辑器,如CodePen
1. 打开 https://codepen.io/pen/
2. 在HTML编辑器中添加以下代码:
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/turf.js/5.1.6/turf.min.js"></script>
<script>
// 将GeoJSON读入JavaScript对象
const geojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dinagat Islands"
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[125.6, 10.1],
[125.7, 10.2],
[125.8, 10.3]
]
},
"properties": {
"name": "Philippine Trench"
}
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[125.6, 10.1],
[125.7, 10.2],
[125.8, 10.3],
[125.6, 10.1]
]
]
},
"properties": {
"name": "Dinagat Islands"
}
}
]
};
// 将每个要素转换为WKT格式
geojson.features.forEach(function(feature) {
const wkt = turf.wkt.stringify(feature);
console.log(wkt);
});
</script>
```
3. 将GeoJSON数据添加到JavaScript对象中
4. 点击“运行”按钮
5. 在控制台中查看转换后的WKT格式
阅读全文