Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mapnik/node-mapnik
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Feb 20, 2013
2 parents 41a29a9 + 416be96 commit f1bba3a
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 77 deletions.
148 changes: 78 additions & 70 deletions src/mapnik_projection.cpp
Expand Up @@ -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())));
}
}

Expand All @@ -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())));
}
}

2 changes: 0 additions & 2 deletions test/data/_/foo.csv

This file was deleted.

Binary file removed test/data/_/long_lat.dbf
Binary file not shown.
1 change: 0 additions & 1 deletion test/data/_/long_lat.prj

This file was deleted.

Binary file removed test/data/_/long_lat.shp
Binary file not shown.
Binary file removed test/data/_/long_lat.shx
Binary file not shown.
4 changes: 4 additions & 0 deletions test/proj_transform.test.js
Expand Up @@ -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');
Expand All @@ -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); });
});
*/

});

Expand Down
6 changes: 2 additions & 4 deletions test/projection.test.js
Expand Up @@ -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({}); });
});
Expand Down

0 comments on commit f1bba3a

Please sign in to comment.