Changeset View
Changeset View
Standalone View
Standalone View
tools/vectorosm-tilecreator/VectorClipper.cpp
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 70 | for (GeoDataPlacemark const * placemark: potentialIntersections(tileBoundary)) { | |||
---|---|---|---|---|---|
71 | GeoDataGeometry const * const geometry = placemark ? placemark->geometry() : nullptr; | 71 | GeoDataGeometry const * const geometry = placemark ? placemark->geometry() : nullptr; | ||
72 | if (geometry && tileBoundary.intersects(geometry->latLonAltBox())) { | 72 | if (geometry && tileBoundary.intersects(geometry->latLonAltBox())) { | ||
73 | if (geodata_cast<GeoDataPolygon>(geometry)) { | 73 | if (geodata_cast<GeoDataPolygon>(geometry)) { | ||
74 | clipPolygon(placemark, clip, minArea, tile, osmIds); | 74 | clipPolygon(placemark, clip, minArea, tile, osmIds); | ||
75 | } else if (geodata_cast<GeoDataLineString>(geometry)) { | 75 | } else if (geodata_cast<GeoDataLineString>(geometry)) { | ||
76 | clipString<GeoDataLineString>(placemark, clip, minArea, tile, osmIds); | 76 | clipString<GeoDataLineString>(placemark, clip, minArea, tile, osmIds); | ||
77 | } else if (geodata_cast<GeoDataLinearRing>(geometry)) { | 77 | } else if (geodata_cast<GeoDataLinearRing>(geometry)) { | ||
78 | clipString<GeoDataLinearRing>(placemark, clip, minArea, tile, osmIds); | 78 | clipString<GeoDataLinearRing>(placemark, clip, minArea, tile, osmIds); | ||
79 | } else if (const auto building = geodata_cast<GeoDataBuilding>(geometry)) { | ||||
80 | if (geodata_cast<GeoDataPolygon>(&building->multiGeometry()->at(0))) { | ||||
81 | clipPolygon(placemark, clip, minArea, tile, osmIds); | ||||
82 | } else if (geodata_cast<GeoDataLinearRing>(&building->multiGeometry()->at(0))) { | ||||
83 | clipString<GeoDataLinearRing>(placemark, clip, minArea, tile, osmIds); | ||||
84 | } | ||||
79 | } else { | 85 | } else { | ||
80 | tile->append(placemark->clone()); | 86 | tile->append(placemark->clone()); | ||
81 | osmIds << placemark->osmData().id(); | 87 | osmIds << placemark->osmData().id(); | ||
82 | } | 88 | } | ||
83 | } | 89 | } | ||
84 | } | 90 | } | ||
85 | 91 | | |||
86 | for (auto relation: m_relations) { | 92 | for (auto relation: m_relations) { | ||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Line(s) | 224 | } else if (point.Y > maxY) { | |||
219 | maxY = point.Y; | 225 | maxY = point.Y; | ||
220 | } | 226 | } | ||
221 | } | 227 | } | ||
222 | } | 228 | } | ||
223 | 229 | | |||
224 | void VectorClipper::clipPolygon(const GeoDataPlacemark *placemark, const ClipperLib::Path &tileBoundary, qreal minArea, | 230 | void VectorClipper::clipPolygon(const GeoDataPlacemark *placemark, const ClipperLib::Path &tileBoundary, qreal minArea, | ||
225 | GeoDataDocument *document, QSet<qint64> &osmIds) | 231 | GeoDataDocument *document, QSet<qint64> &osmIds) | ||
226 | { | 232 | { | ||
227 | const GeoDataPolygon* polygon = static_cast<const GeoDataPolygon*>(placemark->geometry()); | 233 | bool isBuilding = false; | ||
234 | GeoDataPolygon* polygon; | ||||
235 | if (const auto building = geodata_cast<GeoDataBuilding>(placemark->geometry())) { | ||||
236 | polygon = geodata_cast<GeoDataPolygon>(&building->multiGeometry()->at(0)); | ||||
237 | isBuilding = true; | ||||
238 | } else { | ||||
239 | GeoDataPlacemark* copyPlacemark = new GeoDataPlacemark(*placemark); | ||||
240 | polygon = geodata_cast<GeoDataPolygon>(copyPlacemark->geometry()); | ||||
241 | } | ||||
242 | | ||||
228 | if (minArea > 0.0 && area(polygon->outerBoundary()) < minArea) { | 243 | if (minArea > 0.0 && area(polygon->outerBoundary()) < minArea) { | ||
229 | return; | 244 | return; | ||
230 | } | 245 | } | ||
231 | using namespace ClipperLib; | 246 | using namespace ClipperLib; | ||
232 | Path path; | 247 | Path path; | ||
233 | for(auto const & node: polygon->outerBoundary()) { | 248 | for(auto const & node: polygon->outerBoundary()) { | ||
234 | path << IntPoint(&node); | 249 | path << IntPoint(&node); | ||
235 | } | 250 | } | ||
Show All 24 Lines | 271 | for(const auto &point: path) { | |||
260 | if (originalOsmData.id() > 0) { | 275 | if (originalOsmData.id() > 0) { | ||
261 | newOuterRingOsmData.addNodeReference(coordinates, originalOsmData); | 276 | newOuterRingOsmData.addNodeReference(coordinates, originalOsmData); | ||
262 | } | 277 | } | ||
263 | ++nodeIndex; | 278 | ++nodeIndex; | ||
264 | } | 279 | } | ||
265 | 280 | | |||
266 | GeoDataPolygon* newPolygon = new GeoDataPolygon; | 281 | GeoDataPolygon* newPolygon = new GeoDataPolygon; | ||
267 | newPolygon->setOuterBoundary(outerRing); | 282 | newPolygon->setOuterBoundary(outerRing); | ||
283 | if (isBuilding) { | ||||
284 | const auto building = geodata_cast<GeoDataBuilding>(placemark->geometry()); | ||||
285 | GeoDataBuilding* newBuilding = new GeoDataBuilding(*building); | ||||
286 | newBuilding->multiGeometry()->clear(); | ||||
287 | newBuilding->multiGeometry()->append(newPolygon); | ||||
288 | newPlacemark->setGeometry(newBuilding); | ||||
289 | } else { | ||||
268 | newPlacemark->setGeometry(newPolygon); | 290 | newPlacemark->setGeometry(newPolygon); | ||
291 | } | ||||
269 | if (placemarkOsmData.id() > 0) { | 292 | if (placemarkOsmData.id() > 0) { | ||
270 | newPlacemarkOsmData.addTag(QStringLiteral("mx:oid"), QString::number(placemarkOsmData.id())); | 293 | newPlacemarkOsmData.addTag(QStringLiteral("mx:oid"), QString::number(placemarkOsmData.id())); | ||
271 | } | 294 | } | ||
272 | copyTags(placemarkOsmData, newPlacemarkOsmData); | 295 | copyTags(placemarkOsmData, newPlacemarkOsmData); | ||
273 | copyTags(outerRingOsmData, newOuterRingOsmData); | 296 | copyTags(outerRingOsmData, newOuterRingOsmData); | ||
274 | if (outerRingOsmData.id() > 0) { | 297 | if (outerRingOsmData.id() > 0) { | ||
275 | newOuterRingOsmData.addTag(QStringLiteral("mx:oid"), QString::number(outerRingOsmData.id())); | 298 | newOuterRingOsmData.addTag(QStringLiteral("mx:oid"), QString::number(outerRingOsmData.id())); | ||
276 | } | 299 | } | ||
▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines |