在前文中我们添加了对QGIS2系列的支持,
但是随著QGIS3的发布,其插件开发介面也做了非常大的更新,这次我们也做了相应的适配,大家可以到QGIS3的菜单Plugins-->Manage and Install Plugin..中安装.
除了在QGIS中,还可以在python中直接调用,或者在命令行中对shp、geojson等矢量文件进行火星坐标转换。
推荐使用: pip install coord-convert
或者也可以从源码安装:
git clone https://github.com/sshuair/coord-convert.git pip install -r requirements.txt python setup.py install
在python程序中调用相应的坐标转换介面:coord-convert
from coord_convert.transform import wgs2gcj, wgs2bd, gcj2wgs, gcj2bd, bd2wgs, bd2gcj lon, lat = 120, 40 gcj_lon, gcj_lat = wgs2gcj(lon, lat) bd_lon, bd_lat = wgs2bd(lon, lat) print(gcj_lon, gcj_lat) # the result should be: 120.00567568355486 40.0013047896019
火星坐标转换还支持命令行直接对shp、geojson等文件进行转换,比如
~/temp > coord_covert gcj2wgs tests/data/Polyline/polyline.geojson aa.geojson 100%|██████████████████████████████████████████████████████| 219/219 [00:00<00:00, 550.93it/s]
更详细的用法:
convert input china coordinate to another.
Arguments: convert_type {string} -- [coordinate convert type, e.g. wgs2bd]
wgs2gcj : convert WGS-84 to GCJ-02 wgs2bd : convert WGS-84 to DB-09 gcj2wgs : convert GCJ-02 to WGS-84 gcj2bd : convert GCJ-02 to BD-09 bd2wgs : convert BD-09 to WGS-84 bd2gcj : convert BD-09 to GCJ-02
src_path {string} -- [source file path] dst_path {string} -- [destination file path]
Example: coord_covert wgs2gcj ./examples/data/polygon/polygon_wgs.shp ~/temp/polygon_gcj.shp
文/sshuair
推荐阅读: