Created
September 3, 2011 04:10
-
-
Save AlainODea/1190539 to your computer and use it in GitHub Desktop.
Quick and dirty FIPS code lookup by state and county using Scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Site endpoint deprecated. Files can be found here: https://geonames.usgs.gov/domestic/download_data.htm