Polygon (arcpy)

摘要

A Polygon object is a closed shape defined by a connected sequence of x,y coordinate pairs.

讨论

在许多地理处理工作流中,您可能需要使用坐标和几何信息运行特定操作,但不一定想经历创建新(临时)要素类、使用光标填充要素类、使用要素类,然后删除临时要素类的过程。可以使用几何对象替代输入和输出,从而使地理处理变得更简单。可以使用 GeometryMultipointPointGeometryPolygonPolyline 类从头开始创建几何对象。

语法

Polygon (inputs, {spatial_reference}, {has_z}, {has_m})
参数说明数据类型
inputs

The coordinates used to create the object. The datatype can be either Point or Array objects.

Object
spatial_reference

The spatial reference of the new geometry.

(默认值为 None)

SpatialReference
has_z

The Z state: True for geometry if Z is enabled and False if it is not.

(默认值为 False)

Boolean
has_m

The M state: True for geometry if M is enabled and False if it is not.

(默认值为 False)

Boolean

属性

属性说明数据类型
JSON
(只读)

返回一个字符串形式的几何 JSON 制图表达。

提示提示:

通过 Python 的 eval 函数,返回的字符串可转换至字典。

String
WKB
(只读)

返回 OGC 几何的熟知二进制 (WKB) 制图表达。 该存储类型将几何值表示为不间断的字节流形式。

Bytearray
WKT
(只读)

返回 OGC 几何的熟知文本 (WKT) 制图表达。其将几何值表示为文本字符串。

String
area
(只读)

面要素的面积。其他所有要素类型为空。

Double
centroid
(只读)

如果质心位于要素之内或要素之上则为真;否则返回标注点。返回点对象。

Point
extent
(只读)

几何范围。

Extent
firstPoint
(只读)

第一个几何坐标点。

Point
hullRectangle
(只读)

以空格分隔的凸包矩形坐标对的字符串。

String
isMultipart
(只读)

如果此几何的部分数大于一,则为真。

Boolean
labelPoint
(只读)

标注位置所在的点。标注点始终位于要素之内/之上。

Point
lastPoint
(只读)

要素的最后一个坐标。

Point
length
(只读)

线状要素的长度。点和多点要素类型为零。

Double
length3D
(读写)

线状要素的 3D 长度。点和多点要素类型为零。

Double
partCount
(只读)

要素几何部分的数目。

Integer
pointCount
(只读)

要素的总点数。

Integer
trueCentroid
(只读)

要素的重心。

Point
type
(只读)

几何类型:面、折线、点、多点、多面体、尺寸或注记。

String

方法概述

方法说明
boundary ()

构造几何边界。

边界运算符
buffer (distance)

在距几何的指定距离处构造一个面。

缓冲运算符
clip (envelope)

构造几何体与指定范围的交集。

裁剪运算符
contains (second_geometry)

Indicates if the base geometry contains the comparison geometry.

contains is the opposite of within.

本图仅显示 True 关系。

Possible contains relationships
convexHull ()

构造具有最小边界多边形的几何,以便所有外角均为凸角。

凸包运算符
crosses (second_geometry)

Indicates if the two geometries intersect in a geometry of a lesser shape type.

Two polylines cross if they share only points in common, at least one of which is not an endpoint. A polyline and an polygon cross if they share a polyline or a point (for vertical line) in common on the interior of the polygon which is not equivalent to the entire polyline.

本图仅显示 True 关系。

Possible crosses relationships
difference (other)

构造一个几何体,该几何体仅由基础几何所特有、而其他几何所没有的区域组成。下图显示当红色多边形为源几何时的结果。

不同运算符
disjoint (second_geometry)

Indicates if the base and comparison geometries share no points in common.

Two geometries intersect if disjoint returns False.

本图仅显示 True 关系。

Possible disjoint relationships
distanceTo (other)

返回两个几何之间的最小距离。如果两个几何相交,则最小距离为 0。

两个几何必须具有相同的投影。

equals (second_geometry)

指示原几何和参照几何的 shape 类型是否相同并在平面中定义相同点集。这仅是 2D 的比较;已忽略 M 值和 Z 值。

本图仅显示 True 关系。

可能的相等关系
getArea (type)

使用测量类型返回要素的面积。

getLength (measurement_type)

使用测量类型返回要素的长度。

getPart ({index})

Returns an array of point objects for a particular part of geometry or an array containing a number of arrays, one for each part.

intersect (other, dimension)

构造作为两个输入几何交集的几何体。不同的维数可用于创建不同的 shape 类型。

对于同一 shape 类型的两个几何体,其交集为仅包含原始几何重叠区域的几何。

相交运算符

为了更快地获取结果,请在调用 intersect 类之前先测试两个几何体是否不相交

overlaps (second_geometry)

Indicates if the intersection of the two geometries has the same shape type as one of the input geometries and is not equivalent to either of the input geometries.

本图仅显示 True 关系。

Possible overlaps relationships
positionAlongLine (value, {use_percentage})

返回线上距线起点指定距离处的点。

projectAs (spatial_reference, {transformation_name})

定义几何投影,并应用相应的地理变换。

要进行投影,几何体需要具有一个空间参考且不具有 UnknownCoordinateSystem。传递到该方法的新空间参考系统参数定义了一个输出坐标系。如果任一空间参考未知,坐标将不会发生更改。ProjectAs 方法并不更改 Z 值和测量值。

symmetricDifference (other)

构造一个几何体,该几何体由两个几何的并集减去其交集所形成。

两个输入几何必须为同一 shape 类型。

symmetricDifference 运算符
touches (second_geometry)

Indicates if the boundaries of the geometries intersect.

Two geometries touch when the intersection of the geometries is not empty, but the intersection of their interiors is empty. For example, a point touches a polyline only if the point is coincident with one of the polyline end points.

本图仅显示 True 关系。

Possible touches relationships
union (other)

构造一个几何体,该几何体是输入几何的并集。

要合并的两个几何必须为同一 shape 类型。

联合运算符
within (second_geometry)

Indicates if the base geometry is within the comparison geometry.

within is the opposite operator of contains.

本图仅显示 True 关系。

Possible within relationships

方法

boundary ()
返回值
数据类型说明
Object

面的边界为折线。折线的边界为多点,与线的端点相对应。点或多点的边界为空点或多点。

buffer (distance)
参数说明数据类型
distance

The buffer distance.

The buffer distance is in the same units as the geometry that is being buffered.

A negative distance can only be specified against a polygon geometry.

Double
返回值
数据类型说明
Polygon

缓冲的面几何。

clip (envelope)
参数说明数据类型
envelope

An extent object used to define the clip extent.

Extent
返回值
数据类型说明
Object

将输出几何体按指定范围进行裁剪。

contains (second_geometry)
参数说明数据类型
second_geometry

A second geometry.

Object
返回值
数据类型说明
Boolean

A return Boolean value of True indicates this geometry contains the second geometry.

convexHull ()
返回值
数据类型说明
Object

生成的几何。单个点的凸包为该点本身。

crosses (second_geometry)
参数说明数据类型
second_geometry

A second geometry.

Object
返回值
数据类型说明
Boolean

A return Boolean value of True indicates the two geometries intersect in a geometry of a lesser shape type.

difference (other)
参数说明数据类型
other

A second geometry.

Object
返回值
数据类型说明
Object

生成的几何。

disjoint (second_geometry)
参数说明数据类型
second_geometry

A second geometry.

Object
返回值
数据类型说明
Boolean

A return Boolean value of True indicates that the two geometries share no points in common.

distanceTo (other)
参数说明数据类型
other

A second geometry.

Object
返回值
数据类型说明
Double

两个几何之间的距离。

equals (second_geometry)
参数说明数据类型
second_geometry

A second geometry.

Object
返回值
数据类型说明
Boolean

返回布尔值为 True 表示两个几何的 shape 类型相同并在平面中定义了相同点集。

getArea (type)
参数说明数据类型
type

PLANAR measurements reflect the projection of geographic data onto the 2D surface (in other words, they will not take into account the curvature of the earth). GEODESIC, GREAT_ELLIPTIC, LOXODROME, and PRESERVE_SHAPE measurement types may be chosen as an alternative, if desired.

  • GEODESICThe shortest line between any two points on the earth's surface on a spheroid (ellipsoid). One use for a geodesic line is when you want to determine the shortest distance between two cities for an airplane's flight path. This is also known as a great circle line if based on a sphere rather than an ellipsoid.
  • GREAT_ELLIPTICThe line on a spheroid (ellipsoid) defined by the intersection at the surface by a plane that passes through the center of the spheroid and the start and endpoints of a segment. This is also known as a great circle when a sphere is used.
  • LOXODROMEA loxodrome is not the shortest distance between two points but instead defines the line of constant bearing, or azimuth. Great circle routes are often broken into a series of loxodromes, which simplifies navigation. This is also known as a rhumb line.
  • PLANARPlanar measurement use 2D Cartesian mathematics to calculate lengths and areas. This option is only available when measuring in a projected coordinate system and the 2D plane of that coordinate system will be used as the basis for the measurements.
  • PRESERVE_SHAPEThis type calculates the area or length of the geometry on the surface of the Earth ellipsoid, for geometry defined in a projected or geographic coordinate system. This option preserves the shape of the geometry in its coordinate system.
String
返回值
数据类型说明
Double

要素的面积。返回的面积值始终以平方米为单位。

getLength (measurement_type)
参数说明数据类型
measurement_type

PLANAR measurements reflect the projection of geographic data onto the 2D surface (in other words, they will not take into account the curvature of the earth). GEODESIC, GREAT_ELLIPTIC, LOXODROME, and PRESERVE_SHAPE measurement types may be chosen as an alternative, if desired.

  • GEODESICThe shortest line between any two points on the earth's surface on a spheroid (ellipsoid). One use for a geodesic line is when you want to determine the shortest distance between two cities for an airplane's flight path. This is also known as a great circle line if based on a sphere rather than an ellipsoid.
  • GREAT_ELLIPTICThe line on a spheroid (ellipsoid) defined by the intersection at the surface by a plane that passes through the center of the spheroid and the start and endpoints of a segment. This is also known as a great circle when a sphere is used.
  • LOXODROMEA loxodrome is not the shortest distance between two points but instead defines the line of constant bearing, or azimuth. Great circle routes are often broken into a series of loxodromes, which simplifies navigation. This is also known as a rhumb line.
  • PLANARPlanar measurement use 2D Cartesian mathematics to calculate lengths and areas. This option is only available when measuring in a projected coordinate system and the 2D plane of that coordinate system will be used as the basis for the measurements.
  • PRESERVE_SHAPEThis type calculates the area or length of the geometry on the surface of the Earth ellipsoid, for geometry defined in a projected or geographic coordinate system. This option preserves the shape of the geometry in its coordinate system.
String
返回值
数据类型说明
Double

线状要素的长度。返回的长度值始终以米为单位。

getPart ({index})
参数说明数据类型
index

The index position of the geometry.

Integer
返回值
数据类型说明
Array

getPart returns an array of point objects for a particular part of the geometry if an index is specified. If an index is not specified, an array containing an array of point objects for each geometry part is returned.

intersect (other, dimension)
参数说明数据类型
other

The second geometry.

Object
dimension

The topological dimension (shape type) of the resulting geometry.

  • 1A zero-dimensional geometry (point or multipoint).
  • 2A one-dimensional geometry (polyline).
  • 4A two-dimensional geometry (polygon).
Integer
返回值
数据类型说明
Object

作为两个输入几何体的交集的新几何体(点、多点、折线或面)。

overlaps (second_geometry)
参数说明数据类型
second_geometry

A second geometry.

Object
返回值
数据类型说明
Boolean

A return Boolean value of True indicates the intersection of the two geometries has the same dimension as one of the input geometries.

positionAlongLine (value, {use_percentage})
参数说明数据类型
value

The distance along the line.

If the distance is less than zero, then the starting point of the line will be returned; if the distance is greater than the length of the line, then the end point of the line will be returned.

Double
use_percentage

The distance may be specified as a fixed unit of measure or a ratio of the length of the line.

If True, value is used as a percentage; if False, value is used as a distance.

(默认值为 False)

Boolean
返回值
数据类型说明
PointGeometry

线上距线起点指定距离的点。

projectAs (spatial_reference, {transformation_name})
参数说明数据类型
spatial_reference

The new spatial reference. This can be a SpatialReference object or the coordinate system name.

SpatialReference
transformation_name

The geotransformation name.

String
返回值
数据类型说明
Object

经投影的几何。

symmetricDifference (other)
参数说明数据类型
other

A second geometry.

Object
返回值
数据类型说明
Object

生成的几何。

touches (second_geometry)
参数说明数据类型
second_geometry

A second geometry.

Object
返回值
数据类型说明
Boolean

A return Boolean value of True indicates the boundaries of the geometries intersect.

union (other)
参数说明数据类型
other

A second geometry.

Object
返回值
数据类型说明
Object

生成的几何。

within (second_geometry)
参数说明数据类型
second_geometry

A second geometry.

Object
返回值
数据类型说明
Boolean

A return Boolean value of True indicates this geometry is contained within the second geometry.

代码实例

Polygon example

Create a polyline feature class from scratch.

import arcpy

# A list of features and coordinate pairs
#
coordList = [[[1,2], [2,4], [3,7]],
            [[6,8], [5,7], [7,2], [9,5]]]

# Create empty Point and Array objects
#
point = arcpy.Point()
array = arcpy.Array()

# A list that will hold each of the Polygon objects 
# 
featureList = []

for feature in coordList:
    # For each coordinate pair, set the x,y properties and add to the 
    #  Array object.
    #
    for coordPair in feature:
        point.X = coordPair[0]
        point.Y = coordPair[1]
        array.add(point)

    # Add the first point of the array in to close off the polygon
    #
    array.add(array.getObject(0))

    # Create a Polygon object based on the array of points
    #
    polygon = arcpy.Polygon(array)

    # Clear the array for future use
    #
    array.removeAll()

    # Append to the list of Polygon objects
    #
    featureList.append(polygon)

# Create a copy of the Polygon objects, by using featureList as input to 
#  the CopyFeatures tool.
#
arcpy.CopyFeatures_management(featureList, "c:/geometry/polygons.shp")

相关主题

9/15/2013