Skip to content

Commit

Permalink
Add unit tests for ArcGIS rest style parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 7, 2018
1 parent 6002cc4 commit 7a34152
Show file tree
Hide file tree
Showing 6 changed files with 459 additions and 58 deletions.
8 changes: 8 additions & 0 deletions src/providers/arcgisrest/CMakeLists.txt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 1 addition & 58 deletions src/providers/arcgisrest/qgsafsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
#include "qgssourceselectprovider.h"
#endif

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

#include <QEventLoop>
#include <QMessageBox>
#include <QNetworkRequest>
Expand Down Expand Up @@ -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 );
}


Expand Down
62 changes: 62 additions & 0 deletions src/providers/arcgisrest/qgsarcgisrestutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/providers/arcgisrest/qgsarcgisrestutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class QgsSymbol;
class QgsLineSymbol;
class QgsFillSymbol;
class QgsMarkerSymbol;
class QgsFeatureRenderer;

class QgsArcGisRestUtils
{
Expand All @@ -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 );
Expand Down
5 changes: 5 additions & 0 deletions tests/src/providers/CMakeLists.txt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 7a34152

Please sign in to comment.