序号 |
类名称 |
|
功能说明
|
|
语法 & 举例 |
01 |
Raster |
|
====<<<< Description >>>>====
创建一个可在 Python 脚本或地图代数表达式中使用的栅格对象。 ----------------------------------------------------------------------------------
====<<<< Syntax >>>>====
Raster (inRaster) ----------------------------------------------------------------------------------
====<<<< Parameters >>>>====
◈ inRaster:输入栅格数据集。 ----------------------------------------------------------------------------------
====<<<< Properties >>>>====
◈ height:行数。(只读) ◈ width:列数。(只读) ◈ maximum:栅格数据集的最大值。(只读) ◈ minimum:栅格数据集的最小值。(只读) ◈ mean:栅格数据集的平均值。(只读) ◈ meanCellHeight:y 方向上的象元大小。(只读) ◈ meanCellWidth:x 方向上的象元大小。(只读) ◈ name/path/ ----------------------------------------------------------------------------------
====<<<< Methods >>>>====
◈ save ({name}):永久保存栅格对象引用的数据集。 name:分配给磁盘上的栅格数据集的名称。(String)
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | arcpy.env.workspace = r "D:\01-Working\2017\20171204-IDL_Average\temp\TSM"
rs = arcpy.ListRasters()
fo = open ( "D:\\01-Working\\2017\\20171204-IDL_Average\\temp\\tsm_stats.txt" , "w+" )
for r in rs:
ro = arcpy.Raster(r)
fo.writelines(ro.name + "\n" )
fo.writelines( "MAX: " + str ( round (ro.maximum, 2 )) + "\n" )
fo.writelines( "MIN: " + str ( round (ro.minimum, 2 )) + "\n" )
fo.writelines( "MEAN: " + str ( round (ro.mean, 2 )) + "\n\n" )
fo.close()
|
|
02 |
Cursor |
|
====<<<< Description >>>>====
Cursor 是一种数据访问对象,可用于在表中迭代一组行或者向表中插入新行。游标有三种形式:搜索、插入或更新。游标通常用于读取和更新属性。(不同于arcpy.da.SearchCursor)
----------------------------------------------------------------------------------
====<<<< Methods >>>>====
◈ deleteRow (row):删除数据库中的某一行。将删除与游标当前所在位置相对应的行。 ◈ insertRow (row):向数据库中插入新行。 ◈ newRow ():创建空行对象。 ◈ next ():返回当前索引中的下一个对象。(返回 Row) ◈ reset ():将当前枚举索引(由 next 方法使用)设置回第一个元素。 ◈ updateRow (row):updateRow 方法可用于对更新游标当前所在的行进行更新。
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import arcpy
mxd = arcpy.mapping.MapDocument( "CURRENT" )
lyr = arcpy.mapping.ListLayers(mxd)[ 0 ]
cursor = arcpy.UpdateCursor(lyr)
for row in cursor:
row.setValue( "AREA" , 200 )
cursor.updateRow(row)
del cursor, row
cursor = arcpy.SearchCursor(lyr)
for row in cursor:
name = row.getValue( "NAME" )
print name
del cursor, row
cursor = arcpy.InsertCursor(lyr)
for i in range ( 1 , 10 ):
row = cursor.newRow()
row.setValue( "NAME" , "阿拉斯加" )
row.setValue( "ID" , i)
cursor.insertRow(row)
del cursor, row
|
|
03 |
Row |
|
====<<<< Description >>>>====
行对象表示表中的某一行。行对象会从 InsertCursor、SearchCursor 和 UpdateCursor 中返回。 ----------------------------------------------------------------------------------
====<<<< Methods >>>>====
◈ getValue (field_name):获取字段值。 ◈ isNull (field_name):字段值是否为空。 ◈ setNull (field_name):将字段值设置为空。 ◈ setValue (field_name):设置字段值。
|
|
04 |
Array
|
|
====<<<< Description>>>>====
数组对象中可包含点和数组,它用于构造几何对象。 ----------------------------------------------------------------------------------
====<<<< Syntax >>>>====
Array ({items}) ----------------------------------------------------------------------------------
====<<<< Parameters >>>>====
◈ items:项目可以包含列表、点对象或另一个数组对象。 ----------------------------------------------------------------------------------
====<<<< Methods >>>>====
◈ add (value):将点或数组对象添加到数组的结尾处。 ◈ append (value):在数组中的最后一个位置追加一个对象。 ◈ clone (point_object):克隆点对象。 ◈ extend (items):通过追加元素扩展数组。 ◈ getObject (index):返回数组中给定索引位置上的对象。 ◈ insert (index, value):在数组中的指定索引处添加一个对象。 ◈ next ():返回当前索引中的下一个对象。 ◈ remove (index):从数组中的指定索引位置移除对象。 ◈ removeAll ():移除所有值并创建一个空对象。 ◈ replace (index, value):替换数组中指定索引位置上的对象。 ◈ reset ():将当前枚举索引(由 next 方法使用)设置回第一个元素。 ----------------------------------------------------------------------------------
====<<<< Attributes >>>>====
◈ count:数组的元素个数。
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | >>> coords = [( 1 , 2 ), ( 1 , - 2 ), ( - 1 , - 2 ), ( - 1 , 2 ), ( 1 , 2 )]
>>> ar = arcpy.Array()
>>> ar
<Array []>
>>> for x, y in coords:
... ar.add(arcpy.Point(x, y))
...
>>> ar
<Array [<Point ( 1.0 , 2.0 ,
<Point ( - 1.0 , - 2.0 ,
<Point ( 1.0 , 2.0 ,
|
1 2 3 4 5 6 7 8 9 10 11 12 | >>> coords = [( 1 , 2 ), ( 1 , - 2 ), ( - 1 , - 2 ), ( - 1 , 2 ), ( 1 , 2 )]
>>> points = [arcpy.Point(x, y) for x, y in coords]
>>> ar1 = arcpy.Array(points)
>>> ar1
<Array [<Point ( 1.0 , 2.0 ,
<Point ( - 1.0 , - 2.0 ,
<Point ( 1.0 , 2.0 ,
|
|
05
|
Point
|
|
====<<<< Description>>>>====
点对象经常与光标配合使用。点要素将返回单个点对象而不是点对象数组。而其他要素类型(面、折线和多点)都将返回一个点对象数组,并且当这些要素具有多个部分时,则返回包含多个点对象数组的数组。 ----------------------------------------------------------------------------------
====<<<< Syntax >>>>====
Point ({X}, {Y}, {Z}, {M}, {ID}) ----------------------------------------------------------------------------------
====<<<< Parameters >>>>====
◈ X:点的 X 坐标。 ◈ Y:点的 Y 坐标。 ◈ Z:点的 Z 坐标。 ◈ M:点的 M 值。 ◈ ID:点的形状 ID。 ----------------------------------------------------------------------------------
====<<<< Methods >>>>====
◈ clone ():克隆点对象。 ◈ contains (second_geometry):包含 ◈ crosses (second_geometry):交叉 ◈ disjoint (second_geometry):不相交 ◈ equals (second_geometry):相同 ◈ overlaps (second_geometry):重叠 ◈ touches (second_geometry):接触 ◈ within (second_geometry):内部 ----------------------------------------------------------------------------------
====<<<< Attributes >>>>====
◈ ID:唯一标识点的整数。 ◈ M:点的 measure value。 ◈ X:点的横坐标。 ◈ Y:点的纵坐标。 ◈ Z:点的高程值。
|
|
1 2 3 4 5 6 7 8 9 10 11 12 | >>> coords = [( 1 , 2 ), ( 1 , - 2 ), ( - 1 , - 2 ), ( - 1 , 2 ), ( 1 , 2 )]
>>> points = [arcpy.Point(x, y) for x, y in coords]
>>> arr = arcpy.Array(points)
>>> arr
<Array [<Point ( 1.0 , 2.0 ,
<Point ( - 1.0 , - 2.0 ,
<Point ( 1.0 , 2.0 ,
|
1 2 3 4 5 6 7 8 9 10 11 12 | >>> coords = [[ 1 , 2 ], [ 1 , - 2 ], [ - 1 , - 2 ], [ - 1 , 2 ], [ 1 , 2 ]]
>>> points = [arcpy.Point( * p) for p in coords]
>>> arr = arcpy.Array(points)
>>> arr
<Array [<Point ( 1.0 , 2.0 ,
<Point ( - 1.0 , - 2.0 ,
<Point ( 1.0 , 2.0 ,
|
1 2 3 | >>> coords = [[ 1 , 2 ], [ 1 , - 2 ], [ - 1 , - 2 ], [ - 1 , 2 ], [ 1 , 2 ]]
>>> points = [arcpy.Point(x, y) for x, y in coords]
|
|
06 |
Polyline |
|
====<<<< Description>>>>====
折线对象是由一个或多个路径定义的形状,其中路径是指一系列相连线段。 ----------------------------------------------------------------------------------
====<<<< Syntax >>>>====
Polyline (inputs, {spatial_reference}, {has_z}, {has_m}) ----------------------------------------------------------------------------------
====<<<< Parameters >>>>====
◈ inputs:用来创建对象的坐标。数据类型可以是点或者数组对象。 ----------------------------------------------------------------------------------
====<<<< Methods >>>>====
◈ boundary ():构造几何边界。面→线、线→点、点→空 ◈ buffer (distance):在距几何的指定距离处构造一个面。 ◈ clip (envelope):构造几何体与指定范围(extent)的交集。 ◈ convexHull ():构造具有最小边界多边形的几何,以便所有外角均为凸角。 ◈ cut (cutter):将该几何分割到剪切折线的左右两侧。 ◈ distanceTo (other):返回两个几何之间的最小距离。
◈ contains (second_geometry):包含 ◈ crosses (second_geometry):交叉 ◈ disjoint (second_geometry):不相交 ◈ intersect (other, dimension):相交(结果 Geometry,1-点、2-线、4-面) ◈ symmetricDifference (other):交集取反 ◈ union (other):联合 ◈ equals (second_geometry):相同 ◈ overlaps (second_geometry):重叠 ◈ touches (second_geometry):接触 ◈ within (second_geometry):内部
◈ getLength ({measurement_type}, {units}):使用测量类型返回要素的长度。 ◈ getPart ({index}):返回几何特定部分的点对象数组,或包含多个数组(每个数组对应一个部分)的数组。 ----------------------------------------------------------------------------------
====<<<< Attributes >>>>====
◈ extent:几何范围。 ◈ firstPoint:第一个几何坐标点。 ◈ isMultipart:如果此几何的部分数大于一,则为 True。 ◈ lastPoint:要素的最后一个坐标。 ◈ length:线状要素的长度。点和多点要素类型为零。 ◈ partCount:要素几何部分的数目。 ◈ pointCount:要素的总点数。 ◈ type:几何类型:面、折线、点、多点、多面体、尺寸或注记。
|
|
|
07 |
Polygon |
|
====<<<< Description>>>>====
面对象是指由一系列相连的 x,y 坐标对定义的闭合形状。 ----------------------------------------------------------------------------------
====<<<< Syntax >>>>====
Polygon (inputs, {spatial_reference}, {has_z}, {has_m}) ----------------------------------------------------------------------------------
====<<<< Parameters >>>>====
◈ inputs:用来创建对象的坐标。数据类型可以是点或者数组对象。 ----------------------------------------------------------------------------------
====<<<< Methods >>>>====
◈ boundary ():构造几何边界。面→线、线→点、点→空 ◈ buffer (distance):在距几何的指定距离处构造一个面。 ◈ clip (envelope):构造几何体与指定范围(extent)的交集。 ◈ convexHull ():构造具有最小边界多边形的几何,以便所有外角均为凸角。 ◈ cut (cutter):将该几何分割到剪切折线的左右两侧。 ◈ distanceTo (other):返回两个几何之间的最小距离。
◈ difference (other):差异 ◈ contains (second_geometry):包含 ◈ crosses (second_geometry):交叉 ◈ disjoint (second_geometry):不相交 ◈ intersect (other, dimension):相交(结果 Geometry,1-点、2-线、4-面) ◈ symmetricDifference (other):交集取反 ◈ union (other):联合 ◈ equals (second_geometry):相同 ◈ overlaps (second_geometry):重叠 ◈ touches (second_geometry):接触 ◈ within (second_geometry):内部
◈ getArea ({type}, {units}):使用测量类型返回要素的面积。 ◈ getLength ({measurement_type}, {units}):使用测量类型返回要素的长度。 ◈ getPart ({index}):返回几何特定部分的点对象数组,或包含多个数组(每个数组对应一个部分)的数组。 ----------------------------------------------------------------------------------
====<<<< Attributes >>>>====
◈ area:面要素的面积。 ◈ centroid:如果质心位于要素之内或要素之上则为真;否则返回标注点。返回点对象。 ◈ trueCentroid:要素的重心。 ◈ extent:几何范围。 ◈ firstPoint:第一个几何坐标点。 ◈ isMultipart:如果此几何的部分数大于一,则为 True。 ◈ lastPoint:要素的最后一个坐标。 ◈ length:线状要素的长度。点和多点要素类型为零。 ◈ partCount:要素几何部分的数目。 ◈ pointCount:要素的总点数。 ◈ type:几何类型:面、折线、点、多点、多面体、尺寸或注记。
|
|
Polygon 解析:
一个 Polygon 含有多个部分,需要通过 for 循环读取,每个部分是一个 Array 对象
一个 Array 对象内部包括 N 个 Point,需要通过 for 循环读取每个 Point
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | >>> cursor = arcpy.da.SearchCursor( "CNTRY92" , "SHAPE@" , "NAME = 'China'" )
>>> polygons = [row[ 0 ] for row in cursor]
>>> len (polygons)
1
>>> china = polygons[ 0 ]
>>> china.isMultipart
True
>>> china.partCount
2
>>> china.pointCount
839
>>> lands = [part for part in china]
>>> lands
>>> len (lands)
2
>>> points = [pnt for pnt in lands[ 0 ]]
>>> mainland = arcpy.Polygon(lands[ 1 ])
>>> arcpy.CopyFeatures_management(mainland, "mainland.shp" )
<Result 'D:\\McDelfino\\Documents\\ArcGIS\\mainland.shp' >
|
|
08 |
Extent |
|
====<<<< Description>>>>====
范围是在地图单位下提供左下角和右上角坐标指定的一个矩形。 ----------------------------------------------------------------------------------
====<<<< Syntax >>>>====
Extent ({XMin}, {YMin}, {XMax}, {YMax}, {ZMin}, {ZMax}, {MMin}, {MMax}) ----------------------------------------------------------------------------------
====<<<< Parameters >>>>====
◈ XMin:范围 XMin 值。 ◈ YMin:范围 YMin 值。 ◈ XMax:范围 XMax 值。 ◈ YMin:范围 YMax 值。 ----------------------------------------------------------------------------------
====<<<< Methods >>>>====
◈ contains / crosses / disjoint / equals / overlaps / touches / within ◈ 方法使用与 Polygon 类似 ◈ union (other):联合◈ equals (second_geometry):相同◈ overlaps (second_geometry):重叠◈ touches (second_geometry):接触◈ within (second_geometry):内部 ----------------------------------------------------------------------------------
====<<<< Attributes >>>>====
◈ XMin:范围 XMin 值。 ◈ YMin:范围 YMin 值。 ◈ XMax:范围 XMax 值。 ◈ YMin:范围 YMax 值。 ◈ height:范围高度值。( YMax - YMin ) ◈ width:范围宽度值。( XMax - XMin )
◈ lowerLeft:左下角属性:将返回点对象。 ◈ lowerRight:右下角属性:将返回点对象。 ◈ upperLeft:左上角属性:将返回点对象。 ◈ upperRight:右上角属性:将返回点对象。
◈ polygon:以多边形对象的形式返回范围。 ◈ spatialReference:范围的空间参考。
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | >>> e2 = df.extent
>>> e2.XMax
149.1029612143459
>>> e2.XMin
64.02167430592488
>>> e2.YMax
50.20513847572508
>>> e2.YMin
18.71509185629973
>>> e2.MMax
>>> e2.ZMax
>>> pnt = e2.lowerLeft
>>> pnt
<Point ( 64.0216743059 , 18.7150918563 ,
>>> e2.height
31.49004661942535
>>> e2.width
85.08128690842102
|
|
|
|
|
1 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2012-01-10 为小7文件夹右键添加“复制到”“移动到”