ABS suburbs data of AUS

1. Dissolve

  Merge polygons with the same attribute of "SA2_NAME16".

>>> import arcpy
>>> mxd = arcpy.mapping.MapDocument("CURRENT")
>>> df = arcpy.mapping.ListDataFrames(mxd)[0]
>>> lyrs = arcpy.mapping.ListLayers(df)
>>> for lyr in lyrs:
... arcpy.Dissolve_management(lyr, "Dissolve_" + lyr.name, 'SA2_NAME16', '#', 'MULTI_PART', 'DISSOLVE_LINES')
...

2. Add Centroid XY

  After using the "Add Geometry Attributes" tool, we should close shp files and add them again and will see the results. (Sometimes it can show directly, WTF!!!)

...
>>> for lyr in lyrs:
... arcpy.AddGeometryAttributes_management(lyr, "CENTROID")
...

  

3. Add a state field

  Before merging those polygons, we should point a specific field storing state info.

  Before doing this, atrribute window should be closed, or it won't work.

...
>>> for i in range(1, 9):
... arcpy.AddField_management(lyrs[i], "State", "TEXT")
...
>>> # file name like "Suburbs_MB_2016_NSW"
>>> # we want to get "NSW"
>>> for i in range(1, 9):
... cursor = arcpy.UpdateCursor(lyrs[i])
... fn = lyrs[i].name
... for row in cursor:
... row.setValue("State", fn[fn.rfind("_")+1:])
... cursor.updateRow(row)
...

  

4. Merge the whole polygons into one

>>> mxd = arcpy.mapping.MapDocument("CURRENT")
>>> df = arcpy.mapping.ListDataFrames(mxd)[0]
>>> lyrs = arcpy.mapping.ListLayers(df)
>>> arcpy.Merge_management(lyrs, "Suburbs_MB_2016_AUS")

  

5. Export table to csv file

  Tool: Export Feature Attribute to ASCII

  ref: Export an attribute table to .txt using arcpy.

>>> arcpy.ExportXYv_stats('Suburbs_MB_2016_AUS', 'SA2_NAME16;CENTROID_X;CENTROID_Y;State;Shape_Area', 'COMMA', r'D:\Twitter Data\Data\test\2.csv', 'ADD_FIELD_NAMES')

  

6. Get specific columns

  Based on pandas lib.

>>> df = pd.read_csv(r"D:\Twitter Data\Data\test\2.csv")
>>> df.head()
XCoord YCoord ... STATE SHAPE_AREA
0 117.899601 -35.008360 ... WA 0.003012
1 118.207172 -34.718972 ... WA 0.394533
2 115.865812 -31.834866 ... WA 0.000638
3 115.677976 -31.600241 ... WA 0.003104
4 115.836085 -32.019166 ... WA 0.000518 [5 rows x 7 columns]
>>> df.columns
Index(['XCoord', 'YCoord', 'SA2_NAME16', 'CENTROID_X', 'CENTROID_Y', 'STATE',
'SHAPE_AREA'],
dtype='object')
>>> df1 = df[['SA2_NAME16', 'CENTROID_X', 'CENTROID_Y', 'STATE', 'SHAPE_AREA']]
>>> df1.columns
Index(['SA2_NAME16', 'CENTROID_X', 'CENTROID_Y', 'STATE', 'SHAPE_AREA'], dtype='object')
>>> df1.head()
SA2_NAME16 CENTROID_X ... STATE SHAPE_AREA
0 Albany 117.899601 ... WA 0.003012
1 Albany Region 118.207172 ... WA 0.394533
2 Alexander Heights - Koondoola 115.865812 ... WA 0.000638
3 Alkimos - Eglinton 115.677976 ... WA 0.003104
4 Applecross - Ardross 115.836085 ... WA 0.000518 [5 rows x 5 columns]
>>> df1.to_csv(r"D:\Twitter Data\Data\test\Suburbs_AUS.csv", index=False)

  

7.   

【444】Data Analysis (shp, arcpy)的更多相关文章

  1. 【443】Tweets Analysis Q&A

        [Question 01] When converting Tweets info to csv file, commas in the middle of data (i.e. locati ...

  2. 【avalon】data

    if (root.dataset) { avalon.fn.data = function (name, val) { name = name && camelize(name) va ...

  3. -_-#【jQuery】data

    .data() <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <t ...

  4. 【推荐】Data Structure Visualizations

    University of San Francisco    David Galles 功能:可视化数据结构&算法实现过程 网站地址  https://www.cs.usfca.edu/~ga ...

  5. 【转】Data URL和图片,及Data URI的利弊

    Data URL给了我们一种很巧妙的将图片“嵌入”到HTML中的方法.跟传统的用img标记将服务器上的图片引用到页面中的方式不一样,在Data URL协议中,图片被转换成base64编码的字符串形式, ...

  6. 【CSAPP】Data Lab实验笔记

    前天讲到要刚CSAPP,这一刚就是两天半.CSAPP果然够爽,自带完整的说明文档,评判程序,辅助程序.样例直接百万组走起,管饱! datalab讲的是整数和浮点数怎么用二进制表示的,考验的是用基本只用 ...

  7. 【codeforces】【比赛题解】#950 CF Round #469 (Div. 2)

    剧毒比赛,至少涨了分对吧.: ( [A]Left-handers, Right-handers and Ambidexters 题意: 有\(l\)个右撇子,\(r\)个左撇子,\(a\)个双手都惯用 ...

  8. 【LeetCode】二叉查找树 binary search tree(共14题)

    链接:https://leetcode.com/tag/binary-search-tree/ [220]Contains Duplicate III (2019年4月20日) (好题) Given ...

  9. 【LeetCode】图论 graph(共20题)

    [133]Clone Graph (2019年3月9日,复习) 给定一个图,返回它的深拷贝. 题解:dfs 或者 bfs 都可以 /* // Definition for a Node. class ...

随机推荐

  1. 在idea中编写自动拉取、编译、启动springboot项目的shell脚本

    idea 开发环境搭建 idea中安装shell开发插件 服务器具备的条件 已经安装 lsof(用于检查端口占用) 已安装 git 安装 maven 有 java 环境 背景 代码提交到仓库后,需要在 ...

  2. 使用Redis分布式锁处理并发,解决超卖问题

    一.使用Apache ab模拟并发压测 1.压测工具介绍 $ ab -n 100 -c 100 http://www.baidu.com/ -n表示发出100个请求,-c模拟100个并发,相当是100 ...

  3. stm32f103c8t6 怎么使用IAP下载程序

    首先下载官方STM32F10X的IAP Bootloader源码,STM32F10x_AN2557_FW_V3.3.0. 用Keil4打开工程代码STM32F10x_AN2557_FW_V3.3.0P ...

  4. javascript单一复制粘贴

    <div id="copy-txt">内容内容</div> <button type="submit" onclick=" ...

  5. JDK9的JShell简单使用

    JShell其实就是一个命令行工具,输入片段代码马上就可以看到结果,相当于脚本一行行解析执行,用户可以体验一把Java交互式编程环境.

  6. [LuoguP1462]通往奥格瑞玛的道路

    题目链接 题意简述:现在有一个图,每经过一个点就会交钱,走一条路就会扣血.在血量>0的前提下,要从1走到n点,并且要求路径上交钱的最大值最小. 解题思路:首先最大值最小,我们选择二分.目前有两个 ...

  7. ES 调优查询亿级数据毫秒级返回!怎么做到的?--文件系统缓存

    一道面试题的引入: 如果面试的时候碰到这样一个面试题:ElasticSearch(以下简称ES) 在数据量很大的情况下(数十亿级别)如何提高查询效率? 这个问题说白了,就是看你有没有实际用过 ES,因 ...

  8. C# 分割字符串 分隔符是字符串的情况

    string[] arr = System.Text.RegularExpressions.Regex.Split(str, "\r\n");

  9. 关于Keil4 转到 Keil5以后的一些错误解决

    一, 看自己选择CPU型号,根据型号再做配置 根据自己型号填写

  10. 猴猴吃香蕉 背包DP

    猴猴吃香蕉 背包DP \(D\)次询问,第\(i\)次询问,每次有\(n_i\)个带权香蕉,问有多少方案使香蕉之积为\(k_i\),对结果取模\(1000000007\) \(n\le 10^3,k\ ...