I am often critical of the lack of, or inconsistent availability of administrative data from public authorities in New Jersey. But one bright spot I recently discovered has been the free geocoding service maintained by the NJ Geographic Information Network.
This blog post introduces {njgeo}, a new package for R that provides an R client to New Jersey’s publicly available geocoding API to improve the workflow of analyzing spatial data specific to the state of New Jersey.
New Jersey’s official geocoding service
The New Jersey Office of GIS (NJOGIS) runs several public ArcGIS REST API endpoints via NJGIN that can be queried by the public. The state’s official geocoding service (“NJ_Geocode”) can geocode addresses in New Jersey, converting addresses into latitude and longitudes within a coordinate reference system used for mapping.
The API is a convenient, free alternative to many commercial platforms that charge for geocoding by the API request. One advantage this geocoding service has is that it takes into account NJOGIS’s New Jersey-specific datasets, such as the road centerlines and enhanced source address points data.
The problem
The ArcGIS APIs were only designed to work directly with ESRI’s software, or through manually generated user requests via their spartan web interface. There have been other third party and official clients for ArcGIS written for R, however none have been targeted specifically to work with New Jersey’s implementation of the REST APIs.
ArcGIS may work for some people, but I prefer to work on GIS-related analysis in a scripting/command line environment. Being able to make requests to the ArcGIS APIs in R is better aligned with my preferred workflow in data science.
The njgeo R package
{njgeo} is a new package for R that can be used to query the state’s geocoding API without having to use ArcGIS on the desktop or use up any limited enterprise credits for geocoding. The package processes the JSON data received from the API and formulates the queries needed to perform geocoding, address candidate matching and reverse geocoding, fully within R.
Installation
The package can be downloaded from CRAN:
install.packages('njgeo')
Basic geocoding
library(njgeo)
geocode_address_candidates("33 Livingston Ave. New Brunswick, NJ")
Batch geocoding
It is possible to batch geocode up to 1000 addresses at once using the batch_geocode_addresses() and batch_geocode_sl() functions.
Reverse geocoding
Provide a point to get matching addresses:
reverse_geocode(-74.44513, 40.49297)
Shape and boundary files
You can easily obtain spatial boundary data for use in projects via this package. All objects are returned as an {sf} object and a coordinate reference system can be specified via arguments.
# Get state boundaries
get_state_bounds()
# Get county boundaries
get_county_bounds()
# Get municipal boundaries
get_muni_bounds()