[Python] arcpy simple to use.

every blog every motto: Don`t talk,show me you activition.

0. Introduction

simply try arcpy, including clip, intersect, buffer, etc.
Description:

  1. Source files and official documents ArcGIS
  2. Based on python2.7,

1. text

1. clip

1.1 program

# -*- coding: utf-8 -*-
import arcpy
from arcpy import env

# 配置环境
env.workspace = "D:/Data_saved/Desktop/graduate_down/GIS/postgraudate"
# env.workspace = "D:\Data_saved\Desktop\graduate_down\GIS\postgraudate"
# 设置变量
input_features = "切分格网.shp"
clip_features = "土地调查图斑.shp"
ouput_feature_class = "D:/Data_saved/Desktop/graduate_down/GIS/output/cliped.shp"

# 执行

arcpy.Clip_analysis(input_features, clip_features, ouput_feature_class)

1.2 Results FIG.

Here Insert Picture Description

2. intersect

2.1 program files

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/3/20 11:44
# @Author  : none
# @File    : intersection_.py
import arcpy
import traceback, sys
from arcpy import env

try:

    # 设置工作环境
    env.workspace = "D:/Data_saved/Desktop/graduate_down/GIS/postgraudate"

    # 第一步 相交 intersect
    inFeatures = ["土地调查图斑.shp", "切分格网.shp"]
    intersectOutput = "intersection1.shp"  # step1 output
    arcpy.Intersect_analysis(inFeatures, intersectOutput)

    # 第二步 增加缓冲区 buffer
    bufferOutput = "buffer_5m.shp"  # step2 output
    bufferDist = "5 meters"  # 5m 缓冲区
    arcpy.Buffer_analysis(intersectOutput, bufferOutput, bufferDist)

    # 第三步 clip
    clipInput = "clip_polygon.shp"
    clipOutput = "clipOoutput.shp"  # step3 output
    arcpy.Clip_analysis(bufferOutput, clipInput, clipOutput)

    # 第四步 statsFields
    statsOutput = 'statsOutput.shp'  # step4 ouput
    statsFields = [["shape_area", "sum"]]
    caseField = "ydlx_Y"
    arcpy.Statistics_analysis(clipOutput, statsOutput, statsFields, caseField)

except Exception, e:
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message

Figure 2.2 Results

intersect below
Here Insert Picture Description
added buffer, following FIG
Here Insert Picture Description
clip, as shown below
Here Insert Picture Description
statistical results, as shown below.
Here Insert Picture Description

Published 39 original articles · won praise 32 · views 5777

Guess you like

Origin blog.csdn.net/weixin_39190382/article/details/104999001