Skip to content

Instantly share code, notes, and snippets.

@AlainODea
Created September 3, 2011 04:10
Show Gist options
  • Save AlainODea/1190539 to your computer and use it in GitHub Desktop.
Save AlainODea/1190539 to your computer and use it in GitHub Desktop.
Quick and dirty FIPS code lookup by state and county using Scala
import java.net.URI
import io.Source
object FipsCode {
def forStateAndCounty(state: String, county: String): Option[String] =
fipsCodeLookup.get((state, county))
lazy val fipsCodeLookup = {
val url = ((URI create "http://www.census.gov/geo/www/ansi/national.txt") toURL)
((for (line <- Source.fromInputStream(url.openStream()).getLines();
Array(state, _, countyCode, countyName, _) = line.split(","))
yield ((state, countyName) -> countyCode)) toMap)
}
}
@DrewWeth
Copy link

Site endpoint deprecated. Files can be found here: https://geonames.usgs.gov/domestic/download_data.htm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment