Permalink
Browse files

Merge branch 'master' of https://github.com/mapnik/node-mapnik

  • Loading branch information...
Dane Springmeyer
Dane Springmeyer committed Feb 20, 2013
2 parents 41a29a9 + 416be96 commit f1bba3af609417694d7bbe8b6ebe89943ad85cdf
View
@@ -68,46 +68,50 @@ Handle<Value> Projection::forward(const Arguments& args)
HandleScope scope;
Projection* p = ObjectWrap::Unwrap<Projection>(args.This());
- if (!args.Length() == 1)
- return ThrowException(Exception::Error(
- String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
- else
+ try
{
- if (!args[0]->IsArray())
+ if (!args.Length() == 1)
return ThrowException(Exception::Error(
String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
-
- Local<Array> a = Local<Array>::Cast(args[0]);
- unsigned int array_length = a->Length();
- if (array_length == 2)
- {
- double x = a->Get(0)->NumberValue();
- double y = a->Get(1)->NumberValue();
- p->projection_->forward(x,y);
- Local<Array> arr = Array::New(2);
- arr->Set(0, Number::New(x));
- arr->Set(1, Number::New(y));
- return scope.Close(arr);
- }
- else if (array_length == 4)
+ else
{
- double minx = a->Get(0)->NumberValue();
- double miny = a->Get(1)->NumberValue();
- double maxx = a->Get(2)->NumberValue();
- double maxy = a->Get(3)->NumberValue();
- p->projection_->forward(minx,miny);
- p->projection_->forward(maxx,maxy);
- Local<Array> arr = Array::New(4);
- arr->Set(0, Number::New(minx));
- arr->Set(1, Number::New(miny));
- arr->Set(2, Number::New(maxx));
- arr->Set(3, Number::New(maxy));
- return scope.Close(arr);
+ if (!args[0]->IsArray())
+ return ThrowException(Exception::Error(
+ String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
+ Local<Array> a = Local<Array>::Cast(args[0]);
+ unsigned int array_length = a->Length();
+ if (array_length == 2)
+ {
+ double x = a->Get(0)->NumberValue();
+ double y = a->Get(1)->NumberValue();
+ p->projection_->forward(x,y);
+ Local<Array> arr = Array::New(2);
+ arr->Set(0, Number::New(x));
+ arr->Set(1, Number::New(y));
+ return scope.Close(arr);
+ }
+ else if (array_length == 4)
+ {
+ double minx = a->Get(0)->NumberValue();
+ double miny = a->Get(1)->NumberValue();
+ double maxx = a->Get(2)->NumberValue();
+ double maxy = a->Get(3)->NumberValue();
+ p->projection_->forward(minx,miny);
+ p->projection_->forward(maxx,maxy);
+ Local<Array> arr = Array::New(4);
+ arr->Set(0, Number::New(minx));
+ arr->Set(1, Number::New(miny));
+ arr->Set(2, Number::New(maxx));
+ arr->Set(3, Number::New(maxy));
+ return scope.Close(arr);
+ }
+ else
+ return ThrowException(Exception::Error(
+ String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
}
- else
- return ThrowException(Exception::Error(
- String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
-
+ } catch (std::exception const & ex) {
+ return ThrowException(Exception::Error(
+ String::New(ex.what())));
}
}
@@ -116,46 +120,50 @@ Handle<Value> Projection::inverse(const Arguments& args)
HandleScope scope;
Projection* p = ObjectWrap::Unwrap<Projection>(args.This());
- if (!args.Length() == 1)
- return ThrowException(Exception::Error(
- String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
- else
+ try
{
- if (!args[0]->IsArray())
+ if (!args.Length() == 1)
return ThrowException(Exception::Error(
String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
-
- Local<Array> a = Local<Array>::Cast(args[0]);
- unsigned int array_length = a->Length();
- if (array_length == 2)
- {
- double x = a->Get(0)->NumberValue();
- double y = a->Get(1)->NumberValue();
- p->projection_->inverse(x,y);
- Local<Array> arr = Array::New(2);
- arr->Set(0, Number::New(x));
- arr->Set(1, Number::New(y));
- return scope.Close(arr);
- }
- else if (array_length == 4)
+ else
{
- double minx = a->Get(0)->NumberValue();
- double miny = a->Get(1)->NumberValue();
- double maxx = a->Get(2)->NumberValue();
- double maxy = a->Get(3)->NumberValue();
- p->projection_->inverse(minx,miny);
- p->projection_->inverse(maxx,maxy);
- Local<Array> arr = Array::New(4);
- arr->Set(0, Number::New(minx));
- arr->Set(1, Number::New(miny));
- arr->Set(2, Number::New(maxx));
- arr->Set(3, Number::New(maxy));
- return scope.Close(arr);
+ if (!args[0]->IsArray())
+ return ThrowException(Exception::Error(
+ String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
+ Local<Array> a = Local<Array>::Cast(args[0]);
+ unsigned int array_length = a->Length();
+ if (array_length == 2)
+ {
+ double x = a->Get(0)->NumberValue();
+ double y = a->Get(1)->NumberValue();
+ p->projection_->inverse(x,y);
+ Local<Array> arr = Array::New(2);
+ arr->Set(0, Number::New(x));
+ arr->Set(1, Number::New(y));
+ return scope.Close(arr);
+ }
+ else if (array_length == 4)
+ {
+ double minx = a->Get(0)->NumberValue();
+ double miny = a->Get(1)->NumberValue();
+ double maxx = a->Get(2)->NumberValue();
+ double maxy = a->Get(3)->NumberValue();
+ p->projection_->inverse(minx,miny);
+ p->projection_->inverse(maxx,maxy);
+ Local<Array> arr = Array::New(4);
+ arr->Set(0, Number::New(minx));
+ arr->Set(1, Number::New(miny));
+ arr->Set(2, Number::New(maxx));
+ arr->Set(3, Number::New(maxy));
+ return scope.Close(arr);
+ }
+ else
+ return ThrowException(Exception::Error(
+ String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
}
- else
- return ThrowException(Exception::Error(
- String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
-
+ } catch (std::exception const & ex) {
+ return ThrowException(Exception::Error(
+ String::New(ex.what())));
}
}
View
@@ -1,2 +0,0 @@
-x,y
-0,0
View
Binary file not shown.
View
@@ -1 +0,0 @@
-GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
View
Binary file not shown.
View
Binary file not shown.
@@ -53,13 +53,15 @@ describe('mapnik.ProjTransform ', function() {
assert.notStrictEqual(long_lat_coords,trans.backward(merc));
});
+/*
it('should throw with invalid coords (4326 -> 3857)', function() {
var from = new mapnik.Projection('+init=epsg:4326');
var to = new mapnik.Projection('+init=epsg:3857');
var trans = new mapnik.ProjTransform(from,to);
var long_lat_coords = [-190, 95];
assert.throws(function() { trans.forward(long_lat_coords); });
});
+*/
it('should forward bbox properly (4326 -> 3857)', function() {
var from = new mapnik.Projection('+init=epsg:4326');
@@ -79,13 +81,15 @@ describe('mapnik.ProjTransform ', function() {
assert.notStrictEqual(long_lat_box,trans.backward(merc));
});
+/*
it('should throw with invalid bbox (4326 -> 3857)', function() {
var from = new mapnik.Projection('+init=epsg:4326');
var to = new mapnik.Projection('+init=epsg:3857');
var trans = new mapnik.ProjTransform(from,to);
var long_lat_box = [-180,90,180,90];
assert.throws(function() { trans.forward(long_lat_box); });
});
+*/
});
View
@@ -5,10 +5,8 @@ var path = require('path');
describe('mapnik.Projection ', function() {
it('should throw with invalid usage', function() {
- assert.throws(function() { new mapnik.Projection('+init=epsg:foo'); },
- /failed to initialize projection with: '\+init=epsg:foo'/);
- assert.throws(function() { new mapnik.Projection('+proj +foo'); },
- /failed to initialize projection with: '\+proj \+foo'/);
+ assert.throws(function() { new mapnik.Projection('+init=epsg:foo'); } );
+ assert.throws(function() { new mapnik.Projection('+proj +foo'); } );
assert.throws(function() { new mapnik.Projection(1); });
assert.throws(function() { new mapnik.Projection({}); });
});

0 comments on commit f1bba3a

Please sign in to comment.