• elipse+pydev+python开发arcgis脚本程序


     

    环境配置参考:http://www.cnblogs.com/halfacre/archive/2012/07/22/2603848.html

    添加arcpy类库、arctoolbox、arcgis-bin如下所示。

    windos——preference——pydev

     完成环境配置。

    二、获取文件路径Python方法

     

    os.getcwd()返回的是当前文件的目录。假如我的代码文件放在C:Usersscfengworkspacearcgispythonsrc oot ested包下

    1 import os
    2 print(os.getcwd())

    返回C:Usersscfengworkspacearcgispythonsrc oot ested文件路径

    print(os.path.dirname(os.getcwd()))

    Return the directory name of pathname path。即获取脚本所在文件夹的上一层文件目录C:Usersscfengworkspacearcgispythonsrc oot

    获取root文本下文件夹date下面的text.txt文件路径:

    os.path.join(os.path.dirname(os.getcwd()),"date","text.txt")

    print返回:C:Usersscfengworkspacearcgispythonsrc ootdate ext.txt

     环境可作为环境类中的读/写属性进行访问,方法为 arcpy.env.<环境名称>。还可以利用 Python 的 from-import 语句简化代码,而不必为每个环境名称都添加 arcpy.env 前缀。

    import arcpy                         
    arcpy.env.workspace = "c:/data"     

    简化写法

    import arcpy
    from arcpy import env
    env.workspace = "c:/data"

    一种设置geodatabase作为存储数据的工作空间环境,读/写 数据环境变量设置为如下:

    import arcpy
    arcpy.env.overwriteOutput = True
    arcpy.env.workspace = os.path.join(os.path.dirname(os.getcwd()), "data", "Habitat_Analysis.gdb")
    roads = "MajorRoads"
    veg = "Vegetation"
    climate = "ClimateZones"
    import arcpy
    from arcpy import env
    # Set the workspace environment setting
    env.workspace = "c:/St_Johns/data.gdb"
    # Set the XYTolerance environment setting
    env.XYTolerance = 2.5

    第二种设置文件夹为工作空间环境。

    import arcpy
    #设置环境
    arcpy.env.workspace="E:/test3"
    #buffer areas of roads
    roads="roads.shp"
    roadsBuffer = "E:/test3/buffer_ouput"
    arcpy.Buffer_analysis(roads,roadsBuffer,"40 Meters","","","ALL")
    print('finished')

    roads.shp放在test3文件夹目录下,通过工作空间访问路网数据。

    第三种,也可以不设置工作空间,但是不建议这样做,对于养成良好的代码习惯不利。如

    import arcpy
    #buffer areas of roads
    roads="E:/test3/roads.shp"
    roadsBuffer = "E:/test3/buffer_ouput"
    arcpy.Buffer_analysis(roads,roadsBuffer,"40 Meters","","","ALL")
    print('finished')

     假如输出的要素不想保留,则放在内存里,在后续的运行处理中自动清除。

    buffer = arcpy.Buffer_analysis(roads, "in_memory/buffer", "1000 Feet", "", "", "ALL")

    默认输出的路径为工作空间里,如空间为gdb则输出到gdb,如果输出空间为文件夹,则输出到文件夹。

    habitat = arcpy.Select_analysis(dissolve, "Habitat", """ "Area" >100 AND "Climate" = 'Coastal' """)


     

    三、查看运行时间

    import datetime  #用来查看运行时间的命令与该程序无关
    startTime=datetime.datetime.now()
    print("start time:",startTime)

    .........#写你的程序

    endTime=datetime.datetime.now()
    print("end time:",endTime)
    print("耗时",endTime-startTime)

  • 相关阅读:
    响应式网页设计简单入门
    食品企业模拟大作业
    pyqt5 QTreeWiget删除节点的问题
    递归问题记录attention
    pyinstaller打包:AttributeError: module 'win32ctypes.pywin32.win32api' has no attribute 'error'
    QT调用python的部分问题
    QT编译出现ld.exe: cannot open output file debug h_03testCallPy.exe: Permission denied collect2.exe: error: ld returned 1 exit status
    pyinstaller执行后出现maximum recursion depth exceeded while calling a Python object
    优学院辅助_全自动视频...
    年产xx吨xx食品工厂设计资料
  • 原文地址:https://www.cnblogs.com/suncf/p/4116217.html
Copyright © 2020-2023  润新知