What is @mapbox/geojson-types?
@mapbox/geojson-types is a TypeScript library that provides type definitions for GeoJSON objects. It helps developers ensure that their GeoJSON data adheres to the correct structure and types, making it easier to work with GeoJSON data in a type-safe manner.
What are @mapbox/geojson-types's main functionalities?
Point
Defines a GeoJSON Point object with specific coordinates.
const point: GeoJSON.Point = { type: 'Point', coordinates: [100.0, 0.0] };
LineString
Defines a GeoJSON LineString object with an array of coordinate pairs.
const lineString: GeoJSON.LineString = { type: 'LineString', coordinates: [[100.0, 0.0], [101.0, 1.0]] };
Polygon
Defines a GeoJSON Polygon object with an array of linear rings.
const polygon: GeoJSON.Polygon = { type: 'Polygon', coordinates: [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]] };
Feature
Defines a GeoJSON Feature object that includes a geometry and properties.
const feature: GeoJSON.Feature<GeoJSON.Point> = { type: 'Feature', geometry: { type: 'Point', coordinates: [100.0, 0.0] }, properties: { name: 'Sample Point' } };
FeatureCollection
Defines a GeoJSON FeatureCollection object that includes an array of features.
const featureCollection: GeoJSON.FeatureCollection<GeoJSON.Geometry> = { type: 'FeatureCollection', features: [{ type: 'Feature', geometry: { type: 'Point', coordinates: [100.0, 0.0] }, properties: { name: 'Sample Point' } }] };
Other packages similar to @mapbox/geojson-types
geojson
The 'geojson' package provides utilities for creating and manipulating GeoJSON data. It offers a more comprehensive set of tools for working with GeoJSON, including validation and transformation functions, compared to @mapbox/geojson-types which focuses on type definitions.
geojson-utils
The 'geojson-utils' package offers a set of utility functions for working with GeoJSON data, such as calculating distances and bounding boxes. It provides more functional utilities for GeoJSON data manipulation, whereas @mapbox/geojson-types is primarily concerned with type safety.
terraformer
The 'terraformer' package is a library for working with GeoJSON and other geographic data formats. It includes tools for parsing, converting, and manipulating GeoJSON data. Terraformer offers a broader range of functionalities compared to @mapbox/geojson-types, which is focused on type definitions.
geojson-types
Flow type declarations for GeoJSON.
Install
npm install @mapbox/geojson-types
Use
import type {
GeoJSONFeatureCollection,
GeoJSONFeature,
GeoJSONPoint,
GeoJSONLineString,
GeoJSONPolygon,
GeoJSONMultiPoint,
GeoJSONMultiLineString,
GeoJSONMultiPolygon,
GeoJSONGeometry,
GeoJSON,
} from '@mapbox/geojson-types';
function doSomething(data: GeoJSON) {
}