KMLファイルは複数のポイントを読み取り、密度を分析します



Kml File Reads Multiple Points



#geoogel earth The midpoint location is stored in a folder, directly reading the .kml file # _*_ coding: cp936 _*_ import re,arcpy,os,codecs from arcpy import env txtfile='' workspace=os.path.dirname(txtfile) env.workspace=workspace tf=os.path.basename(txtfile) reader=codecs.open(txtfile,'r','utf-8') inputname=tf.split('.')[0]+'.shp' prjFile='WGS 1984.prj' patA=re.compile('.*') patB=re.compile('.*') ncdic={} while True: line=reader.readline() if len(line)==0: break line=line.strip() if line=='': while True: line=reader.readline() line=line.strip() if line=='': break m=patA.match(line) if m: names=re.sub('(.*?)',r'1',line) n=patB.match(line) if n: coordi=re.sub('(.*?)',r'1',line) ncdic[names]=coordi reader.close() arcpy.CreateFeatureclass_management(workspace,inputname,'Point','','','',prjFile) fieldName1='Name' arcpy.AddField_management(inputname,fieldName1,'TEXT') keys=ncdic.keys() newdic={} for key in keys: newdic[key]=[float(a) for a in ncdic[key].split(',')] cursor=arcpy.da.InsertCursor(inputname,['root@xxxxx','Name']) point=arcpy.Point() for key in keys: point.X=newdic[key][0] point.Y=newdic[key][1] cursor.insertRow([point,key]) del cursor #defined function txtfile=arcpy.GetParameterAsText(0) prjFile=arcpy.GetParameterAsText(1) def KMLLoad(txtfile,prjFile): import re,arcpy,os,codecs from arcpy import env workspace=os.path.dirname(txtfile) env.workspace=workspace tf=os.path.basename(txtfile) reader=codecs.open(txtfile,'r','utf-8') inputname=tf.split('.')[0]+'.shp' patA=re.compile('.*') patB=re.compile('.*') ncdic={} while True: line=reader.readline() if len(line)==0: break line=line.strip() if line=='': while True: line=reader.readline() line=line.strip() if line=='': break m=patA.match(line) if m: names=re.sub('(.*?)',r'1',line) n=patB.match(line) if n: coordi=re.sub('(.*?)',r'1',line) ncdic[names]=coordi reader.close() arcpy.CreateFeatureclass_management(workspace,inputname,'Point','','','',prjFile) fieldName1='Name' arcpy.AddField_management(inputname,fieldName1,'TEXT') keys=ncdic.keys() newdic={} for key in keys: newdic[key]=[float(a) for a in ncdic[key].split(',')] cursor=arcpy.da.InsertCursor(inputname,['root@xxxxx','Name']) point=arcpy.Point() for key in keys: point.X=newdic[key][0] point.Y=newdic[key][1] cursor.insertRow([point,key]) del cursor return inputname,workspace pg,nd=KMLLoad(txtfile,prjFile) arcpy.SetParameter(2,nd+'\'+pg) # Txtfile=''# needs to be processed, shp file path Prj=''#projection file, which can be a file with projection information Def prjdensity(txtfile,prj,pg):#convert projection, calculate point density import arcpy,os from arcpy import env from arcpy.sa import * workspace=os.path.dirname(txtfile) env.workspace=workspace Prjfc=workspace+'\'+pg+'_prj'+'.shp'# filename with projection information arcpy.Project_management(pg,prjfc,prj) densityR=PointDensity(prjfc,'NONE',5,NbrCircle(3500,'MAP')) densityR.save(workspace+'\'+'densityR') return densityR