没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Python 是一种不受局限、跨平台的开源编程语言,它功能强大且简单易学。因而得到了广泛应用和支持。要了解有关 Python 的详细信息,请访问
python.org。
ArcGIS 9.0 社区中引入了 Python。此后,Python 被视为可供地理处理用户选择的脚本语言并得以不断发展。每个版本都进一步增强了 Python 体验,从而为
您提供更多的功能以及更丰富、更友好的 Python 体验。
ESRI 已将 Python 完全纳入 ArcGIS 中,并将其视为可满足我们用户社区需求的语言。下面仅介绍 Python 的部分优势:
l 易于学习,非常适合初学者,也特别适合专家使用
l 可伸缩程度高,适于大型项目或小型的一次性程序(称为脚本)
l 可移植,跨平台
l 可嵌入(使 ArcGIS 可脚本化)
l 稳定成熟
l 用户社区规模大
Python 已延伸到 ArcGIS 中,成为了一种用于进行数据分析、数据转换、数据管理和地图自动化的语言,因而有助于提高工作效率。
了解 Python
以下包含的信息并不是 Python 的语言参考。而是根据一些用于说明如何编写地理处理脚本的示例和概念来介绍某些 Python 语法和行为。
强烈建议您结合相应的 Python 参考书来进一步了解此处介绍的信息。对于 Python 初学者,建议使用以下两本书籍:《学习 Python》(Learning Python)
(作者:Mark Lutz 和 David Ascher,出版社:O’Reilly & Associates)和《Python 核心编程》(Core Python Programming)(作者:Wesley J.
Chun,出版社:Prentice Hall),这两本书都对该语言进行了详尽介绍,并且内容上不重叠。还有很多其他书籍也介绍了 Python 及其具体用途,其中有些
新书会定期出版,因此可以探究可用的内容。Python 网站上提供了 Python 的完整文档,但内容很简明,主要是面向开发人员的。还有一个大型的 Python
在线社区,其中包含很多在线资源,您可通过 Python 主页访问这些资源。
Python 教程
如果您是 Python 的初学者,我们推荐您学习此处列出的一些外部教程。
l Python 教程 是 Python 文档本身的一部分。
l 针对非程序员的 Python为编程经验有限的人士提供教程。
l Python 语言参考介绍 Python 的语法和语义。
针对程序员的 Python 教程
此处所列的外部教程主要面向以前学习过其他编程语言(Perl、Visual Basic、C)的人员。
l Python 教程是 Python 文档本身的一部分。
l 针对程序员的 Python为具有其他编程语言经验的人士提供教程。
相关主题
Python 快速浏览
什么是 ArcPy?
什么是 Python 窗口?
基本 Python 词汇
本文档介绍要理解“使用 Python 进行地理处理”帮助需要掌握的一些词汇。
版权所有 © 1995-2010 Esri. 保留所有权利。
术语 描述
Python Python 是由 Guido van Rossum 在上世纪八十年代末构想并于 1991 年推出的一种开源编程语言。它最早集成于 ArcGIS 9.0
中,从此以后便成为用户创建地理数据库工作流的首选。
Python 得到了不断壮大的多元化用户群体的支持,具备简洁易读、语法清晰、支持动态定型等特点,并且具有大量标准库和第三方
库。
PythonWin PythonWin 是一种广泛使用的针对 Python 的第三方 Windows 接口,可以通过 ArcGIS 安装介质进行安装。
ArcPy ArcGIS 10 采用了 ArcPy(通常称为 ArcPy 站点包),为用户提供了使用 Python 语言操作所有地理处理工具(包括扩展模块)的
机会,并提供了多种有用的函数和类,以用于处理和询问 GIS 数据。站点包是 Python 术语,表示将附加函数添加到 Python 的
库。使用 Python 和 ArcPy,可以开发出数量无限的可用于处理地理数据的实用程序。
ArcPy 模块 模块为通常包含函数和类的 Python 文件。有一系列模块支持 ArcPy,包括制图模块 (arcpy.mapping)、Spatial Analyst 模块
(arcpy.sa) 和Geostatistical Analyst 模块 (arcpy.ga)。
ArcPy 类 类的作用类似于建筑设计蓝图。蓝图为如何创建事物提供框架,而类则可用来创建对象,即通常所称的实例。ArcPy 类,如
SpatialReference 和 Extent 类,通常用作地理处理工具参数设置的快捷方式,否则的话,这些参数会使用更加复杂的字符串。
ArcPy 函数
函数是用于执行某项特定任务并能够纳入更大的程序的已定义功能。
在 ArcPy 中,所有地理处理工具均以函数形式提供,但并非所有函数都是地理处理工具。除工具之外,ArcPy 还提供多种函数来更好
地支持 Python 地理处理工作流。函数或方法可用于列出某些数据集、检索数据集的属性、在将表添加到地理数据库之前验证表名
称,或执行其他许多有用的脚本任务。
独立的
Python 脚本
Python 脚本是可以执行的 .py 文件。独立 Python 脚本是一种 .py 文件,可通过两种方式执行:通过操作系统提示或开发应用程
序(如 PythonWin),或在 Windows 资源管理器中双击 .py 文件。
Python 脚本 Python 脚本工具是已添加到地理处理工具箱的 Python 脚本。添加为脚本工具后,便可以像使用其他地理处理工具一样使用此脚本工
ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10 ArcGIS 10
基本 Python 词汇
什么是 Python?
Page
1
of
59
什么是
Python
?
2011
-
3
-
19
file://E:\temp\S
-
1
-
5
-
21
-
1417001333
-
299502267
-
682003330
-
500\temp\~hhF46D.htm
相关主题
Python 快速浏览
什么是 Python?
Python 是一种通用的开源编程语言,在 ArcGIS 地理处理中用作脚本语言。使用 Python 中用于 ArcGIS 软件的 ArcPy 站点包可访问地理处理功能。通过
ArcPy 可访问地理处理工具和其他函数、类和模块,使用它们可快速轻松地创建简单或复杂工作流。
使用以 ArcPy 编写的 ArcGIS 应用程序和脚本的优势在于,可以访问并使用由来自多种不同领域的 GIS 专业人员和程序员开发的大量 Python 模块。使用
Python 中的 ArcPy 的另一个主要原因是,Python 是一种通用的编程语言,易于学习和使用。通过解释和动态输入这种编程语言,用户可以在交互式环境中快速
地创建脚本原型并进行测试,同时这种编程语言功能强大,可编写大型应用程序。
一般来说,ArcPy 按工具、环境、函数、类和模块进行组织。
Running a tool
This next example shows how to execute the Buffer tool. As the tool executes, the messages will appear by default on the right side of
the Python window in the help section.
Here is another example of running tools. This example uses tools in the data management and conversion toolboxes. A field is added to
the input streets feature class, the field is calculated, and the feature class is then loaded into an ArcSDE enterprise geodatabase.
Learn more about using tools in Python
Getting results from a tool
When a geoprocessing tool is executed, the results of the tool are returned in a result object. Typically, this object is the path to the
output dataset produced or updated by the tool. In other cases, it may contain other value types, such as a number or Boolean. If an
output for a tool is a multivalue parameter, the values can be returned as a list within a list.
The following code examples show how return values are captured and what their values could be:
Return the path of the output feature class. The result can be used as input to another function.
Return the number of features.
Return a list of default spatial grid indexes for a feature class.
工具
具 - 可以从工具对话框打开和执行、可以在 Python 窗口和 ModelBuilder 中使用,并可以从其他脚本和脚本工具中调用。
Python 窗口 ArcGIS 10 提供了一种新的嵌入式 Python 体验。过去版本中的地理处理命令行已被重新设计成一个完全交互式的 Python 窗口。通
过此窗口,用户可以快捷地在 ArcGIS 内部使用 Python,从而以交互方式运行地理处理工具和功能以及充分利用其他 Python 模块
和库。此窗口还为用户学习 Python 提供了一个途径。
Python 窗口可用于执行单行 Python 代码,并会将由此生成的消息输出到窗口。借助此窗口,您可以对语法进行试验和处理短代码,
并可以在大型脚本范围之外对您的想法进行检验。
版权所有 © 1995-2010 Esri. 保留所有权利。
>>> arcpy.Buffer_analysis("c:/data/Portland.gdb/streets", "c:/data/Portland.gdb/steets_buffer", "500 METERS")
>>> import arcpy
>>> arcpy.AddField_management("c:/data/Portland.gdb/streets", "LENGTH_MILES", "TEXT")
>>> arcpy.CalculateField_management("c:/data/Portland.gdb/streets", "LENGTH_MILES", "!shape.length@miles!", "PYTHON_9.3")
>>> arcpy.FeatureClassToFeatureClass_conversion("c:/data/Portland.gdb/streets", “
Database Connections/MySDE.sde/PortlandDataset", "streets")
>>> result = arcpy.Buffer_analysis("rivers", "riverBuf", "50 METERS")
>>> print result
C:\Portland\Portland_OR.gdb\riverBuf
>>> arcpy.Clip_analysis("streets", result, "streets_50m_of_rivers")
>>> result = arcpy.GetCount_management("streets_50m_of_rivers")
>>> print result.getOutput(0)
54
Python 快速浏览
Page
2
of
59
什么是
Python
?
2011
-
3
-
19
file://E:\temp\S
-
1
-
5
-
21
-
1417001333
-
299502267
-
682003330
-
500\temp\~hhF46D.htm
Using environment settings
Geoprocessing environment settings can be thought of as additional parameters that affect a tool's results. They differ from normal tool
parameters in that they are set separately from the tool and are interrogated and used by tools when they are run. Environment settings
such as an area of interest, the coordinate system of the output dataset, and the cell size of a new raster dataset can all be specified and
honored by the tools.
Environment settings are available from the env class as properties. These properties can be used to retrieve the current environment
values and set them. Below are examples of how to use environment values:
Set the workspace environment.
Set the spatial grid index to the return value of a tool.
Get the current raster cell size setting and make sure it is a specific size for standard output.
Learn more about using environment settings in Python
Using functions
A function is a defined bit of functionality that does a specific task and can be incorporated into a larger program. In addition to tools,
ArcPy exposes a number of functions to better support geoprocessing workflows. Functions can be used to list certain datasets, retrieve a
dataset's properties, check for existence of data, validate a table name before adding it to a geodatabase, or perform many other useful
scripting tasks.
The example code below shows getting the properties of data and checking out an extension:
Learn more about using functions in Python
Using classes
ArcPy classes, such as the SpatialReference and Extent classes, are often used as shortcuts to complete geoprocessing tool parameters
that would otherwise have a more complicated string equivalent. A class is analogous to an architectural blueprint. The blueprint provides
the framework for how to create something. Classes can be used to create objects; this is often referred to as an instance.
Learn more about using classes in Python
>>> result = arcpy.CalculateDefaultGridIndex_management("streets_50m_of_rivers")
>>> for i in range(0, result.outputCount):
... print result.getOutput(i)
...
560
200
0
>>> arcpy.env.workspace = "c:/data/Portland.gdb"
>>> arcpy.Buffer_analysis("streets", "streetBuf", "500 METERS")
>>> arcpy.env.spatialGrid1 = arcpy.CalculateDefaultSpatialGridIndex_management("streets").getOutput(0)
if arcpy.env.cellSize != 30:
arcpy.env.cellSize = 30
import arcpy
# prints
True
print arcpy.Exists("c:/data/Portland.gdb/streets")
# prints
NAD_1983_StatePlane_Oregon_North_FIPS_3601_Feet
sr = arcpy.Describe("c:/data/Portland.gdb/streets").spatialReference
print sr.name
# prints
Available
print arcpy.CheckExtension("spatial")
arcpy.CheckOutExtension("spatial")
import arcpy
prjFile = "c:/projections/North America Equidistant Conic.prj"
spatialRef = arcpy.SpatialReference(prjFile)
Page
3
of
59
什么是
Python
?
2011
-
3
-
19
file://E:\temp\S
-
1
-
5
-
21
-
1417001333
-
299502267
-
682003330
-
500\temp\~hhF46D.htm
Working with modules
ArcPy includes modules covering other areas of ArcGIS. ArcPy is supported by a series of modules, including a mapping module
(arcpy.mapping), a Spatial Analyst module (arcpy.sa), and a Geostatistical Analyst module (arcpy.ga).
For example, the tools of the arcpy.sa module use tools in the Spatial Analyst toolbox but are configured to support Map Algebra. Thus,
executing arcpy.sa.Slope is the same as executing the Slope tool from the Spatial Analyst toolbox.
相关主题
什么是 Python?
基本 Python 词汇
ArcGIS 10 采用了 ArcPy,这是一种 Python 站点包,它涵盖并进一步加强了 ArcGIS 9.2 中所采用的 arcgisscripting 模块的功能。ArcPy 提供了一种用于
开发 Python 脚本的功能丰富的动态环境,同时提供每个函数、模块和类的代码完成和集成文档。
使用以 ArcPy 编写的 ArcGIS 应用程序和脚本的优势在于,可以访问并使用由来自多种不同领域的 GIS 专业人员和程序员开发的大量 Python 模块。使用
Python 中的 ArcPy 的另一个主要原因是,Python 是一种通用的编程语言,易于学习和使用。通过解释和动态输入这种编程语言,用户可以在交互式环境中快速
地创建脚本原型并进行测试,同时这种编程语言功能强大,可编写大型应用程序。
在导入 ArcPy 之后,可以运行随 ArcGIS 安装的标准工具箱中的所有地理处理工具。
分析工具箱
制图工具箱
转换工具箱
数据管理工具箱
编辑工具箱
地理编码工具箱
线性参照工具箱
多维工具箱
空间统计分析工具集
导入模块
模块为通常包含函数和类的 Python 文件。有一系列模块支持 ArcPy,包括制图模块 (arcpy.mapping)、Spatial Analyst 模块 (arcpy.sa) 和
Geostatistical Analyst 模块 (arcpy.ga)。
要导入整个模块,请使用导入模块:
当然,Python 还具有很多其他核心模块和第三方模块。如果还想使用 Python 的核心 os 和 sys 模块,可以使用相似的导入方式:
在很多情况下,用户可能不想使用整个模块或无需使用整个模块。如果只导入某一模块的一部分,可以使用 from-import 语句。在下例中,将导入 env 类
(env 类包含所有地理处理环境)。现在无需以 arcpy.env 的形式访问环境,而可以将其简化为 env。
遵循相同的思路,有时用户可能需要注意:如何对模块或模块的一部分进行标识以使脚本更具可读性,以及对于首选项来说默认名称可能过长。在上述任一情
况下,均可以使用 from-import-as 的形式。与先前的示例相同,下面的示例中也将导入 env 类,但会指定 ENV 作为 env 类的名称:
版权所有 © 1995-2010 Esri. 保留所有权利。
# Importing arcpy
#
import arcpy
# Set the workspace environment and run Clip_analysis
arcpy.env.workspace = "C:/Data/Tongass"
arcpy.Clip_analysis("standb4", 'clipcov", "standby_clip", "1.25")
# Import all of arcpy
#
import arcpy.mapping
# Import arcpy, os and sys
#
import arcpy
import os
import sys
# Import env from arcpy and set the workspace environment
#
from arcpy import env
env.workspace = "c:/data"
导入 ArcPy
Page
4
of
59
什么是
Python
?
2011
-
3
-
19
file://E:\temp\S
-
1
-
5
-
21
-
1417001333
-
299502267
-
682003330
-
500\temp\~hhF46D.htm
剩余59页未读,继续阅读
资源评论
梅里雪山GIS
- 粉丝: 2w+
- 资源: 500
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- JSP基于网络超市商品销售管理系统的设计与实现(源代码+lw).zip
- JSP基于WEB网上论坛设计与实现(源代码+lw+开题报告+答辩PPT+外文翻译).zip
- JSP基于WEB的图书馆借阅系统的设计与实现(源代码+lw).zip
- 数电实验三:74LS151逻辑功能测试、74LS153逻辑功能测试、74LS153全加器、三输入多数表决电路
- 基于python知识图谱抖音舆情数据可视化分析系统python + flask web + mysql + 知识图谱
- jsp基于Web的可维护的数据库浏览器(源代码+lw+答辩PPT).zip
- jsp基于WEB的考务管理系统的设计与实现(源代码+lw).zip
- jsp基于WEB操作系统课程教学网站的设计与实现(源代码+lw).zip
- 数据库课程实践在IDEA上使用java语言采用JDBC技术连接Mysql数据库,实现购物系统.zip
- JSP基于SSH2的网络在线问答系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功