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

project-geojson

v1.0.2

Published

Project GeoJSON files or a stream of GeoJSON or GeoJSON objects with proj4

Downloads

6

Readme

project-geojson

npm js-standard-style

Project GeoJSON files or a stream of GeoJSON or GeoJSON objects with proj4

You might not want to do this - the latest GeoJSON spec expects all GeoJSON to be in WGS84 / EPSG:4326.

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

This might be useful if you want "lie to leaflet" or such like hacks to trick web mapping tools to display data in different projections. Also useful if you are parsing .shp files that are in a different coordinate system.

Table of Contents

Install

npm install --save geojson-project

Usage

project file.geojson --t_srs EPSG:3857

  Project `file.geojson` to Pseudo Mercator (`EPSG:3857`), outputs to stdout

project --t_srs EPSG:3857
project - --t_srs EPSG:3857

  Read input from stdin

options:

  -t, --t_srs <srs_def>   Destination projection, either a EPSG string or a proj4 string
  -s, --s_srs <srs_def>   Source projection, if omitted assumed to be `EPSG:4326`
  -o                      Output file, if omitted outputs to stdout

API

var projectStream = require('project-geojson')

var stream = projectStream([fromProjection,] toProjection)

Returns a transform stream that expects GeoJSON as a string or buffer and will return GeoJSON. fromProjection and toProjection can be proj or wkt strings, or EPSG strings e.g. EPSG:4326. Uses epsg-to-proj to look up EPSG codes - you will need to provide the proj or wkt string if your EPSG code is not in that database. If fromProjection is omitted it is assumed to be EPSG:4326

var objStream = projectStream.obj([fromProjection,] toProjection)

Returns an objectMode transform stream that expects and returns a stream of GeoJSON feature objects.

Example

Project the USA to Albers USA and back to WGS84 but via Pseudo Mercator - a web mapping library that projects the geojson via Psuedo Mercator will unknowingly project it to Albers USA. (N.B. I found this approx. 3x faster than doing the same with ogr2ogr)

#!/usr/bin/env node

var project = require('../')
var geojsonStream = require('geojson-stream')

var ALBERS = '+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs '

var wgs84ToAlbersUSA = project.obj('EPSG:4326', ALBERS)
var psuedoMercToWgs84 = project.obj('EPSG:3857', 'EPSG:4326')

process.stdin
  .pipe(geojsonStream.parse())
  .pipe(wgs84ToAlbersUSA)
  .pipe(psuedoMercToWgs84)
  .pipe(geojsonStream.stringify())
  .pipe(process.stdout)
cd example
cat usa.geojson | node example.js > usa_albers.geojson

Known Issues

It doesn't touch any bbox that might be defined on the GeoJSON, and doesn't touch any crs, which is no longer part of the current GeoJSON Spec.

Contribute

PRs accepted.

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © Gregor MacLennan