-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor parser, improve centroid func, add fixture
- Loading branch information
1 parent
2e3a471
commit cd16e84
Showing
6 changed files
with
108 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
/** | ||
normalize co-ordinates that lie outside of the normal ranges. | ||
longitude wrapping simply requires adding +- 360 to the value until it comes | ||
in to range. | ||
for the latitude values we need to flip the longitude whenever the latitude | ||
crosses a pole. | ||
**/ | ||
|
||
|
||
function wrap( lat, lon ){ | ||
|
||
var point = { lat: lat, lon: lon }; | ||
var quadrant = Math.floor( Math.abs(lat) / 90) % 4; | ||
var pole = ( lat > 0 ) ? 90 : -90; | ||
var offset = lat % 90; | ||
|
||
switch( quadrant ){ | ||
case 0: | ||
point.lat = offset; | ||
break; | ||
case 1: | ||
point.lat = pole - offset; | ||
point.lon += 180; | ||
break; | ||
case 2: | ||
point.lat = -offset; | ||
point.lon += 180; | ||
break; | ||
case 3: | ||
point.lat = -pole + offset; | ||
break; | ||
} | ||
|
||
if( point.lon > 180 || point.lon <= -180 ){ | ||
point.lon -= Math.floor(( point.lon + 180 ) / 360) * 360; | ||
} | ||
|
||
return point; | ||
} | ||
|
||
module.exports = wrap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
var through = require('through2'), | ||
wrap = require('../src/wrap'); | ||
|
||
function unwrap(){ | ||
return through.obj( function( geojson, _, next ){ | ||
try { | ||
|
||
// unwrap coordinates which go around the globe | ||
geojson.coordinates = geojson.coordinates.map( function( coord ){ | ||
var w = wrap( coord[1], coord[0] ); | ||
return [ w.lon, w.lat ]; | ||
}); | ||
|
||
this.push( geojson ); | ||
|
||
} catch( e ){ | ||
console.error( 'polyline unwrap error', e ); | ||
} | ||
|
||
next(); | ||
}); | ||
} | ||
|
||
module.exports = unwrap; |
Binary file not shown.