In [14]:
import pandas as pd
import pylab as pl
import geopandas as gpd
from fiona.crs import from_epsg

In [67]:
mn = gpd.read_file("/home/dj/Desktop/Manhattan16V2/MNMapPLUTO.shp")
mn.to_crs(epsg=2263, inplace=True)
grid = gpd.read_file("/home/dj/Documents/hp/polygon_grid.shp")
grid.crs = from_epsg(2263)
res = gpd.sjoin(mn, grid, how='inner')

In [72]:
res.columns


Out[72]:
Index([     u'APPBBL',     u'APPDate',     u'Address',  u'AreaSource',
        u'AssessLand',   u'AssessTot',         u'BBL',    u'BldgArea',
         u'BldgClass',   u'BldgDepth',   u'BldgFront',       u'Block',
          u'BoroCode',     u'Borough',    u'BsmtCode',    u'BuiltFAR',
            u'CB2010',          u'CD',      u'CT2010',     u'ComArea',
           u'CommFAR',     u'CondoNo',     u'Council',   u'EDesigNum',
         u'Easements',  u'ExemptLand',   u'ExemptTot',         u'Ext',
          u'FacilFAR',  u'FactryArea',    u'FireComp',  u'GarageArea',
        u'HealthArea',    u'HistDist',  u'IrrLotCode',     u'LandUse',
          u'Landmark',         u'Lot',     u'LotArea',    u'LotDepth',
          u'LotFront',     u'LotType',   u'LtdHeight',  u'MAPPLUTO_F',
          u'NumBldgs',   u'NumFloors',  u'OfficeArea',   u'OtherArea',
          u'Overlay1',    u'Overlay2',   u'OwnerName',   u'OwnerType',
        u'PLUTOMapID',  u'PolicePrct',    u'ProxCode',     u'ResArea',
          u'ResidFAR',  u'RetailArea',  u'SHAPE_Area',  u'SHAPE_Leng',
           u'SPDist1',     u'SPDist2',     u'SPDist3',     u'Sanborn',
         u'SanitBoro',  u'SanitDistr',    u'SanitSub',  u'SchoolDist',
         u'SplitZone',   u'StrgeArea',      u'TaxMap',   u'Tract2010',
          u'UnitsRes',  u'UnitsTotal',     u'Version',      u'XCoord',
            u'YCoord',  u'YearAlter1',  u'YearAlter2',   u'YearBuilt',
            u'ZMCode',     u'ZipCode',   u'ZoneDist1',   u'ZoneDist2',
         u'ZoneDist3',   u'ZoneDist4',     u'ZoneMap',    u'geometry',
       u'index_right',          u'ID'],
      dtype='object')

In [68]:
res.head()


Out[68]:
APPBBL APPDate Address AreaSource AssessLand AssessTot BBL BldgArea BldgClass BldgDepth ... ZMCode ZipCode ZoneDist1 ZoneDist2 ZoneDist3 ZoneDist4 ZoneMap geometry index_right ID
1 1.000090e+09 12/26/1985 17 STATE STREET 2 14670000.0 59250600.0 1.000090e+09 544015 O4 118.0 ... 10004 C5-5 12b POLYGON ((980492.3622000068 195423.9452120797,... 100496 100497
1 1.000090e+09 12/26/1985 17 STATE STREET 2 14670000.0 59250600.0 1.000090e+09 544015 O4 118.0 ... 10004 C5-5 12b POLYGON ((980492.3622000068 195423.9452120797,... 100210 100211
1 1.000090e+09 12/26/1985 17 STATE STREET 2 14670000.0 59250600.0 1.000090e+09 544015 O4 118.0 ... 10004 C5-5 12b POLYGON ((980492.3622000068 195423.9452120797,... 99924 99925
1 1.000090e+09 12/26/1985 17 STATE STREET 2 14670000.0 59250600.0 1.000090e+09 544015 O4 118.0 ... 10004 C5-5 12b POLYGON ((980492.3622000068 195423.9452120797,... 99638 99639
1 1.000090e+09 12/26/1985 17 STATE STREET 2 14670000.0 59250600.0 1.000090e+09 544015 O4 118.0 ... 10004 C5-5 12b POLYGON ((980492.3622000068 195423.9452120797,... 99352 99353

5 rows × 90 columns


In [20]:
# mn.UnitsRes
# mn.UnitsTotal

In [69]:
df = pd.DataFrame(res.groupby('ID').apply(lambda x: sum(x.UnitsRes)), columns=[['UnitsRes']])
df['ID'] = df.index
df.reset_index(drop=True, inplace=True)
res2 = pd.merge(grid, df, on='ID')
res2.to_file("ResUnit")

In [71]:
res2.head()


Out[71]:
ID geometry UnitsRes
0 133 POLYGON ((981437.7442907944 212819.6018336797,... 0
1 134 POLYGON ((981487.7442907944 212819.6018336797,... 0
2 135 POLYGON ((981537.7442907944 212819.6018336797,... 0
3 136 POLYGON ((981587.7442907944 212819.6018336797,... 0
4 137 POLYGON ((981637.7442907944 212819.6018336797,... 0