A robust, TypeScript-powered library for constructing and validating GeoJSON geometry objects, including support for all core GeoJSON types and circle extension.
- Type-safe classes for Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection
- Extended Circle geometry (as per Azure Maps/MapLibre conventions)
- Strict coordinate validation
- Factory methods for safe, declarative geometry creation
- Designed for modern JavaScript & TypeScript
npm install geojson-geometryimport GeoJSON from "geojson-geometry";
// Point
const point = GeoJSON.point([102.0, 0.5]);
console.log(point.toJSON());
console.log(point.toFeature());
// Circle
const circle = GeoJSON.circle([102.0, 0.5], 100);
console.log(circle.toJSON());
console.log(circle.toFeature({ name: 'Search Area' }));
// MultiPoint
const multiPoint = GeoJSON.multiPoint([
[102.0, 0.5]
]);
console.log(multiPoint.toJSON());
console.log(multiPoint.toFeature());
// LineString
const lineString = GeoJSON.lineString([
[102.0, 0.0],
[103.0, 1.0]
])
console.log(lineString.toJSON());
console.log(lineString.toFeature());
// Polygon
const polygon = GeoJSON.polygon([
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0] // polygon must close on first coordinates
]
]);
console.log(polygon.toJSON());
console.log(polygon.toFeature());
// GeometryCollection
const collection = GeoJSON.geometryCollection([ point, circle, multiPoint, lineString, polygon ])
console.log(collection.toJSON());- All geometry classes provide
.toJSON()and.toString() - All geometry classes provide
.toFeature(properties?)for GeoJSON Feature compatibility exceptGeometryCollection
| Type | Coordinates Type | Notes |
|---|---|---|
| Point | [number, number] |
Latitude, longitude |
| LineString | Array<[number, number]> |
Sequence of positions |
| Polygon | Array<Array<[number, number]>> |
Linear ring array |
| MultiPoint | Array<[number, number]> |
Points array |
| MultiLineString | Array<Array<[number, number]>> |
Lines array |
| MultiPolygon | Array<Array<Array<[number, number]>>> |
Polygons array |
| GeometryCollection | Array<Geometry> |
Heterogeneous Geometries |
| Circle (extension) | [number, number] + radius |
Not standard GeoJSON |
This project is licensed under the MIT License.
© 2025 Harshal Khairnar, Hitraa Technologies.