What is @mapbox/geojson-normalize?
@mapbox/geojson-normalize is a utility for normalizing various GeoJSON objects into a consistent format. It ensures that different types of GeoJSON inputs (like Feature, FeatureCollection, Geometry, etc.) are converted into a standard FeatureCollection format, making it easier to work with GeoJSON data.
What are @mapbox/geojson-normalize's main functionalities?
Normalize a single Feature
This feature allows you to normalize a single GeoJSON Feature into a FeatureCollection. The code sample demonstrates how to convert a single Feature into a FeatureCollection.
const normalize = require('@mapbox/geojson-normalize');
const feature = {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [102.0, 0.5]
},
properties: {
prop0: 'value0'
}
};
const normalized = normalize(feature);
console.log(JSON.stringify(normalized, null, 2));
Normalize a FeatureCollection
This feature allows you to normalize an already existing FeatureCollection. The code sample shows how to ensure that a FeatureCollection is in the correct format.
const normalize = require('@mapbox/geojson-normalize');
const featureCollection = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [102.0, 0.5]
},
properties: {
prop0: 'value0'
}
}
]
};
const normalized = normalize(featureCollection);
console.log(JSON.stringify(normalized, null, 2));
Normalize a Geometry
This feature allows you to normalize a GeoJSON Geometry object into a FeatureCollection. The code sample demonstrates how to convert a Geometry into a FeatureCollection.
const normalize = require('@mapbox/geojson-normalize');
const geometry = {
type: 'Point',
coordinates: [102.0, 0.5]
};
const normalized = normalize(geometry);
console.log(JSON.stringify(normalized, null, 2));
Other packages similar to @mapbox/geojson-normalize
geojson-utils
geojson-utils is a library that provides utility functions for working with GeoJSON data. It includes functions for calculating distances, bounding boxes, and other spatial operations. Unlike @mapbox/geojson-normalize, it focuses more on spatial calculations rather than normalization.
turf
Turf is a powerful geospatial analysis library that includes a wide range of functions for manipulating and analyzing GeoJSON data. It offers more comprehensive geospatial operations compared to @mapbox/geojson-normalize, which is focused specifically on normalization.
geojson-flatten
geojson-flatten is a utility for flattening nested GeoJSON geometries into simpler geometries. While @mapbox/geojson-normalize focuses on converting various GeoJSON types into a consistent FeatureCollection format, geojson-flatten is more about simplifying complex geometries.
geojson-normalize
Normalize any GeoJSON object into a GeoJSON FeatureCollection.
install
npm install --save geojson-normalize
api
normalize(object) -> featurecollection object