Skip to content

Commit 207acbf

Browse files
author
wonder
committed
Update to OSM provider+plugin from Lukas Berka:
-osm provider code documentation; refactoring git-svn-id: http://svn.osgeo.org/qgis/trunk@11284 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 8a7b9c4 commit 207acbf

File tree

3 files changed

+167
-175
lines changed

3 files changed

+167
-175
lines changed

python/plugins/osm/DlgLoadOSM.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ def onOK(self):
135135
# remove layers of current data first
136136
QgsMapLayerRegistry.instance().removeMapLayer(self.canvas.currentLayer().getLayerID(),True)
137137

138-
tags = "&tags=yes"
139-
140138
if self.chkCustomRenderer.isChecked():
141139
styleFile=self.styleFiles[self.styleCombo.currentIndex()]
142140
style="&style="+styleFile
@@ -160,7 +158,7 @@ def onOK(self):
160158
self.setProperty("osm_stop_parsing",QVariant(0))
161159

162160
# add polygon layer
163-
polygonLayer = QgsVectorLayer(self.fname+"?type=polygon"+observer + tags + tag + style, basename+" polygons", "osm")
161+
polygonLayer = QgsVectorLayer(self.fname+"?type=polygon"+observer + tag + style, basename+" polygons", "osm")
164162

165163
if self.loadingCanceled:
166164
polygonLayer=None
@@ -174,7 +172,7 @@ def onOK(self):
174172
QgsMapLayerRegistry.instance().addMapLayer(polygonLayer)
175173

176174
# add line layer
177-
lineLayer = QgsVectorLayer(self.fname+"?type=line"+observer + tags + tag + style, basename+" lines", "osm")
175+
lineLayer = QgsVectorLayer(self.fname+"?type=line"+observer + tag + style, basename+" lines", "osm")
178176

179177
if self.loadingCanceled:
180178
lineLayer=None
@@ -188,7 +186,7 @@ def onOK(self):
188186
QgsMapLayerRegistry.instance().addMapLayer(lineLayer)
189187

190188
# add point layer
191-
pointLayer = QgsVectorLayer(self.fname+"?type=point"+observer + tags + tag + style, basename+" points", "osm")
189+
pointLayer = QgsVectorLayer(self.fname+"?type=point"+observer + tag + style, basename+" points", "osm")
192190

193191
if self.loadingCanceled:
194192
pointLayer=None

src/providers/osm/osmprovider.cpp

+5-89
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ QgsOSMDataProvider::QgsOSMDataProvider( QString uri )
5656
mDatabase = NULL;
5757
mInitObserver = NULL;
5858
mFeatureType = PointType; // default
59-
mTagsRetrieval = false;
59+
6060
// set default boundaries
6161
xMin = -DEFAULT_EXTENT;
6262
xMax = DEFAULT_EXTENT;
@@ -102,10 +102,6 @@ QgsOSMDataProvider::QgsOSMDataProvider( QString uri )
102102
mInitObserver = ( QObject* ) observerAddr;
103103
mInitObserver->setProperty( "osm_state", QVariant( 1 ) );
104104
}
105-
if ( propName == "tags" )
106-
{
107-
mTagsRetrieval = ( propValue == "yes" );
108-
}
109105
if ( propName == "tag" )
110106
{
111107
mCustomTagsList = propValue.split( "+" );
@@ -265,7 +261,7 @@ bool QgsOSMDataProvider::isDatabaseCompatibleWithInput( QString mFileName )
265261
{
266262
QFile osmFile( mFileName );
267263
QFileInfo osmFileInfo( osmFile );
268-
mOsmFileLastModif = osmFileInfo.lastModified();
264+
QDateTime mOsmFileLastModif = osmFileInfo.lastModified();
269265

270266
QString cmd = QString( "SELECT val FROM meta WHERE key='osm-file-last-modified';" );
271267
QByteArray cmd_bytes = cmd.toAscii();
@@ -522,7 +518,7 @@ bool QgsOSMDataProvider::fetchNode( QgsFeature& feature, sqlite3_stmt* stmt, boo
522518
geo[geo[0] == QgsApplication::NDR ? 1 : 4] = QGis::WKBPoint;
523519
std::memcpy( geo + 5, &selLon, sizeof( double ) );
524520
std::memcpy( geo + 13, &selLat, sizeof( double ) );
525-
feature.setGeometryAndOwnership(( unsigned char * )geo, sizeof( wkbPoint ) );
521+
feature.setGeometryAndOwnership(( unsigned char * )geo, 24 ); // 24 is size of wkb point structure!
526522
}
527523

528524
// fetch attributes
@@ -536,10 +532,7 @@ bool QgsOSMDataProvider::fetchNode( QgsFeature& feature, sqlite3_stmt* stmt, boo
536532
case UserAttr:
537533
feature.addAttribute( UserAttr, QString::fromUtf8( selUser ) ); break;
538534
case TagAttr:
539-
if ( mTagsRetrieval )
540-
feature.addAttribute( TagAttr, tagsForObject( "node", selId ) );
541-
else
542-
feature.addAttribute( TagAttr, QString() );
535+
feature.addAttribute(TagAttr, tagsForObject("node",selId));
543536
break;
544537

545538
default: // suppose it's a custom tag
@@ -652,10 +645,7 @@ bool QgsOSMDataProvider::fetchWay( QgsFeature& feature, sqlite3_stmt* stmt, bool
652645
feature.addAttribute( UserAttr, QString::fromUtf8( selUser ) );
653646
break;
654647
case TagAttr:
655-
if ( mTagsRetrieval )
656-
feature.addAttribute( TagAttr, tagsForObject( "way", selId ) );
657-
else
658-
feature.addAttribute( TagAttr, QString() );
648+
feature.addAttribute(TagAttr, tagsForObject("way",selId));
659649
break;
660650
default: // suppose it's a custom tag
661651
if ( *iter >= CustomTagAttr && *iter < CustomTagAttr + mCustomTagsList.count() )
@@ -670,32 +660,6 @@ bool QgsOSMDataProvider::fetchWay( QgsFeature& feature, sqlite3_stmt* stmt, bool
670660
}
671661

672662

673-
int QgsOSMDataProvider::relationMemberCount( int relId )
674-
{
675-
const char *zSql = "select count(*) from relation_member rm, way_member wm, node n where rm.relation_id=? and rm.member_type='way' and rm.member_id=wm.way_id and wm.node_id=n.id and wm.u=1 and n.u=1 and rm.u=1;";
676-
sqlite3_stmt *pStmt;
677-
int rc = sqlite3_prepare_v2( mDatabase, zSql, -1, &pStmt, 0 );
678-
679-
if ( rc != SQLITE_OK )
680-
{
681-
QgsDebugMsg( QString( "Failed (1)." ) );
682-
return 0;
683-
}
684-
685-
sqlite3_bind_int( pStmt, 1, relId );
686-
687-
rc = sqlite3_step( pStmt );
688-
if ( rc != SQLITE_ROW )
689-
{
690-
QgsDebugMsg( QString( "Failed (2)." ) );
691-
return 0;
692-
}
693-
694-
int memberCnt = sqlite3_column_int( pStmt, 0 );
695-
sqlite3_finalize( pStmt );
696-
return memberCnt;
697-
}
698-
699663

700664
QString QgsOSMDataProvider::tagForObject( const char* type, int id, QString tagKey )
701665
{
@@ -945,54 +909,6 @@ bool QgsOSMDataProvider::changeAttributeValues( const QgsChangedAttributesMap &
945909
}
946910

947911

948-
bool QgsOSMDataProvider::changeGeometryValue( const int & featid, QgsGeometry & geom )
949-
{
950-
if ( mFeatureType == PointType )
951-
{
952-
QgsDebugMsg( QString( "Changing geometry of point with id=%1." ).arg( featid ) );
953-
QgsPoint point = geom.asPoint();
954-
955-
const char *zSql = "UPDATE node SET lat=?, lon=?, status='U' WHERE id=? AND u=1";
956-
sqlite3_stmt *pStmt;
957-
int rc;
958-
959-
rc = sqlite3_prepare_v2( mDatabase, zSql, -1, &pStmt, 0 );
960-
if ( rc != SQLITE_OK )
961-
return rc;
962-
963-
sqlite3_bind_double( pStmt, 1, point.y() );
964-
sqlite3_bind_double( pStmt, 2, point.x() );
965-
sqlite3_bind_int( pStmt, 3, featid );
966-
967-
rc = sqlite3_step( pStmt );
968-
rc = sqlite3_finalize( pStmt );
969-
}
970-
else if ( mFeatureType == LineType )
971-
{
972-
QgsDebugMsg( QString( "Changing geometry of way with id=%1." ).arg( featid ) );
973-
QgsPolyline way = geom.asPolyline();
974-
unsigned char *wkb = geom.asWkb();
975-
976-
const char *zSql = "UPDATE way SET wkb=?, membercnt=?, status='U' WHERE id=? AND u=1";
977-
sqlite3_stmt *pStmt;
978-
int rc;
979-
980-
rc = sqlite3_prepare_v2( mDatabase, zSql, -1, &pStmt, 0 );
981-
if ( rc != SQLITE_OK )
982-
return rc;
983-
984-
sqlite3_bind_blob( pStmt, 1, wkb, 9 + 16 * way.size(), SQLITE_STATIC );
985-
sqlite3_bind_int( pStmt, 2, way.size() );
986-
sqlite3_bind_int( pStmt, 3, featid );
987-
988-
rc = sqlite3_step( pStmt );
989-
rc = sqlite3_finalize( pStmt );
990-
991-
}
992-
return true;
993-
}
994-
995-
996912
int QgsOSMDataProvider::capabilities() const
997913
{
998914
return QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;

0 commit comments

Comments
 (0)