All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Geometry.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/geometry/Geometry.cpp
22 
23  \brief Geometry is the root class of the geometries hierarchy, it follows OGC Simple Feature Specification - SFS (Simple Feature Access - Part 1: Common Architecture) and ISO SQL/MM Spatial.
24 */
25 
26 // TerraLib
27 #include "terralib_config.h"
28 #include "../common/Globals.h"
29 #include "../common/Translator.h"
30 #include "../datatype/Enums.h"
31 #include "Envelope.h"
32 #include "Exception.h"
33 #include "Geometry.h"
34 #include "GEOSReader.h"
35 #include "GEOSWriter.h"
36 #include "Utils.h"
37 #include "WKTReader.h"
38 #include "WKTWriter.h"
39 #include "WKBSize.h"
40 #include "WKBWriter.h"
41 
42 // STL
43 #include <cassert>
44 #include <cstring>
45 #include <memory>
46 #include <sstream>
47 
48 #ifdef TERRALIB_GEOS_ENABLED
49 // GEOS
50 #include <geos/geom/Geometry.h>
51 #include <geos/geom/IntersectionMatrix.h>
52 #include <geos/operation/buffer/OffsetCurveBuilder.h>
53 #include <geos/operation/union/CascadedPolygonUnion.h>
54 #include <geos/util/GEOSException.h>
55 #endif
56 
57 std::map<std::string, te::gm::GeomType> te::gm::Geometry::sm_geomTypeMap;
58 
59 te::gm::Geometry::Geometry(GeomType t, int srid, Envelope* mbr) throw()
60  : m_gType(t),
61  m_srid(srid),
62  m_mbr(mbr)
63 {
64 }
65 
67  : m_gType(rhs.m_gType),
68  m_srid(rhs.m_srid),
69  m_mbr(0)
70 {
71 }
72 
74 {
75  delete m_mbr;
76 }
77 
79 {
80  if(this != &rhs)
81  {
82  m_gType = rhs.m_gType;
83 
84  m_srid = rhs.m_srid;
85 
86  delete m_mbr;
87 
88  m_mbr = rhs.m_mbr ? new Envelope(*rhs.m_mbr) : 0;
89  }
90 
91  return *this;
92 }
93 
95 {
96  return GetCoordDimension(m_gType);
97 }
98 
100 {
101  return GetGeomFromEnvelope(getMBR(), m_srid);
102 }
103 
105 {
106  if(m_mbr == 0)
107  computeMBR(true);
108 
109  return m_mbr;
110 }
111 
112 std::string te::gm::Geometry::asText() const throw()
113 {
114  std::stringstream stream(std::ios_base::in | std::ios_base::out);
115 
116  stream.precision(18);
117 
118  WKTWriter::write(this, stream);
119 
120  return stream.str();
121 }
122 
123 char* te::gm::Geometry::asBinary(std::size_t& size) const throw(Exception)
124 {
125  size = WKBSize::size(this);
126 
127  char* wkb = new char[size];
128 
130 
131  return wkb;
132 }
133 
134 std::size_t te::gm::Geometry::getWkbSize() const throw()
135 {
136  return WKBSize::size(this);
137 }
138 
139 void te::gm::Geometry::getWkb(char* wkb, te::common::MachineByteOrder byteOrder) const throw(Exception)
140 {
141  WKBWriter::write(this, wkb, byteOrder);
142 }
143 
144 bool te::gm::Geometry::isEmpty() const throw(std::exception)
145 {
146 #ifdef TERRALIB_GEOS_ENABLED
147  std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(this));
148 
149  return g->isEmpty();
150 
151 #else
152  throw Exception(TE_TR("isEmpty routine is supported by GEOS! Please, enable the GEOS support."));
153 #endif
154 }
155 
156 bool te::gm::Geometry::isSimple() const throw(std::exception)
157 {
158 #ifdef TERRALIB_GEOS_ENABLED
159  std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(this));
160 
161  return g->isSimple();
162 
163 #else
164  throw Exception(TE_TR("isSimple routine is supported by GEOS! Please, enable the GEOS support."));
165 #endif
166 }
167 
168 bool te::gm::Geometry::isValid() const throw(std::exception)
169 {
170 #ifdef TERRALIB_GEOS_ENABLED
171  std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(this));
172 
173  return g->isValid();
174 
175 #else
176  throw Exception(TE_TR("isValid routine is supported by GEOS! Please, enable the GEOS support."));
177 #endif
178 }
179 
180 bool te::gm::Geometry::is3D() const throw()
181 {
182  if((m_gType & 0xF00) == 0xB00) // it is zm
183  return true;
184 
185  if((m_gType & 0x0F00) == 0x300) // it is z
186  return true;
187 
188  return false; // it is 2D or M
189 }
190 
191 bool te::gm::Geometry::isMeasured() const throw()
192 {
193  if((m_gType & 0xF00) == 0xB00) // it is zm
194  return true;
195 
196  if((m_gType & 0xF00) == 0x700) // it is m
197  return true;
198 
199  return false; // it is 2D or z
200 }
201 
202 te::gm::Geometry* te::gm::Geometry::getBoundary() const throw(std::exception)
203 {
204 #ifdef TERRALIB_GEOS_ENABLED
205  std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(this));
206  std::auto_ptr<geos::geom::Geometry> b(g->getBoundary());
207  return GEOSReader::read(b.get());
208 
209 #else
210  throw te::common::Exception(TE_TR("getBoundary routine is supported by GEOS! Please, enable the GEOS support."));
211 #endif
212 }
213 
214 bool te::gm::Geometry::equals(const Geometry* const rhs, const bool exact) const throw(std::exception)
215 {
216 #ifdef TERRALIB_GEOS_ENABLED
217  if( m_srid != rhs->m_srid )
218  {
219  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
220  }
221 
222  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
223 
224  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
225 
226  if(exact == true)
227  return thisGeom->equalsExact(rhsGeom.get());
228  else
229  return thisGeom->equals(rhsGeom.get());
230 #else
231  throw te::common::Exception(TE_TR("equals routine is supported by GEOS! Please, enable the GEOS support."));
232 #endif
233 }
234 
235 bool te::gm::Geometry::disjoint(const Geometry* const rhs) const throw(std::exception)
236 {
237 #ifdef TERRALIB_GEOS_ENABLED
238  if( m_srid != rhs->m_srid )
239  {
240  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
241  }
242 
243  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
244 
245  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
246 
247  return thisGeom->disjoint(rhsGeom.get());
248 
249 #else
250  throw te::common::Exception(TE_TR("disjoint routine is supported by GEOS! Please, enable the GEOS support."));
251 #endif
252 }
253 
254 bool te::gm::Geometry::intersects(const Geometry* const rhs) const throw(std::exception)
255 {
256 #ifdef TERRALIB_GEOS_ENABLED
257  if( m_srid != rhs->m_srid )
258  {
259  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
260  }
261 
262  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
263 
264  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
265 
266  return thisGeom->intersects(rhsGeom.get());
267 
268 #else
269  throw te::common::Exception(TE_TR("intersects routine is supported by GEOS! Please, enable the GEOS support."));
270 #endif
271 }
272 
273 bool te::gm::Geometry::touches(const Geometry* const rhs) const throw(std::exception)
274 {
275 #ifdef TERRALIB_GEOS_ENABLED
276  if( m_srid != rhs->m_srid )
277  {
278  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
279  }
280 
281  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
282 
283  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
284 
285  return thisGeom->touches(rhsGeom.get());
286 
287 #else
288  throw te::common::Exception(TE_TR("touches routine is supported by GEOS! Please, enable the GEOS support."));
289 #endif
290 }
291 
292 bool te::gm::Geometry::crosses(const Geometry* const rhs) const throw(std::exception)
293 {
294 #ifdef TERRALIB_GEOS_ENABLED
295  if( m_srid != rhs->m_srid )
296  {
297  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
298  }
299 
300  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
301 
302  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
303 
304  return thisGeom->crosses(rhsGeom.get());
305 
306 #else
307  throw te::common::Exception(TE_TR("crosses routine is supported by GEOS! Please, enable the GEOS support."));
308 #endif
309 }
310 
311 bool te::gm::Geometry::within(const Geometry* const rhs) const throw(std::exception)
312 {
313 #ifdef TERRALIB_GEOS_ENABLED
314  if( m_srid != rhs->m_srid )
315  {
316  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
317  }
318 
319  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
320 
321  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
322 
323  return thisGeom->within(rhsGeom.get());
324 
325 #else
326  throw te::common::Exception(TE_TR("within routine is supported by GEOS! Please, enable the GEOS support."));
327 #endif
328 }
329 
330 bool te::gm::Geometry::contains(const Geometry* const rhs) const throw(std::exception)
331 {
332 #ifdef TERRALIB_GEOS_ENABLED
333  if( m_srid != rhs->m_srid )
334  {
335  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
336  }
337 
338  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
339 
340  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
341 
342  return thisGeom->contains(rhsGeom.get());
343 
344 #else
345  throw te::common::Exception(TE_TR("contains routine is supported by GEOS! Please, enable the GEOS support."));
346 #endif
347 }
348 
349 bool te::gm::Geometry::overlaps(const Geometry* const rhs) const throw(std::exception)
350 {
351 #ifdef TERRALIB_GEOS_ENABLED
352  if( m_srid != rhs->m_srid )
353  {
354  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
355  }
356 
357  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
358 
359  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
360 
361  return thisGeom->overlaps(rhsGeom.get());
362 
363 #else
364  throw te::common::Exception(TE_TR("overlaps routine is supported by GEOS! Please, enable the GEOS support."));
365 #endif
366 }
367 
368 bool te::gm::Geometry::relate(const Geometry* const rhs, const std::string& matrix) const throw(std::exception)
369 {
370  assert(matrix.size() == 9);
371 
372 #ifdef TERRALIB_GEOS_ENABLED
373  if( m_srid != rhs->m_srid )
374  {
375  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
376  }
377 
378  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
379 
380  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
381 
382  return thisGeom->relate(rhsGeom.get(), matrix);
383 
384 #else
385  throw te::common::Exception(TE_TR("relate routine is supported by GEOS! Please, enable the GEOS support."));
386 #endif
387 }
388 
389 std::string te::gm::Geometry::relate(const Geometry* const rhs) const throw(std::exception)
390 {
391 #ifdef TERRALIB_GEOS_ENABLED
392  if( m_srid != rhs->m_srid )
393  {
394  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
395  }
396 
397  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
398 
399  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
400 
401  std::auto_ptr<geos::geom::IntersectionMatrix> m(thisGeom->relate(rhsGeom.get()));
402 
403  return m->toString();
404 
405 #else
406  throw te::common::Exception(TE_TR("relate routine is supported by GEOS! Please, enable the GEOS support."));
407 #endif
408 }
409 
410 bool te::gm::Geometry::covers(const Geometry* const rhs) const throw(std::exception)
411 {
412 #ifdef TERRALIB_GEOS_ENABLED
413  if( m_srid != rhs->m_srid )
414  {
415  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
416  }
417 
418  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
419 
420  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
421 
422  return thisGeom->covers(rhsGeom.get());
423 
424 #else
425  throw te::common::Exception(TE_TR("covers routine is supported by GEOS! Please, enable the GEOS support."));
426 #endif
427 }
428 
429 bool te::gm::Geometry::coveredBy(const Geometry* const rhs) const throw(std::exception)
430 {
431 #ifdef TERRALIB_GEOS_ENABLED
432  if( m_srid != rhs->m_srid )
433  {
434  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
435  }
436 
437  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
438 
439  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
440 
441  return thisGeom->coveredBy(rhsGeom.get());
442 
443 #else
444  throw te::common::Exception(TE_TR("coveredBy routine is supported by GEOS! Please, enable the GEOS support."));
445 #endif
446 }
447 
448 te::gm::Geometry* te::gm::Geometry::locateBetween(const double& /*mStart*/, const double& /*mEnd*/) const throw(Exception)
449 {
450  return 0;
451 }
452 
453 double te::gm::Geometry::distance(const Geometry* const rhs) const throw(std::exception)
454 {
455 #ifdef TERRALIB_GEOS_ENABLED
456  if( m_srid != rhs->m_srid )
457  {
458  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
459  }
460 
461  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
462 
463  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
464 
465  return thisGeom->distance(rhsGeom.get());
466 
467 #else
468  throw te::common::Exception(TE_TR("distance routine is supported by GEOS! Please, enable the GEOS support."));
469 #endif
470 }
471 
472 te::gm::Geometry* te::gm::Geometry::buffer(const double& distance) const throw(std::exception)
473 {
474 #ifdef TERRALIB_GEOS_ENABLED
475  return buffer(distance, TE_GEOS_DEFAULT_QUADRANT_SEGMENTS, CapRoundType);
476 #else
477  return buffer(distance, 16, CapRoundType);
478 #endif
479 }
480 
481 te::gm::Geometry* te::gm::Geometry::buffer(const double& distance, int quadrantSegments) const throw(std::exception)
482 {
483  return buffer(distance, quadrantSegments, CapRoundType);
484 }
485 
487  int quadrantSegments,
488  BufferCapStyle endCapStyle) const throw(std::exception)
489 {
490 #ifdef TERRALIB_GEOS_ENABLED
491  std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(this));
492 
493  std::auto_ptr<geos::geom::Geometry> bg(g->buffer(distance, quadrantSegments, static_cast<int>(endCapStyle)));
494 
495  bg->setSRID(m_srid);
496 
497  return GEOSReader::read(bg.get());
498 
499 
500 #else
501  throw te::common::Exception(TE_TR("buffer routine is supported by GEOS! Please, enable the GEOS support."));
502 #endif
503 }
504 
505 te::gm::Geometry* te::gm::Geometry::convexHull() const throw(std::exception)
506 {
507 #ifdef TERRALIB_GEOS_ENABLED
508  std::auto_ptr<geos::geom::Geometry> g(GEOSWriter::write(this));
509 
510  std::auto_ptr<geos::geom::Geometry> hull(g->convexHull());
511 
512  hull->setSRID(m_srid);
513 
514  return GEOSReader::read(hull.get());
515 
516 #else
517  throw te::common::Exception(TE_TR("convexHull routine is supported by GEOS! Please, enable the GEOS support."));
518 #endif
519 }
520 
521 te::gm::Geometry* te::gm::Geometry::intersection(const Geometry* const rhs) const throw(std::exception)
522 {
523 #ifdef TERRALIB_GEOS_ENABLED
524  if( m_srid != rhs->m_srid )
525  {
526  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
527  }
528 
529  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
530 
531  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
532 
533  std::auto_ptr<geos::geom::Geometry> intersectionGeom(thisGeom->intersection(rhsGeom.get()));
534 
535  intersectionGeom->setSRID(m_srid);
536 
537  return GEOSReader::read(intersectionGeom.get());
538 
539 #else
540  throw te::common::Exception(TE_TR("intersection routine is supported by GEOS! Please, enable the GEOS support."));
541 #endif
542 }
543 
544 te::gm::Geometry* te::gm::Geometry::Union(const Geometry* const rhs) const throw(std::exception)
545 {
546 #ifdef TERRALIB_GEOS_ENABLED
547  if( m_srid != rhs->m_srid )
548  {
549  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
550  }
551 
552  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
553 
554  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
555 
556  std::auto_ptr<geos::geom::Geometry> unionGeom(thisGeom-> Union(rhsGeom.get()));
557 
558  unionGeom->setSRID(m_srid);
559 
560  return GEOSReader::read(unionGeom.get());
561 
562 #else
563  throw te::common::Exception(TE_TR("Union routine is supported by GEOS! Please, enable the GEOS support."));
564 #endif
565 }
566 
567 te::gm::Geometry* te::gm::Geometry::difference(const Geometry* const rhs) const throw(std::exception)
568 {
569 #ifdef TERRALIB_GEOS_ENABLED
570  if( m_srid != rhs->m_srid )
571  {
572  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
573  }
574 
575  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
576 
577  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
578 
579  std::auto_ptr<geos::geom::Geometry> differenceGeom(thisGeom->difference(rhsGeom.get()));
580 
581  differenceGeom->setSRID(m_srid);
582 
583  return GEOSReader::read(differenceGeom.get());
584 
585 #else
586  throw te::common::Exception(TE_TR("difference routine is supported by GEOS! Please, enable the GEOS support."));
587 #endif
588 }
589 
590 te::gm::Geometry* te::gm::Geometry::symDifference(const Geometry* const rhs) const throw(std::exception)
591 {
592 #ifdef TERRALIB_GEOS_ENABLED
593  if( m_srid != rhs->m_srid )
594  {
595  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
596  }
597 
598  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
599 
600  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
601 
602  std::auto_ptr<geos::geom::Geometry> symDifferenceGeom(thisGeom->symDifference(rhsGeom.get()));
603 
604  symDifferenceGeom->setSRID(m_srid);
605 
606  return GEOSReader::read(symDifferenceGeom.get());
607 #else
608  throw te::common::Exception(TE_TR("symDifference routine is supported by GEOS! Please, enable the GEOS support."));
609 #endif
610 }
611 
612 bool te::gm::Geometry::dWithin(const Geometry* const rhs, const double& distance) const throw(std::exception)
613 {
614  assert(distance >= 0.0);
615 
616 #ifdef TERRALIB_GEOS_ENABLED
617  if( m_srid != rhs->m_srid )
618  {
619  throw te::common::Exception(TE_TR("this method must not be used with different SRIDs geometries."));
620  }
621 
622  std::auto_ptr<geos::geom::Geometry> thisGeom(GEOSWriter::write(this));
623 
624  std::auto_ptr<geos::geom::Geometry> rhsGeom(GEOSWriter::write(rhs));
625 
626  return thisGeom->isWithinDistance(rhsGeom.get(), distance);
627 
628 #else
629  throw te::common::Exception(TE_TR("dWithin routine is supported by GEOS! Please, enable the GEOS support."));
630 #endif
631 }
632 
634 {
635  std::map<std::string, GeomType>::const_iterator it = sm_geomTypeMap.find(gtype);
636 
637  if(it != sm_geomTypeMap.end())
638  return it->second;
639 
641 }
642 
643 bool te::gm::Geometry::isGeomType(const std::string& stype)
644 {
645  return getGeomTypeId(stype) != te::gm::UnknownGeometryType;
646 }
647 
649 {
650  if(!sm_geomTypeMap.empty())
651  return;
652 
653  sm_geomTypeMap["GEOMETRY"] = te::gm::GeometryType;
654  sm_geomTypeMap["GEOMETRYZ"] = te::gm::GeometryZType;
655  sm_geomTypeMap["GEOMETRYM"] = te::gm::GeometryMType;
656  sm_geomTypeMap["GEOMETRYZM"] = te::gm::GeometryZMType;
657 
658  sm_geomTypeMap["POINT"] = te::gm::PointType;
659  sm_geomTypeMap["POINTM"] = te::gm::PointMType;
660  sm_geomTypeMap["POINTZ"] = te::gm::PointZType;
661  sm_geomTypeMap["POINTZM"] = te::gm::PointZMType;
662 
663  sm_geomTypeMap["LINESTRING"] = te::gm::LineStringType;
664  sm_geomTypeMap["LINESTRINGM"] = te::gm::LineStringMType;
665  sm_geomTypeMap["LINESTRINGZ"] = te::gm::LineStringZType;
666  sm_geomTypeMap["LINESTRINGZM"] = te::gm::LineStringZMType;
667 
668  sm_geomTypeMap["POLYGON"] = te::gm::PolygonType;
669  sm_geomTypeMap["POLYGONM"] = te::gm::PolygonMType;
670  sm_geomTypeMap["POLYGONZ"] = te::gm::PolygonZType;
671  sm_geomTypeMap["POLYGONZM"] = te::gm::PolygonZMType;
672 
673  sm_geomTypeMap["MULTIPOINT"] = te::gm::MultiPointType;
674  sm_geomTypeMap["MULTIPOINTM"] = te::gm::MultiPointMType;
675  sm_geomTypeMap["MULTIPOINTZ"] = te::gm::MultiPointZType;
676  sm_geomTypeMap["MULTIPOINTZM"] = te::gm::MultiPointZMType;
677 
678  sm_geomTypeMap["MULTILINESTRING"] = te::gm::MultiLineStringType;
679  sm_geomTypeMap["MULTILINESTRINGM"] = te::gm::MultiLineStringMType;
680  sm_geomTypeMap["MULTILINESTRINGZ"] = te::gm::MultiLineStringZType;
681  sm_geomTypeMap["MULTILINESTRINGZM"] = te::gm::MultiLineStringZMType;
682 
683  sm_geomTypeMap["MULTIPOLYGON"] = te::gm::MultiPolygonType;
684  sm_geomTypeMap["MULTIPOLYGONM"] = te::gm::MultiPolygonMType;
685  sm_geomTypeMap["MULTIPOLYGONZ"] = te::gm::MultiPolygonZType;
686  sm_geomTypeMap["MULTIPOLYGONZM"] = te::gm::MultiPolygonZMType;
687 
688  sm_geomTypeMap["GEOMETRYCOLLECTION"] = te::gm::GeometryCollectionType;
689  sm_geomTypeMap["GEOMETRYCOLLECTIONM"] = te::gm::GeometryCollectionMType;
690  sm_geomTypeMap["GEOMETRYCOLLECTIONZ"] = te::gm::GeometryCollectionZType;
691  sm_geomTypeMap["GEOMETRYCOLLECTIONZM"] = te::gm::GeometryCollectionZMType;
692 }
693 
695 {
696  return te::dt::GEOMETRY_TYPE;
697 }
698 
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
virtual Geometry * buffer(const double &distance) const
This method calculates the buffer of a geometry.
Definition: Geometry.cpp:472
virtual Geometry & operator=(const Geometry &rhs)
Assignment operator.
Definition: Geometry.cpp:78
int getCoordinateDimension() const
It returns the number of measurements or axes needed to describe a position in a coordinate system...
Definition: Geometry.cpp:94
BufferCapStyle
Buffer end cap style.
Definition: Enums.h:157
static void loadGeomTypeId()
It loads the internal MAP of geometry type names to geometry type ids.
Definition: Geometry.cpp:648
virtual bool covers(const Geometry *const rhs) const
It returns true if this geometry object spatially covers the rhs geometry.
Definition: Geometry.cpp:410
virtual bool intersects(const Geometry *const rhs) const
It returns true if the geometry object spatially intersects rhs geometry.
Definition: Geometry.cpp:254
void getWkb(char *wkb, te::common::MachineByteOrder byteOrder) const
It serializes the geometry to a WKB representation into the specified buffer.
Definition: Geometry.cpp:139
bool isMeasured() const
It returns true if this geometric object has m coordinate values.
Definition: Geometry.cpp:191
static const MachineByteOrder sm_machineByteOrder
A flag that indicates the machine byte order (Big Endian or Little Endian).
Definition: Globals.h:54
static std::size_t size(const Geometry *geom)
It calculates the number of bytes required to encode the geometry in a WKB format.
Definition: WKBSize.cpp:51
virtual bool contains(const Geometry *const rhs) const
It returns true if this geometry object spatially contains rhs geometry.
Definition: Geometry.cpp:330
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
virtual Geometry * locateBetween(const double &mStart, const double &mEnd) const
It returns a derived geometry collection value according to the range of coordinate values inclusivel...
Definition: Geometry.cpp:448
std::size_t getWkbSize() const
It returns the size required by a WKB representation for this geometric object.
Definition: Geometry.cpp:134
int GetCoordDimension(GeomType t)
It returns the number of measurements or axes needed to describe a position in a coordinate system...
Definition: Utils.h:58
void write(const Geometry *geom)
It serializes the geometry to a WKB representation into the specified buffer.
Definition: WKBWriter.cpp:149
virtual Geometry * getBoundary() const
It returns the geometry boundary.
Definition: Geometry.cpp:202
virtual bool relate(const Geometry *const rhs, const std::string &matrix) const
It returns true if this geometry object is spatially related to rhs geometry according to the pattern...
Definition: Geometry.cpp:368
A class that serializes a geometry to the WKB format.
virtual bool crosses(const Geometry *const rhs) const
It returns true if the geometry object spatially crosses rhs geometry.
Definition: Geometry.cpp:292
An Envelope defines a 2D rectangular region.
#define TE_GEOS_DEFAULT_QUADRANT_SEGMENTS
Determines the number of default segments used to create buffers.
Definition: Config.h:44
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
int getTypeCode() const
It returns the data type code associated to the data value.
Definition: Geometry.cpp:694
virtual bool disjoint(const Geometry *const rhs) const
It returns true if the geometry object is spatially disjoint from rhs geometry.
Definition: Geometry.cpp:235
void write(const Geometry *geom)
It serializes the geometry to a WKT representation.
Definition: WKTWriter.cpp:56
Geometry * getEnvelope() const
It returns the minimum bounding rectangle (MBR) for the geometry.
Definition: Geometry.cpp:99
char * asBinary(std::size_t &size) const
It serializes the geometric object to a Well-known Binary Representation (WKB).
Definition: Geometry.cpp:123
bool is3D() const
It returns true if this geometric object has z coordinate values.
Definition: Geometry.cpp:180
virtual bool isValid() const
It tells if the geometry is well formed.
Definition: Geometry.cpp:168
Utility functions for the Geometry Module.
MachineByteOrder
Endianness.
Definition: Enums.h:116
virtual ~Geometry()
Virtual destructor.
Definition: Geometry.cpp:73
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
Definition: Geometry.h:178
A class that converts a GEOS geometry to a TerraLib geometry.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
Envelope * m_mbr
The geometry minimum bounding rectangle.
Definition: Geometry.h:866
virtual bool overlaps(const Geometry *const rhs) const
It returns true if this geometry object spatially overlaps rhs geometry.
Definition: Geometry.cpp:349
A class that converts a TerraLib geometry to a GEOS geometry.
virtual bool isEmpty() const
It returns true if this geometric object is the empty Geometry.
Definition: Geometry.cpp:144
An exception class for the Geometry module.
virtual bool touches(const Geometry *const rhs) const
It returns true if the geometry object spatially touches rhs geometry.
Definition: Geometry.cpp:273
Geometry(GeomType t, int srid=-1, Envelope *mbr=0)
It initializes the Geometry with the specified spatial reference system id and envelope.
Definition: Geometry.cpp:59
virtual bool dWithin(const Geometry *const rhs, const double &distance) const
It returns true if the geometries are within the specified distance.
Definition: Geometry.cpp:612
static bool isGeomType(const std::string &stype)
It tells if the given string is a geometry data type.
Definition: Geometry.cpp:643
A class that computes the number of bytes necessary to encode a geometry in WKB.
virtual bool equals(const Geometry *const rhs, const bool exact=false) const
It returns true if the geometry object is spatially equal to rhs geometry.
Definition: Geometry.cpp:214
virtual Geometry * convexHull() const
This method calculates the Convex Hull of a geometry.
Definition: Geometry.cpp:505
virtual bool coveredBy(const Geometry *const rhs) const
It returns true if this geometry object is spatially covered by rhs geometry.
Definition: Geometry.cpp:429
GeomType m_gType
Internal geometry type.
Definition: Geometry.h:864
virtual Geometry * intersection(const Geometry *const rhs) const
It returns a geometric object that represents the point set intersection with another geometry...
Definition: Geometry.cpp:521
virtual Geometry * Union(const Geometry *const rhs) const
It returns a geometric object that represents the point set union with another geometry.
Definition: Geometry.cpp:544
static std::map< std::string, GeomType > sm_geomTypeMap
A set of geometry type names (in UPPER CASE).
Definition: Geometry.h:868
virtual Geometry * symDifference(const Geometry *const rhs) const
It returns a geometric object that represents the point set symetric difference with another geometry...
Definition: Geometry.cpp:590
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
Definition: Geometry.cpp:104
virtual double distance(const Geometry *const rhs) const
It returns the shortest distance between any two points in the two geometry objects.
Definition: Geometry.cpp:453
virtual bool isSimple() const
It returns true if this geometric object has no anomalous points, such as self intersection or self t...
Definition: Geometry.cpp:156
A class that serializes a geometry to the WKT format.
A class that deserializes a geometry from a valid WKT.
std::string asText() const
It returns an string with the Well-Known Text Representation for the geometry.
Definition: Geometry.cpp:112
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
Definition: Utils.cpp:38
virtual Geometry * difference(const Geometry *const rhs) const
It returns a geometric object that represents the point set difference with another geometry...
Definition: Geometry.cpp:567
virtual bool within(const Geometry *const rhs) const
It returns true if the geometry object is spatially within rhs geometry.
Definition: Geometry.cpp:311