4 #include <simo/geom/detail/geometry.hpp> 5 #include <simo/geom/point.hpp> 6 #include <simo/geom/multipoint.hpp> 7 #include <simo/geom/linestring.hpp> 8 #include <simo/geom/multilinestring.hpp> 9 #include <simo/geom/polygon.hpp> 10 #include <simo/geom/multipolygon.hpp> 24 std::cout <<
"DEFAULT CONSTRUCTOR" << std::endl;
30 std::cout <<
"COPY CONSTRUCTOR" << std::endl;
36 case geometry_type::POINT:
38 m_value = geom_value(*other.get_point());
41 case geometry_type::POINTZ:
43 m_value = geom_value(*other.get_point_z());
46 case geometry_type::POINTM:
48 m_value = geom_value(*other.get_point_m());
51 case geometry_type::POINTZM:
53 m_value = geom_value(*other.get_point_zm());
59 case geometry_type::MULTIPOINT:
61 m_value = geom_value(*other.get_multipoint());
64 case geometry_type::MULTIPOINTZ:
66 m_value = geom_value(*other.get_multipoint_z());
69 case geometry_type::MULTIPOINTM:
71 m_value = geom_value(*other.get_multipoint_m());
74 case geometry_type::MULTIPOINTZM:
76 m_value = geom_value(*other.get_multipoint_zm());
82 case geometry_type::LINESTRING:
84 m_value = geom_value(*other.get_linestring());
87 case geometry_type::LINESTRINGZ:
89 m_value = geom_value(*other.get_linestring_z());
92 case geometry_type::LINESTRINGM:
94 m_value = geom_value(*other.get_linestring_m());
97 case geometry_type::LINESTRINGZM:
99 m_value = geom_value(*other.get_linestring_zm());
105 case geometry_type::MULTILINESTRING:
107 m_value = geom_value(*other.get_multilinestring());
110 case geometry_type::MULTILINESTRINGZ:
112 m_value = geom_value(*other.get_multilinestring_z());
115 case geometry_type::MULTILINESTRINGM:
117 m_value = geom_value(*other.get_multilinestring_m());
120 case geometry_type::MULTILINESTRINGZM:
122 m_value = geom_value(*other.get_multilinestring_zm());
128 case geometry_type::POLYGON:
130 m_value = geom_value(*other.get_polygon());
133 case geometry_type::POLYGONZ:
135 m_value = geom_value(*other.get_polygon_z());
138 case geometry_type::POLYGONM:
140 m_value = geom_value(*other.get_polygon_m());
143 case geometry_type::POLYGONZM:
145 m_value = geom_value(*other.get_polygon_zm());
151 case geometry_type::MULTIPOLYGON:
153 m_value = geom_value(*other.get_multipolygon());
156 case geometry_type::MULTIPOLYGONZ:
158 m_value = geom_value(*other.get_multipolygon_z());
161 case geometry_type::MULTIPOLYGONM:
163 m_value = geom_value(*other.get_multipolygon_m());
166 case geometry_type::MULTIPOLYGONZM:
168 m_value = geom_value(*other.get_multipolygon_zm());
176 std::cout <<
"COPY ASSIGNMENT" << std::endl;
186 std::cout <<
"MOVE CONSTRUCTOR" << std::endl;
193 swap(lhs.m_value, rhs.m_value);
194 swap(lhs.m_geom_type, rhs.m_geom_type);
200 : m_value(p), m_geom_type(geometry_type::POINT)
205 : m_value(p), m_geom_type(geometry_type::POINTZ)
210 : m_value(value), m_geom_type(geometry_type::POINTM)
215 : m_value(value), m_geom_type(geometry_type::POINTZM)
222 : m_value(value), m_geom_type(geometry_type::MULTIPOINT)
227 : m_value(value), m_geom_type(geometry_type::MULTIPOINTZ)
232 : m_value(value), m_geom_type(geometry_type::MULTIPOINTM)
237 : m_value(value), m_geom_type(geometry_type::MULTIPOINTZM)
244 : m_value(value), m_geom_type(geometry_type::LINESTRING)
249 : m_value(value), m_geom_type(geometry_type::LINESTRINGZ)
254 : m_value(value), m_geom_type(geometry_type::LINESTRINGM)
259 : m_value(value), m_geom_type(geometry_type::LINESTRINGZM)
266 : m_value(value), m_geom_type(geometry_type::MULTILINESTRING)
271 : m_value(value), m_geom_type(geometry_type::MULTILINESTRINGZ)
276 : m_value(value), m_geom_type(geometry_type::MULTILINESTRINGM)
281 : m_value(value), m_geom_type(geometry_type::MULTILINESTRINGZM)
288 : m_value(value), m_geom_type(geometry_type::POLYGON)
293 : m_value(value), m_geom_type(geometry_type::POLYGONZ)
298 : m_value(value), m_geom_type(geometry_type::POLYGONM)
303 : m_value(value), m_geom_type(geometry_type::POLYGONZM)
310 : m_value(value), m_geom_type(geometry_type::MULTIPOLYGON)
315 : m_value(value), m_geom_type(geometry_type::MULTIPOLYGONZ)
320 : m_value(value), m_geom_type(geometry_type::MULTIPOLYGONM)
325 : m_value(value), m_geom_type(geometry_type::MULTIPOLYGONZM)
335 case geometry_type::POINT:
337 delete m_value.m_point;
338 m_value.m_point =
nullptr;
339 std::cout <<
"DELETE POINT" << std::endl;
342 case geometry_type::POINTZ:
344 delete m_value.m_point_z;
345 m_value.m_point_z =
nullptr;
346 std::cout <<
"DELETE POINT Z" << std::endl;
349 case geometry_type::POINTM:
351 delete m_value.m_point_m;
352 m_value.m_point_m =
nullptr;
353 std::cout <<
"DELETE POINT M" << std::endl;
356 case geometry_type::POINTZM:
358 delete m_value.m_point_zm;
359 m_value.m_point_zm =
nullptr;
360 std::cout <<
"DELETE POINT ZM" << std::endl;
366 case geometry_type::MULTIPOINT:
368 delete m_value.m_multipoint;
369 m_value.m_multipoint =
nullptr;
370 std::cout <<
"DELETE MULTIPOINT" << std::endl;
373 case geometry_type::MULTIPOINTZ:
375 delete m_value.m_multipoint_z;
376 m_value.m_multipoint_z =
nullptr;
377 std::cout <<
"DELETE MULTIPOINT Z" << std::endl;
380 case geometry_type::MULTIPOINTM:
382 delete m_value.m_multipoint_m;
383 m_value.m_multipoint_m =
nullptr;
384 std::cout <<
"DELETE MULTIPOINT M" << std::endl;
387 case geometry_type::MULTIPOINTZM:
389 delete m_value.m_multipoint_zm;
390 m_value.m_multipoint_zm =
nullptr;
391 std::cout <<
"DELETE MULTIPOINT ZM" << std::endl;
397 case geometry_type::LINESTRING:
399 delete m_value.m_linestring;
400 m_value.m_linestring =
nullptr;
401 std::cout <<
"DELETE LINESTRING" << std::endl;
404 case geometry_type::LINESTRINGZ:
406 delete m_value.m_linestring_z;
407 m_value.m_linestring_z =
nullptr;
408 std::cout <<
"DELETE LINESTRING Z" << std::endl;
411 case geometry_type::LINESTRINGM:
413 delete m_value.m_linestring_m;
414 m_value.m_linestring_m =
nullptr;
415 std::cout <<
"DELETE LINESTRING M" << std::endl;
418 case geometry_type::LINESTRINGZM:
420 delete m_value.m_linestring_zm;
421 m_value.m_linestring_zm =
nullptr;
422 std::cout <<
"DELETE LINESTRING ZM" << std::endl;
428 case geometry_type::MULTILINESTRING:
430 delete m_value.m_multilinestring;
431 m_value.m_multilinestring =
nullptr;
432 std::cout <<
"DELETE MULTILINESTRING" << std::endl;
435 case geometry_type::MULTILINESTRINGZ:
437 delete m_value.m_multilinestring_z;
438 m_value.m_multilinestring_z =
nullptr;
439 std::cout <<
"DELETE MULTILINESTRING Z" << std::endl;
442 case geometry_type::MULTILINESTRINGM:
444 delete m_value.m_multilinestring_m;
445 m_value.m_multilinestring_m =
nullptr;
446 std::cout <<
"DELETE MULTILINESTRING M" << std::endl;
449 case geometry_type::MULTILINESTRINGZM:
451 delete m_value.m_multilinestring_zm;
452 m_value.m_multilinestring_zm =
nullptr;
453 std::cout <<
"DELETE MULTILINESTRING ZM" << std::endl;
459 case geometry_type::POLYGON:
461 delete m_value.m_polygon;
462 m_value.m_polygon =
nullptr;
463 std::cout <<
"DELETE POLYGON" << std::endl;
466 case geometry_type::POLYGONZ:
468 delete m_value.m_polygon_z;
469 m_value.m_polygon_z =
nullptr;
470 std::cout <<
"DELETE POLYGON Z" << std::endl;
473 case geometry_type::POLYGONM:
475 delete m_value.m_polygon_m;
476 m_value.m_polygon_m =
nullptr;
477 std::cout <<
"DELETE POLYGON M" << std::endl;
480 case geometry_type::POLYGONZM:
482 delete m_value.m_polygon_zm;
483 m_value.m_polygon_zm =
nullptr;
484 std::cout <<
"DELETE POLYGON ZM" << std::endl;
490 case geometry_type::MULTIPOLYGON:
492 delete m_value.m_multipolygon;
493 m_value.m_multipolygon =
nullptr;
494 std::cout <<
"DELETE MULTIPOLYGON" << std::endl;
497 case geometry_type::MULTIPOLYGONZ:
499 delete m_value.m_multipolygon_z;
500 m_value.m_multipolygon_z =
nullptr;
501 std::cout <<
"DELETE MULTIPOLYGON Z" << std::endl;
504 case geometry_type::MULTIPOLYGONM:
506 delete m_value.m_multipolygon_m;
507 m_value.m_multipolygon_m =
nullptr;
508 std::cout <<
"DELETE MULTIPOLYGON M" << std::endl;
511 case geometry_type::MULTIPOLYGONZM:
513 delete m_value.m_multipolygon_zm;
514 m_value.m_multipolygon_zm =
nullptr;
515 std::cout <<
"DELETE MULTIPOLYGON ZM" << std::endl;
527 template <
typename ReturnType>
534 return reinterpret_cast<ReturnType*
>(get_point());
538 return reinterpret_cast<ReturnType*
>(get_point_z());
542 return reinterpret_cast<ReturnType*
>(get_point_m());
546 return reinterpret_cast<ReturnType*
>(get_point_zm());
553 return reinterpret_cast<ReturnType*
>(get_multipoint());
557 return reinterpret_cast<ReturnType*
>(get_multipoint_z());
561 return reinterpret_cast<ReturnType*
>(get_multipoint_m());
565 return reinterpret_cast<ReturnType*
>(get_multipoint_zm());
572 return reinterpret_cast<ReturnType*
>(get_linestring());
576 return reinterpret_cast<ReturnType*
>(get_linestring_z());
580 return reinterpret_cast<ReturnType*
>(get_linestring_m());
584 return reinterpret_cast<ReturnType*
>(get_linestring_zm());
591 return reinterpret_cast<ReturnType*
>(get_multilinestring());
595 return reinterpret_cast<ReturnType*
>(get_multilinestring_z());
599 return reinterpret_cast<ReturnType*
>(get_multilinestring_m());
603 return reinterpret_cast<ReturnType*
>(get_multilinestring_zm());
610 return reinterpret_cast<ReturnType*
>(get_polygon());
614 return reinterpret_cast<ReturnType*
>(get_polygon_z());
618 return reinterpret_cast<ReturnType*
>(get_polygon_m());
622 return reinterpret_cast<ReturnType*
>(get_polygon_zm());
629 return reinterpret_cast<ReturnType*
>(get_multipolygon());
633 return reinterpret_cast<ReturnType*
>(get_multipolygon_z());
637 return reinterpret_cast<ReturnType*
>(get_multipolygon_m());
641 return reinterpret_cast<ReturnType*
>(get_multipolygon_zm());
649 inline bool is_point()
651 return m_geom_type == geometry_type::POINT;
654 inline bool is_point_z()
656 return m_geom_type == geometry_type::POINTZ;
659 inline bool is_point_m()
661 return m_geom_type == geometry_type::POINTM;
664 inline bool is_point_zm()
666 return m_geom_type == geometry_type::POINTZM;
671 inline bool is_multipoint()
673 return m_geom_type == geometry_type::MULTIPOINT;
676 inline bool is_multipoint_z()
678 return m_geom_type == geometry_type::MULTIPOINTZ;
681 inline bool is_multipoint_m()
683 return m_geom_type == geometry_type::MULTIPOINTM;
686 inline bool is_multipoint_zm()
688 return m_geom_type == geometry_type::MULTIPOINTZM;
693 inline bool is_linestring()
695 return m_geom_type == geometry_type::LINESTRING;
698 inline bool is_linestring_z()
700 return m_geom_type == geometry_type::LINESTRINGZ;
703 inline bool is_linestring_m()
705 return m_geom_type == geometry_type::LINESTRINGM;
708 inline bool is_linestring_zm()
710 return m_geom_type == geometry_type::LINESTRINGZM;
715 inline bool is_multilinestring()
717 return m_geom_type == geometry_type::MULTILINESTRING;
720 inline bool is_multilinestring_z()
722 return m_geom_type == geometry_type::MULTILINESTRINGZ;
725 inline bool is_multilinestring_m()
727 return m_geom_type == geometry_type::MULTILINESTRINGM;
730 inline bool is_multilinestring_zm()
732 return m_geom_type == geometry_type::MULTILINESTRINGZM;
737 inline bool is_polygon()
739 return m_geom_type == geometry_type::POLYGON;
742 inline bool is_polygon_z()
744 return m_geom_type == geometry_type::POLYGONZ;
747 inline bool is_polygon_m()
749 return m_geom_type == geometry_type::POLYGONM;
752 inline bool is_polygon_zm()
754 return m_geom_type == geometry_type::POLYGONZM;
759 inline bool is_multipolygon()
761 return m_geom_type == geometry_type::MULTIPOLYGON;
764 inline bool is_multipolygon_z()
766 return m_geom_type == geometry_type::MULTIPOLYGONZ;
769 inline bool is_multipolygon_m()
771 return m_geom_type == geometry_type::MULTIPOLYGONM;
774 inline bool is_multipolygon_zm()
776 return m_geom_type == geometry_type::MULTIPOLYGONZM;
784 return m_value.m_point;
789 assert(is_point_z());
790 return m_value.m_point_z;
795 assert(is_point_m());
796 return m_value.m_point_m;
801 assert(is_point_zm());
802 return m_value.m_point_zm;
809 assert(is_multipoint());
810 return m_value.m_multipoint;
815 assert(is_multipoint_z());
816 return m_value.m_multipoint_z;
821 assert(is_multipoint_m());
822 return m_value.m_multipoint_m;
827 assert(is_multipoint_zm());
828 return m_value.m_multipoint_zm;
835 assert(is_linestring());
836 return m_value.m_linestring;
841 assert(is_linestring_z());
842 return m_value.m_linestring_z;
847 assert(is_linestring_m());
848 return m_value.m_linestring_m;
853 assert(is_linestring_zm());
854 return m_value.m_linestring_zm;
861 assert(is_multilinestring());
862 return m_value.m_multilinestring;
867 assert(is_multilinestring_z());
868 return m_value.m_multilinestring_z;
873 assert(is_multilinestring_m());
874 return m_value.m_multilinestring_m;
879 assert(is_multilinestring_zm());
880 return m_value.m_multilinestring_zm;
887 assert(is_polygon());
888 return m_value.m_polygon;
893 assert(is_polygon_z());
894 return m_value.m_polygon_z;
899 assert(is_polygon_m());
900 return m_value.m_polygon_m;
905 assert(is_polygon_zm());
906 return m_value.m_polygon_zm;
913 assert(is_multipolygon());
914 return m_value.m_multipolygon;
919 assert(is_multipolygon_z());
920 return m_value.m_multipolygon_z;
925 assert(is_multipolygon_m());
926 return m_value.m_multipolygon_m;
931 assert(is_multipolygon_zm());
932 return m_value.m_multipolygon_zm;
967 geom_value() =
default;
1102 geom_value m_value = {};
1103 geometry_type m_geom_type = geometry_type::GEOMETRY;
1106 geometry_type geom_type_() const noexcept
1112 std::string tagged_text_() const noexcept
1118 dimension_type dim_() const noexcept
1120 return dimension_type::XY;
1124 int32_t ndim_() const noexcept
1130 bool is_closed_() const noexcept
1136 void throw_for_invalid_()
const 1148 bool has_z_() const noexcept
1154 bool has_m_() const noexcept
1169 std::string json_(std::int32_t precision = -1)
const 1171 switch (m_geom_type)
1174 case geometry_type::POINT:
1176 return m_value.m_point->json(precision);
1178 case geometry_type::POINTZ:
1180 return m_value.m_point_z->json(precision);
1182 case geometry_type::POINTM:
1184 return m_value.m_point_m->json(precision);
1186 case geometry_type::POINTZM:
1188 return m_value.m_point_zm->json(precision);
1192 case geometry_type::MULTIPOINT:
1194 return m_value.m_multipoint->json(precision);
1196 case geometry_type::MULTIPOINTZ:
1198 return m_value.m_multipoint_z->json(precision);
1200 case geometry_type::MULTIPOINTM:
1202 return m_value.m_multipoint_m->json(precision);
1204 case geometry_type::MULTIPOINTZM:
1206 return m_value.m_multipoint_zm->json(precision);
1210 case geometry_type::LINESTRING:
1212 return m_value.m_linestring->json(precision);
1214 case geometry_type::LINESTRINGZ:
1216 return m_value.m_linestring_z->json(precision);
1218 case geometry_type::LINESTRINGM:
1220 return m_value.m_linestring_m->json(precision);
1222 case geometry_type::LINESTRINGZM:
1224 return m_value.m_linestring_zm->json(precision);
1228 case geometry_type::MULTILINESTRING:
1230 return m_value.m_multilinestring->json(precision);
1232 case geometry_type::MULTILINESTRINGZ:
1234 return m_value.m_multilinestring_z->json(precision);
1236 case geometry_type::MULTILINESTRINGM:
1238 return m_value.m_multilinestring_m->json(precision);
1240 case geometry_type::MULTILINESTRINGZM:
1242 return m_value.m_multilinestring_zm->json(precision);
1246 case geometry_type::POLYGON:
1248 return m_value.m_polygon->json(precision);
1250 case geometry_type::POLYGONZ:
1252 return m_value.m_polygon_z->json(precision);
1254 case geometry_type::POLYGONM:
1256 return m_value.m_polygon_m->json(precision);
1258 case geometry_type::POLYGONZM:
1260 return m_value.m_polygon_zm->json(precision);
1264 case geometry_type::MULTIPOLYGON:
1266 return m_value.m_multipolygon->json(precision);
1268 case geometry_type::MULTIPOLYGONZ:
1270 return m_value.m_multipolygon_z->json(precision);
1272 case geometry_type::MULTIPOLYGONM:
1274 return m_value.m_multipolygon_m->json(precision);
1276 case geometry_type::MULTIPOLYGONZM:
1278 return m_value.m_multipolygon_zm->json(precision);
1293 auto result = reader.
read(wkt);
1294 auto data = result.
data;
1295 switch (data.geom_type)
1297 case geometry_type::POINT:
1299 case geometry_type::POINTZ:
1301 case geometry_type::POINTM:
1303 case geometry_type::POINTZM:
1319 std::string wkt_(std::int32_t precision = -1)
const 1321 switch (m_geom_type)
1324 case geometry_type::POINT:
1326 return m_value.m_point->wkt(precision);
1328 case geometry_type::POINTZ:
1330 return m_value.m_point_z->wkt(precision);
1332 case geometry_type::POINTM:
1334 return m_value.m_point_m->wkt(precision);
1336 case geometry_type::POINTZM:
1338 return m_value.m_point_zm->wkt(precision);
1342 case geometry_type::MULTIPOINT:
1344 return m_value.m_multipoint->wkt(precision);
1346 case geometry_type::MULTIPOINTZ:
1348 return m_value.m_multipoint_z->wkt(precision);
1350 case geometry_type::MULTIPOINTM:
1352 return m_value.m_multipoint_m->wkt(precision);
1354 case geometry_type::MULTIPOINTZM:
1356 return m_value.m_multipoint_zm->wkt(precision);
1360 case geometry_type::LINESTRING:
1362 return m_value.m_linestring->wkt(precision);
1364 case geometry_type::LINESTRINGZ:
1366 return m_value.m_linestring_z->wkt(precision);
1368 case geometry_type::LINESTRINGM:
1370 return m_value.m_linestring_m->wkt(precision);
1372 case geometry_type::LINESTRINGZM:
1374 return m_value.m_linestring_zm->wkt(precision);
1378 case geometry_type::MULTILINESTRING:
1380 return m_value.m_multilinestring->wkt(precision);
1382 case geometry_type::MULTILINESTRINGZ:
1384 return m_value.m_multilinestring_z->wkt(precision);
1386 case geometry_type::MULTILINESTRINGM:
1388 return m_value.m_multilinestring_m->wkt(precision);
1390 case geometry_type::MULTILINESTRINGZM:
1392 return m_value.m_multilinestring_zm->wkt(precision);
1396 case geometry_type::POLYGON:
1398 return m_value.m_polygon->wkt(precision);
1400 case geometry_type::POLYGONZ:
1402 return m_value.m_polygon_z->wkt(precision);
1404 case geometry_type::POLYGONM:
1406 return m_value.m_polygon_m->wkt(precision);
1408 case geometry_type::POLYGONZM:
1410 return m_value.m_polygon_zm->wkt(precision);
1414 case geometry_type::MULTIPOLYGON:
1416 return m_value.m_multipolygon->wkt(precision);
1418 case geometry_type::MULTIPOLYGONZ:
1420 return m_value.m_multipolygon_z->wkt(precision);
1422 case geometry_type::MULTIPOLYGONM:
1424 return m_value.m_multipolygon_m->wkt(precision);
1426 case geometry_type::MULTIPOLYGONZM:
1428 return m_value.m_multipolygon_zm->wkt(precision);
geometry_type geom_type() const noexcept
Returns the geometry type.
Base class for all geometries.
wkt_data data
the parser result data
wkt_result read(const std::string &wkt)
parse the given wkt string
Represents an axis-aligned bounding box.
Exception thrown when an error has been found while parsing.
std::string wkt(std::int32_t precision=-1) const
Dumps the wkt representation of the geometry.