Skip to content

Commit

Permalink
Updating to using epsg.io as backend instead of spatialreference.org
Browse files Browse the repository at this point in the history
  • Loading branch information
lyaunzbe committed May 27, 2015
1 parent d3aae13 commit b798420
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

![ptolemy](http://i.imgur.com/OEqohGJ.png)

A simple way to retrieve geographic projection information, in a variety of formats, from an [EPSG SRID](http://en.wikipedia.org/wiki/SRID). Uses the [spatialreference.org](http://spatialreference.org/about/) website.
A simple way to retrieve geographic projection information, in a variety of formats, from an [EPSG SRID](http://en.wikipedia.org/wiki/SRID). Uses the [epsg.io](http://epsig.io/about/) website.

The following formats for projections are supported:

* proj4
* ogcwkt
* wkt
* prettywkt (human-readable)
* esriwkt
* gml
Expand Down Expand Up @@ -39,7 +39,7 @@ ptolemy.get('4326', 'ogcwkt', function (err, resp) {

Credits
---------
[http://spatialreference.org/](http://spatialreference.org/)
[http://epsg.io/](http://epsg.io/)

Copyright
---------
Expand Down
13 changes: 6 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
var needle = require('needle');

var BASE_URI = 'http://spatialreference.org/',
EPSG_URI = BASE_URI + 'ref/epsg/',
var BASE_URI = 'http://epsg.io/',
Ptolemy = {},
formatWhiteList = [
'proj4',
'ogcwkt',
'wkt',
'prettywkt',
'esriwkt',
'gml',
Expand Down Expand Up @@ -42,11 +41,11 @@ Ptolemy.get = function(epsg, format, callback) {
epsg = epsg.toString();
if (validateEPSG(epsg)) {
if (formatWhiteList.indexOf(format) > -1) {
var requestURI = EPSG_URI + epsg + '/' + format + '/';
needle.get(requestURI, function(error, response) {
if (!error && response.statusCode == 200){
var requestURI = BASE_URI + epsg + '.' + format;
needle.get(requestURI, {timeout:4000}, function(error, response) {
if (!error && response && response.statusCode == 200){
callback(null, response.body);
} else if (response.statusCode) {
} else if (response && response.statusCode) {
callback(response.statusCode + ' : ' + response.body);
} else {
callback(error);
Expand Down
9 changes: 5 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var ptolemy = require('../'),
should = require('should');

var wgs84_ogcwkt = 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]';
var wgs84_ogcwkt = 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]';

describe('Basic Usage', function () {

Expand All @@ -17,16 +17,17 @@ describe('Basic Usage', function () {

describe('when invalid epsg srid is passed', function () {
it('returns a validation error', function (done) {
ptolemy.get('JGD2000', 'ogcwkt', function (err, resp) {
ptolemy.get('JGD2000', 'wkt', function (err, resp) {
should.exist(err);
done();
});
});
});

describe('when non-existant epsg srid is passed', function () {
this.timeout(5000);
it('returns a 404 error', function (done) {
ptolemy.get('9999', 'ogcwkt', function (err, resp) {
ptolemy.get('9999', 'wkt', function (err, resp) {
should.exist(err);
done();
});
Expand All @@ -35,7 +36,7 @@ describe('Basic Usage', function () {

describe('when valid epsg srid and projection format is passed', function () {
it('returns the proper projection in the format requested', function (done) {
ptolemy.get('4326', 'ogcwkt', function (err, resp) {
ptolemy.get('4326', 'wkt', function (err, resp) {
should.not.exist(err);
resp.should.equal(wgs84_ogcwkt);
done();
Expand Down

0 comments on commit b798420

Please sign in to comment.