Ejemplo n.º 1
0
def insert_new_results(selected_auth_fl, selected_res_fl, authoritative_fc,
                       schema):
    selected_auth_sdf = SpatialDataFrame.from_featureclass(selected_auth_fl)
    print(len(selected_auth_sdf))
    selected_res_sdf = SpatialDataFrame.from_featureclass(selected_res_fl)
    print(len(selected_res_sdf))

    fields = field_schema.get(schema)
    #for f in fields:
    #    print(f)

    # Write this function
    dtypes = dts.get(schema)
    fields = field_schema.get(schema)

    for idx, sel_auth_row in enumerate(selected_auth_sdf.iterrows()):

        geom = sel_auth_row[1].SHAPE.buffer(-.01)
        oid = sel_auth_row[1].OBJECTID

        # print(oid)

        ext = geom.extent

        sq = selected_res_sdf['SHAPE'].disjoint(geom) == False
        df_current = selected_res_sdf[sq].copy()
        df_current.reset_index(inplace=True)
        #print(df_current.head())

        if len(df_current) > 0:
            # print("Here")
            #['MEAN_CE90']
            for f in fields:
                try:
                    cur_val = df_current.loc[0].at[f]
                    #print(cur_val)
                    selected_auth_sdf.at[idx, f] = cur_val
                except:
                    # break
                    print("Field doesn't exist")

    insert_df = selected_auth_sdf.drop(['SHAPE'], axis=1, inplace=False)

    records = insert_df.to_records(index=False)

    rows = np.array(records, dtype=dtypes)

    array = rows  # np.array(rows, dtypes)
    da.ExtendTable(authoritative_fc, "OID@", array, "_ID", False)

    return authoritative_fc
from arcgis.gis import GIS
from arcgis.features import SpatialDataFrame
from arcgis.raster import ImageryLayer
from arcgis.geometry import Polygon
from arcgis.geometry import Geometry
import sys
import json
import arcgis_config

# type of coordinate referrence system 
crs_id = 3857
gis = GIS("https://www.arcgis.com", arcgis_config.username, arcgis_config.password)

shp_file = 'raw/bottom_part.shp'
building_data = SpatialDataFrame.from_featureclass(shp_file)
# print(type(building_data.geometry))
# print(df.dtypes)
# print(df.shape)

# naip = gis.content.search('Views', 'Imagery Layer', outside_org=True)
naip = gis.content.get('3f8d2d3828f24c00ae279db4af26d566')
# for layer in naip.layers:
#     print(layer)
naip_image_layer = naip.layers[0]
# naip_image_layer = apply(naip_image_layer, 'FalseColorComposite')
# print(naip_image_layer.extent)

# redefine occupancy type to be residential(1) and non-residential(2)
with open('residential_occupancy_types.json', 'r') as f:
    res_types = json.load(f)
Ejemplo n.º 3
0
fc_parcels = r"I:\Projects\Darren\PPA_V2_GIS\PPA_V2.gdb\TEST_parcels_for_mixIndex_point2"

out_csv = r'I:\Projects\Darren\PPA_V2_GIS\CSV\Simpson_div_idx_x_taz{}.csv'.format(
    dt_suffix)
csv_lutypes_lookup = r"I:\Projects\Darren\PPA_V2_GIS\CSV\lutypes_lookup.csv"

col_taz = 'TAZ07'
col_netarea = 'GISAc'
col_lutype = 'LUTYPE'
col_lutype_rev = 'LUTYPE_rev'

excl_lutypes = 'EXCLUDE'

cols = [col_taz, col_netarea, col_lutype]

sdf_parcel = SDF.from_featureclass(fc_parcels)

df_x_taz_and_type = sdf_parcel.groupby(
    [col_taz, col_lutype])[col_netarea].sum()  #total TAZ area x land use type

dfpp = df_x_taz_and_type.reset_index()

#lookup of land use type sto consolidate similar land use types
df_lutypes_lookup = pd.read_csv(csv_lutypes_lookup)

dfpp = dfpp.merge(df_lutypes_lookup, on=col_lutype)

#pivot: cols = land use types, rows = TAZ IDs, values = total net acres of that land use on that TAZ
df_pivot = dfpp.pivot_table(values=col_netarea,
                            index=col_taz,
                            columns=col_lutype_rev,