Git Product home page Git Product logo

geojson-equality's Introduction

geojson-equality

Check two valid geojson geometries for equality.

installation

npm install geojson-equality

usage

var GeojsonEquality = require('geojson-equality');
var eq = new GeojsonEqaulity();
 
var g1 = { "type": "Polygon", "coordinates": [
  [[30, 10], [40, 40], [20, 40], [10, 20], [30, 10]]
]};
var g2 = { "type": "Polygon", "coordinates": [
  [[30, 10], [40, 40], [20, 40], [10, 20], [30, 10]]
]};

eq.compare(g1,g2);    // returns true
var g3 = { "type": "Polygon", "coordinates": [
  [[30o, 100], [400, 400], [200, 400], [100, 200], [300, 100]]
]};

eq.compare(g1,g3);    // returns false

For including in browser, download file geojson-equality.min.js

<script type="text/javascipt" src="path/to/geojson-equality.min.js"></script>

This create a global variable 'GeojsonEquality' GeojsonEquality class can be initiated with many options that are used to match the geojson.

  • precision number as floating points precision required. Defualt is 17
var g1 = { "type": "Point", "coordinates": [30.2, 10] };
var g1 = { "type": "Point", "coordinates": [30.22233, 10] };
var eq = new GeojsonEqaulity({precision: 3});
eq.compare(g1,g2);  // returns false
var eq = new GeojsonEqaulity({precision: 1});
eq.compare(g1,g2);  // returns true
  • direction true | false, direction of LineString or Polygon (orientation) is ignored if false. Default is false.
  var g1 = { "type": "LineString", "coordinates": 
    [ [30, 10], [10, 30], [40, 40] ] };
  var g2 = { "type": "LineString", "coordinates": 
    [ [40, 40], [10, 30], [30, 10] ] };
  var eq = new GeojsonEqaulity({direction: false});
  eq.compare(g1,g2);  // returns true
  var eq = new GeojsonEqaulity({direction: true});
  eq.compare(g1,g2);  // returns false
  • objectComparator function, custom function for use in comparing Feature properties. Default is a shallow comparison.
  // using lodash isEqual to deep comparison
  var isEqual = require('lodash/lang/isEqual')
  var eq = new GeojsonEqaulity({objectComparator: isEqual});

developing

Once you run

npm install

then for running test

npm run test

to create build

npm run build

license

This project is licensed under the terms of the MIT license.

geojson-equality's People

Contributors

gagan-bansal avatar tcql avatar

Watchers

 avatar

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.