Skip to content

Instantly share code, notes, and snippets.

View d-wasserman's full-sized avatar

David Wasserman d-wasserman

View GitHub Profile
@d-wasserman
d-wasserman / FeatureTabletoDataframe.py
Last active October 18, 2024 20:23
Functions to convert a ArcGIS Table/Feature Class in arcpy to a pandas dataframe. For other options, check the new ArcGIS Python API, but this works across versions.
import arcpy
import pandas as pd
def arcgis_table_to_df(in_fc, input_fields=None, query=""):
"""Function will convert an arcgis table into a pandas dataframe with an object ID index, and the selected
input fields using an arcpy.da.SearchCursor.
:param - in_fc - input feature class or table to convert
:param - input_fields - fields to input to a da search cursor for retrieval
:param - query - sql query to grab appropriate values
:returns - pandas.DataFrame"""
@d-wasserman
d-wasserman / ArcPyValidateDFColNames.py
Last active April 19, 2021 20:50
Returns pandas dataframe with all col names renamed to be valid ArcGIS table names.
import pandas as pd
import arcpy
def validate_df_names(dataframe,output_feature_class_workspace):
"""Returns pandas dataframe with all col names renamed to be valid arcgis table names."""
new_name_list=[]
old_names=dataframe.columns.names
for name in old_names:
new_name=arcpy.ValidateFieldName(name,output_feature_class_workspace)
new_name_list.append(new_name)
rename_dict={i:j for i,j in zip(old_names,new_name_list)}
@d-wasserman
d-wasserman / Write Geojson To Feature Class.py
Last active April 19, 2021 20:47
This gist is intended to share a sample worker function to write Geojson to an ArcGIS Feature Class using Arcpy.
def write_geojson_to_records(geojson):
"""Will write geojson to a list of dictionaries with geometry keys holding coordinates and storing the properties
to dictionaries.
@param: geojson- geojson file to write to records."""
gjson_data = json.load(geojson, encoding='utf-8')
records = []
arcpy.AddMessage("Geojson being read by row...")
for feature in gjson_data["features"]:
try:
row = {}
@d-wasserman
d-wasserman / Request Mapillary Image Locations.py
Last active December 1, 2017 15:14
This is a sample python example that makes a list of geojson loads encoded in utf-8 by making requests for image locations using the Mapillary V3 API.
import requests
import json
def request_mapillary_image_locations(bbox_list, client_id, max_request_count=10000000,
root="https://a.mapillary.com/v3/"):
"""Function will make a request for images locations using the Mapillary V3 API within a bbox. It returns a
list of geojson loads for use."""
return_lists = []
arc_print("Requesting first geojson payload from Mapillary using bbox: {0}...".format(str(bbox_list)))
bbox_string = str(bbox_list[0]) + str(",") + str(bbox_list[1]) + str(",") + str(bbox_list[2]) + str(",") + str(
@d-wasserman
d-wasserman / Crossing_Clustering_Analysis_for_OSM_South_Bay.ipynb
Last active December 16, 2017 08:49
Crossing Clustering Analysis - OSM South Bay Work Zones - Goal: Develop spatially balanced zones of roughly equivalent number of pedestrian crossing elements for OSM contributors to validate as part of pedestrian network detailing in OpenStreetMap. Provide an example for others in Code for San Jose to work with geospatial data in python.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@d-wasserman
d-wasserman / LICENSE
Created December 1, 2017 15:41
This license applies to all public gists
MIT License
Copyright (c) 2017 David Wasserman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@d-wasserman
d-wasserman / EDAStatsModels.ipynb
Last active February 21, 2018 15:27
Exploratory Data Analysis of Transit Ridership and Variables Relating to Demographics and Service Characteristics - This notebook demonstrates the use of pandas, statsmodels, and seaborn for the purpose of urban data analysis. This regression modeling script is an exploratory exercise used to identify possible determinants of P & R ridership.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@d-wasserman
d-wasserman / Citi_Bike_OD_Analysis.ipynb
Last active March 27, 2018 19:35
Project: Summarize 1 Month of 2017 Citibike OD Data into a a format accepted by Spatial Sankey (geojson for ODs, and flow csv). Uses Google Datalab.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@d-wasserman
d-wasserman / EDA_HIN_Transit_Charts.ipynb
Created February 11, 2018 21:09
This notebook is a quick exploration of the relationship between different metrics of transit frequency at the stop level (~12,000 stops in the SF Bay Area) and the collision density indexes (severity weighted) from a Bay Area wide High Injury Network (HIN) analysis.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@d-wasserman
d-wasserman / Scikit_Image_Experiments.ipynb
Created April 29, 2018 08:24
This is just a series of random experiments using the scikit-image library (filters, histograms, etc) to inspect an image.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.