27 #include "../../../../geometry/Coord2D.h" 28 #include "../../../../geometry/LineString.h" 29 #include "../../../../geometry/Point.h" 30 #include "../../common/Utils.h" 37 if(args.Holder().IsEmpty())
38 return ::v8::ThrowException(::v8::String::New(
"In order to use setNumCoordinates method you must use object notation: \"line.setNumCoordinates(10);\""));
43 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setNumCoordinates method!"));
45 if(args.Length() != 1 || args[0].IsEmpty() || !args[0]->IsInt32())
46 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for setNumCoordinates!"));
48 int n = args[0]->ToInt32()->Value();
52 return hs.Close(::v8::Undefined());
59 if(args.Holder().IsEmpty())
60 return ::v8::ThrowException(::v8::String::New(
"In order to use makeEmpty method you must use object notation: \"line.makeEmpty();\""));
65 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setNumCoordinates method!"));
69 return hs.Close(::v8::Undefined());
76 if(args.Holder().IsEmpty())
77 return ::v8::ThrowException(::v8::String::New(
"In order to use getPointN method you must use object notation: \"pt = line.getPointN(3);\""));
82 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getPointN method!"));
84 if(args.Length() != 1 || args[0].IsEmpty() || !args[0]->IsInt32())
85 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for getPointN!"));
87 int i = args[0]->ToInt32()->Value();
89 std::auto_ptr<te::gm::Point> pt(g->
getPointN(i));
95 return hs.Close(jsgeom);
100 ::v8::HandleScope hs;
102 if(args.Holder().IsEmpty())
103 return ::v8::ThrowException(::v8::String::New(
"In order to use setPointN method you must use object notation: \"line.setPointN(i, pt);\""));
108 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setPointN method!"));
110 if(args.Length() != 2 || args[0].IsEmpty() || !args[0]->IsInt32() || args[1].IsEmpty() || !args[1]->IsObject())
111 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for setPointN!"));
113 int i = args[0]->ToInt32()->Value();
115 te::gm::Point* pt = te::v8::common::Unwrap<te::gm::Point>(args[1]->ToObject());
119 return hs.Close(::v8::Undefined());
124 ::v8::HandleScope hs;
126 if(args.Holder().IsEmpty())
127 return ::v8::ThrowException(::v8::String::New(
"In order to use setPoint method you must use object notation: \"line.setPoint(i, x, y);\""));
132 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setPoint method!"));
134 if(args.Length() != 3 ||
135 args[0].IsEmpty() || !args[0]->IsInt32() ||
136 args[1].IsEmpty() || !args[1]->IsNumber() ||
137 args[2].IsEmpty() || !args[2]->IsNumber())
138 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for setPoint!"));
140 int i = args[0]->ToInt32()->Value();
141 double x = args[1]->ToNumber()->Value();
142 double y = args[2]->ToNumber()->Value();
146 return hs.Close(::v8::Undefined());
151 ::v8::HandleScope hs;
153 if(args.Holder().IsEmpty())
154 return ::v8::ThrowException(::v8::String::New(
"In order to use setPointZ method you must use object notation: \"line.setPointZ(i, x, y, z);\""));
159 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setPointZ method!"));
161 if(args.Length() != 4 ||
162 args[0].IsEmpty() || !args[0]->IsInt32() ||
163 args[1].IsEmpty() || !args[1]->IsNumber() ||
164 args[2].IsEmpty() || !args[2]->IsNumber() ||
165 args[3].IsEmpty() || !args[3]->IsNumber())
166 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for setPointZ!"));
168 int i = args[0]->ToInt32()->Value();
169 double x = args[1]->ToNumber()->Value();
170 double y = args[2]->ToNumber()->Value();
171 double z = args[3]->ToNumber()->Value();
175 return hs.Close(::v8::Undefined());
180 ::v8::HandleScope hs;
182 if(args.Holder().IsEmpty())
183 return ::v8::ThrowException(::v8::String::New(
"In order to use setPointM method you must use object notation: \"line.setPointM(i, x, y, m);\""));
188 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setPointM method!"));
190 if(args.Length() != 4 ||
191 args[0].IsEmpty() || !args[0]->IsInt32() ||
192 args[1].IsEmpty() || !args[1]->IsNumber() ||
193 args[2].IsEmpty() || !args[2]->IsNumber() ||
194 args[3].IsEmpty() || !args[3]->IsNumber())
195 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for setPointM!"));
197 int i = args[0]->ToInt32()->Value();
198 double x = args[1]->ToNumber()->Value();
199 double y = args[2]->ToNumber()->Value();
200 double m = args[3]->ToNumber()->Value();
204 return hs.Close(::v8::Undefined());
209 ::v8::HandleScope hs;
211 if(args.Holder().IsEmpty())
212 return ::v8::ThrowException(::v8::String::New(
"In order to use setPointZM method you must use object notation: \"line.setPointZM(i, x, y, z, m);\""));
217 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setPointZM method!"));
219 if(args.Length() != 4 ||
220 args[0].IsEmpty() || !args[0]->IsInt32() ||
221 args[1].IsEmpty() || !args[1]->IsNumber() ||
222 args[2].IsEmpty() || !args[2]->IsNumber() ||
223 args[3].IsEmpty() || !args[3]->IsNumber() ||
224 args[4].IsEmpty() || !args[4]->IsNumber())
225 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for setPointZM!"));
227 int i = args[0]->ToInt32()->Value();
228 double x = args[1]->ToNumber()->Value();
229 double y = args[2]->ToNumber()->Value();
230 double z = args[3]->ToNumber()->Value();
231 double m = args[4]->ToNumber()->Value();
235 return hs.Close(::v8::Undefined());
240 ::v8::HandleScope hs;
242 if(args.Holder().IsEmpty())
243 return ::v8::ThrowException(::v8::String::New(
"In order to use getX method you must use object notation: \"x = line.getX(i);\""));
248 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getX method!"));
250 if(args.Length() != 1 || args[0].IsEmpty() || !args[0]->IsInt32())
251 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for getX!"));
253 int i = args[0]->ToInt32()->Value();
255 double x = g->
getX(i);
257 ::v8::Handle<::v8::Number> jx = ::v8::Number::New(x);
264 ::v8::HandleScope hs;
266 if(args.Holder().IsEmpty())
267 return ::v8::ThrowException(::v8::String::New(
"In order to use getY method you must use object notation: \"y = line.getY(i);\""));
272 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getY method!"));
274 if(args.Length() != 1 || args[0].IsEmpty() || !args[0]->IsInt32())
275 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for getY!"));
277 int i = args[0]->ToInt32()->Value();
279 double y = g->
getY(i);
281 ::v8::Handle<::v8::Number> jy = ::v8::Number::New(y);
288 ::v8::HandleScope hs;
290 if(args.Holder().IsEmpty())
291 return ::v8::ThrowException(::v8::String::New(
"In order to use getZ method you must use object notation: \"z = line.getZ(i);\""));
296 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getZ method!"));
298 if(args.Length() != 1 || args[0].IsEmpty() || !args[0]->IsInt32())
299 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for getZ!"));
301 int i = args[0]->ToInt32()->Value();
303 double z = g->
getZ(i);
305 ::v8::Handle<::v8::Number> jz = ::v8::Number::New(z);
312 ::v8::HandleScope hs;
314 if(args.Holder().IsEmpty())
315 return ::v8::ThrowException(::v8::String::New(
"In order to use getM method you must use object notation: \"m = line.getM(i);\""));
320 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getM method!"));
322 if(args.Length() != 1 || args[0].IsEmpty() || !args[0]->IsInt32())
323 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for getM!"));
325 int i = args[0]->ToInt32()->Value();
327 double m = g->
getM(i);
329 ::v8::Handle<::v8::Number> jm = ::v8::Number::New(m);
336 ::v8::HandleScope hs;
338 if(args.Holder().IsEmpty())
339 return ::v8::ThrowException(::v8::String::New(
"In order to use setX method you must use object notation: \"line.setX(i, x);\""));
344 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setX method!"));
346 if(args.Length() != 2 || args[0].IsEmpty() || !args[0]->IsInt32() || args[1].IsEmpty() || !args[1]->IsNumber())
347 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for setX!"));
349 int i = args[0]->ToInt32()->Value();
350 double x = args[1]->ToNumber()->Value();
354 return hs.Close(::v8::Undefined());
359 ::v8::HandleScope hs;
361 if(args.Holder().IsEmpty())
362 return ::v8::ThrowException(::v8::String::New(
"In order to use setY method you must use object notation: \"line.setY(i, y);\""));
367 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setY method!"));
369 if(args.Length() != 2 || args[0].IsEmpty() || !args[0]->IsInt32() || args[1].IsEmpty() || !args[1]->IsNumber())
370 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for setY!"));
372 int i = args[0]->ToInt32()->Value();
373 double y = args[1]->ToNumber()->Value();
377 return hs.Close(::v8::Undefined());
382 ::v8::HandleScope hs;
384 if(args.Holder().IsEmpty())
385 return ::v8::ThrowException(::v8::String::New(
"In order to use setZ method you must use object notation: \"line.setZ(i, z);\""));
390 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setZ method!"));
392 if(args.Length() != 2 || args[0].IsEmpty() || !args[0]->IsInt32() || args[1].IsEmpty() || !args[1]->IsNumber())
393 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for setZ!"));
395 int i = args[0]->ToInt32()->Value();
396 double z = args[1]->ToNumber()->Value();
400 return hs.Close(::v8::Undefined());
405 ::v8::HandleScope hs;
407 if(args.Holder().IsEmpty())
408 return ::v8::ThrowException(::v8::String::New(
"In order to use setM method you must use object notation: \"line.setM(i, m);\""));
413 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setM method!"));
415 if(args.Length() != 2 || args[0].IsEmpty() || !args[0]->IsInt32() || args[1].IsEmpty() || !args[1]->IsNumber())
416 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for setM!"));
418 int i = args[0]->ToInt32()->Value();
419 double m = args[1]->ToNumber()->Value();
423 return hs.Close(::v8::Undefined());
428 ::v8::HandleScope hs;
430 if(args.Holder().IsEmpty())
431 return ::v8::ThrowException(::v8::String::New(
"In order to use getCoordinates method you must use object notation: \"cs = line.getCoordinates();\""));
436 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getCoordinates method!"));
442 ::v8::Handle<::v8::Array> jcs = ::v8::Array::New(len);
444 for(
int i = 0; i < len; ++i)
447 return hs.Close(jcs);
452 ::v8::HandleScope hs;
454 if(args.Holder().IsEmpty())
455 return ::v8::ThrowException(::v8::String::New(
"In order to use getZCoords method you must use object notation: \"zs = line.getZCoords();\""));
460 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getZCoords method!"));
462 double* zs = g->
getZ();
466 ::v8::Handle<::v8::Array> jzs = ::v8::Array::New(len);
468 for(
int i = 0; i < len; ++i)
469 jzs->Set(i, ::v8::Number::New(zs[i]));
471 return hs.Close(jzs);
476 ::v8::HandleScope hs;
478 if(args.Holder().IsEmpty())
479 return ::v8::ThrowException(::v8::String::New(
"In order to use getMCoords method you must use object notation: \"ms = line.getMCoords();\""));
484 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getMCoords method!"));
486 double* ms = g->
getM();
490 ::v8::Handle<::v8::Array> jms = ::v8::Array::New(len);
492 for(
int i = 0; i < len; ++i)
493 jms->Set(i, ::v8::Number::New(ms[i]));
495 return hs.Close(jms);
500 ::v8::HandleScope hs;
502 if(!args.IsConstructCall())
503 return ::v8::ThrowException(::v8::String::New(
"In order to create a LineString you need to call its constructor like: var mygc = new TeLineString(3, TE_OGC_LINESTRING, 4326)."));
505 if(args.Holder().IsEmpty())
506 return ::v8::ThrowException(::v8::String::New(
"LineString constructor must use object notation!"));
508 if((args.Length() != 3) ||
509 args[0].IsEmpty() || !args[0]->IsInt32() ||
510 args[1].IsEmpty() || !args[1]->IsInt32() ||
511 args[2].IsEmpty() || !args[2]->IsInt32())
512 return ::v8::ThrowException(::v8::String::New(
"Missing parameter or wrong parameter type in LineString constructor method!!"));
515 int npts = args[0]->Int32Value();
516 int geomType = args[1]->Int32Value();
517 int srid = args[2]->ToInt32()->Int32Value();
519 std::auto_ptr<te::gm::LineString> g(
new te::gm::LineString(npts, static_cast<te::gm::GeomType>(geomType), srid));
530 ::v8::HandleScope hs;
534 global->Set(::v8::String::New(
"TeLineString"), jsgc->GetFunction());
544 ::v8::Local<::v8::FunctionTemplate> result = ::v8::FunctionTemplate::New();
545 result->Inherit(curveTpl);
547 ::v8::Handle<::v8::ObjectTemplate> prototype = result->PrototypeTemplate();
550 prototype->Set(::v8::String::NewSymbol(
"makeEmpty"), ::v8::FunctionTemplate::New(
LineString_MakeEmpty));
551 prototype->Set(::v8::String::NewSymbol(
"getPointN"), ::v8::FunctionTemplate::New(
LineString_GetPointN));
552 prototype->Set(::v8::String::NewSymbol(
"setPointN"), ::v8::FunctionTemplate::New(
LineString_SetPointN));
553 prototype->Set(::v8::String::NewSymbol(
"setPoint"), ::v8::FunctionTemplate::New(
LineString_SetPoint));
554 prototype->Set(::v8::String::NewSymbol(
"setPointZ"), ::v8::FunctionTemplate::New(
LineString_SetPointZ));
555 prototype->Set(::v8::String::NewSymbol(
"setPointM"), ::v8::FunctionTemplate::New(
LineString_SetPointM));
556 prototype->Set(::v8::String::NewSymbol(
"setPointZM"), ::v8::FunctionTemplate::New(
LineString_SetPointZM));
557 prototype->Set(::v8::String::NewSymbol(
"getX"), ::v8::FunctionTemplate::New(
LineString_GetX));
558 prototype->Set(::v8::String::NewSymbol(
"getY"), ::v8::FunctionTemplate::New(
LineString_GetY));
559 prototype->Set(::v8::String::NewSymbol(
"getZ"), ::v8::FunctionTemplate::New(
LineString_GetZ));
560 prototype->Set(::v8::String::NewSymbol(
"getM"), ::v8::FunctionTemplate::New(
LineString_GetM));
561 prototype->Set(::v8::String::NewSymbol(
"setX"), ::v8::FunctionTemplate::New(
LineString_SetX));
562 prototype->Set(::v8::String::NewSymbol(
"setY"), ::v8::FunctionTemplate::New(
LineString_SetY));
563 prototype->Set(::v8::String::NewSymbol(
"setZ"), ::v8::FunctionTemplate::New(
LineString_SetZ));
564 prototype->Set(::v8::String::NewSymbol(
"setM"), ::v8::FunctionTemplate::New(
LineString_SetM));
566 prototype->Set(::v8::String::NewSymbol(
"getZCoords"), ::v8::FunctionTemplate::New(
LineString_GetZCoords));
567 prototype->Set(::v8::String::NewSymbol(
"getMCoords"), ::v8::FunctionTemplate::New(
LineString_GetMCoords));
void setZ(std::size_t i, const double &z)
It sets the n-th z coordinate value.
::v8::Local<::v8::Object > Make(T *obj, TF tfunc, const bool isOwner)
It creates a new JavaScript object from a C++ object (obj).
::v8::Handle<::v8::Value > LineString_SetX(const ::v8::Arguments &args)
::v8::Persistent<::v8::FunctionTemplate > & GetPointTemplate()
It returns a reference to the persistent template of a Point object.
::v8::Handle<::v8::Value > LineString_SetPoint(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > LineString_SetNumCoordinates(const ::v8::Arguments &args)
void setX(std::size_t i, const double &x)
It sets the n-th x coordinate value.
::v8::Handle<::v8::Value > LineString_SetPointZM(const ::v8::Arguments &args)
Coord2D * getCoordinates() const
It returns a pointer to the internal array of coordinates.
::v8::Handle<::v8::Value > LineString_GetZ(const ::v8::Arguments &args)
void makeEmpty()
It clears all the coordinates.
::v8::Handle<::v8::Value > LineString_GetY(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > LineString_SetPointM(const ::v8::Arguments &args)
std::unique_ptr< Point > getPointN(std::size_t i) const
It returns the specified point in this LineString.
::v8::Persistent<::v8::FunctionTemplate > & GetCoord2DTemplate()
It returns a reference to the persistent template of a Coord2D object.
An utility struct for representing 2D coordinates.
::v8::Handle<::v8::Value > LineString_SetZ(const ::v8::Arguments &args)
::v8::Persistent<::v8::FunctionTemplate > & GetLineStringTemplate()
It returns a reference to the persistent template of a LineString object.
const double & getY(std::size_t i) const
It returns the n-th y coordinate value.
::v8::Handle<::v8::Value > LineString_SetY(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > LineString_GetX(const ::v8::Arguments &args)
LineString is a curve with linear interpolation between points.
A point with x and y coordinate values.
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
const double & getX(std::size_t i) const
It returns the n-th x coordinate value.
::v8::Handle<::v8::Value > LineString_SetM(const ::v8::Arguments &args)
void setNumCoordinates(std::size_t size)
It reserves room for the number of coordinates in this LineString.
::v8::Handle<::v8::Value > LineString_SetPointZ(const ::v8::Arguments &args)
std::size_t getNPoints() const
It returns the number of points (vertexes) in the linestring.
void setPointZ(std::size_t i, const double &x, const double &y, const double &z)
It sets the value of the specified point.
::v8::Handle<::v8::Value > LineString_Constructor(const ::v8::Arguments &args)
void setM(std::size_t i, const double &m)
It sets the n-th m measure value.
::v8::Handle<::v8::Value > LineString_MakeEmpty(const ::v8::Arguments &args)
void setPointZM(std::size_t i, const double &x, const double &y, const double &z, const double &m)
It sets the value of the specified point.
void RegisterLineString(::v8::Local<::v8::Object > &global)
It register the LineString class.
::v8::Handle<::v8::Value > LineString_GetPointN(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > LineString_SetPointN(const ::v8::Arguments &args)
::v8::Persistent<::v8::FunctionTemplate > & GetCurveTemplate()
It returns a reference to the persistent template of a Curve object.
::v8::Handle<::v8::Value > LineString_GetCoordinates(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > LineString_GetZCoords(const ::v8::Arguments &args)
const double & getZ(std::size_t i) const
It returns the n-th z coordinate value.
void setPointM(std::size_t i, const double &x, const double &y, const double &m)
It sets the value of the specified point.
const double & getM(std::size_t i) const
It returns the n-th m measure value.
void setPointN(std::size_t i, const Point &p)
It sets the value of the specified point to this new one.
void setY(std::size_t i, const double &y)
It sets the n-th y coordinate value.
::v8::Handle<::v8::Value > LineString_GetMCoords(const ::v8::Arguments &args)
static::v8::Persistent<::v8::FunctionTemplate > sg_line_template
::v8::Handle<::v8::Value > LineString_GetM(const ::v8::Arguments &args)