Commit a927ef05 authored by Dávid Kolozsvári's avatar Dávid Kolozsvári

Latest version of the osm-simplify tool. Added TinyPlanetProcessor class,...

Latest version of the osm-simplify tool. Added TinyPlanetProcessor class, which cuts to tiles .osm files.
parent 725400a8
......@@ -110,14 +110,14 @@ qreal BaseClipper::_m( const QPointF & start, const QPointF & end )
{
qreal divisor = end.x() - start.x();
// Had to add mre zeros, because what is acceptable in screen coordinates
// Had to add more zeros, because what is acceptable in screen coordinates
// could be meters on 10 meters in geographic coordinates.
if ( std::fabs( divisor ) < 0.00000000000000001 ) {
divisor = 0.00000000000000001 * (divisor < 0 ? -1 : 1);
}
return ( end.y() - start.y() )
/ divisor;
/ divisor;
}
......@@ -224,6 +224,7 @@ void BaseClipper::clipPolyObject ( const QPolygonF & polygon,
// sector that is located off screen to another one that
// is located off screen. In this situation the line
// can get clipped once, twice, or not at all.
clipMultiple( clippedPolyObject, clippedPolyObjects, isClosed );
}
......@@ -234,9 +235,6 @@ void BaseClipper::clipPolyObject ( const QPolygonF & polygon,
if ( m_currentSector == 4 ) {
clippedPolyObject << m_currentPoint;
#ifdef MARBLE_DEBUG
++(m_debugNodeCount);
#endif
}
m_previousPoint = m_currentPoint;
......@@ -748,11 +746,8 @@ void BaseClipper::clipOnceCorner( QPolygonF & clippedPolyObject,
QVector<QPolygonF> & clippedPolyObjects,
const QPointF& corner,
const QPointF& point,
bool isClosed ) const
bool isClosed )
{
Q_UNUSED( clippedPolyObjects )
Q_UNUSED( isClosed )
if ( m_currentSector == 4) {
// Appearing
clippedPolyObject << corner;
......@@ -767,7 +762,7 @@ void BaseClipper::clipOnceCorner( QPolygonF & clippedPolyObject,
void BaseClipper::clipOnceEdge( QPolygonF & clippedPolyObject,
QVector<QPolygonF> & clippedPolyObjects,
const QPointF& point,
bool isClosed ) const
bool isClosed )
{
if ( m_currentSector == 4) {
// Appearing
......@@ -779,8 +774,10 @@ void BaseClipper::clipOnceEdge( QPolygonF & clippedPolyObject,
else {
// Disappearing
clippedPolyObject << point;
if ( !isClosed ) {
clippedPolyObjects << clippedPolyObject;
clippedPolyObject = QPolygonF();
}
}
}
......
......@@ -61,11 +61,11 @@ private:
QVector<QPolygonF> & clippedPolyObjects,
const QPointF& corner,
const QPointF& point,
bool isClosed ) const;
bool isClosed );
inline void clipOnceEdge( QPolygonF & clippedPolyObject,
QVector<QPolygonF> & clippedPolyObjects,
const QPointF& point,
bool isClosed ) const;
bool isClosed );
static inline qreal _m( const QPointF & start, const QPointF & end );
......
......@@ -25,6 +25,7 @@ BaseFilter.cpp
PlacemarkFilter.cpp
ShpCoastlineProcessor.cpp
LineStringProcessor.cpp
TinyPlanetProcessor.cpp
NodeReducer.cpp
)
......
//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2016 David Kolozsvari <freedawson@gmail.com>
//
#include "TinyPlanetProcessor.h"
#include "BaseClipper.h"
#include "GeoDataPlacemark.h"
#include "OsmPlacemarkData.h"
#include <QDebug>
#include <QPolygonF>
TinyPlanetProcessor::TinyPlanetProcessor(GeoDataDocument* document) :
PlacemarkFilter(document)
{
}
void TinyPlanetProcessor::process()
{
// ?
}
GeoDataDocument *TinyPlanetProcessor::cutToTiles(unsigned int zoomLevel, unsigned int tileX, unsigned int tileY)
{
unsigned int N = pow(2, zoomLevel);
GeoDataDocument* tile = new GeoDataDocument();
QString tileName = QString("%1/%2/%3").arg(zoomLevel).arg(tileX).arg(tileY);
tile->setName(tileName);
GeoDataLatLonBox tileBoundary;
qreal north = BaseClipper::tileY2lat(tileY, N);
qreal south = BaseClipper::tileY2lat(tileY+1, N);
qreal west = BaseClipper::tileX2lon(tileX, N);
qreal east = BaseClipper::tileX2lon(tileX+1, N);
tileBoundary.setBoundaries(north, south, east, west);
BaseClipper clipper;
clipper.initClipRect(tileBoundary);
foreach (GeoDataObject* object, m_objects) {
GeoDataPlacemark* placemark = static_cast<GeoDataPlacemark*>(object);
if(tileBoundary.intersects(placemark->geometry()->latLonAltBox())) {
if( placemark->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType ||
placemark->visualCategory() == GeoDataFeature::Landmass) {
GeoDataLinearRing* marblePolygon;
if(placemark->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType) {
marblePolygon = &static_cast<GeoDataPolygon*>(placemark->geometry())->outerBoundary();
} else if (placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLinearRingType) {
marblePolygon = static_cast<GeoDataLinearRing*>(placemark->geometry());
}
QVector<QPolygonF> clippedPolygons;
QPolygonF outerBoundary = BaseClipper::linearRing2Qpolygon(*marblePolygon);
clipper.clipPolyObject(outerBoundary, clippedPolygons, true);
foreach(const QPolygonF& polygon, clippedPolygons) {
GeoDataLinearRing outerBoundary = BaseClipper::qPolygon2linearRing(polygon);
GeoDataPolygon* newMarblePolygon = new GeoDataPolygon();
newMarblePolygon->setOuterBoundary(outerBoundary);
GeoDataPlacemark* newPlacemark = new GeoDataPlacemark();
newPlacemark->setGeometry(newMarblePolygon);
newPlacemark->setVisualCategory(GeoDataFeature::Landmass);
OsmPlacemarkData marbleLand;
marbleLand.addTag("marble_land","landmass");
newPlacemark->setOsmData(marbleLand);
tile->append(newPlacemark);
}
} else if (placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLineStringType) {
GeoDataLineString* marbleWay = static_cast<GeoDataLineString*>(placemark->geometry());
QVector<QPolygonF> clippedPolygons;
QPolygonF way = BaseClipper::lineString2Qpolygon(*marbleWay);
clipper.clipPolyObject(way, clippedPolygons, false);
foreach(const QPolygonF& polygon, clippedPolygons) {
GeoDataLineString* newMarbleWay = new GeoDataLineString(BaseClipper::qPolygon2lineString(polygon));
GeoDataPlacemark* newPlacemark = new GeoDataPlacemark();
newPlacemark->setGeometry(newMarbleWay);
newPlacemark->setVisualCategory(placemark->visualCategory());
OsmPlacemarkData osmData;
auto it = placemark->osmData().tagsBegin();
auto itEnd = placemark->osmData().tagsEnd();
while(it != itEnd) {
osmData.addTag(it.key(), it.value());
++it;
}
newPlacemark->setOsmData(osmData);
tile->append(newPlacemark);
}
} else if (placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLinearRingType) {
GeoDataLinearRing* marbleClosedWay = static_cast<GeoDataLinearRing*>(placemark->geometry());
QVector<QPolygonF> clippedPolygons;
QPolygonF closedWay = BaseClipper::linearRing2Qpolygon(*marbleClosedWay);
// If we cut a closed way to pieces, the results shouldn't be closed ways too
clipper.clipPolyObject(closedWay, clippedPolygons, false);
foreach(const QPolygonF& polygon, clippedPolygons) {
// When a linearRing is cut to pieces, the resulting geometries will be lineStrings
GeoDataLineString* newMarbleWay = new GeoDataLineString(BaseClipper::qPolygon2lineString(polygon));
GeoDataPlacemark* newPlacemark = new GeoDataPlacemark();
newPlacemark->setGeometry(newMarbleWay);
newPlacemark->setVisualCategory(placemark->visualCategory());
OsmPlacemarkData osmData;
auto it = placemark->osmData().tagsBegin();
auto itEnd = placemark->osmData().tagsEnd();
while(it != itEnd) {
osmData.addTag(it.key(), it.value());
++it;
}
newPlacemark->setOsmData(osmData);
tile->append(newPlacemark);
}
} else {
tile->append(placemark);
}
}
}
return tile;
}
//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2016 David Kolozsvari <freedawson@gmail.com>
//
#ifndef TINYPLANETPROCESSOR_H
#define TINYPLANETPROCESSOR_H
#include "PlacemarkFilter.h"
class TinyPlanetProcessor : public PlacemarkFilter
{
public:
TinyPlanetProcessor(GeoDataDocument* document);
virtual void process();
GeoDataDocument* cutToTiles(unsigned int zoomLevel, unsigned int tileX, unsigned int tileY);
};
#endif // TINYPLANETPROCESSOR_H
This diff is collapsed.
Markdown is supported
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