市区择房分析(ArcPy实现)

2021/10/9 23:04:24

本文主要是介绍市区择房分析(ArcPy实现),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1, 背景

如何找到环境好、购物方便、小孩上学方便的居住区地段是购房者最关心的问题。因此购房者就需要从总体上对商品房的信息进行研究分析,选择最适宜的购房地段。

2,目的

学会利用缓冲区分析和叠置分析解决实际问题。

3,数据

试验数据位于,“\Chp7\Ex_1.

4,要求

所寻求的市区是噪声要小,距离商业中心和各大名牌高中要近,是为了环境优雅离名胜古迹较近。综合上述条件,给定一个定量的限定如下:
(1)离主要市区交通要道200m之外,交通要道的车流量大,噪声产生的主要源于此(ST为道路类型中的主要市区交通要道);
(2)距大型商业中心的影响,以商业中心的大小来确定影响区域,具体是以其属性字段YUZHI;
(3)距名牌高中在750m之内,以便小孩上学便捷;
(4)距名胜古迹500m之内环境优雅;

具体流程图如下:

5,模型构建器

6,ArcPy实现

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# 7-1 市区择房分析.py
# Created on: 2021-10-09 20:55:29.00000
#   (generated by ArcGIS/ModelBuilder)
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
import os

path = raw_input("请输入所需数据的对应绝对路径:").decode("utf-8")
paths = path + '\\result'
if not os.path.exists(paths):
    os.mkdir(paths)

# Local variables:
network = path + "\\network.shp"
network_Select_shp = "network_Select.shp"
network_Select_Buffer200_shp = "network_Select_Buffer200.shp"

Marketplace = path + "\\Marketplace.shp"
Marketplace_Buffer_shp = "Marketplace_Buffer.shp"

school = path + "\\school.shp"
school_Buffer_shp = "school_Buffer.shp"

famous_place = path + "\\famous place.shp"
famousplace_Buffer_shp = "famousplace_Buffer.shp"

suitable_shp = u"区域居住适宜性分级.shp"

# Set Geoprocessing environments
arcpy.env.scratchWorkspace = paths
arcpy.env.workspace = paths

# Process: 筛选
print "print Process: 筛选"
arcpy.Select_analysis(network, network_Select_shp, "\"TYPE\" = 'ST'")

# Process: 缓冲区
print "Process: 缓冲区"
arcpy.Buffer_analysis(network_Select_shp, network_Select_Buffer200_shp, "200 Meters", "FULL", "ROUND", "ALL", "", "PLANAR")

# Process: 添加字段
print "Process: 添加字段"
arcpy.AddField_management(network_Select_Buffer200_shp, "voice", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

# Process: 计算字段
print "Process: 计算字段"
arcpy.CalculateField_management(network_Select_Buffer200_shp, "voice", "-1", "VB", "")

# Process: 缓冲区 (2)
print "Process: 缓冲区 (2)"
arcpy.Buffer_analysis(Marketplace, Marketplace_Buffer_shp, "YUZHI_", "FULL", "ROUND", "ALL", "", "PLANAR")

# Process: 添加字段 (2)
print "Process: 添加字段 (2)"
arcpy.AddField_management(Marketplace_Buffer_shp, "market", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

# Process: 计算字段 (2)
print "Process: 计算字段 (2)"
arcpy.CalculateField_management(Marketplace_Buffer_shp, "market", "1", "VB", "")

# Process: 缓冲区 (3)
print "Process: 缓冲区 (3)"
arcpy.Buffer_analysis(school, school_Buffer_shp, "750 Meters", "FULL", "ROUND", "ALL", "", "PLANAR")

# Process: 添加字段 (3)
print "Process: 添加字段 (3)"
arcpy.AddField_management(school_Buffer_shp, "school", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

# Process: 计算字段 (3)
print "Process: 计算字段 (3)"
arcpy.CalculateField_management(school_Buffer_shp, "school", "1", "VB", "")

# Process: 缓冲区 (4)
print "Process: 缓冲区 (4)"
arcpy.Buffer_analysis(famous_place, famousplace_Buffer_shp, "500 Meters", "FULL", "ROUND", "ALL", "", "PLANAR")

# Process: 添加字段 (4)
print "Process: 添加字段 (4)"
arcpy.AddField_management(famousplace_Buffer_shp, "famous", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

# Process: 计算字段 (4)
print "Process: 计算字段 (4)"
arcpy.CalculateField_management(famousplace_Buffer_shp, "famous", "1", "VB", "")

# Process: 联合
print "Process: 联合"
arcpy.Union_analysis(u"{}\\network_Select_Buffer200.shp #;{}\\Marketplace_Buffer.shp #;{}\\school_Buffer.shp #;{}\\famousplace_Buffer.shp #".format(paths,paths,paths,paths), suitable_shp, "ALL", "", "GAPS")

# Process: 删除字段
print "Process: 删除字段"
arcpy.DeleteField_management(suitable_shp, "METERS;NAME;TYPE;L_F_ADD;R_T_ADD;CALLE;ONEWAY;L_T_ADD;R_F_ADD;FT_SPEED;TF_SPEED;TF_MINUTES;FT_MINUTES;MINUTES;SPEED;value;BUFF_DIST;ORIG_FID;ID;NAME_1;TYPE_1;YUZHI_;LABEL;value_1;BUFF_DIS_1;ORIG_FID_1;Id_1;name_12;value_12;BUFF_DIS_2;ORIG_FID_2;ID_12;NAME_12_13;LABEL_1;ADDRESS;ʱDDͨESS;ʱDDͨͨSS;ʱDDͨͨ_1;ʱDDͨͨ_2;value_1_13;BUFF_DIS_3;ORIG_FID_3")

# Process: 添加字段 (5)
print "Process: 添加字段 (5)"
arcpy.AddField_management(suitable_shp, "class", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

# Process: 计算字段 (5)
print "Process: 计算字段 (5)"
arcpy.CalculateField_management(suitable_shp, "class", "[voice] + [market] + [famous] + [school]", "VB", "")

ListFeatureClasses = arcpy.ListFeatureClasses()  # 统计要素类个数
for Feature in ListFeatureClasses:  # 循环遍历,删除不必要要素类
    if u"适宜" not in Feature:
        print "正在删除{}".format(Feature)
        arcpy.Delete_management(Feature)

print "运行完毕~~~"

注意:删除字段那里,如果出现错误的话,可能是乱码问题,干脆直接把删除字段这代码删除,继续执行也可以,
删除字段只是简化属性表罢了!

7,结果展示





后面对最终结果分五个等级,区域居住适宜性分级就制作完毕了。

继续下一个实验O(∩_∩)O~~~



这篇关于市区择房分析(ArcPy实现)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程