npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reproject

v1.2.7

Published

Reproject GeoJSON from one projection/CRS to another

Downloads

35,592

Readme

reproject Build status NPM version

Greenkeeper badge

Transforms GeoJSON from one projection / CRS to another.

According to the latest GeoJSON spec (RFC 7946), GeoJSON coordinates should be assumed to be in WGS84, but sometimes it's useful to use other CRS anyway, and the spec actually leaves some room for this:

However, where all involved parties have a prior arrangement, alternative coordinate reference systems can be used without risk of data being misinterpreted.

Reproject lets you either explicitly specify a GeoJSON's CRS, or use the conventions from the earlier GeoJSON spec: GeoJSON 2008.

cli

install:

$ npm install -g reproject

use:

$ echo '{"type":"Point","coordinates":[319180, 6399862]}' | reproject --use-epsg-io --from=EPSG:3006 --to=EPSG:4326

Options:

  • --from=crs-name is the CRS to convert the GeoJSON from; either a name from crs-defs, or a Proj4 CRS definition string
  • --to=crs-name is the CRS to convert the GeoJSON to; either a name from crs-defs, or a Proj4 CRS definition string
  • --use-epsg-io or --eio to use epsg.io to look up any CRS definitions that aren't already known
  • --use-spatialreference or --sr to use spatialreference.org to look up any CRS definitions that aren't already known
  • --crs-defs=file to provide a JSON dictionary of known CRS definitions. A sample file of CRS definitions, crs-defs.json, is supplied.
  • --reverse to reverse the axis (swap x and y) before performing the reprojection

reproject can be used together with for example wellknown and geojsonio-cli:

$ echo "POINT(319180 6399862)" | wellknown | reproject --crs-defs=crs-defs.json --from=EPSG:3006 --to=EPSG:4326 | geojsonio

usage

Installation is easy with npm:

npm install reproject

It works well in the browser with for example browserify.

api

reproject(geojson, from, to, crss)

Reprojects the given GeoJSON from the CRS given in from to the CRS given in to.

The from and to arguments can either be a proj4 projection object, a string containing a CRS name, or a Proj4 CRS definition string. In the case of a CRS name, the proj4 projection instance is looked up using the crss argument. crss is assumed to be a dictionary of projection names to proj4 objects.

If from is left undefined or null, the CRS will be detected from the GeoJSON's crs property and looked up in the crss dictionary.

toWgs84(geojson, from, crss)

Shortcut equivalent to

reproject(geojson, from, proj4.WGS84, crss)

For a fully automatic "convert almost any common projection to lat/lon", try this:

var epsg = require('epsg');
toWgs84(geojson, undefined, epsg);

detectCrs(geojson, crss)

Detects the CRS defined in the given GeoJSON and returns the corresponding proj4 projection instance from crss. If no CRS is defined in the GeoJSON, or the defined CRS isn't present in crss, an error is thrown.

reverse(geojson)

Reverses the axis order of the coordinates in the given GeoJSON, such that x becomes y and y becomes x.