geojson-data-link
v0.3.2
Published
A tool to match GeoJSON point coordinates (or a polygon centroid) to a polygon and copy over properties
Downloads
3
Readme
GeoJSON Data Link
A NodeJS library to link properties on two different GeoJSON files by determining if a geographic point is within a larger geographic region and linking the metadata. This project is sponsored by The Data Center of Southeast Louisiana
Installation
npm install geojson-data-link
or
yarn install geojson-data-link
About The Data Center
The Data Center of Southeast Louisiana is a fully independent, data-focused non-profit with a mission to build prosperous, inclusive, and sustainable communities by making informed decisions possible. If you find this tool useful, please visit our web site to learn more about our work and consider supporting us in our mission.
Usage
Command Line Interface
The command line version accepts as arguments the two geojson files, the fields you want to merge, and some formatting options. It returns your new, merged file to stdout. (If you don't work with the CLI often, you can append > filename.geojson
to the command to save the output to a file instead of display it in the terminal.)
The long example might be:
npx geojson-data-link --coordinatesfile ~/geography/library-locations.geojson --polyfile ~/geography/census-tracts.geojson --fields GEOID STATEFP > ~/geography/libraries-with-new-data.geojson
This is equivalent to:
npx geojson-data-link -c ~/geography/library-locations.geojson -p ~/geography/census-tracts.geojson -f GEOID STATEFP > ~/geography/libraries-with-new-data.geojson
Here's the options:
Link fields between a GeoJSON point file and a GeoJSON polygon file
Options:
-p, --polyfile GeoJSON file with Polygons [required]
-c, --coordinatesfile GeoJSON file with either Points or Polygons. (If matching has polygons, intersect will be used) [required]
-o, --output Output format; options include geojson (default) or just the metadata in csv or json format
-r, --reverse Copy the data from the coordinates file data to the polygon file instead [boolean]
-b, --beautify Beautify the output [boolean]
-f, --fields Fields to match, separated by a space [array] [required]
--version, -v Show version number [boolean]
-h, --help Show help [boolean]
As a Library
const match = require('./matchGEOID').matchGEOID;
const polyfile = '~/geography/census-track.geojson';
const coordinatesfile = '~/geography/library-locations.geojson';
match({
polyfile: polyfile,
coordinatesfile: coordinatesfile,
fields: ["GEOID","STATEFP","COUNTYFP","TRACTCE"],
sync: false,
reverse: false
}, function(err, asyncCoordsFile) {
if (err) console.error(err);
else console.log(JSON.stringify(asyncCoordsFile));
});
Your options are:
polyfile
: the geojson file with your polygon features (i.e., regions to check)coordinatesfile
: the geojson file with your point/coordinate featuresfields
: an array of fields to copy over after linkingsync
: whether the command to get the files runs asynchronously or synchronously.
If you set sync: true
, be warned that it will block I/O while it fetches the (potentially large) files. It's faster for one-off scripts but is not recommended for larger projects.