summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kolozsvari <freedawson@gmail.com>2016-08-15 05:55:43 (GMT)
committerDavid Kolozsvari <freedawson@gmail.com>2016-08-15 05:55:43 (GMT)
commit65afbafa914a0e98b73d7ad24e5383ab4e4793ea (patch)
tree47dd07ad8ed7a2ec0e3134181e62968ab29a2c0d
parentdf03e7af538da9c1194f24fc0fdd63580ac60754 (diff)
Adding more points to the edges of the generated tiles
-rw-r--r--tools/osm-simplify/BaseClipper.cpp70
-rw-r--r--tools/osm-simplify/BaseClipper.h7
-rw-r--r--tools/osm-simplify/ShpCoastlineProcessor.cpp2
-rw-r--r--tools/osm-simplify/TinyPlanetProcessor.cpp2
4 files changed, 67 insertions, 14 deletions
diff --git a/tools/osm-simplify/BaseClipper.cpp b/tools/osm-simplify/BaseClipper.cpp
index 9e6fce6..96d06ff 100644
--- a/tools/osm-simplify/BaseClipper.cpp
+++ b/tools/osm-simplify/BaseClipper.cpp
@@ -165,7 +165,7 @@ qreal BaseClipper::tileY2lat( unsigned int y, unsigned int maxTileY )
-void BaseClipper::initClipRect (const GeoDataLatLonBox &clippingBox)
+void BaseClipper::initClipRect (const GeoDataLatLonBox &clippingBox, int pointsToAddAtEdges)
{
m_left = clippingBox.west();
m_right = clippingBox.east();
@@ -182,6 +182,38 @@ void BaseClipper::initClipRect (const GeoDataLatLonBox &clippingBox)
m_bottomRight = QPointF(m_right, m_bottom);
m_bottomLeft = QPointF(m_left, m_bottom);
+ qreal x, y;
+ qreal deltaX = fabs(m_right - m_left) / (pointsToAddAtEdges + 1);
+ qreal deltaY = fabs(m_bottom - m_top) / (pointsToAddAtEdges + 1);
+
+ m_topEdge.clear();
+ x = m_left;
+ for(int i = 0; i < pointsToAddAtEdges; ++i) {
+ x += deltaX;
+ m_topEdge << QPointF(x, m_top);
+ }
+
+ m_rightEdge.clear();
+ y = m_top;
+ for(int i = 0; i < pointsToAddAtEdges; ++i) {
+ y += deltaY;
+ m_rightEdge << QPointF(m_right, y);
+ }
+
+ m_bottomEdge.clear();
+ x = m_right;
+ for(int i = 0; i < pointsToAddAtEdges; ++i) {
+ x -= deltaX;
+ m_bottomEdge << QPointF(x, m_bottom);
+ }
+
+ m_leftEdge.clear();
+ y = m_bottom;
+ for(int i = 0; i < pointsToAddAtEdges; ++i) {
+ y -= deltaY;
+ m_leftEdge << QPointF(m_left, y);
+ }
+
m_viewport.clear();
m_viewport << m_topLeft << m_topRight << m_bottomRight << m_bottomLeft;
m_viewport.isClosed();
@@ -321,7 +353,7 @@ void BaseClipper::clipPolyObject ( const QPolygonF & polygon,
bool processingLastNode = false;
- qDebug() << "\nNew polygon, size:" << polygon.size();
+ // qDebug() << "\nNew polygon, size:" << polygon.size();
while ( itPoint != itEndPoint ) {
m_currentPoint = (*itPoint);
@@ -359,7 +391,7 @@ void BaseClipper::clipPolyObject ( const QPolygonF & polygon,
if(!clippedPolyObject.isEmpty()) {
- if(isCornerPoint(clippedPolyObject.last())) {
+ if(isCornerPoint(clippedPolyObject.last()) && clippedPolyObject.size() > 1) {
clippedPolyObject.removeLast();
}
@@ -389,7 +421,7 @@ void BaseClipper::clipPolyObject ( const QPolygonF & polygon,
clipMultiple( clippedPolyObject, clippedPolyObjects, isClosed );
if(isClosed && m_clippedTwice) {
- qDebug() << "Clipped twice";
+ // qDebug() << "Clipped twice";
QPointF firstAddedPoint = clippedPolyObject.at(clippedPolyObject.size()-2);
QPointF secondAddedPoint = clippedPolyObject.last();
@@ -453,27 +485,39 @@ void BaseClipper::clipPolyObject ( const QPolygonF & polygon,
if(!intersections.isEmpty()) {
- qDebug() << "intersections count:" << intersections.size();
- qDebug() << "intersectionsTop count:" << intersectionsTop.size();
- qDebug() << "intersectionsRight count:" << intersectionsRight.size();
- qDebug() << "intersectionsBottom count:" << intersectionsBottom.size();
- qDebug() << "intersectionsLeft count:" << intersectionsLeft.size();
+// qDebug() << "intersections count:" << intersections.size();
+// qDebug() << "intersectionsTop count:" << intersectionsTop.size();
+// qDebug() << "intersectionsRight count:" << intersectionsRight.size();
+// qDebug() << "intersectionsBottom count:" << intersectionsBottom.size();
+// qDebug() << "intersectionsLeft count:" << intersectionsLeft.size();
clippedPolyObjects.clear();
clippedPolyObject = QPolygonF();
+ for(const auto& point : m_topEdge) {
+ intersectionsTop << QSharedPointer<LinkedPoint>(new LinkedPoint(point));
+ }
std::sort(intersectionsTop.begin(), intersectionsTop.end(), [](QSharedPointer<LinkedPoint>& A, QSharedPointer<LinkedPoint>& B) {
return A->point().x() < B->point().x();
});
+ for(const auto& point : m_rightEdge) {
+ intersectionsRight << QSharedPointer<LinkedPoint>(new LinkedPoint(point));
+ }
std::sort(intersectionsRight.begin(), intersectionsRight.end(), [](QSharedPointer<LinkedPoint>& A, QSharedPointer<LinkedPoint>& B) {
return A->point().y() < B->point().y();
});
+ for(const auto& point : m_bottomEdge) {
+ intersectionsBottom << QSharedPointer<LinkedPoint>(new LinkedPoint(point));
+ }
std::sort(intersectionsBottom.begin(), intersectionsBottom.end(), [](QSharedPointer<LinkedPoint>& A, QSharedPointer<LinkedPoint>& B) {
return B->point().x() < A->point().x();
});
+ for(const auto& point : m_leftEdge) {
+ intersectionsLeft << QSharedPointer<LinkedPoint>(new LinkedPoint(point));
+ }
std::sort(intersectionsLeft.begin(), intersectionsLeft.end(), [](QSharedPointer<LinkedPoint>& A, QSharedPointer<LinkedPoint>& B) {
return B->point().y() < A->point().y();
});
@@ -533,13 +577,17 @@ void BaseClipper::clipPolyObject ( const QPolygonF & polygon,
}
} else {
clippedPolyObjects.clear();
- clippedPolyObject = QPolygonF();
clippedPolyObject = polygon.intersected(m_viewport);
if(clippedPolyObject == polygon) {
clippedPolyObjects << polygon;
} else if (clippedPolyObject == m_viewport.intersected(m_viewport)) {
- clippedPolyObjects << m_viewport;
+ clippedPolyObject = QPolygonF();
+ clippedPolyObject << m_topLeft << m_topEdge
+ << m_topRight << m_rightEdge
+ << m_bottomRight << m_bottomEdge
+ << m_bottomLeft << m_leftEdge;
+ clippedPolyObjects << clippedPolyObject;
}
}
} else if(!clippedPolyObject.isEmpty()) {
diff --git a/tools/osm-simplify/BaseClipper.h b/tools/osm-simplify/BaseClipper.h
index 8e783c3..71b8d76 100644
--- a/tools/osm-simplify/BaseClipper.h
+++ b/tools/osm-simplify/BaseClipper.h
@@ -36,7 +36,7 @@ public:
static GeoDataLinearRing qPolygon2linearRing(const QPolygonF& polygon);
- void initClipRect(const GeoDataLatLonBox& clippingBox);
+ void initClipRect(const GeoDataLatLonBox& clippingBox, int pointsToAddAtEdges);
void clipPolyObject ( const QPolygonF & sourcePolygon,
QVector<QPolygonF> & clippedPolyObjects,
@@ -83,6 +83,11 @@ private:
QPointF m_bottomRight;
QPointF m_bottomLeft;
+ QPolygonF m_topEdge;
+ QPolygonF m_bottomEdge;
+ QPolygonF m_leftEdge;
+ QPolygonF m_rightEdge;
+
QPolygonF m_viewport;
int m_currentSector;
diff --git a/tools/osm-simplify/ShpCoastlineProcessor.cpp b/tools/osm-simplify/ShpCoastlineProcessor.cpp
index d7b25b8..ecf94fe 100644
--- a/tools/osm-simplify/ShpCoastlineProcessor.cpp
+++ b/tools/osm-simplify/ShpCoastlineProcessor.cpp
@@ -64,7 +64,7 @@ GeoDataDocument *ShpCoastlineProcessor::cutToTiles(unsigned int zoomLevel, unsig
if(tileBoundary.intersects(marblePolygon->latLonAltBox())) {
BaseClipper clipper;
- clipper.initClipRect(tileBoundary);
+ clipper.initClipRect(tileBoundary, 20);
QVector<QPolygonF> clippedPolygons;
diff --git a/tools/osm-simplify/TinyPlanetProcessor.cpp b/tools/osm-simplify/TinyPlanetProcessor.cpp
index 496b65d..af4ece2 100644
--- a/tools/osm-simplify/TinyPlanetProcessor.cpp
+++ b/tools/osm-simplify/TinyPlanetProcessor.cpp
@@ -46,7 +46,7 @@ GeoDataDocument *TinyPlanetProcessor::cutToTiles(unsigned int zoomLevel, unsigne
tileBoundary.setBoundaries(north, south, east, west);
BaseClipper clipper;
- clipper.initClipRect(tileBoundary);
+ clipper.initClipRect(tileBoundary, 20);
foreach (GeoDataPlacemark* placemark, placemarks()) {