前言

数据来源于王法辉教授的GIS和数量方法,以后有空,我会利用python来实现里面的案例,这里向王法辉教授致敬。

绘制普查人口密度格局

使用属性查询提取区边界

  1. import numpy as np
  2. import pandas as pd
  3. import geopandas as gpd
  4. import matplotlib.pyplot as plt
  5. import arcpy
  6. from arcpy import env
  7. plt.style.use('ggplot')#使用ggplot样式
  8. %matplotlib inline#输出在线图片
  1. plt.rcParams['font.family'] = ['sans-serif']
  2. plt.rcParams['font.sans-serif'] = ['SimHei']# 替换sans-serif字体为黑体
  3. plt.rcParams['axes.unicode_minus'] = False # 解决坐标轴负数的负号显示问题
  1. regions = gpd.GeoDataFrame.from_file('../Census.gdb',layer='County')
  2. regions

  1. BRTrt = regions[regions.NAMELSAD10=='East Baton Rouge Parish']

投影

  1. BRTrt = BRTrt.to_crs('EPSG:26915')
  2. BRTrt.crs

  1. BRTrt.to_file('BRTrt.shp')

裁剪数据

  1. Tract = gpd.GeoDataFrame.from_file('../Census.gdb',layer='Tract')
  2. Tract = Tract.to_crs('EPSG:26915')
  1. TractUtm = gpd.GeoDataFrame.from_file('TractUtm.shp')
  2. BRTrtUtm = gpd.GeoDataFrame.from_file('BRTrt.shp')
  1. # Set workspace
  2. env.workspace = r"MyProject"
  3. # Set local variables
  4. in_features = "TractUtm.shp"
  5. clip_features = "BRTrt.shp"
  6. out_feature_class = "BRTrtUtm.shp"
  7. xy_tolerance = ""
  8. # Execute Clip
  9. arcpy.Clip_analysis(in_features, clip_features, out_feature_class, xy_tolerance)

计算面积和人口密度

  1. BRTrtUtm = gpd.GeoDataFrame.from_file('BRTrtUtm.shp')
  2. BRTrtUtm['area'] = BRTrtUtm.area/1000000
  1. ## 计算人口密度
  2. BRTrtUtm['PopuDen'] = BRTrtUtm['DP0010001']/BRTrtUtm['area']
  3. BRTrtUtm.to_file('BRTrtUtm.shp')

描述统计

  1. BRTrtUtm['PopuDen'].describe()

人口密度图

  1. fig = plt.figure(figsize=(12,12)) #设置画布大小
  2. ax = plt.gca()
  3. ax.set_title("巴吞鲁日市2010年人口密度模式",fontsize=24,loc='center')
  4. BRTrtUtm.plot(ax=ax,column='PopuDen',linewidth=0.5,cmap='Reds'
  5. ,edgecolor='k',legend=True,)
  6. # plt.savefig('巴吞鲁日市2010年人口密度模式.jpg',dpi=300)
  7. plt.show()

分析同心环区的人口密度格式

生成同心环

  1. ## 两种方法生成多重缓冲区的阈值
  2. dis = list(np.arange(2000,26001,2000))
  3. dis
  4. dis = list(range(2000,26001,2000))
  5. dis

  1. ## 真的特别神奇distances只有这样写列表才可以运行
  2. # Set local variables
  3. inFeatures = "BRCenter"
  4. outFeatureClass = "rings.shp"
  5. distances = [2000, 4000, 6000, 8000, 10000,
  6. 12000, 14000, 16000, 18000,
  7. 20000, 22000, 24000, 26000]
  8. bufferUnit = "meters"
  9. # Execute MultipleRingBuffer
  10. arcpy.MultipleRingBuffer_analysis(inFeatures, outFeatureClass, distances, bufferUnit, "", "ALL")

相交

  1. try:
  2. # Set the workspace (to avoid having to type in the full path to the data every time)
  3. arcpy.env.workspace = "MyProject"
  4. # Process: Find all stream crossings (points)
  5. inFeatures = ["rings", "BRTrtUtm"]
  6. intersectOutput = "TrtRings.shp"
  7. arcpy.Intersect_analysis(inFeatures, intersectOutput,)
  8. except Exception as err:
  9. print(err.args[0])
  1. TrtRings = gpd.GeoDataFrame.from_file('TrtRings.shp')
  2. TrtRings['area'] = TrtRings.area/1000000
  1. TrtRings['EstPopu'] = TrtRings['PopuDen'] * TrtRings['POLY_AREA']

融合

  1. arcpy.env.workspace = "C:/data/Portland.gdb/Taxlots"
  2. # Set local variables
  3. inFeatures = "TrtRings"
  4. outFeatureClass = "DissRings.shp"
  5. dissolveFields = ["distance"]
  6. statistics_fields = [["POLY_AREA","SUM"], ["PopuDen","SUM"]]
  7. # Execute Dissolve using LANDUSE and TAXCODE as Dissolve Fields
  8. arcpy.Dissolve_management(inFeatures, outFeatureClass, dissolveFields, statistics_fields,)
  1. DissRings = gpd.GeoDataFrame.from_file('DissRings.shp')
  2. DissRings

  1. DissRings['PopuDen'] = DissRings['SUM_PopuDe'] / DissRings['SUM_POLY_A']
  2. DissRings.set_index('distance',inplace=True)
  1. DissRings['PopuDen'].plot(kind='bar',x='distance',
  2. xlabel='',figsize=(8,6))
  3. plt.savefig('同心环人口密度图.jpg',dpi=300)
  4. plt.show()

要素转点

  1. # Set environment settings
  2. env.workspace = "BR.gdb"
  3. # Set local variables
  4. inFeatures = "BRBlkUtm"
  5. outFeatureClass = "BRBlkPt.shp"
  6. # Use FeatureToPoint function to find a point inside each park
  7. arcpy.FeatureToPoint_management(inFeatures, outFeatureClass, "INSIDE")

标识

  1. env.workspace = "MyProject"
  2. # Set local parameters
  3. inFeatures = "BRBlkPt"
  4. idFeatures = "DissRings"
  5. outFeatures = "BRBlkPt_Identity.shp"
  6. # Process: Use the Identity function
  7. arcpy.Identity_analysis(inFeatures, idFeatures, outFeatures)

数据筛选

  1. BRBlkPt_Identity = gpd.GeoDataFrame.from_file('BRBlkPt_Identity.shp')
  2. BRBlkPt_Identity.shape

  1. BRBlkPt_Identity.tail()

  1. ## 选取数据
  2. BRBlkPt_Identity = BRBlkPt_Identity[~(BRBlkPt_Identity['distance']==0.0)]

数据分组

  1. rigs_data = pd.DataFrame(BRBlkPt_Identity.groupby(by=['distance'])['POP10'].sum(),columns=['POP10'])
  2. rigs_data.reset_index(inplace=True)
  3. rigs_data

数据连接

  1. EstPopu = BRBlkPt_Identity[['distance','SUM_POLY_A','SUM_PopuDe']]
  2. PopuDen = pd.merge(rigs_data,EstPopu,how='inner',left_on='distance',right_on='distance')
  3. ## 删除重复值,按理来说,应该没有重复值了,可以试试外连接
  4. PopuDen.drop_duplicates(inplace = True)

分析和比较环形区人口和密度估值

  1. PopuDen.set_index('distance',inplace=True)
  2. PopuDen['EstPopu'] = PopuDen['SUM_PopuDe'] / PopuDen['SUM_POLY_A']
  3. PopuDen['PopuDen1'] = PopuDen['POP10'] / PopuDen['SUM_POLY_A']
  1. PopuDen['EstPopu'].plot(figsize=(10,6),marker='o',xlabel='距离(米)',ylabel='密度(人/平方千米)')
  2. PopuDen['PopuDen1'].plot(marker='s',xlabel='距离(米)',ylabel='密度(人/平方千米)')
  3. plt.legend(['基于街道','基于普查区'])
  4. plt.savefig('基于普查区和街区数据的人口密度模式对比.jpg',dpi=300)
  5. plt.show()

总结

2022年的第一次写笔记,写的不是很好,而且发现许多问题,比如就是geopandas里面的area和arcpy里面的area不一样,可能是算法不一样,面积要使用投影坐标系,我相信这个应该没有人不知道了吧,要对ArcGIS Pro里面的arcpy大赞。最近感谢也比较多,比如疫情,已经有点常态化,很影响我们的生活了。心怀感恩,希望我们都有美好的未来。春燕归,巢于林木。接下来一段时间,我要忙我的毕业论文,可能会比较忙,需要数据的可以联系我。

利用python绘制分析路易斯安那州巴吞鲁日市的人口密度格局的更多相关文章

  1. Louis Armstrong【路易斯·阿姆斯特朗】

    Louis Armstrong Louis Armstrong had two famous nicknames. 路易斯·阿姆斯特朗有两个著名的绰号. Some people called him ...

  2. 利用Python绘制一个正方形螺旋线

    1 安装turtle Python2安装命令: pip install turtule Python3安装命令: pip3 install turtle 因为turtle库主要是在Python2中使用 ...

  3. 如何利用Python绘制一个爱心

    刚学习Python几周,闲来无事,突然想尝试画一个爱心,步骤如下: 打开界面 打开Python shell界面,具体是Python语言的IDLE软件脚本. 2.建立脚本 单击左上角’File’,再单击 ...

  4. Python 学习记录----利用Python绘制奥运五环

    import turtle #导入turtle模块 turtle.color("blue") #定义颜色 turtle.penup() #penup和pendown()设置画笔抬起 ...

  5. 利用Python进行数据分析 第4章 IPython的安装与使用简述

    本篇开始,结合前面所学的Python基础,开始进行实战学习.学习书目为<利用Python进行数据分析>韦斯-麦金尼 著. 之前跳过本书的前述基础部分(因为跟之前所学的<Python基 ...

  6. 【Python 16】分形树绘制4.0(利用递归函数绘制分形树fractal tree)

     1.案例描述 树干为80,分叉角度为20,树枝长度小于5则停止.树枝长小于30,可以当作树叶了,树叶部分为绿色,其余为树干部分设为棕色. 2.案例分析 由于分形树具有对称性,自相似性,所以我们可以用 ...

  7. Python股票分析系列——数据整理和绘制.p2

    该系列视频已经搬运至bilibili: 点击查看 欢迎来到Python for Finance教程系列的第2部分. 在本教程中,我们将利用我们的股票数据进一步分解一些基本的数据操作和可视化. 我们将要 ...

  8. 利用Python进行异常值分析实例代码

    利用Python进行异常值分析实例代码 异常值是指样本中的个别值,也称为离群点,其数值明显偏离其余的观测值.常用检测方法3σ原则和箱型图.其中,3σ原则只适用服从正态分布的数据.在3σ原则下,异常值被 ...

  9. 利用Python分析GP服务运行结果的输出路径 & 实现服务输出路径的本地化 分类: Python ArcGIS for desktop ArcGIS for server 2015-08-06 19:49 3人阅读 评论(0) 收藏

    最近,一直纠结一个问题:做好的GP模型或者脚本在本地运行,一切正常:发布为GP服务以后时而可以运行成功,而更多的是运行失败,甚至不能知晓运行成功后的结果输出在哪里. 铺天盖地的文档告诉我,如下信息: ...

随机推荐

  1. 如何在子线程中更新UI

    一:报错情况 android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that creat ...

  2. 安装Redis5.0.8教程图解

    文档:安装Redis5.0.8教程图解.note 链接:http://note.youdao.com/noteshare?id=737620a0441724783c3f8ef14ab8a453& ...

  3. UNCTF2020 pwn题目

    YLBNB 用pwntools直接连接,然后接受就行. 1 from pwn import * 2 3 p = remote('45.158.33.12',8000) 4 context.log_le ...

  4. Java实现HttpGet和HttpPost请求

    maven引入JSON处理jar <dependency> <groupId>com.alibaba</groupId> <artifactId>fas ...

  5. 从K8S部署示例进一步理解容器化编排技术的强大

    概念 Kubernetes,也称为K8s,生产级别的容器编排系统,是一个用于自动化部署.扩展和管理容器化应用程序的开源系统.K8s是一个go语言开发,docker也是go语言开发,可见go语言的是未来 ...

  6. 【剑指Offer】变态跳台阶 解题报告(Python)

    题目地址:https://www.nowcoder.com/ta/coding-interviews 题目描述: 一只青蛙一次可以跳上1级台阶,也可以跳上2级--它也可以跳上n级.求该青蛙跳上一个n级 ...

  7. 基于内存的关系数据库memsql初探

    背景 广告系统中,算法模型预估需要根据广告的实时转化统计结果,才能做出更精准的预估:同时,支持多维度聚合查询(例如按照广告各个不同层级维度,按照时间不同粒度的维度),并跨大区合并.一开始的版本是基于m ...

  8. 人脸搜索项目开源了:人脸识别(M:N)-Java版

    ​ 一.人脸检测相关概念 人脸检测(Face Detection)是检测出图像中人脸所在位置的一项技术,是人脸智能分析应用的核心组成部分,也是最基础的部分.人脸检测方法现在多种多样,常用的技术或工具大 ...

  9. Chapter 12 IP Weighting and Marginal Structural Model

    目录 12.1 The causal question 12.2 Estimating IP weights via modeling 12.3 Stabilized IP weights 12.4 ...

  10. An Introduction to Measure Theory and Probability

    目录 Chapter 1 Measure spaces Chapter 2 Integration Chapter 3 Spaces of integrable functions Chapter 4 ...