Python 在GIS中的使用(一)
本文最后更新于:2022年9月21日 晚上
1.Preface
Python之所以强大是因为能用(依赖)的库多罢了
但是较为繁琐的是环境的搭建、配置和维护
- 使用初期 包、库的安装
- 库的更新、Python版本的更新也会带来问题
- 新版本库不支持老Python
- 新版本Python不支持老库
- 语法规范?感觉像是双刃剑
- 写起来方便
- 有时候理解需要一点时间反应
- Python运行有时候还是比较慢的
可能优点是?
- 在Win和Mac双系统切换的时候,都能正常使用
- 不像某些专业软件比如ArcGIS只有Win版
- 有相同的安装环境就能跑
- 网上可复用的代码块较多、案例较多
- 弥补局限性,代码代替多次操作,Arcpy代替ModelBuilder
2.有关环境
1.使用工具
- Anacoda3 2022.5 MacOSX
- Spyder 5.1.5
- Python 3.8.13
2.配置流程
安装Anaconda 官网下载
Environments中配置自己的编程环境 OSGIS
- Create 创建环境
- Import 导入环境
- Backup 备份环境
安装库
方法1: 环境下利用终端 conda install 或者 pip install
- 优点 直接
- 缺点 非可视化
方法2: 更新Channels 从 conda Channels中导入
问题:文件夹写入权限问题
1
NotWritableError: The current user does not have write permissions to a required path.解决方法:
1
2cd /users/o1/opt //操作opt文件夹下的anaconda3
sūdo chown -R o1 anaconda3 //赋予权限更新具体Channels
1
2
3
4
5
6
7
8
9
10
11
12
13
14conda config --get channels //获取当前环境OSGIS下Channels
conda config --add channels conda-forge //有强大的社区支持,提供了大多数安装包,并且更新及时
conda config --remove-key channels //删除Channel
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/pytorch/
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
conda config --set show_channel_urls yes
# activate my environment
conda activate OSGIS
# update all packages if needed
conda update --all
# set channel priority as strict 设置优先级
conda config --set channel_priority strict
常见的库
- numpy
- GDAL
3. 基本流程
读取、处理、写入(更新)
Python 在GIS中的使用(一)
https://anonymouslosty.ink/2022/06/27/pythonInGIS/