Commit dc4526e9 authored by Dennis Nienhüser's avatar Dennis Nienhüser
Browse files

Avoid code duplication

parent 642c4af6
......@@ -102,91 +102,6 @@ BaseClipper::BaseClipper() :
}
QPolygonF BaseClipper::lineString2Qpolygon(const GeoDataLineString& lineString, bool reverseOrder)
{
QPolygonF polygon;
if(!reverseOrder) {
foreach (const GeoDataCoordinates& coord, lineString) {
// Need to flip the Y axis(latitude)
QPointF point(coord.longitude(), -coord.latitude());
polygon.append(point);
}
} else {
for(int i = lineString.size()-1; i >= 0; --i) {
// Need to flip the Y axis(latitude)
QPointF point(lineString.at(i).longitude(), -lineString.at(i).latitude());
polygon.append(point);
}
}
return polygon;
}
QPolygonF BaseClipper::linearRing2Qpolygon(const GeoDataLinearRing& linearRing, bool reverseOrder)
{
QPolygonF polygon;
if(!reverseOrder) {
foreach (const GeoDataCoordinates& coord, linearRing) {
// Need to flip the Y axis(latitude)
QPointF point(coord.longitude(), -coord.latitude());
polygon.append(point);
}
} else {
for(int i = linearRing.size()-1; i >= 0; --i) {
// Need to flip the Y axis(latitude)
QPointF point(linearRing.at(i).longitude(), -linearRing.at(i).latitude());
polygon.append(point);
}
}
return polygon;
}
GeoDataLineString BaseClipper::qPolygon2lineString(const QPolygonF& polygon, bool reverseOrder)
{
GeoDataLineString lineString;
if(!reverseOrder) {
foreach (const QPointF& point, polygon) {
// Flipping back the Y axis
GeoDataCoordinates coord(point.x(), -point.y());
lineString.append(coord);
}
} else {
for(int i = polygon.size()-1; i >= 0; --i) {
// Need to flip the Y axis(latitude)
GeoDataCoordinates coord(polygon.at(i).x(), -polygon.at(i).y());
lineString.append(coord);
}
}
return lineString;
}
GeoDataLinearRing BaseClipper::qPolygon2linearRing(const QPolygonF& polygon, bool reverseOrder)
{
GeoDataLinearRing linearRing;
if(!reverseOrder) {
foreach (const QPointF& point, polygon) {
// Flipping back the Y axis
GeoDataCoordinates coord(point.x(), -point.y());
linearRing.append(coord);
}
} else {
for(int i = polygon.size()-1; i >= 0; --i) {
// Need to flip the Y axis(latitude)
GeoDataCoordinates coord(polygon.at(i).x(), -polygon.at(i).y());
linearRing.append(coord);
}
}
return linearRing;
}
qreal BaseClipper::tileX2lon( unsigned int x, unsigned int maxTileX )
{
return ( (2*M_PI * x) / maxTileX - M_PI );
......
......@@ -29,12 +29,48 @@ public:
static qreal tileX2lon( unsigned int x, unsigned int maxTileX );
static qreal tileY2lat( unsigned int y, unsigned int maxTileY );
static QPolygonF lineString2Qpolygon(const GeoDataLineString &lineString, bool reverseOrder = false);
static QPolygonF linearRing2Qpolygon(const GeoDataLinearRing &linearRing, bool reverseOrder = false);
static GeoDataLineString qPolygon2lineString(const QPolygonF& polygon, bool reverseOrder = false);
static GeoDataLinearRing qPolygon2linearRing(const QPolygonF& polygon, bool reverseOrder = false);
template<class T>
static QPolygonF toQPolygon(const T &lineString, bool reverseOrder = false)
{
QPolygonF polygon;
if(!reverseOrder) {
foreach (const GeoDataCoordinates& coord, lineString) {
// Need to flip the Y axis(latitude)
QPointF point(coord.longitude(), -coord.latitude());
polygon.append(point);
}
} else {
for(int i = lineString.size()-1; i >= 0; --i) {
// Need to flip the Y axis(latitude)
QPointF point(lineString.at(i).longitude(), -lineString.at(i).latitude());
polygon.append(point);
}
}
return polygon;
}
template<class T>
static T toLineString(const QPolygonF& polygon, bool reverseOrder = false)
{
T lineString;
if(!reverseOrder) {
foreach (const QPointF& point, polygon) {
// Flipping back the Y axis
GeoDataCoordinates coord(point.x(), -point.y());
lineString.append(coord);
}
} else {
for(int i = polygon.size()-1; i >= 0; --i) {
// Need to flip the Y axis(latitude)
GeoDataCoordinates coord(polygon.at(i).x(), -polygon.at(i).y());
lineString.append(coord);
}
}
return lineString;
}
void initClipRect(const GeoDataLatLonBox& clippingBox, int pointsToAddAtEdges);
......
......@@ -68,7 +68,7 @@ GeoDataDocument *ShpCoastlineProcessor::cutToTiles(unsigned int zoomLevel, unsig
QVector<QPolygonF> clippedPolygons;
QPolygonF outerBoundary = BaseClipper::linearRing2Qpolygon(marblePolygon->outerBoundary());
QPolygonF outerBoundary = BaseClipper::toQPolygon(marblePolygon->outerBoundary());
qDebug() << "Size before:" << outerBoundary.size();
qDebug() << "Clipping...";
......@@ -80,7 +80,7 @@ GeoDataDocument *ShpCoastlineProcessor::cutToTiles(unsigned int zoomLevel, unsig
foreach(const QPolygonF& polygon, clippedPolygons) {
qDebug() << polygon.size();
GeoDataLinearRing outerBoundary = BaseClipper::qPolygon2linearRing(polygon);
GeoDataLinearRing outerBoundary = BaseClipper::toLineString<GeoDataLinearRing>(polygon);
GeoDataPolygon* newMarblePolygon = new GeoDataPolygon();
newMarblePolygon->setOuterBoundary(outerBoundary);
......
......@@ -65,7 +65,7 @@ GeoDataDocument *TinyPlanetProcessor::cutToTiles(unsigned int zoomLevel, unsigne
QVector<PolygonPair> newMarblePolygons;
isClockwise = marblePolygon->outerBoundary().isClockwise();
QPolygonF outerBoundaryPolygon = BaseClipper::linearRing2Qpolygon(marblePolygon->outerBoundary(), !isClockwise);
QPolygonF outerBoundaryPolygon = BaseClipper::toQPolygon(marblePolygon->outerBoundary(), !isClockwise);
QVector<QPolygonF> outerBoundaries;
clipper.clipPolyObject(outerBoundaryPolygon, outerBoundaries, true);
......@@ -77,7 +77,7 @@ GeoDataDocument *TinyPlanetProcessor::cutToTiles(unsigned int zoomLevel, unsigne
PolygonPair newMarblePolygon = qMakePair(new GeoDataPlacemark(), polygon);
GeoDataPolygon* geometry = new GeoDataPolygon();
geometry->setOuterBoundary(BaseClipper::qPolygon2linearRing(polygon, !isClockwise));
geometry->setOuterBoundary(BaseClipper::toLineString<GeoDataLinearRing>(polygon, !isClockwise));
newMarblePolygon.first->setGeometry(geometry);
copyTags(*placemark, *(newMarblePolygon.first));
......@@ -93,7 +93,7 @@ GeoDataDocument *TinyPlanetProcessor::cutToTiles(unsigned int zoomLevel, unsigne
foreach (const GeoDataLinearRing& innerBoundary, marblePolygon->innerBoundaries()) {
++index;
isClockwise = innerBoundary.isClockwise();
QPolygonF innerBoundaryPolygon = BaseClipper::linearRing2Qpolygon(innerBoundary, !isClockwise);
QPolygonF innerBoundaryPolygon = BaseClipper::toQPolygon(innerBoundary, !isClockwise);
QVector<QPolygonF> clippedPolygons;
......@@ -104,7 +104,7 @@ GeoDataDocument *TinyPlanetProcessor::cutToTiles(unsigned int zoomLevel, unsigne
foreach (const PolygonPair& newMarblePolygon, newMarblePolygons) {
if(!polygon.intersected(newMarblePolygon.second).isEmpty()) {
GeoDataPolygon* geometry = static_cast<GeoDataPolygon*>(newMarblePolygon.first->geometry());
geometry->appendInnerBoundary(BaseClipper::qPolygon2linearRing(polygon, !isClockwise));
geometry->appendInnerBoundary(BaseClipper::toLineString<GeoDataLinearRing>(polygon, !isClockwise));
OsmObjectManager::initializeOsmData(newMarblePolygon.first);
......@@ -132,7 +132,7 @@ GeoDataDocument *TinyPlanetProcessor::cutToTiles(unsigned int zoomLevel, unsigne
QVector<QPolygonF> clippedPolygons;
QPolygonF way = BaseClipper::lineString2Qpolygon(*marbleWay);
QPolygonF way = BaseClipper::toQPolygon(*marbleWay);
clipper.clipPolyObject(way, clippedPolygons, false);
......@@ -142,7 +142,7 @@ GeoDataDocument *TinyPlanetProcessor::cutToTiles(unsigned int zoomLevel, unsigne
// qDebug() << polygon.size();
GeoDataLineString* newMarbleWay = new GeoDataLineString(BaseClipper::qPolygon2lineString(polygon));
GeoDataLineString* newMarbleWay = new GeoDataLineString(BaseClipper::toLineString<GeoDataLineString>(polygon));
GeoDataPlacemark* newPlacemark = new GeoDataPlacemark();
newPlacemark->setGeometry(newMarbleWay);
......@@ -156,7 +156,7 @@ GeoDataDocument *TinyPlanetProcessor::cutToTiles(unsigned int zoomLevel, unsigne
QVector<QPolygonF> clippedPolygons;
QPolygonF closedWay = BaseClipper::linearRing2Qpolygon(*marbleClosedWay);
QPolygonF closedWay = BaseClipper::toQPolygon(*marbleClosedWay);
clipper.clipPolyObject(closedWay, clippedPolygons, true);
......@@ -165,7 +165,7 @@ GeoDataDocument *TinyPlanetProcessor::cutToTiles(unsigned int zoomLevel, unsigne
// qDebug() << polygon.size();
GeoDataLinearRing* newMarbleWay = new GeoDataLinearRing(BaseClipper::qPolygon2linearRing(polygon));
GeoDataLinearRing* newMarbleWay = new GeoDataLinearRing(BaseClipper::toLineString<GeoDataLinearRing>(polygon));
GeoDataPlacemark* newPlacemark = new GeoDataPlacemark();
newPlacemark->setGeometry(newMarbleWay);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment