From 8ba51a074d733ebde42cd52b1e61aa9b6cff29b1 Mon Sep 17 00:00:00 2001 From: bergwerkgis Date: Thu, 8 Oct 2015 16:57:49 +0000 Subject: [PATCH] expose mapnik::geometry::is_valid --- src/mapnik_geometry.cpp | 18 ++++++++++++++++++ src/mapnik_geometry.hpp | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/mapnik_geometry.cpp b/src/mapnik_geometry.cpp index 0ef2fa6a84..a05283c84a 100644 --- a/src/mapnik_geometry.cpp +++ b/src/mapnik_geometry.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -31,6 +32,7 @@ void Geometry::Initialize(v8::Local target) { lcons->SetClassName(Nan::New("Geometry").ToLocalChecked()); Nan::SetPrototypeMethod(lcons, "extent", extent); + Nan::SetPrototypeMethod(lcons, "isValid", isValid); Nan::SetPrototypeMethod(lcons, "toWKB", toWKB); Nan::SetPrototypeMethod(lcons, "toWKT", toWKT); Nan::SetPrototypeMethod(lcons, "toJSON", toJSON); @@ -309,6 +311,22 @@ NAN_METHOD(Geometry::extent) info.GetReturnValue().Set(a); } +NAN_METHOD(Geometry::isValid) { + info.GetReturnValue().Set(_isValid(info)); +} + +v8::Local Geometry::_isValid(Nan::NAN_METHOD_ARGS_TYPE info) { + Nan::EscapableHandleScope scope; + Geometry* g = Nan::ObjectWrap::Unwrap(info.Holder()); + //std::string message; + if (mapnik::geometry::is_valid(g->feat_->get_geometry())) { + return scope.Escape(Nan::True()); + } + else { + return scope.Escape(Nan::False()); + } +} + /** * Get the geometry's representation as [Well-Known Text](http://en.wikipedia.org/wiki/Well-known_text) * diff --git a/src/mapnik_geometry.hpp b/src/mapnik_geometry.hpp index 37d18ffb5f..8f2e148c8a 100644 --- a/src/mapnik_geometry.hpp +++ b/src/mapnik_geometry.hpp @@ -19,6 +19,8 @@ class Geometry: public Nan::ObjectWrap { static NAN_METHOD(New); static v8::Local NewInstance(mapnik::feature_ptr f); static NAN_METHOD(extent); + static NAN_METHOD(isValid); + static v8::Local _isValid(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(toWKB); static NAN_METHOD(toWKT); static v8::Local _toJSONSync(Nan::NAN_METHOD_ARGS_TYPE info);