forked from mdbartos/RIPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combine_census_tracts.py
49 lines (39 loc) · 1.31 KB
/
combine_census_tracts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import numpy as np
import pandas as pd
import geopandas as gpd
import psutil
import os
def combine_ct(directory):
df = gpd.GeoDataFrame()
memuse = psutil.phymem_usage()[0]
for fn in os.listdir(directory):
if fn.endswith('shp'):
nd = gpd.read_file((directory + '/' + fn))
df = df.append(nd)
if not df.crs:
if nd.crs:
df.crs = nd.crs
else:
df.crs = {'init': 'epsg:4269'}
if nd.crs:
if df.crs != nd.crs:
print('Warning, CRS mismatch')
if df.values.nbytes > 0.95*memuse:
print('Memory warning!')
break
df = df.reset_index()
del df['index']
df = gpd.GeoDataFrame(df, crs=df.crs)
return df
#### 1990 CT BOUNDARIES
c_1990 = '/home/kircheis/data/shp/census/census_tracts_all/src_data/c_1990'
df_1990 = combine_ct(c_1990)
df_1990.to_file('census_tracts_1990.shp')
#### 2000 CT BOUNDARIES
c_2000 = '/home/kircheis/data/shp/census/census_tracts_all/src_data/c_2000'
df_2000 = combine_ct(c_2000)
df_2000.to_file('census_tracts_2000.shp')
#### 2014 CT BOUNDARIES
c_2014 = '/home/kircheis/data/shp/census/census_tracts_all/src_data/c_2014'
df_2014 = combine_ct(c_2014)
df_2014.to_file('census_tracts_2014.shp')