Changeset View
Changeset View
Standalone View
Standalone View
tools/vectorosm-tilecreator/VectorClipper.h
Show All 11 Lines | |||||
12 | #ifndef TINYPLANETPROCESSOR_H | 12 | #ifndef TINYPLANETPROCESSOR_H | ||
13 | #define TINYPLANETPROCESSOR_H | 13 | #define TINYPLANETPROCESSOR_H | ||
14 | 14 | | |||
15 | #include "OsmPlacemarkData.h" | 15 | #include "OsmPlacemarkData.h" | ||
16 | 16 | | |||
17 | #include <GeoDataLatLonBox.h> | 17 | #include <GeoDataLatLonBox.h> | ||
18 | #include "GeoDataPlacemark.h" | 18 | #include "GeoDataPlacemark.h" | ||
19 | #include "GeoDataLinearRing.h" | 19 | #include "GeoDataLinearRing.h" | ||
20 | #include "GeoDataBuilding.h" | ||||
21 | #include "GeoDataMultiGeometry.h" | ||||
20 | #include <TileId.h> | 22 | #include <TileId.h> | ||
21 | #include <GeoSceneMercatorTileProjection.h> | 23 | #include <GeoSceneMercatorTileProjection.h> | ||
22 | #include <OsmObjectManager.h> | 24 | #include <OsmObjectManager.h> | ||
23 | #include "GeoDataDocument.h" | 25 | #include "GeoDataDocument.h" | ||
24 | 26 | | |||
25 | #include "clipper/clipper.hpp" | 27 | #include "clipper/clipper.hpp" | ||
26 | #include <QMap> | 28 | #include <QMap> | ||
27 | #include <QSet> | 29 | #include <QSet> | ||
Show All 17 Lines | 44 | private: | |||
45 | ClipperLib::Path clipPath(const GeoDataLatLonBox &box, int zoomLevel) const; | 47 | ClipperLib::Path clipPath(const GeoDataLatLonBox &box, int zoomLevel) const; | ||
46 | qreal area(const GeoDataLinearRing &ring); | 48 | qreal area(const GeoDataLinearRing &ring); | ||
47 | void getBounds(const ClipperLib::Path &path, ClipperLib::cInt &minX, ClipperLib::cInt &maxX, ClipperLib::cInt &minY, ClipperLib::cInt &maxY) const; | 49 | void getBounds(const ClipperLib::Path &path, ClipperLib::cInt &minX, ClipperLib::cInt &maxX, ClipperLib::cInt &minY, ClipperLib::cInt &maxY) const; | ||
48 | 50 | | |||
49 | template<class T> | 51 | template<class T> | ||
50 | void clipString(const GeoDataPlacemark *placemark, const ClipperLib::Path &tileBoundary, qreal minArea, | 52 | void clipString(const GeoDataPlacemark *placemark, const ClipperLib::Path &tileBoundary, qreal minArea, | ||
51 | GeoDataDocument* document, QSet<qint64> &osmIds) | 53 | GeoDataDocument* document, QSet<qint64> &osmIds) | ||
52 | { | 54 | { | ||
53 | const T* ring = static_cast<const T*>(placemark->geometry()); | 55 | bool isBuilding = false; | ||
56 | T* ring; | ||||
57 | if (const auto building = geodata_cast<GeoDataBuilding>(placemark->geometry())) { | ||||
58 | ring = geodata_cast<T>(&building->multiGeometry()->at(0)); | ||||
59 | isBuilding = true; | ||||
60 | } else { | ||||
61 | GeoDataPlacemark* copyPlacemark = new GeoDataPlacemark(*placemark); | ||||
62 | ring = geodata_cast<T>(copyPlacemark->geometry()); | ||||
63 | } | ||||
54 | bool const isClosed = ring->isClosed() && canBeArea(placemark->visualCategory()); | 64 | bool const isClosed = ring->isClosed() && canBeArea(placemark->visualCategory()); | ||
55 | if (isClosed && minArea > 0.0 && area(*static_cast<const GeoDataLinearRing*>(ring)) < minArea) { | 65 | if (isClosed && minArea > 0.0 && area(*static_cast<const GeoDataLinearRing*>(ring)) < minArea) { | ||
56 | return; | 66 | return; | ||
57 | } | 67 | } | ||
58 | auto const & osmData = placemark->osmData(); | 68 | auto const & osmData = placemark->osmData(); | ||
59 | using namespace ClipperLib; | 69 | using namespace ClipperLib; | ||
60 | Path subject; | 70 | Path subject; | ||
61 | for(auto const & node: *ring) { | 71 | for(auto const & node: *ring) { | ||
Show All 25 Lines | 95 | for(const auto &point: path) { | |||
87 | *newRing << coordinates; | 97 | *newRing << coordinates; | ||
88 | auto const originalOsmData = osmData.nodeReference(coordinates); | 98 | auto const originalOsmData = osmData.nodeReference(coordinates); | ||
89 | if (originalOsmData.id() > 0) { | 99 | if (originalOsmData.id() > 0) { | ||
90 | newPlacemark->osmData().addNodeReference(coordinates, originalOsmData); | 100 | newPlacemark->osmData().addNodeReference(coordinates, originalOsmData); | ||
91 | } | 101 | } | ||
92 | ++index; | 102 | ++index; | ||
93 | } | 103 | } | ||
94 | 104 | | |||
105 | if (isBuilding) { | ||||
106 | const auto building = geodata_cast<GeoDataBuilding>(placemark->geometry()); | ||||
107 | GeoDataBuilding* newBuilding = new GeoDataBuilding(*building); | ||||
108 | newBuilding->multiGeometry()->clear(); | ||||
109 | newBuilding->multiGeometry()->append(newRing); | ||||
110 | newPlacemark->setGeometry(newBuilding); | ||||
111 | } else { | ||||
95 | newPlacemark->setGeometry(newRing); | 112 | newPlacemark->setGeometry(newRing); | ||
113 | } | ||||
96 | if (placemark->osmData().id() > 0) { | 114 | if (placemark->osmData().id() > 0) { | ||
97 | newPlacemark->osmData().addTag(QStringLiteral("mx:oid"), QString::number(placemark->osmData().id())); | 115 | newPlacemark->osmData().addTag(QStringLiteral("mx:oid"), QString::number(placemark->osmData().id())); | ||
98 | } | 116 | } | ||
99 | copyTags(*placemark, *newPlacemark); | 117 | copyTags(*placemark, *newPlacemark); | ||
100 | OsmObjectManager::initializeOsmData(newPlacemark); | 118 | OsmObjectManager::initializeOsmData(newPlacemark); | ||
101 | document->append(newPlacemark); | 119 | document->append(newPlacemark); | ||
102 | osmIds << placemark->osmData().id(); | 120 | osmIds << placemark->osmData().id(); | ||
103 | } | 121 | } | ||
Show All 18 Lines |