arcpy.management.ConvertCoordinateNotation(in_table, out_featureclass, x_field, y_field, input_coordinate_format, output_coordinate_format, {id_field}, {spatial_reference}, {in_coor_system}, {exclude_invalid_records})
|
名称
|
说明
|
数据类型
|
|
in_table
|
输入表或文本文件。 点要素同样有效。
|
Table View
|
|
out_featureclass
|
输出点要素类。 属性表将包括输入表的所有字段以及以输出格式表示转换值的字段。
|
Feature Class
|
|
x_field
|
输入表中包含经度值的字段。
对于 input_coordinate_format 参数的 DD_2、DD_NUMERIC、DDM_2 和 DMS_2 选项,此字段为经度字段。
对于 DD_1、DDM_1 和 DMS_1 选项,此字段包含单个字符串中的纬度值和经度值。
对于 GARS、GEOREF、GEOREF16、UTM_ZONES、UTM_BANDS、USNG、USNG16、MGRS 和 MGRS16 选项,此字段包含单个文本字段中的字母数字记法系统。
|
Field
|
|
y_field
|
输入表中包含纬度值的字段。
对于 input_coordinate_format 参数的 DD_2、DD_NUMERIC、DDM_2 和 DMS_2 选项,此字段为经度字段。
选择其中一种单字符串格式时,此参数将被忽略。
|
Field
|
|
input_coordinate_format
|
指定输入字段的坐标格式。
DD、DDM、DMS 和 UTM 也是有效关键字;要使用这些关键字,可键入(在对话框上)或在脚本中传递该值。 但是,带下划线和限定符的关键字可以提供关于字段值的更多信息。
DD_1—经度值和纬度值均位于单一字段中。 这两个值以空格、逗号或斜线分隔。
DD_2—经度值和纬度值位于两个不同的字段中。这是默认值。
DDM_1—经度值和纬度值均位于单一字段中。 这两个值以空格、逗号或斜线分隔。
DDM_2—经度值和纬度值位于两个不同的字段中。
DMS_1—经度值和纬度值均位于单一字段中。 这两个值以空格、逗号或斜线分隔。
DMS_2—经度值和纬度值位于两个不同的字段中。
GARS—全球区域参考系基于纬度和经度,并将全球划分和细分为多个像元。
GEOREF—世界地理参考系是一个基于格网的系统,它将全球划分为 15 度象限并将这些象限细分为更小的象限。
GEOREF16—世界地理参考系,精度为 16 位。
UTM_ZONES—UTM 区域编号后的字母 N 或 S 表示北半球或南半球。
UTM_BANDS—UTM 区域编号后的字母表示 20 个纬度带之一。 N 或 S 不表示半球。
USNG—美国国家格网与 MGRS 几乎一样,但采用的基准面为1983 年的北美基准面(NAD83)。
USNG16—美国国家格网,精度高于 16 位。
MGRS—军事格网参考系采用 UTM 坐标并将全球划分为 6 度经度带和 20 个纬度带,而 MGRS 会进一步将格网区域细分为更小的 100,000 米格网。 这些 100,000 米格网随后划分为 10,000 米、1,000 米、100 米、10 米和 1 米格网。
MGRS16—军事格网参考系,精度为 16 位。
SHAPE—仅在选择点要素图层作为输入时可用。 每个点的坐标将用于定义输出格式。
|
String
|
|
output_coordinate_format
|
指定输入记法转换后的坐标格式。
DD、DDM、DMS 和 UTM 也是有效关键字;要使用这些关键字,可键入(在对话框上)或在脚本中传递该值。 但是,带下划线和限定符的关键字可以提供关于字段值的更多信息。
DD_1—经度值和纬度值均位于单一字段中。 这两个值以空格、逗号或斜线分隔。
DD_2—经度值和纬度值位于两个不同的字段中。
DD_NUMERIC—经度值和纬度值位于两个不同的“双精度”类型字段中。 “西”部和“南”部的值以减号表示。
DDM_1—经度值和纬度值均位于单一字段中。 这两个值以空格、逗号或斜线分隔。
DDM_2—经度值和纬度值位于两个不同的字段中。
DMS_1—经度值和纬度值均位于单一字段中。 这两个值以空格、逗号或斜线分隔。
DMS_2—经度值和纬度值位于两个不同的字段中。
GARS—全球区域参考系基于纬度和经度,并将全球划分和细分为多个像元。
GEOREF—世界地理参考系是一个基于格网的系统,它将全球划分为 15 度象限并将这些象限细分为更小的象限。
GEOREF16—世界地理参考系,精度为 16 位。
UTM_ZONES—UTM 区域编号后的字母 N 或 S 表示北半球或南半球。
UTM_BANDS—UTM 区域编号后的字母表示 20 个纬度带之一。 N 或 S 不表示半球。
USNG—美国国家格网与 MGRS 几乎一样,但采用的基准面为1983 年的北美基准面(NAD83)。
USNG16—美国国家格网,精度高于 16 位。
MGRS—军事格网参考系采用 UTM 坐标并将全球划分为 6 度经度带和 20 个纬度带,而 MGRS 会进一步将格网区域细分为更小的 100,000 米格网。 这些 100,000 米格网随后划分为 10,000 米、1,000 米、100 米、10 米和 1 米格网。
MGRS16—军事格网参考系,精度为 16 位。
|
String
|
|
id_field
(可选)
|
由于所有字段都被传输到输出表,因此忽略此参数。
|
Field
|
|
spatial_reference
(可选)
|
输出要素类的空间参考。 默认值为 GCS_WGS_1984。
此工具将输出投影到指定的空间参考中。 如果输入坐标系和输出坐标系具有不同的基准面,则将根据输入坐标系和输出坐标系以及数据范围使用默认转换。
|
Spatial Reference
|
|
in_coor_system
(可选)
|
输入数据的空间参考。 如果无法从输入表中获取输入空间参考,则将使用默认值 GCS_WGS_1984。
|
Coordinate System
|
|
exclude_invalid_records
(可选)
|
指定是否排除带无效注记的记录。
|
Boolean
|
代码示例
ConvertCoordinateNotation 示例 1(独立脚本)
以下独立脚本演示了如何将 ConvertCoordinateNotation 函数与一个输入格式字段结合使用。
# import arcpy module
import arcpy
# set locals variables
in_tab = r"c:\data\notation.gdb\loc_mgrs"
out_pts = r"c:\data\notation.gdb\loc_final"
# call Convert Coordinate Notation with MGRS as input field.
# leaving out spatial reference parameter will default to WGS 1984
arcpy.management.ConvertCoordinateNotation(in_tab, out_pts, "m10d", "#", "MGRS", "DD_1")
ConvertCoordinateNotation 示例 2(独立脚本)
以下独立脚本演示了如何将 ConvertCoordinateNotation 函数与两个输入格式字段结合使用。
# imports
import arcpy
arcpy.env.workspace = r"c:\data\mtf.gdb"
# set parameter values
input_table = 'rit_up_DD'
output_points = 'ritLOC'
x_field = 'LON'
y_field = 'LAT'
input_format = 'DD_2'
output_format = 'GARS'
id_field = 'CITY_NAME'
spatial_ref = arcpy.SpatialReference('WGS 1984')
try:
arcpy.management.ConvertCoordinateNotation(input_table, output_points, x_field, y_field,
input_format, output_format, id_field, spatial_ref)
print(arcpy.GetMessages(0))
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
except Exception as ex:
print(ex.args[0])
ConvertCoordinateNotation 示例 3(独立脚本)
以下独立脚本演示了如何将 ConvertCoordinateNotation 函数与 UTM_ZONES 和 UTM_BANDS 格式结合使用。
# imports
import arcpy
arcpy.env.workspace = r"c:\data\ccn.gdb"
# export_utm58 table contains coordinates in UTM_BANDS format
# where N and S indicate latitude bands,
# for example, 58S4144921393176 - here 58S is latitude band
input_table = 'export_utm58'
# the coordinate values in output point table will be in UTM_ZONES format
# for example, 58N4144921393176 - note that it is now 58N because
# the point is in UTM 58 North zone
output_points = 'utm_zone18'
spatial_ref = arcpy.SpatialReference('WGS 1984')
try:
arcpy.management.ConvertCoordinateNotation(input_table, output_points, "LOCS", "",
"UTM_BANDS", "UTM_ZONES", "", spatial_ref)
print(arcpy.GetMessages(0))
except Exception as ex:
print(ex.args[0])
ConvertCoordinateNotation 示例 4(独立脚本)
以下独立脚本演示了如何使用 ConvertCoordinateNotation 函数将输出文本的十进制度值转换为浮点值。 注意,要使用减号取代 S 和 W。
# imports
import arcpy
# output from Convert Coordinate Notation tool
# for DD_2 (and also for DD_1) format, the output values are in string format
# for example, for DD_1, the output values may be '43.63872N 116.24135W'
in_table = r"c:\data\ccn.gdb\ccn_dd1"
# add a field of type DOUBLE to store the numeric longitude value
arcpy.management.AddField(in_table, "DDLonDbl", "DOUBLE")
# now call CalculateField tool to convert the values, 'W' is negative
expr = """def convertToDouble(fldval):
val = float(fldval[:-1])
if fldval[-1:] == 'W':
return val * -1.0
else:
return val"""
try:
# DDLon field contains longitudes in a string field
arcpy.management.CalculateField(in_table, "DDLonDbl", "convertToDouble(!DDLon!)", "PYTHON_9.3", expr)
except:
print(arcpy.GetMessages())
# add another field to store the numeric longitude value
arcpy.management.AddField(in_table, "DDLatDbl", "DOUBLE")
# call CalculateField again to convert the values, 'S' is negative
expr = """def convertToDouble(fldval):
val = float(fldval[:-1])
if fldval[-1:] == 'S':
return val * -1.0
else:
return val"""
try:
# DDLat field contains latitudes in a string field
arcpy.management.CalculateField(in_table, "DDLatDbl", "convertToDouble(!DDLat!)", "PYTHON_9.3", expr)
except:
print(arcpy.GetMessages())