location-conflation
🧩 Define complex geographic regions by including and excluding country codes and geojson shapes.
What is it?
Location-conflation is a tool for generating GeoJSON features by
including and excluding other locations and shapes.
You can define a location set as an Object with include
and exclude
properties:
let locationSet = {
include: [ Array of locations ],
exclude: [ Array of locations ]
};
The "locations" can be any of the following:
- Strings recognized by the country-coder library. These should be ISO 3166-1 2 or 3 letter country codes or UN M.49 numeric codes.
Example: "de"
- Filenames for
.geojson
features. If you want to use your own features, pass them to the LocationConflation constructor in a FeatureCollection
- each Feature
must have an id
that ends in .geojson
.
Example: "de-hamburg.geojson"
- Points as
[longitude, latitude]
coordinate pairs. A 25km radius circle will be computed around the point.
Example: [8.67039, 49.41882]
Usage Examples
const LocationConflation = require('@ideditor/location-conflation');
const myFeatures = require('./featurecollection.geojson');
const loco = new LocationConflation(myFeatures);
Southern Europe:
let result = loco.resolveLocationSet({ include: ['039'] });
Southern Europe and Northern Africa:
let result = loco.resolveLocationSet({ include: ['039','015'] });
Southern Europe and Northern Africa, excluding Egypt and Sudan:
let result = loco.resolveLocationSet({ include: ['039','015'], exclude: ['eg','sd'] });
The Alps, excluding Liechtenstein and regions around Bern and Zürich
let result = loco.resolveLocationSet({ include: ['alps.geojson'], exclude: ['li', [8.55,47.36], [7.45,46.95]] });
Other Fun facts
- This library is a wrapper around
- Results contain an
area
property containing the approximate size of the feature in km²
(This is helpful for sorting features) - Results contain a stable
id
in the form +[included]-[excluded]
(e.g. "+[015,039]-[eg,sd]") - Results are cached, so if you ask for the same thing multiple times we don't repeat the expensive turf calls.
Prerequisites
Installing
- Clone this project, for example:
git clone git@github.com:ideditor/location-conflation.git
cd
into the project folder,- Run
npm install
to install libraries
Building
License
This project is available under the ISC License.
See the LICENSE.md file for more details.