API to reverse geocode latitude, longitude to census tract?

The FCC census block conversion API is exactly what you're looking for.


In PostGIS, if you have a table of points, and the census boundary information that @Sminbamangu refers to you could calculate this using the following approach:

SELECT 
       c.census_tract, 
       p.point_id
FROM
       census_boundary as c,
       table_of_points as p
WHERE
       ST_Contains(c.geom, p.geom);

You can see the description ST_Contains here. This would return a table of the points, and the census tract where they are located.


You could do it locally instead of an online API. One solution with R: Census boundary data for the USA is available through TIGER at census.gov; if you're thinking about the US then you could download the US states and use a function to get the tracts. For example, using California and a random (or random-ish) point:

library(maps)
library(maptools)


tractLookup <- function(x, y, state) {
  pt <- SpatialPoints(data.frame(x = x, y = y))
  overlay.pt <- overlay(pt, state) # what index number does pt fall inside?
  return(census$TRACT[overlay.pt]) # give the Tract number from the census layer
}

Try it out:

california <- readShapePoly("~/Downloads/US_2000_Census_Tracts/tr06_d00_shp/tr06_d00.shp")
tractLookup(-123.123, 40.789, california)

Gives 0004, which is correct.

# Look at the map
plot(census)
map('state', c('California'), lwd = 2, col = 'green', add = F) # optional
points(-123.123, 40.789, col = 'red', lwd = 2)

This works, but takes 5 seconds on my Mac, which would probably be too much if you're going to do a lot of this; I suspect someone will weigh in shortly with a PostGIS solution that will be a million times quicker ...