In [2]:
import shapefile as shp
import math
import pandas as pd
import geopandas as gpd
import pylab as pl
from fiona.crs import from_epsg
%pylab inline
In [10]:
hp_target = gpd.read_file("./hp_target/hp_target.shp")
hp_target.to_crs(epsg=2263, inplace=True)
In [5]:
ct = gpd.read_file("./nyct2010_17b/nyct2010.shp")
cb = gpd.read_file("./nycb2010_17b/nycb2010.shp")
In [9]:
ct.to_crs(epsg=2263, inplace=True)
cb.to_crs(epsg=2263, inplace=True)
In [18]:
ct.BoroCT2010.unique().shape
cb.BCTCB2010.unique().shape
Out[18]:
In [39]:
hp_intersect_ct = gpd.sjoin(hp_target, ct, how='left', op='intersects')
hp_within_ct = gpd.sjoin(hp_target, ct, how='left', op='within')
ct_within_hp = gpd.sjoin(ct, hp_target, how='inner', op='within')
In [28]:
hp_intersect_ct.groupby('developmen').apply(lambda x: x.BoroCT2010)
Out[28]:
In [35]:
hp_within_ct.groupby('developmen').apply(lambda x: x.BoroCT2010)
Out[35]:
In [41]:
ct_within_hp.shape
Out[41]:
In [44]:
hp_intersect_cb = gpd.sjoin(hp_target, cb, how='left', op='intersects')
hp_within_cb = gpd.sjoin(hp_target, cb, how='left', op='within')
cb_within_hp = gpd.sjoin(cb, hp_target, how='inner', op='within')
In [37]:
hp_intersect_cb.groupby('developmen').apply(lambda x: x.BCTCB2010)
Out[37]:
In [38]:
hp_within_cb.groupby('developmen').apply(lambda x: x.BCTCB2010)
Out[38]:
In [45]:
cb_within_hp.shape
Out[45]:
In [49]:
hp_ct = hp_intersect_ct.groupby('developmen').apply(lambda x: x.BoroCT2010.values)
hp_cb = hp_intersect_cb.groupby('developmen').apply(lambda x: x.BCTCB2010.values)
In [55]:
hp_target['CT'] = hp_ct.values
hp_target['CB'] = hp_cb.values
In [56]:
hp_target
Out[56]: