《使用Python进行空间数据处理与分析.docx》由会员分享,可在线阅读,更多相关《使用Python进行空间数据处理与分析.docx(71页珍藏版)》请在第壹文秘上搜索。
1、UCApplyingTheScienceofWhere2017年第十五届ESri中国用户大会欢迎您使用Python进行空间数据处理和分析Esri(中国)信息技术有限公司张舵esrBEUlNGTHfSCIBNCSOFWHeRSPythonperiChinaOIIBEMINGTHfSCIENCEOfWHCRSBsrichinaTHESCIENCEOFWHERE9PythOn是什么?PythOn是一种面向对象、直译式计算机程序设计语言,也是一种功能强大而完善的通用型语言,创始人为GUidOvanRossum(吉多范罗苏姆)。1989年圣诞节期间,在阿姆斯特丹,Guido为了打发圣诞节的无趣,决心开发
2、一个新的脚本解释程序-Python在ArCGIS中使用Python;1RSriChina,O.IBEIJING-THgSCISNCSOFWHSffS Python在ArcGIS9.0版本中被引入到ArcGIS产品 Esri已将Python完全纳入ArCGIS中,与ArCGIS深度集成已成为ArCGIS推荐使用的脚本语言WhatOptionsDoIHaveforScriptingArcGISwithPython?TheArcGISplatformprovidestwotechnologiesforscriptingandautomation:-ArcGISAPIforPythonArcPyThe
3、ArcGISAPIforPythonandArcPycanbeusedindividuallyortogethertopoweryourGISneeds.BEJINGArcGISPythonAPl的发展历程基于dispatchgeoprocessorPython2.1arcgisscriptingPython2.4arcgisscriptinArCPy站点自动化制图Python2.7数据访问第三方包空间分析Python3.4Python2.5ArcGIS9.3ArcGIS10.0ArcGIS10.5ArcGIS9.0/9.1ArcGIS9.2ArcPro2.0Python2.62.制作gp工具
4、ArCGIS中PythOn的用法1.字段计算器明工邮煤王开亘本面e4.PythonAdd-inAddlnsOptions,ContourAddn+CreatedbyfsniCTyPeinadescniptio11forthisAddin.ypemadscptknforthisAddin.AddTmo+Cremcdby:ESnAddTimeWhenEdtingFeatureAuionieCtedby-Typeinadescnpt)forthsAddinEsri2011/9/31.0Signature:NofteforthisAdd-in.ControlsToinstallAdd-Insandco
5、nfiguretheuserinterface1.j,hh.Add-InComPOnOngUsCthecuMmizcdilg.参数表达式getWind(3rcgis.randC,lntger14)代码块fwind=1:returnnorthfwind=2:returneastfwind=3:returnsouth数据类型Variant确定ArCGlS中PythOn的用法3.模型构建器5.Pythonwindow.IoJsJcpSearchCursor(test).r,2=ronext.Unique1.ist=二Wh%嚅getValue(name1)notin1.inique1.ist:rowU
6、nK讲点?JeaqW1d(row.getValue(namer,);fr口。腮(眦喇):骼?ameE4+以+filter+Tcur三arcpy.UpdateCursor(test,str)t,nrrvinCUF:count+=!row.id=countcur.updateRow(row)ArCGlS中PythOrl的用法PORTA1.PASSWORDAGOADMIN-IFO1.DERAGoPASSWoRD(IuneTHESCIENCEOFWHEREr5 .在ArCGlSforSerVer中使用PythOnrogramFlesArcGISServertoolsadnmmanageservce.p
7、ye:manageservice.py-h-uUSERNAME-pPASSWORD-sSITE-nNAME-ostatus9start9stop9delete-l6 .在POrtaI/online中使用PythonpythonPrepareEsriBasemapsForOfflinelse.py一InahWl()22dHBHIsage:prepareEsriBasemapsFoiOfflinelse.py-h-uPORTA1.-oPORTA1.ADMIN-sArcPy介绍Arcpy为用户提供了使用Python语言操作所有地理处理工具(包括扩展模块)的入口,并提供了多种有用的函数和类,以用于处理
8、和访问GIS数据。使用PythOn和ArCPy,可以开发出大量的用于处理地理数据的实用程序。arcpy,daarcpy.mappiarcpy,saarcpy.nangArCPy的函数.列出数据环境和.设置/描述数二据,字段数据存皆知11.储3吊就地理数ArcGISOnline/Portal许可授权瞿安.日雷历布据库管消息和一错题、理获取设.置参数esriShinaTHESCIENCEOFWHEREportarcpyows=arCpyJnsertCurSorKncdata.gdbroadsjutrow=rows.newRow()row.setValue(11rowid,x)row.setValu
9、e(distance”,100)rows.insertRow(row)Cursorj5)-SearchCursor(查询游标)-InSertClJrSor(插入游标)-UPdateCUrSOr(更新游标)klelrowUelrowsimportarcpyrows=arcpy.SearchCursor(“c:/data/CoUntieS.Shplflelds=NAME;STATE_NAME”)forrowinrows:print(state:0,County:111,Population:211.format(row.getValue(,STATE-NAME11),rogetValue(nNAM
10、E11),row.getValue(POP2000n)THESCIENCEOFWHEREimportarcpyrows=arcpy.UpdateCursor(,cdatabase.gdbroads11).SZX.,Crow.setValue(,BUFFER.DISTANCE,row.getValue(11ROAD.TYPE11)*100)rows.updateRow(row)rowrowsarcpy.Describe)返回数据要素的相关属性TabIes3FeatureClasses9Geodatabases,Rasters9Coverage91.ayerFiles5RelationshipCl
11、asses9Workspaces9Datasets9Feature1.ayersJabIeViewsimportarcpy#Getthefeatureclasstodescribe(i.e.11CDataairport.gdbrunways11)#featureClass=arcpy.GetParameterAsText(O)desc=arcpy.Describe(featureClass)Printselectedfeatureclassproperties#printushapeType11,desc.shapeTypeprintnhasSoatialIndex11,desc.hasSpa
12、tialIndexprint11extentXlvIin,desc.extent.XMlnprint11extentYMax11,desc.extent.YMaxprint11thefirstfield,sname,desc.fieldsO.nameIINwprintthefirstfield,stype,desc.fieldsO.typearcpy.1.istXXX函数列出数据1.istDatasets1.istFeatureClasses遍历要素类、表格、栅格等数据-返回结果是一个集合1.istFields1.istFiles1.istIndexes1.istRasters1.istTab
13、les1.istVersions1.istWorkspaces#Getalistofallfeatureclassesfeatureclasses=arcpy.1.istFeatureclasses()#oUtPUtworkspaceout_workspace=,c:towriteto/data/output.gdb,#Settheworkspaceenvironmentarcpy.env.workspace,c:/data/FileGDB.gdbfdsrichina#Clipeachfeatureclasses,forfcinfeature_classes:.outputos.path.join(out-workspace,clip,.format(fc)arcpy.Clip_analysis(fc,boundary,outputCursorExceptions1.FeatureSets/RecordSetsArCPy类一游标I异常J三4要素和记录字段信息FieldsGeneralParameterGeometry参数类,参数读取和设置riChinaTHESCIE