kikita & Maps

GIS,spatial and artificial intellegence learning and share

UPDATE 2017-1-3 ArcGIS Python API V1.0

准备环境

1 获取并安装Conda

下载安装 Anaconda for Python(python 3.5),下载地址。 如果机器上已经安装过ArcGIS Pro 1.3及以上版本,那么Conda已经被自动安装了,直接执行“Python Command Prompt”即可继续下一步。

就更新这天的测试结果看,ArcGIS Pro 1.4 Alpha4 版本自带的conda环境为:4.0.11, 手动可以下载到的最高版本为 4.2.0.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[arcgispro-py3] C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3>conda info
Current conda install:

platform : win-64
conda version : 4.0.11
conda-build version : not installed
python version : 3.5.2.final.0
requests version : 2.11.1
root environment : C:\Program Files\ArcGIS\Pro\bin\Python (writable)
default environment : C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3
envs directories : C:\Program Files\ArcGIS\Pro\bin\Python\envs
package cache : C:\Program Files\ArcGIS\Pro\bin\Python\pkgs
channel URLs : https://conda.anaconda.org/esri/win-64/
https://conda.anaconda.org/esri/noarch/
https://repo.continuum.io/pkgs/free/win-64/
https://repo.continuum.io/pkgs/free/noarch/
https://repo.continuum.io/pkgs/pro/win-64/
https://repo.continuum.io/pkgs/pro/noarch/
config file : C:\Program Files\ArcGIS\Pro\bin\Python\.condarc
is foreign system : False

2 安装arcgis包

在Python Command Prompt,执行如下命令下载安装 ArcGIS Python API 到Conda环境。

conda install -c esri arcgis

Read more »

在我们建模的过程中,通常会遇到一些实际问题,例如,如何在道路右边放置交通指示灯? 如何在道路的左边放置行树?如何在管线的末尾放置阀门?等等。

这些有关线状要素的方向和左右的判断,可以通过UV坐标系来确定的。 线的UV坐标系与线的方向相关,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
* File: LineDirection.cga
* Created: 22 Sep 2016 06:06:18 GMT
* Author: kikit
*/

version "2016.0"

init -->
Line2

split(u,unitSpace,0){'0.1:StartSegment|'0.8:NIL|'0.1:EndSegment}
StartSegment --> color(0,1,0) #Green
EndSegment --> color(1,0,0) #Red

Line2 -->
translate(rel,world,0,0,-20)
split(v,unitSpace,0){'0.2:LeftSide|'0.6:NIL|'0.2:RightSide}
LeftSide --> color(1,1,0) #Yellow
RightSide --> color(0,1,1) #Blue

我们可以在ArcGIS之外调用arcpy站点包运行python独立脚本,从而批量化任务提高工作效率。 如果可以把做好的脚本打包成exe是不是就更方便了呢?想想一键式处理也挺开心的。

Python打包的问题最早是在 ArcGIS知乎 中看到的,有人提问为何打包失败,我还有幸被邀请回答,虽然在这一块我也是小白一枚。 后来,得空时也搜了下相关的资源,虽然大部分人持悲观态度说arcpy不支持打包,但刚好有个帖子说可以实现,并且宣称 “It can be done easily!”,那我就动手试试吧。

Step1 下载安装Py2exe

Py2exe是一个Python工具发布扩展包,可以用来将Python脚本转化为Windows的可执行程序,详情看 官网 py2exe.org

下载Py2exe安装程序,下载地址戳 这里

ArcGIS Desktop使用的Python 2.7.x版本,可以对应下载安装 py2exe-0.6.9.win32-py2.7.exe 这个32位的版本;如果你的机器上安装 ArcGIS Desktop 64-bit Background Geoprocessing 补丁或者安装了 ArcGIS Server产品,也可以下载安装 **py2exe-0.6.9.win64-py2.7.amd64.exe**。 在这篇博客中,我就以 64位的包为例来说明打包的过程。


Step2 编写脚本文件准备打包

打包时需要有至少两个脚本文件,一个是 setup_py2exe.py, 一个是执行实际任务的 HelloPy2exe.py 脚本文件。

看第一个脚本 setup_py2exe.py,包含如下两行:

Read more »

背景

ArcGIS Pro像ArcMap一样,其中也嵌入了Python。 不同在于ArcGIS Pro采用了python较新的版本3.4,ArcMap仍然沿用2.x版本。 ArcGIS Pro 1.3版本开始Python环境有点小变化,为了方便包管理esri开始采用Conda。 并且不像开始 ArcGIS Pro 1.1,1.2 版本,需要单独安装Python for ArcGIS Pro,在1.3版本python包随ArcGIS Pro一同自行安装。

文档的原文摘过来能更好的理解esri采用Conda的意图:

Python has a rich ecosystem of preexisting packages that can be leveraged within ArcGIS, but managing which packages are installed on a system can be a complex and time-consuming task, especially when working on multiple projects or trying to share code with others.

To leverage this versatility, the Python community has created methods to easily create projects in multiple versions of Python and simplifies the process of installing nearly all publicly available Python packages. Conda is the most popular and widely used Python package manager.

看到这里,你也也许和我有一样的疑问,啥是Conda?这里 。这页文档是esri刚更新的内容,需要在英文语言版本文档中才能找到。


执行脚本

这些改变,对于习惯在 ArcGIS Pro 内部的脚本命令行中执行脚本的用户并没有多大影响。 但是如果已经习惯了在ArcGIS Pro 之外独立执行脚本,那如下的改变要注意下了。

ArcGIS Pro 的Python包不再是ArcMap默认安装的位置 C:\Python27 ,而是安装在 ArcGIS Pro的安装目录\bin\Python

ArcGIS Pro 采用了的Conda环境为 arcgispro-py3,有几个方式可以访问这个环境。

Read more »
0%