Skip to content

Instantly share code, notes, and snippets.

@black-tea
black-tea / apply_StringMatch.py
Created June 25, 2019 03:09
Code snippet to show how to use the StringMatch class
# Application of StringMatch class, using default args
titlematch = StringMatch(source_titles, target_titles)
titlematch.tokenize()
match_df = titlematch.match()
@black-tea
black-tea / StringMatch.py
Last active June 10, 2024 12:04
StringMatch: A class for matching one list of strings to another
# Load libraries
import re
import time
import operator
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer
from scipy.sparse import csr_matrix
import pandas as pd
@black-tea
black-tea / save_svg.r
Created December 2, 2017 14:55
code snippet to save a plot as an svg
```{r}
svg(filename="LAStreets_slope.svg",
width=15,
height=20,
pointsize=12)
plot(streets["slope"])
dev.off()
```
@black-tea
black-tea / StrangerThings_v1.io
Created October 30, 2017 06:40
Stranger Things Arduino Code
#include <FastLED.h>
#define DATA_PIN 6 //this is the data pin connected to the LED strip. If using WS2801 you also need a clock pin
#define NUM_LEDS 100 //change this for the number of LEDs in the strip. i changed it from 100 to 50
#define COLOR_ORDER RGB
CRGB leds[NUM_LEDS];
//I have a few additional integers in here from different tests.
int y = 1;
int z = 0;
#-------------------------------------------------------------------------------
# Name: UploadPublishCSVMultipart
# Purpose: This script uploads and publishes a CSV that includes XY data, not
# addresses. This uses a multipart upload for the CSV and requires
# username, password, CSVfile, X and Y fields, and tags to be defined
# Author: Melanie Summers
import requests
import os
@black-tea
black-tea / ArcPyMatchStreetNames_with_DifferentSuffix.py
Created February 1, 2016 19:24
This script splits a field called "AllStreets," which contains multiple streets separated by " & " and then checks to see if any matches a street name in the "Cross_St" field and updates a field called "Doyourname" with 0,1,2
import arcpy
from arcpy import env
##### Input #####
shp = "C:/Users/dotcid034/Desktop/Export_Output (1)/Export_Output.shp"
col_fields = ["Cross_St","AllStreets","Doyourname"]
cur = arcpy.da.UpdateCursor(shp,col_fields)
for row in cur:
val = None
@black-tea
black-tea / RiitsVolumeProcessing.R
Created January 7, 2016 19:34
This script summarizes volume data we obtained from the RIITS program. It filters data for only those sensors performing above 90% reporting and then sums over each LinkID for the day/week.
library(data.table)
library(fasttime)
#input
week1.file = "Z:/GIS/DataLibrary/Riits/TrafficVolumes/data dump/EXPORT - 2015/october.dsv"
#parameters that will apply to the data
chunkSize <- 500000
#date ranges
@black-tea
black-tea / ArcPySpatialJoin.py
Last active April 8, 2022 03:57
Basic Spatial Join in ArcPy. In this case, a one-to-many that will create new rows for every match.
#### This script will take the Riits Sensor Shp, and copy the assetIDs of all intersecting points to the attribute table of the Riits layer
import arcpy
from arcpy import env
env.workspace = "Z:/GIS/DataLibrary/Transportation/BOE_Centerline_Intersections150930/collisiontoInt_test.gdb"
env.overwriteOutput = True #so we can rerun this script and overwrite our output feature class
#input
Riits_sensor_shp = "Z:/GIS/DataLibrary/Riits/TrafficVolumes/data dump/EXPORT - 2015/RiitsSensorsproj.shp"
library(data.table)
### Inputs ###
meta.file <- "Z:/GIS/DataLibrary/Riits/TrafficVolumes/data dump/EXPORT - 2015/config.dsv"
### Load Data ###
meta.df <- fread(meta.file, header=T,sep="|",stringsAsFactors=F)
### Clean XY Data ###
x <- gsub('.+\\((-[0-9]+\\.[0-9]+) {1}([0-9]+\\.[0-9]+).+','\\1',meta.df$START_LAT_LONG)
@black-tea
black-tea / ArcPy_AssignNodeIDstoSegment.py
Created December 30, 2015 22:42
This script will take the centerline layer, and copy the assetIDs of all intersecting points to the attribute table of the centerline layer. It will also make sure that merged intersections are appropriately accounted for as well.
import arcpy
from arcpy import env
##### Input #####
env.workspace = "Z:/GIS/DataLibrary/Transportation/BOE_Centerline_Intersections150930/collisiontoInt_test.gdb"
env.overwriteOutput = True #so we can rerun this script and overwrite our output feature class
#input fc
col_fc = "Collisions_2009to2013"
input_centerline_fc = "Street_Centerline_Raw"