Skip to content
Permalink
Browse files

Add unit tests for ArcGIS rest style parsing

  • Loading branch information
nyalldawson committed Mar 7, 2018
1 parent 6002cc4 commit 7a3415257b4a82af324136dc06914adfad5d8f66
@@ -53,16 +53,24 @@ ENDIF ()

QT5_WRAP_CPP (AFS_MOC_SRCS ${AFS_MOC_HDRS})

ADD_LIBRARY (arcgisfeatureserverprovider_a STATIC ${AFS_SRCS} ${AFS_MOC_SRCS})
ADD_LIBRARY(arcgisfeatureserverprovider MODULE ${AFS_SRCS} ${AFS_MOC_SRCS})

TARGET_LINK_LIBRARIES(arcgisfeatureserverprovider
qgis_core
)

TARGET_LINK_LIBRARIES (arcgisfeatureserverprovider_a
qgis_core
)

IF (WITH_GUI)
TARGET_LINK_LIBRARIES(arcgisfeatureserverprovider
qgis_gui
)
TARGET_LINK_LIBRARIES(arcgisfeatureserverprovider_a
qgis_gui
)
ENDIF ()

INSTALL (TARGETS arcgisfeatureserverprovider
@@ -28,9 +28,6 @@
#include "qgssourceselectprovider.h"
#endif

#include "qgssinglesymbolrenderer.h"
#include "qgscategorizedsymbolrenderer.h"

#include <QEventLoop>
#include <QMessageBox>
#include <QNetworkRequest>
@@ -295,61 +292,7 @@ void QgsAfsProvider::reloadData()

QgsFeatureRenderer *QgsAfsProvider::createRenderer( const QVariantMap & ) const
{
const QString type = mRendererDataMap.value( QStringLiteral( "type" ) ).toString();
if ( type == QLatin1String( "simple" ) )
{
const QVariantMap symbolProps = mRendererDataMap.value( QStringLiteral( "symbol" ) ).toMap();
std::unique_ptr< QgsSymbol > symbol = QgsArcGisRestUtils::parseEsriSymbolJson( symbolProps );
if ( symbol )
return new QgsSingleSymbolRenderer( symbol.release() );
else
return nullptr;
}
else if ( type == QLatin1String( "uniqueValue" ) )
{
const QString attribute = mRendererDataMap.value( QStringLiteral( "field1" ) ).toString();
// TODO - handle field2, field3
const QVariantList categories = mRendererDataMap.value( QStringLiteral( "uniqueValueInfos" ) ).toList();
QgsCategoryList categoryList;
for ( const QVariant &category : categories )
{
const QVariantMap categoryData = category.toMap();
const QString value = categoryData.value( QStringLiteral( "value" ) ).toString();
const QString label = categoryData.value( QStringLiteral( "label" ) ).toString();
std::unique_ptr< QgsSymbol > symbol = QgsArcGisRestUtils::parseEsriSymbolJson( categoryData.value( QStringLiteral( "symbol" ) ).toMap() );
if ( symbol )
{
categoryList.append( QgsRendererCategory( value, symbol.release(), label ) );
}
}

std::unique_ptr< QgsSymbol > defaultSymbol = QgsArcGisRestUtils::parseEsriSymbolJson( mRendererDataMap.value( QStringLiteral( "defaultSymbol" ) ).toMap() );
if ( defaultSymbol )
{
categoryList.append( QgsRendererCategory( QVariant(), defaultSymbol.release(), mRendererDataMap.value( QStringLiteral( "defaultLabel" ) ).toString() ) );
}

if ( categoryList.empty() )
return nullptr;

return new QgsCategorizedSymbolRenderer( attribute, categoryList );
}
else if ( type == QLatin1String( "classBreaks" ) )
{
// currently unsupported
return nullptr;
}
else if ( type == QLatin1String( "heatmap" ) )
{
// currently unsupported
return nullptr;
}
else if ( type == QLatin1String( "vectorField" ) )
{
// currently unsupported
return nullptr;
}
return nullptr;
return QgsArcGisRestUtils::parseEsriRenderer( mRendererDataMap );
}


@@ -33,6 +33,9 @@
#include "qgslinesymbollayer.h"
#include "qgsfillsymbollayer.h"
#include "qgsmarkersymbollayer.h"
#include "qgsrenderer.h"
#include "qgssinglesymbolrenderer.h"
#include "qgscategorizedsymbolrenderer.h"
#include <QEventLoop>
#include <QNetworkRequest>
#include <QNetworkReply>
@@ -641,6 +644,65 @@ std::unique_ptr<QgsMarkerSymbol> QgsArcGisRestUtils::parseEsriMarkerSymbolJson(
return symbol;
}

QgsFeatureRenderer *QgsArcGisRestUtils::parseEsriRenderer( const QVariantMap &rendererData )
{
const QString type = rendererData.value( QStringLiteral( "type" ) ).toString();
if ( type == QLatin1String( "simple" ) )
{
const QVariantMap symbolProps = rendererData.value( QStringLiteral( "symbol" ) ).toMap();
std::unique_ptr< QgsSymbol > symbol = parseEsriSymbolJson( symbolProps );
if ( symbol )
return new QgsSingleSymbolRenderer( symbol.release() );
else
return nullptr;
}
else if ( type == QLatin1String( "uniqueValue" ) )
{
const QString attribute = rendererData.value( QStringLiteral( "field1" ) ).toString();
// TODO - handle field2, field3
const QVariantList categories = rendererData.value( QStringLiteral( "uniqueValueInfos" ) ).toList();
QgsCategoryList categoryList;
for ( const QVariant &category : categories )
{
const QVariantMap categoryData = category.toMap();
const QString value = categoryData.value( QStringLiteral( "value" ) ).toString();
const QString label = categoryData.value( QStringLiteral( "label" ) ).toString();
std::unique_ptr< QgsSymbol > symbol = QgsArcGisRestUtils::parseEsriSymbolJson( categoryData.value( QStringLiteral( "symbol" ) ).toMap() );
if ( symbol )
{
categoryList.append( QgsRendererCategory( value, symbol.release(), label ) );
}
}

std::unique_ptr< QgsSymbol > defaultSymbol = parseEsriSymbolJson( rendererData.value( QStringLiteral( "defaultSymbol" ) ).toMap() );
if ( defaultSymbol )
{
categoryList.append( QgsRendererCategory( QVariant(), defaultSymbol.release(), rendererData.value( QStringLiteral( "defaultLabel" ) ).toString() ) );
}

if ( categoryList.empty() )
return nullptr;

return new QgsCategorizedSymbolRenderer( attribute, categoryList );
}
else if ( type == QLatin1String( "classBreaks" ) )
{
// currently unsupported
return nullptr;
}
else if ( type == QLatin1String( "heatmap" ) )
{
// currently unsupported
return nullptr;
}
else if ( type == QLatin1String( "vectorField" ) )
{
// currently unsupported
return nullptr;
}
return nullptr;
}

QColor QgsArcGisRestUtils::parseEsriColorJson( const QVariant &colorData )
{
const QVariantList colorParts = colorData.toList();
@@ -31,6 +31,7 @@ class QgsSymbol;
class QgsLineSymbol;
class QgsFillSymbol;
class QgsMarkerSymbol;
class QgsFeatureRenderer;

class QgsArcGisRestUtils
{
@@ -54,6 +55,7 @@ class QgsArcGisRestUtils
static std::unique_ptr< QgsLineSymbol > parseEsriLineSymbolJson( const QVariantMap &symbolData );
static std::unique_ptr< QgsFillSymbol > parseEsriFillSymbolJson( const QVariantMap &symbolData );
static std::unique_ptr< QgsMarkerSymbol > parseEsriMarkerSymbolJson( const QVariantMap &symbolData );
static QgsFeatureRenderer *parseEsriRenderer( const QVariantMap &rendererData );

static QColor parseEsriColorJson( const QVariant &colorData );
static Qt::PenStyle parseEsriLineStyle( const QString &style );
@@ -11,8 +11,10 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/core/geometry
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/symbology
${CMAKE_SOURCE_DIR}/src/providers/wms
${CMAKE_SOURCE_DIR}/src/providers/postgres
${CMAKE_SOURCE_DIR}/src/providers/arcgisrest
${CMAKE_SOURCE_DIR}/src/test
${CMAKE_BINARY_DIR}/src/core
)
@@ -64,6 +66,9 @@ SET_TARGET_PROPERTIES(qgis_wcsprovidertest PROPERTIES
COMPILE_FLAGS "-DTEST_SERVER_URL=\\\"${TEST_SERVER_URL}\\\""
)

ADD_QGIS_TEST(arcgisrestutilstest testqgsarcgisrestutils.cpp)
TARGET_LINK_LIBRARIES(qgis_arcgisrestutilstest arcgisfeatureserverprovider_a)

ADD_QGIS_TEST(gdalprovidertest testqgsgdalprovider.cpp)

ADD_QGIS_TEST(ogrprovidertest testqgsogrprovider.cpp)

0 comments on commit 7a34152

Please sign in to comment.
You can’t perform that action at this time.