Git Product home page Git Product logo

gbify-geojson's Introduction

gbify-geojson

Build Status npm version

Reproject GeoJSON between OSGB36 GB National Grid and WGS84 CRSs.

Description

The default reference system used by GeoJSON to describe the geospatial data contained is usually ESPG:4326, cartesian coordinates are referenced using the WGS84 datum.

With this library we can reproject to or from the coordinate reference system WGS84 and the projected local coordinate system OSGB36, EPSG:27700, British National Grid. The library will reproject all coordinate data in a GeoJSON object to / from these reference systems.

This library uses proj4js to do the tranformation.

An example GeoJSON reprojected;

// WGS84
{
  "type": "Feature",
  "properties": {
    "popupContent": "Golden Square, Soho, London."
  },
  "geometry": {
    "type": "Point",
    "coordinates": [
      -0.1371467113494873,
      51.511566985991124
    ]
  }
}

// OSGB36
{
  "type": "Feature",
  "properties": {
    "popupContent": "Golden Square, Soho, London."
  },
  "geometry": {
    "type": "Point",
    "coordinates": [
      529368.34,
      180826.93
    ]
  }
}

Caveats

In using this project, please note the following points - these may be fixed in future versions.

  • We ignore the CRS property specified by GeoJSON spec. This has no impact on tranformation and is removed if present.
  • A bounding box member is reprojected, this probably is not correct.

Web example

This library is used by gb-geojson project that allows you to view, create, edit, transform GeoJSON map data in British National Grid reference system and WGS84. The app reprojects between each CRS when updated, you can try it out http://rob-murray.github.io/gb-geojson/.

Getting started

You can get hold of the code with npm and it should work fine with browserify. Or you can just manually import the source.

Dependency management

With npm:

$ npm install gbify-geojson

Interface

Given the library is loaded

> gbify = require('gbify-geojson')

toOSGB36(geoJson)

Reproject the geoJson object to EPSG:27700.

> var point = {"type":"Feature","properties":{"popupContent":"Golden Square, Soho, London."},"geometry":{"type":"Point","coordinates":[-0.1371467113494873, 51.511566985991124]}}
> gbify.toOSGB36(point)
{ type: 'Feature',
  properties: { popupContent: 'Golden Square, Soho, London.' },
  geometry:
   { type: 'Point',
     coordinates: [ 529368.34, 180826.93 ] } }

toWGS84(geoJson)

Reproject the geoJson object to EPSG:4326.

> var poly = {"type":"Feature","properties":{"popupContent":"I am SU43."},"geometry":{"type":"Polygon","coordinates":[[[440000,130000],[450000,130000],[450000,140000],[440000,140000],[440000,130000]]]}}
> gbify.toWGS84(poly) // JSON.stringify(gbify.toWGS84(poly))
'{"type":"Feature","properties":{"popupContent":"I am SU43."},"geometry":{"type":"Polygon","coordinates":[[[-1.43051,51.067945],[-1.287804,51.067163],[-1.286421,51.157077],[-1.429404,51.157861],[-1.43051,51.067945]]]}}'

Development

Run tests

Run the tests with mocha and expect.js.

$ npm test

Alternatives

The excellent reproject library was a basis for building this specific OS GB flavour.

GDAL can do this also with something like this to reproject OSGB36 > WGS84.

$ ogr2ogr -s_srs EPSG:27700 -f "GeoJSON" output.json input.json -t_srs EPSG:4326

Contributions

Please use the GitHub pull-request mechanism to submit contributions.

License

This project is available for use under the MIT software license. See LICENSE

gbify-geojson's People

Contributors

rob-murray avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gbify-geojson's Issues

Tests. Improve

Simple. The tests were implemented very quickly and need redesigning.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.