geojson-area
Advanced tools
Comparing version 0.2.0 to 0.2.1
31
index.js
@@ -56,10 +56,25 @@ var wgs84 = require('wgs84'); | ||
function ringArea(coords) { | ||
var area = 0; | ||
var p1, p2, p3, lowerIndex, middleIndex, upperIndex, | ||
area = 0, | ||
coordsLength = coords.length; | ||
if (coords.length > 2) { | ||
var p1, p2; | ||
for (var i = 0; i < coords.length - 1; i++) { | ||
p1 = coords[i]; | ||
p2 = coords[i + 1]; | ||
area += rad(p2[0] - p1[0]) * (2 + Math.sin(rad(p1[1])) + Math.sin(rad(p2[1]))); | ||
if (coordsLength > 2) { | ||
for (i = 0; i < coordsLength; i++) { | ||
if (i === coordsLength - 2) {// i = N-2 | ||
lowerIndex = coordsLength - 2; | ||
middleIndex = coordsLength -1; | ||
upperIndex = 0; | ||
} else if (i === coordsLength - 1) {// i = N-1 | ||
lowerIndex = coordsLength - 1; | ||
middleIndex = 0; | ||
upperIndex = 1; | ||
} else { // i = 0 to N-3 | ||
lowerIndex = i; | ||
middleIndex = i+1; | ||
upperIndex = i+2; | ||
} | ||
p1 = coords[lowerIndex]; | ||
p2 = coords[middleIndex]; | ||
p3 = coords[upperIndex]; | ||
area += ( rad(p3[0]) - rad(p1[0]) ) * Math.sin( rad(p2[1])); | ||
} | ||
@@ -75,2 +90,2 @@ | ||
return _ * Math.PI / 180; | ||
} | ||
} |
{ | ||
"name": "geojson-area", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "calculate the physical area of a geojson geometry", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,3 +5,3 @@ [![Build Status](https://travis-ci.org/mapbox/geojson-area.png)](https://travis-ci.org/mapbox/geojson-area) | ||
Calculate the area inside of a [GeoJSON](http://geojson.org/) Polygon. | ||
Calculate the area inside of any [GeoJSON](http://geojson.org/) geometry. | ||
@@ -24,5 +24,5 @@ ## usage | ||
Given a Geometry object of type Polygon or MultiPolygon, return contained | ||
Given a Geometry object, return contained | ||
area as square meters. Invalid input will return `null`. | ||
Adapted from [OpenLayers](http://openlayers.org/) |
@@ -8,3 +8,3 @@ var gjArea = require('../'), | ||
t.test('computes the area of illinois', function(t) { | ||
t.equal(gjArea.geometry(ill), 145978332359.37125); | ||
t.equal(gjArea.geometry(ill), 145978332359.36746); | ||
t.end(); | ||
@@ -11,0 +11,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24354
1429