Skip to content
Permalink
Browse files

Merge pull request #34989 from rldhont/tests-geojson-stringtofields-m…

…ulti-features

[Tests] GeoJSON stringToFields with a feature collection
  • Loading branch information
rldhont committed Mar 11, 2020
2 parents c2f2900 + 9ae479a commit 912ffdec3ee0f19bc090423176987da4c4c01705
Showing with 16 additions and 0 deletions.
  1. +8 −0 tests/src/core/testqgsogrutils.cpp
  2. +8 −0 tests/src/python/test_qgsjsonutils.py
@@ -479,6 +479,14 @@ void TestQgsOgrUtils::stringToFields()
QCOMPARE( fields.at( 0 ).type(), QVariant::String );
QCOMPARE( fields.at( 1 ).name(), QString( "height" ) );
QCOMPARE( fields.at( 1 ).type(), QVariant::Double );

// geojson string with 2 features
fields = QgsOgrUtils::stringToFields( QStringLiteral( "{ \"type\": \"FeatureCollection\",\"features\":[{\n\"type\": \"Feature\",\"geometry\": {\"type\": \"Point\",\"coordinates\": [125, 10]},\"properties\": {\"name\": \"Dinagat Islands\",\"height\":5.5}}, {\n\"type\": \"Feature\",\"geometry\": {\"type\": \"Point\",\"coordinates\": [110, 20]},\"properties\": {\"name\": \"Henry Gale Island\",\"height\":6.5}}]}" ), QTextCodec::codecForName( "System" ) );
QCOMPARE( fields.count(), 2 );
QCOMPARE( fields.at( 0 ).name(), QString( "name" ) );
QCOMPARE( fields.at( 0 ).type(), QVariant::String );
QCOMPARE( fields.at( 1 ).name(), QString( "height" ) );
QCOMPARE( fields.at( 1 ).type(), QVariant::Double );
}


@@ -96,6 +96,14 @@ def testStringToFields(self):
self.assertEqual(fields[1].name(), "height")
self.assertEqual(fields[1].type(), QVariant.Double)

# geojson string with 2 features
fields = QgsJsonUtils.stringToFields('{ "type": "FeatureCollection","features":[{\n"type": "Feature","geometry": {"type": "Point","coordinates": [125, 10]},"properties": {"name": "Dinagat Islands","height":5.5}}, {\n"type": "Feature","geometry": {"type": "Point","coordinates": [110, 20]},"properties": {"name": "Henry Gale Island","height":6.5}}]}', codec)
self.assertEqual(fields.count(), 2)
self.assertEqual(fields[0].name(), "name")
self.assertEqual(fields[0].type(), QVariant.String)
self.assertEqual(fields[1].name(), "height")
self.assertEqual(fields[1].type(), QVariant.Double)

def testEncodeValue(self):
""" test encoding various values for use in GeoJSON strings """
self.assertEqual(QgsJsonUtils.encodeValue(NULL), 'null')

0 comments on commit 912ffde

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