<jupyter_start><jupyter_text>1. Tag p10 parcels by if falling into Communities of Concern (convert FileGDB to .csv)2. Tag p10 parcels by if residential building is present on the parcel<jupyter_code>import fiona
import geopandas as gpd
import pandas as pd<jupyter_output><empty_output><jupyter_text>p10 parcel-coc tagging<jupyter_code>f = (r'C:\Users\ywang\Documents\ArcGIS\Projects\EIR_zoningmods\EIR_zoningmods.gdb')
layers = fiona.listlayers(f)
display(layers)

df =  gpd.read_file(f,
                     driver='FileGDB',
                     layer='p10_pba50_coc_tbl_v2_02172021')
print('read {} rows from parcel_coc tagging file'.format(df.shape[0]))

p10_pba50_cocid = df[['PARCEL_ID', 'coc_id']]
p10_pba50_cocid.loc[p10_pba50_cocid.coc_id != 'CoC', 'coc_id'] = 'NA'

p10_pba50_cocid['PARCEL_ID'] = p10_pba50_cocid['PARCEL_ID'].apply(lambda x: int(round(x)))

print('{} parcels fall into CoC'.format(p10_pba50_cocid.loc[p10_pba50_cocid.coc_id == 'CoC'].shape[0]))

# export 
p10_pba50_cocid.to_csv('C:\\Users\\ywang\\Box\\Modeling and Surveys\\Urban Modeling\\Bay Area UrbanSim\\PBA50\\Policies\\Zoning Modifications\\p10_pba50_cocid.csv', index=False)<jupyter_output><empty_output><jupyter_text>p10 existing residential present<jupyter_code># read basemap p10 and b10 data
p10 = pd.read_csv(r'M:\Data\GIS layers\UrbanSim smelt\2020 03 12\p10.csv')
b10 = pd.read_csv(r'M:\Data\GIS layers\UrbanSim smelt\2020 03 12\b10.csv')

# make sure PARCEL_ID is integer
p10['PARCEL_ID'] = p10['PARCEL_ID'].apply(lambda x: int(round(x)))
print('Read {} rows from p10, with {} unique PARCEL_IDs'.format(p10.shape[0], len(p10.PARCEL_ID.unique())))

b10['parcel_id'] = b10['parcel_id'].apply(lambda x: int(round(x)))
print('Read {} rows from b10, with {} unique PARCEL_IDs'.format(b10.shape[0], len(b10.parcel_id.unique())))
# merge parcels to buildings 
building_parcel = b10.merge(p10[['PARCEL_ID','LAND_VALUE','ACRES']],
                            left_on='parcel_id', 
                            right_on='PARCEL_ID', 
                            how='outer')

# aggregate building data by parcel
building_groupby_parcel = building_parcel.groupby(['PARCEL_ID']).agg({
    'improvement_value'   :'sum',
    'residential_units'   :'sum',
    'residential_sqft'    :'sum',
    'non_residential_sqft':'sum',
    'building_sqft'       :'sum',
    'year_built'          :'min',
    'building_id'         :'min'}).reset_index()


# tag 
building_groupby_parcel['ex_res_bldg'] = 'NA'

has_res1 = building_groupby_parcel.loc[building_groupby_parcel.residential_units > 0]
print('{} parcels have positive residential_units'.format(has_res1.shape[0]))

has_res2 = building_groupby_parcel.loc[building_groupby_parcel.residential_sqft > 0]
print('{} parcels have positive residential_sqft'.format(has_res2.shape[0]))

building_groupby_parcel.loc[building_groupby_parcel.residential_sqft > 0, 'ex_res_bldg'] = 'res'
# export

print('export {} rows'.format(building_groupby_parcel.shape[0]))

building_groupby_parcel[['PARCEL_ID', 'ex_res_bldg']].to_csv('C:\\Users\\ywang\\Box\\Modeling and Surveys\\Urban Modeling\\Bay Area UrbanSim\\PBA50\\Policies\\Zoning Modifications\\p10_existing_res_bldg.csv', index=False)<jupyter_output>export 1956208 rows
{'fraction_non_alphanumeric': 0.14356435643564355, 'fraction_numerical': 0.0426980198019802, 'mean_word_length': 4.998144712430427, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '411898', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1232, 'n_words': 194, 'path': 'policies/plu/p10_tagging.ipynb', 'repo_name': 'BayAreaMetro/petrale', 'size': '3232'}