在城市规划相关分析中,通过台下载大数据量的路径轨迹后,需要在arcGIS中合并轨迹以进一步分析
首先第一步在arcGIS模型构建器中转换kml格式
获得了与下载轨迹数量相同的数据库与图层组
最后在arcpy中合并数据库与需要的"Polyline"图层组
#-*-coding:utf8-*-
import os
import arcpy
def MergeFileGDB(inPath,outPath,outName):
arcpy.env.workspace = inPath
mergeFilePath = outPath + os.sep + outName
workspaces1 = arcpy.ListWorkspaces("*","FileGDB")
for workspace1 in workspaces1:
arcpy.env.workspace = workspace1
print workspace1
workspaces2 = arcpy.ListDatasets("*", "Feature")
for workspace2 in workspaces2:
arcpy.env.workspace = workspace2
mergeFileExist = os.path.exists(mergeFilePath)
if mergeFileExist:
print mergeFileExist
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
if fc == "Polylines":
arcpy.Append_management(fc, os.path.join(outPath + os.sep + outName, os.path.splitext(fc)[0]), "NO_TEST", "", "")
break
else:
continue
else:
arcpy.CreateFileGDB_management(outPath, outName)
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
if fc == "Polylines":
arcpy.FeatureClassToFeatureClass_conversion(fc, outPath + os.sep + outName, os.path.splitext(fc)[0])
in_file = unicode(r"G:\hthgis\NewFolder","utf-8")#替换文件路径
out_location = unicode(r"G:\hthgis\trajectory_data","utf-8")#替换文件路径
out_name = "Merge_919.gdb"#替换输出数据库名称
MergeFileGDB(in_file, out_location,out_name)
得到在同一个图层且含有信息的shp属性表