Skip to content

Commit d6495ab

Browse files
committed
wms provider:
* support JSON for feature info * implement feature info for WMTS * cleanup metadata display
1 parent 6691332 commit d6495ab

9 files changed

+772
-434
lines changed

python/core/raster/qgsraster.sip

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ class QgsRaster
3333

3434
enum IdentifyFormat
3535
{
36-
IdentifyFormatUndefined = 0,
37-
IdentifyFormatValue = 1, // numerical pixel value
38-
IdentifyFormatText = 0x2, // WMS text
39-
IdentifyFormatHtml = 0x4, // WMS HTML
40-
IdentifyFormatFeature = 0x8 // WMS GML -> feature
36+
IdentifyFormatUndefined,
37+
IdentifyFormatValue,
38+
IdentifyFormatText,
39+
IdentifyFormatHtml,
40+
IdentifyFormatFeature,
4141
};
4242

4343
// Progress types

python/core/raster/qgsrasterinterface.sip

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class QgsRasterInterface
4141
%End
4242

4343
public:
44+
//! If you add to this, please also add to capabilitiesString()
4445
enum Capability
4546
{
4647
NoCapabilities,
@@ -52,7 +53,7 @@ class QgsRasterInterface
5253
IdentifyValue,
5354
IdentifyText,
5455
IdentifyHtml,
55-
IdentifyFeature
56+
IdentifyFeature,
5657
};
5758

5859
QgsRasterInterface( QgsRasterInterface * input = 0 );

src/core/qgsproviderregistry.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ QgsProviderRegistry::~QgsProviderRegistry()
208208

209209
while ( it != mProviders.end() )
210210
{
211+
QgsDebugMsg( QString( "cleanup:%1" ).arg( it->first ) );
211212
QString lib = it->second->library();
212213
QLibrary myLib( lib );
213214
if ( myLib.isLoaded() )

src/core/raster/qgsraster.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ class CORE_EXPORT QgsRaster
5353

5454
enum IdentifyFormat
5555
{
56-
IdentifyFormatUndefined = 0,
57-
IdentifyFormatValue = 1, // numerical pixel value
56+
IdentifyFormatUndefined = 0,
57+
IdentifyFormatValue = 1, // numerical pixel value
5858
IdentifyFormatText = 1 << 1, // WMS text
5959
IdentifyFormatHtml = 1 << 2, // WMS HTML
60-
IdentifyFormatFeature = 1 << 3 // WMS GML -> feature
60+
IdentifyFormatFeature = 1 << 3, // WMS GML/JSON -> feature
6161
};
6262

6363
// Progress types

src/core/raster/qgsrasterinterface.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ class CORE_EXPORT QgsRasterInterface
4040
//! If you add to this, please also add to capabilitiesString()
4141
enum Capability
4242
{
43-
NoCapabilities = 0,
44-
Size = 1 << 1, // original data source size (and thus resolution) is known, it is not always available, for example for WMS
45-
Create = 1 << 2, // create new datasets
46-
Remove = 1 << 3, // delete datasets
47-
BuildPyramids = 1 << 4, // supports building of pyramids (overviews)
48-
Identify = 1 << 5, // at least one identify format supported
49-
IdentifyValue = 1 << 6, // numerical values
50-
IdentifyText = 1 << 7, // WMS text
51-
IdentifyHtml = 1 << 8, // WMS HTML
52-
IdentifyFeature = 1 << 9 // WMS GML -> feature
43+
NoCapabilities = 0,
44+
Size = 1 << 1, // original data source size (and thus resolution) is known, it is not always available, for example for WMS
45+
Create = 1 << 2, // create new datasets
46+
Remove = 1 << 3, // delete datasets
47+
BuildPyramids = 1 << 4, // supports building of pyramids (overviews)
48+
Identify = 1 << 5, // at least one identify format supported
49+
IdentifyValue = 1 << 6, // numerical values
50+
IdentifyText = 1 << 7, // WMS text
51+
IdentifyHtml = 1 << 8, // WMS HTML
52+
IdentifyFeature = 1 << 9, // WMS GML -> feature
5353
};
5454

5555
QgsRasterInterface( QgsRasterInterface * input = 0 );

src/gui/qgsmaptoolidentify.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,13 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
418418
bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, QgsRasterLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel )
419419
{
420420
QgsDebugMsg( "point = " + point.toString() );
421-
if ( !layer ) return false;
421+
if ( !layer )
422+
return false;
422423

423424
QgsRasterDataProvider *dprovider = layer->dataProvider();
424425
int capabilities = dprovider->capabilities();
425426
if ( !dprovider || !( capabilities & QgsRasterDataProvider::Identify ) )
426-
{
427427
return false;
428-
}
429428

430429
QgsPoint pointInCanvasCrs = point;
431430
try
@@ -571,8 +570,6 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
571570
if ( featureType.compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.isEmpty() )
572571
{
573572
labels << featureType;
574-
575-
576573
}
577574

578575
QMap< QString, QString > derAttributes = derivedAttributes;

src/providers/wms/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
SET (WMS_SRCS
32
qgswmscapabilities.cpp
43
qgswmsprovider.cpp
@@ -22,15 +21,18 @@ QT4_WRAP_CPP (WMS_MOC_SRCS ${WMS_MOC_HDRS})
2221

2322
INCLUDE_DIRECTORIES( . ../../core ../../core/raster ../../gui
2423
${CMAKE_CURRENT_BINARY_DIR}/../../ui
25-
${GDAL_INCLUDE_DIR} # temporary solution until gdal get removed completely form QgsRasterLayer
24+
${GDAL_INCLUDE_DIR}
2625
${GEOS_INCLUDE_DIR}
26+
${QT_QTSCRIPT_INCLUDE_DIR}
2727
)
2828

2929
ADD_LIBRARY(wmsprovider MODULE ${WMS_SRCS} ${WMS_MOC_SRCS})
3030

3131
TARGET_LINK_LIBRARIES(wmsprovider
3232
qgis_core
3333
qgis_gui
34+
${QT_QTSCRIPT_LIBRARY}
35+
${GDAL_LIBRARY} # for OGR_G_CreateGeometryFromJson()
3436
)
3537

3638
INSTALL (TARGETS wmsprovider

src/providers/wms/qgswmscapabilities.cpp

+59-1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ bool QgsWmsCapabilities::parseResponse( const QByteArray& response, const QgsWms
171171
format = QgsRaster::IdentifyFormatFeature; // 1.0
172172
else if ( f == "application/vnd.ogc.gml" )
173173
format = QgsRaster::IdentifyFormatFeature;
174+
else if ( f == "application/json" )
175+
format = QgsRaster::IdentifyFormatFeature;
174176
else if ( f.contains( "gml", Qt::CaseInsensitive ) )
175177
format = QgsRaster::IdentifyFormatFeature;
176178

@@ -349,7 +351,7 @@ void QgsWmsCapabilities::parseOnlineResource( QDomElement const & e, QgsWmsOnlin
349351
{
350352
QgsDebugMsg( "entering." );
351353

352-
onlineResourceAttribute.xlinkHref = e.attribute( "xlink:href" );
354+
onlineResourceAttribute.xlinkHref = QUrl::fromEncoded( e.attribute( "xlink:href" ).toUtf8() ).toString();
353355

354356
QgsDebugMsg( "exiting." );
355357
}
@@ -1470,7 +1472,36 @@ void QgsWmsCapabilities::parseWMTSContents( QDomElement const &e )
14701472

14711473
for ( QDomElement e1 = e0.firstChildElement( "InfoFormat" ); !e1.isNull(); e1 = e1.nextSiblingElement( "InfoFormat" ) )
14721474
{
1475+
QString format = e1.text();
1476+
14731477
l.infoFormats << e1.text();
1478+
1479+
QgsRaster::IdentifyFormat fmt = QgsRaster::IdentifyFormatUndefined;
1480+
1481+
QgsDebugMsg( QString( "format=%1" ).arg( format ) );
1482+
1483+
if ( format == "MIME" )
1484+
fmt = QgsRaster::IdentifyFormatText; // 1.0
1485+
else if ( format == "text/plain" )
1486+
fmt = QgsRaster::IdentifyFormatText;
1487+
else if ( format == "text/html" )
1488+
fmt = QgsRaster::IdentifyFormatHtml;
1489+
else if ( format.startsWith( "GML." ) )
1490+
fmt = QgsRaster::IdentifyFormatFeature; // 1.0
1491+
else if ( format == "application/vnd.ogc.gml" )
1492+
fmt = QgsRaster::IdentifyFormatFeature;
1493+
else if ( format.contains( "gml", Qt::CaseInsensitive ) )
1494+
fmt = QgsRaster::IdentifyFormatFeature;
1495+
else if ( format == "application/json" )
1496+
fmt = QgsRaster::IdentifyFormatFeature;
1497+
else
1498+
{
1499+
QgsDebugMsg( QString( "Unsupported featureInfoUrl format: %1" ).arg( format ) );
1500+
continue;
1501+
}
1502+
1503+
QgsDebugMsg( QString( "fmt=%1" ).arg( fmt ) );
1504+
mIdentifyFormats.insert( fmt, format );
14741505
}
14751506

14761507
for ( QDomElement e1 = e0.firstChildElement( "Dimension" ); !e1.isNull(); e1 = e1.nextSiblingElement( "Dimension" ) )
@@ -1595,6 +1626,33 @@ void QgsWmsCapabilities::parseWMTSContents( QDomElement const &e )
15951626
else if ( resourceType == "FeatureInfo" )
15961627
{
15971628
l.getFeatureInfoURLs.insert( format, tmpl );
1629+
1630+
QgsRaster::IdentifyFormat fmt = QgsRaster::IdentifyFormatUndefined;
1631+
1632+
QgsDebugMsg( QString( "format=%1" ).arg( format ) );
1633+
1634+
if ( format == "MIME" )
1635+
fmt = QgsRaster::IdentifyFormatText; // 1.0
1636+
else if ( format == "text/plain" )
1637+
fmt = QgsRaster::IdentifyFormatText;
1638+
else if ( format == "text/html" )
1639+
fmt = QgsRaster::IdentifyFormatHtml;
1640+
else if ( format.startsWith( "GML." ) )
1641+
fmt = QgsRaster::IdentifyFormatFeature; // 1.0
1642+
else if ( format == "application/vnd.ogc.gml" )
1643+
fmt = QgsRaster::IdentifyFormatFeature;
1644+
else if ( format.contains( "gml", Qt::CaseInsensitive ) )
1645+
fmt = QgsRaster::IdentifyFormatFeature;
1646+
else if ( format == "application/json" )
1647+
fmt = QgsRaster::IdentifyFormatFeature;
1648+
else
1649+
{
1650+
QgsDebugMsg( QString( "Unsupported featureInfoUrl format: %1" ).arg( format ) );
1651+
continue;
1652+
}
1653+
1654+
QgsDebugMsg( QString( "fmt=%1" ).arg( fmt ) );
1655+
mIdentifyFormats.insert( fmt, format );
15981656
}
15991657
else
16001658
{

0 commit comments

Comments
 (0)