summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Stanciu <[email protected]>2015-07-19 18:08:43 +0300
committerMarius Stanciu <[email protected]>2015-07-19 18:08:43 +0300
commit850587966cf2d5aa218d23de37b45399b3b972f0 (patch)
treeb6b5fb173c00db385f6020f9f46a3a963e091a19
parent6c64f0e66b2d88f4b381c30ba9098316d16558ac (diff)
Translator classes used in writing osm files
REVIEW: 124097
-rw-r--r--src/plugins/runner/osm/translators/OsmDocumentTagTranslator.cpp116
-rw-r--r--src/plugins/runner/osm/translators/OsmDocumentTagTranslator.h52
-rw-r--r--src/plugins/runner/osm/translators/OsmFeatureTagTranslator.cpp27
-rw-r--r--src/plugins/runner/osm/translators/OsmFeatureTagTranslator.h37
-rw-r--r--src/plugins/runner/osm/translators/OsmPlacemarkTagTranslator.cpp65
-rw-r--r--src/plugins/runner/osm/translators/OsmPlacemarkTagTranslator.h32
6 files changed, 329 insertions, 0 deletions
diff --git a/src/plugins/runner/osm/translators/OsmDocumentTagTranslator.cpp b/src/plugins/runner/osm/translators/OsmDocumentTagTranslator.cpp
new file mode 100644
index 0000000..cac7852
--- /dev/null
+++ b/src/plugins/runner/osm/translators/OsmDocumentTagTranslator.cpp
@@ -0,0 +1,116 @@
+//
+// 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 2015 Stanciu Marius-Valeriu <[email protected]>
+//
+
+//Self
+#include "OsmDocumentTagTranslator.h"
+
+//Marble
+#include "OsmNodeTagWriter.h"
+#include "OsmWayTagWriter.h"
+#include "OsmObjectManager.h"
+#include "OsmElementDictionary.h"
+#include "GeoDataDocument.h"
+#include "GeoWriter.h"
+#include "GeoDataPlacemark.h"
+#include "GeoDataGeometry.h"
+#include "GeoDataPoint.h"
+#include "GeoDataPolygon.h"
+#include "GeoDataLinearRing.h"
+#include "GeoDataTypes.h"
+#include "osm/OsmPlacemarkData.h"
+
+//Qt
+#include <QVector>
+
+namespace Marble
+{
+
+static GeoTagWriterRegistrar s_writerDocument( GeoTagWriter::QualifiedName( GeoDataTypes::GeoDataDocumentType,
+ osm::osmTag_version06 ),
+ new OsmDocumentTagTranslator() );
+
+
+bool OsmDocumentTagTranslator::writeMid( const GeoNode *node, GeoWriter& writer ) const
+{
+ const GeoDataDocument *document = static_cast<const GeoDataDocument*>(node);
+
+ // Creating separate lists, to improve efficiency
+ QList<const GeoDataObject*> polylines, polygons;
+ QList<OsmBound> bounds;
+
+ // Writing all the component nodes ( points, nodes of polylines, nodes of polygons )
+ foreach ( GeoDataFeature* feature, document->featureList() ) {
+
+ if ( feature->nodeType() != GeoDataTypes::GeoDataPlacemarkType ) {
+ continue;
+ }
+ GeoDataPlacemark* placemark = static_cast<GeoDataPlacemark*>( feature );
+
+ // If the placemark does not have osmData, it is initialized by the OsmObjectManager
+ if ( !placemark->hasOsmData() ) {
+ OsmObjectManager::initializeOsmData( placemark );
+ }
+
+ const OsmPlacemarkData osmData = placemark->osmData();
+
+ if ( placemark->geometry()->nodeType() == GeoDataTypes::GeoDataPointType ) {
+ writeElement( placemark, writer );
+ }
+ else if ( placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLineStringType ) {
+ // Writing all the lineString nodes directly from the hash, as order is irrelevant
+ OsmNodeTagWriter::writeAllNodes( osmData, writer );
+ polylines.append( placemark );
+ }
+ else if ( placemark->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType ) {
+ const GeoDataPolygon *polygon = static_cast<const GeoDataPolygon*>( placemark->geometry() );
+
+ // Writing all the outerRing's nodes
+ const GeoDataLinearRing &outerRing = polygon->outerBoundary();
+ const OsmPlacemarkData outerRingOsmData = osmData.reference( &outerRing );
+ OsmNodeTagWriter::writeAllNodes( outerRingOsmData, writer );
+ bounds.append( OsmBound( &outerRing, outerRingOsmData ) );
+
+ // Writing all nodes for each innerRing
+ foreach ( const GeoDataLinearRing &innerRing, polygon->innerBoundaries() ) {
+ const OsmPlacemarkData innerRingOsmData = osmData.reference( &innerRing );
+ OsmNodeTagWriter::writeAllNodes( innerRingOsmData, writer );
+ bounds.append( OsmBound( &innerRing, innerRingOsmData ) );
+ }
+ polygons.append( placemark );
+ }
+ }
+
+
+ // Writing the ways
+ foreach ( const GeoDataObject* polyline, polylines ) {
+ writeElement( polyline, writer );
+ }
+
+ // Writing the bounds ( innerBounds and outerBounds, part of polygons )
+ foreach ( OsmBound bound, bounds ) {
+ OsmWayTagWriter::writeWay( *bound.first, bound.second, writer );
+ }
+
+ // Writing polygons
+ foreach ( const GeoDataObject* polygon, polygons ) {
+ writeElement( polygon, writer );
+ }
+
+ return true;
+}
+
+
+OsmDocumentTagTranslator::OsmDocumentTagTranslator():
+ OsmFeatureTagTranslator() {
+ //nothing to do
+}
+
+}
+
diff --git a/src/plugins/runner/osm/translators/OsmDocumentTagTranslator.h b/src/plugins/runner/osm/translators/OsmDocumentTagTranslator.h
new file mode 100644
index 0000000..452bb8f
--- /dev/null
+++ b/src/plugins/runner/osm/translators/OsmDocumentTagTranslator.h
@@ -0,0 +1,52 @@
+//
+// 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 2015 Stanciu Marius-Valeriu <[email protected]>
+//
+
+#ifndef MARBLE_OSMDOCUMENTTAGWRITER_H
+#define MARBLE_OSMDOCUMENTTAGWRITER_H
+
+#include "GeoTagWriter.h"
+#include "OsmFeatureTagTranslator.h"
+
+namespace Marble
+{
+/**
+ This helper class organizes a GeoDataDocument to
+ meet the following OSM standard structure:
+
+ <xml>
+ <bounds>
+
+ block of nodes: ( <node>...) 1st
+ block of ways: ( <way> ...) 2nd
+ block of relations: ( <relation> ...) 3rd
+
+ See http://wiki.openstreetmap.org/wiki/OSM_XML#Contents
+
+*/
+class GeoDataLineString;
+class OsmPlacemarkData;
+
+class OsmDocumentTagTranslator : public OsmFeatureTagTranslator
+{
+public:
+ OsmDocumentTagTranslator();
+
+protected:
+ virtual bool writeMid( const GeoNode *node, GeoWriter& writer ) const;
+
+private:
+ typedef QPair<const GeoDataLineString*, OsmPlacemarkData > OsmBound;
+
+};
+
+}
+
+#endif
+
diff --git a/src/plugins/runner/osm/translators/OsmFeatureTagTranslator.cpp b/src/plugins/runner/osm/translators/OsmFeatureTagTranslator.cpp
new file mode 100644
index 0000000..4ceea91
--- /dev/null
+++ b/src/plugins/runner/osm/translators/OsmFeatureTagTranslator.cpp
@@ -0,0 +1,27 @@
+//
+// 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 2015 Stanciu Marius-Valeriu <[email protected]>
+//
+
+#include "OsmFeatureTagTranslator.h"
+
+
+namespace Marble
+{
+OsmFeatureTagTranslator::OsmFeatureTagTranslator() {
+//nothing to do
+}
+
+bool OsmFeatureTagTranslator::write( const Marble::GeoNode *node, GeoWriter &writer ) const
+{
+ // Write identifiers
+ bool const result = writeMid( node, writer );
+ return result;
+}
+
+}
diff --git a/src/plugins/runner/osm/translators/OsmFeatureTagTranslator.h b/src/plugins/runner/osm/translators/OsmFeatureTagTranslator.h
new file mode 100644
index 0000000..c6180e1
--- /dev/null
+++ b/src/plugins/runner/osm/translators/OsmFeatureTagTranslator.h
@@ -0,0 +1,37 @@
+//
+// 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 2015 Stanciu Marius-Valeriu <[email protected]>
+//
+
+#ifndef MARBLE_OSMFEATURETAGTRANSLATOR_H
+#define MARBLE_OSMFEATURETAGTRANSLATOR_H
+
+#include "GeoTagWriter.h"
+
+#include <QString>
+
+namespace Marble
+{
+
+// No registration needed for this class, as it is abstract.
+
+class OsmFeatureTagTranslator: public GeoTagWriter
+{
+public:
+ explicit OsmFeatureTagTranslator();
+
+ bool write( const GeoNode *node, GeoWriter& writer ) const;
+
+protected:
+ virtual bool writeMid( const GeoNode *node, GeoWriter& writer ) const = 0;
+};
+
+}
+
+#endif
+
diff --git a/src/plugins/runner/osm/translators/OsmPlacemarkTagTranslator.cpp b/src/plugins/runner/osm/translators/OsmPlacemarkTagTranslator.cpp
new file mode 100644
index 0000000..5870ba2
--- /dev/null
+++ b/src/plugins/runner/osm/translators/OsmPlacemarkTagTranslator.cpp
@@ -0,0 +1,65 @@
+//
+// 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 2015 Stanciu Marius-Valeriu <[email protected]>
+//
+
+//Self
+#include "OsmPlacemarkTagTranslator.h"
+
+//Marble
+#include "OsmObjectManager.h"
+#include "OsmNodeTagWriter.h"
+#include "OsmWayTagWriter.h"
+#include "OsmRelationTagWriter.h"
+#include "OsmElementDictionary.h"
+#include "GeoDataPoint.h"
+#include "GeoDataCoordinates.h"
+#include "GeoDataLineString.h"
+#include "GeoDataPolygon.h"
+#include "GeoDataPlacemark.h"
+#include "GeoDataGeometry.h"
+#include "GeoWriter.h"
+#include "GeoDataTypes.h"
+#include "osm/OsmPlacemarkData.h"
+
+namespace Marble
+{
+
+static GeoTagWriterRegistrar s_writerPlacemark( GeoTagWriter::QualifiedName( GeoDataTypes::GeoDataPlacemarkType,
+ osm::osmTag_version06 ), new OsmPlacemarkTagTranslator() );
+
+OsmPlacemarkTagTranslator::OsmPlacemarkTagTranslator():
+ OsmFeatureTagTranslator() {
+ //nothing to do
+}
+
+bool OsmPlacemarkTagTranslator::writeMid( const GeoNode *node, GeoWriter& writer ) const
+{
+ const GeoDataPlacemark *placemark = static_cast<const GeoDataPlacemark*>( node );
+ const OsmPlacemarkData &osmData = placemark->osmData();
+
+ if ( placemark->geometry()->nodeType() == GeoDataTypes::GeoDataPointType ) {
+ const GeoDataPoint* point = static_cast<const GeoDataPoint*>( placemark->geometry() );
+ const GeoDataCoordinates& coordinates = point->coordinates();
+ OsmNodeTagWriter::writeNode( coordinates, osmData, writer );
+ }
+ else if ( placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLineStringType ) {
+ const GeoDataLineString* lineString = static_cast<const GeoDataLineString*>( placemark->geometry() );
+ OsmWayTagWriter::writeWay( *lineString, osmData, writer );
+ }
+ else if ( placemark->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType ) {
+ const GeoDataPolygon* polygon = static_cast<const GeoDataPolygon*>( placemark->geometry() );
+ OsmRelationTagWriter::writeMultipolygon( *polygon, osmData, writer );
+ }
+
+ return true;
+}
+
+}
+
+
diff --git a/src/plugins/runner/osm/translators/OsmPlacemarkTagTranslator.h b/src/plugins/runner/osm/translators/OsmPlacemarkTagTranslator.h
new file mode 100644
index 0000000..1d7929f
--- /dev/null
+++ b/src/plugins/runner/osm/translators/OsmPlacemarkTagTranslator.h
@@ -0,0 +1,32 @@
+//
+// 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 2015 Stanciu Marius-Valeriu <[email protected]>
+//
+
+#ifndef MARBLE_OSMPLACEMARKTAGTRANSLATOR_H
+#define MARBLE_OSMPLACEMARKTAGTRANSLATOR_H
+
+#include "GeoTagWriter.h"
+#include "OsmFeatureTagTranslator.h"
+
+namespace Marble
+{
+
+class OsmPlacemarkTagTranslator : public OsmFeatureTagTranslator
+{
+public:
+ OsmPlacemarkTagTranslator();
+
+protected:
+ virtual bool writeMid( const GeoNode *node, GeoWriter& writer ) const;
+};
+
+}
+
+#endif
+