Answers:
创建点:
ptList =[[20.000,43.000],[25.500, 45.085],[26.574, 46.025], [28.131, 48.124]]
pt = arcpy.Point()
ptGeoms = []
for p in ptList:
pt.X = p[0]
pt.Y = p[1]
ptGeoms.append(arcpy.PointGeometry(pt))
arcpy.CopyFeatures_management(ptGeoms, r"C:\Temp\test.shp")
它将返回如下消息:
<Result 'C:\\Temp\\test.shp'>
另一种选择是仅使用现有的arcpy地理处理工具,请参见下面的代码。
# Import arcpy module
import arcpy
# Local variables:
table_dbf = "C:\\temp\\table.dbf"
table_Layer2 = "table_Layer2"
point3_shp = "C:\\temp\\point3.shp"
# Process: Make XY Event Layer
arcpy.MakeXYEventLayer_management(table_dbf, "x_coord", "y_coord", table_Layer2, "", "")
# Process: Copy Features
arcpy.CopyFeatures_management(table_Layer2, point3_shp, "", "0", "0", "0")
mxd = arcpy.mapping.MapDocument(r"C:\temp\Untitled.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
addLayer = arcpy.mapping.Layer(point3_shp)
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
mxd.saveACopy(r"C:\temp\Untitled1.mxd")
您可以使用“ 创建要素类”工具在Python中创建shapefile 。页面底部有一个示例。
要使用经纬度数据填充shapefile,可以使用插入光标。
也许您可以将经纬度数据作为列表加载到Python中,然后使用插入游标遍历数组,以填充新shapefile的行。
可以这样构造python坐标列表:
latLonList = [[40.000,-75.000],[39.998,-75.432],[39.981,-75.343]]
然后要遍历列表中的坐标(例如,打印它们),请执行以下操作:
for coord in latLonList:
print "lat: " + str(coord[0])
print "lon: " + str(coord[1])
要将图层添加到mxd文件,请参见使用Python / ArcPy在ArcGIS Desktop中将shapefile或要素类添加为图层吗?