block by veltman 4f3a55a779175ded6760774040997376

Geosupport w/ JS

Using NYC’s Geosupport library with Node

Following on Chris Whong’s excellent writeup of how to make calls directly to NYC’s geosupport client, here’s a basic way to call it as a child process in Node.js.

  1. Follow Chris’s instructions on installing the desktop edition on Linux.
  2. Instead of his test.c, use this geocode.c, which is modified to treat the first command line argument as the contents of Work Area 1, and the (optional) second argument as the contents of Work Area 2. It prints the two resulting work areas to stdout, separated by a newline.
  3. Compile geocode.c with the same instructions.
  4. Use something like this geocode.js to call it repeatedly as a child process, constructing the proper work area string as needed by following the user guide.

This geocode.js constructs the working area for geocoding an address into a lat/lng, census tract, and census block based on address components (Geosupport function 1). But by changing the input string you send (line 20), and by how you parse the output (lines 27 - 46), you could do any other function.

Spawning a new child process over and over introduces a lot of unnecessary overhead, but in a Docker container on my machine this still does ~250 addresses per second. There at least two alternatives that would be much faster:

Notes

geocode.c

geocode.js