![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
geojson-tools
Advanced tools
GeoJSON-Tools is a JavaScript module for working with location data, primarily using the GeoJSON specification.
We created GeoJSON-Tools from rwt.to in order to use it on related projects that rely on GeoJSON (primarily for MongoDB's GeoJSON support).
You are welcome to use it, submit bug reports, add feature and pull requests!
Install node.js, then:
$ npm install geojson-tools
Calculates the distance of an array of locations.
Arguments
[lat, lng]
.Example
var array = [
[20, 30],
[20.5, 29.5]
];
getDistance(array, 4);
// 76.321
To get the distance between two points, pass two points in the array, to get the distance of a linestring, pass the coordinates of the linestring.
Takes an input of an array and a GeoJSON
type, and returns that GeoJSON
object.
Arguments
[lat, lng]
.GeoJSON
object to return (note that this is not case-sensitive.
The default type is 'Point', which is returned when pushing an array of a single set of coordinates.
Other types are LineString
and Polygon
.Note: Other GeoJSON
types will be supported in future versions.
Examples
To convert to GeoJSON::Point
Note that the array can be shallow or nested, but has to contain only one set of coordinates.
var array = [[20, 30]];
toGeoJSON(array); // or toGeoJSON(array, 'point');
// {"type":"Point","coordinates":[30,20]}
To convert to GeoJSON::LineString
var array = [
[20, 30],
[20.5, 29.5]
];
toGeoJSON(array, 'linestring');
// {"type":"LineString","coordinates":[[30,20],[29.5,20.5]]}
To convert to GeoJSON::Polygon
The minimum number of coordinates should be 4, and there is no need to add the last coordinate in the array.
Polygons
with holes are supported, however we currently do not test the validity of the holes.
var array = [
[20, 30],
[20.5, 29.5],
[21, 30.5]
];
toGeoJSON(array, 'polygon');
// {"type":"Polygon","coordinates":[[[30,20],[29.5,20.5],[30.5,21],[30,20]]]}
### toArray(geoobj)
Takes an input of a GeoJSON
type, and returns coordinates in [lat, lng]
format.
A single set of coordinates for a Point
, or an array for other types.
Arguments
GeoJSON
object of the following types: Point
, LineString
or Polygon
.Note: Other GeoJSON
types will be supported in future versions.
Examples
To convert from GeoJSON::Point
Note that the array can be shallow or nested, but has to contain only one set of coordinates.
var geoobj = {"type":"Point","coordinates":[30,20]};
toArray(geoobj);
// [20,30]
To convert from GeoJSON::LineString
var geoobj = {"type":"LineString","coordinates":[[30,20],[29.5,20.5]]};
toArray(geoobj);
// [[20,30],[20.5,29.5]]
To convert from GeoJSON::Polygon
The minimum number of coordinates should be 3, and there is no need to add the last coordinate in the array.
var geoobj = {"type":"Polygon","coordinates":[[[30,20],[29.5,20.5],[30.5,21],[30,20]]]};
toArray(geoobj);
// [[20,30],[20.5,29.5],[21,30.5]]
FAQs
Tools for working with location data, using the GeoJSON specification
The npm package geojson-tools receives a total of 0 weekly downloads. As such, geojson-tools popularity was classified as not popular.
We found that geojson-tools demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.