summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <[email protected]>2015-08-29 17:00:08 +0200
committerDennis Nienhüser <[email protected]>2015-08-29 17:00:08 +0200
commit8da4cb55941fd578fb373d6f832b278f3e8e038d (patch)
tree5b83620c13eaa9877965b6146c5dfbb20c8fc258
parent0ddf8013fc397c42a766b8367b24b33befaf0407 (diff)
Extract more fields from OSM.
-rw-r--r--src/plugins/runner/nominatim-reversegeocoding/OsmNominatimReverseGeocodingRunner.cpp28
-rw-r--r--src/plugins/runner/nominatim-reversegeocoding/OsmNominatimReverseGeocodingRunner.h4
-rw-r--r--src/plugins/runner/nominatim-search/OsmNominatimSearchRunner.cpp17
-rw-r--r--src/plugins/runner/nominatim-search/OsmNominatimSearchRunner.h4
4 files changed, 32 insertions, 21 deletions
diff --git a/src/plugins/runner/nominatim-reversegeocoding/OsmNominatimReverseGeocodingRunner.cpp b/src/plugins/runner/nominatim-reversegeocoding/OsmNominatimReverseGeocodingRunner.cpp
index 8ac7f55..93c0083 100644
--- a/src/plugins/runner/nominatim-reversegeocoding/OsmNominatimReverseGeocodingRunner.cpp
+++ b/src/plugins/runner/nominatim-reversegeocoding/OsmNominatimReverseGeocodingRunner.cpp
@@ -107,19 +107,9 @@ void OsmNominatimRunner::handleResult( QNetworkReply* reply )
placemark.setAddress( address );
placemark.setCoordinate( m_coordinates );
- QDomNodeList details = root.elementsByTagName( "addressparts" );
- if ( details.size() == 1 ) {
- GeoDataExtendedData extendedData;
- addData( details, "road", &extendedData );
- addData( details, "house_number", &extendedData );
- addData( details, "village", &extendedData );
- addData( details, "city", &extendedData );
- addData( details, "county", &extendedData );
- addData( details, "state", &extendedData );
- addData( details, "postcode", &extendedData );
- addData( details, "country", &extendedData );
- placemark.setExtendedData( extendedData );
- }
+ QDomNode details = root.firstChildElement( "addressparts" );
+ GeoDataExtendedData extendedData = extractChildren( details );
+ placemark.setExtendedData( extendedData );
emit reverseGeocodingFinished( m_coordinates, placemark );
} else {
@@ -127,13 +117,15 @@ void OsmNominatimRunner::handleResult( QNetworkReply* reply )
}
}
-void OsmNominatimRunner::addData( const QDomNodeList &node, const QString &key, GeoDataExtendedData *extendedData )
+GeoDataExtendedData OsmNominatimRunner::extractChildren(const QDomNode &node)
{
- QDomNodeList child = node.item( 0 ).toElement().elementsByTagName( key );
- if ( child.size() > 0 ) {
- QString text = child.item( 0 ).toElement().text();
- extendedData->addValue( GeoDataData( key, text ) );
+ GeoDataExtendedData data;
+ QDomNodeList nodes = node.childNodes();
+ for (int i=0, n=nodes.length(); i<n; ++i) {
+ QDomNode child = nodes.item(i);
+ data.addValue( GeoDataData( child.nodeName(), child.toElement().text() ) );
}
+ return data;
}
} // namespace Marble
diff --git a/src/plugins/runner/nominatim-reversegeocoding/OsmNominatimReverseGeocodingRunner.h b/src/plugins/runner/nominatim-reversegeocoding/OsmNominatimReverseGeocodingRunner.h
index 400621f..dc7baef 100644
--- a/src/plugins/runner/nominatim-reversegeocoding/OsmNominatimReverseGeocodingRunner.h
+++ b/src/plugins/runner/nominatim-reversegeocoding/OsmNominatimReverseGeocodingRunner.h
@@ -20,7 +20,7 @@
#include <QNetworkRequest>
class QNetworkReply;
-class QDomNodeList;
+class QDomNode;
namespace Marble
{
@@ -47,7 +47,7 @@ private Q_SLOTS:
void startReverseGeocoding();
private:
- static void addData( const QDomNodeList &node, const QString &key, GeoDataExtendedData *extendedData );
+ static GeoDataExtendedData extractChildren(const QDomNode &node);
QNetworkAccessManager m_manager;
diff --git a/src/plugins/runner/nominatim-search/OsmNominatimSearchRunner.cpp b/src/plugins/runner/nominatim-search/OsmNominatimSearchRunner.cpp
index a1596f4..287545d 100644
--- a/src/plugins/runner/nominatim-search/OsmNominatimSearchRunner.cpp
+++ b/src/plugins/runner/nominatim-search/OsmNominatimSearchRunner.cpp
@@ -90,6 +90,17 @@ void OsmNominatimRunner::startSearch()
this, SLOT(returnNoResults()));
}
+GeoDataExtendedData OsmNominatimRunner::extractChildren(const QDomNode &node)
+{
+ GeoDataExtendedData data;
+ QDomNodeList nodes = node.childNodes();
+ for (int i=0, n=nodes.length(); i<n; ++i) {
+ QDomNode child = nodes.item(i);
+ data.addValue( GeoDataData( child.nodeName(), child.toElement().text() ) );
+ }
+ return data;
+}
+
void OsmNominatimRunner::handleResult( QNetworkReply* reply )
{
@@ -112,8 +123,13 @@ void OsmNominatimRunner::handleResult( QNetworkReply* reply )
QString key = attributes.namedItem("class").nodeValue();
QString value = attributes.namedItem("type").nodeValue();
+ GeoDataExtendedData placemarkData = extractChildren(place);
+ placemarkData.addValue( GeoDataData( "class", key ) );
+ placemarkData.addValue( GeoDataData( "type", value ) );
+
QString name = place.firstChildElement(value).text();
QString road = place.firstChildElement("road").text();
+ placemarkData.addValue( GeoDataData( "name", name ) );
QString city = place.firstChildElement("city").text();
if( city.isEmpty() ) {
@@ -182,6 +198,7 @@ void OsmNominatimRunner::handleResult( QNetworkReply* reply )
placemark->setCoordinate( lon.toDouble(), lat.toDouble(), 0, GeoDataCoordinates::Degree );
GeoDataFeature::GeoDataVisualCategory category = OsmPresetLibrary::OsmVisualCategory( key + '=' + value );
placemark->setVisualCategory( category );
+ placemark->setExtendedData(placemarkData);
placemarks << placemark;
}
}
diff --git a/src/plugins/runner/nominatim-search/OsmNominatimSearchRunner.h b/src/plugins/runner/nominatim-search/OsmNominatimSearchRunner.h
index b270052..0274bba 100644
--- a/src/plugins/runner/nominatim-search/OsmNominatimSearchRunner.h
+++ b/src/plugins/runner/nominatim-search/OsmNominatimSearchRunner.h
@@ -21,6 +21,7 @@
class QNetworkReply;
class QDomNodeList;
+class QDomNode;
namespace Marble
{
@@ -45,8 +46,9 @@ private Q_SLOTS:
void startSearch();
private:
- QNetworkAccessManager m_manager;
+ static GeoDataExtendedData extractChildren(const QDomNode &node);
+ QNetworkAccessManager m_manager;
QNetworkRequest m_request;
};