FeatureCollection.FromJson just doesn't work for me

834
4
Jump to solution
08-21-2021 09:54 PM
MarcHillman
New Contributor III

I have, for years, been trying to get FeatureCollection.FromJson to work, but it just doesn't. I must be doing something simple wrong. I am using Microsoft Visual Studio Community 2019 (VB.NET), and latest Esri.ArcGISRuntime 100.11.2.

I have a simple code fragment
Dim fs As New FeatureCollection
fs = FeatureCollection.FromJson(responseStr)

responseStr contains the geojson string below. After execution, fs is empty with no runtime failure.

I have had to resort to using the Newtonsoft.Json package to decode the json, which has no problem with it.

What am I doing wrong? (How can something so simple be so hard?)

 

 

 

{
	"type": "FeatureCollection",
	"crs": {
		"type": "name",
		"properties": {
			"name": "EPSG:4326"
		}
	},
	"features": [
		{
			"type": "Feature",
			"id": 1158,
			"geometry": null,
			"properties": {
				"objectid": 1158,
				"featuretype": "Railway Station",
				"type": 1,
				"name": "ABERDEEN",
				"railstationstatus": "Operational",
				"featurereliability": 1103587200000,
				"featuresource": "SP5PAN2P5_388415_21122004",
				"attributereliability": 1189728000000,
				"attributesource": "GEOSCIENCE AUSTRALIA",
				"planimetricaccuracy": 10,
				"revised": 1239667200000,
				"gaid": null,
				"stkehdrid": null,
				"stkehdrname": null,
				"upperscale": 5000000,
				"uscertainty": "Definite",
				"textnote": null,
				"editcode": 88,
				"symbol100k": 222,
				"symbol250k": 222,
				"symbolwac1mil": 2,
				"symbol2_5mil": 2,
				"symbol5mil": 2
			}
		}
	]
}

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
dotMorten_esri
Esri Frequent Contributor

There is no built-in GeoJson support in the runtime, so you'd need your own parser for GeoJson. The method you're using expects json formatted as FeatureCollection JSON. The link you pointed to above, you can use f=json instead of f=geojson to get the format that runtime uses - however that is the features part of the feature collection json, which is only one part of the json needed for a feature collection (you'd also need the feature set schema which comes from the feature service). The FromJson method you're using is mostly meant to be used together with the ToJson method to store feature collections.

Is there a reason you're not using the ServiceFeatureTable class, which will perform all the server rest queries and parsing for you?

View solution in original post

4 Replies
DominiqueBroux
Esri Frequent Contributor

Your JSON string is not an ArcGIS Feature Collection.
ArcGIS Feature Collections are defined here: https://developers.arcgis.com/web-map-specification/objects/featureCollection/

This is more likely an OGC feature collection.


MarcHillman
New Contributor III

I call many different RESTful GIS severs. A typical one is https://services.ga.gov.au/gis/rest/services/NM_Transport_Infrastructure/MapServer/4/query . The format parameter I'm using is geojson. So how am I supposed to parse whatever it is returning with ESRIArcGISRuntime?

0 Kudos
dotMorten_esri
Esri Frequent Contributor

There is no built-in GeoJson support in the runtime, so you'd need your own parser for GeoJson. The method you're using expects json formatted as FeatureCollection JSON. The link you pointed to above, you can use f=json instead of f=geojson to get the format that runtime uses - however that is the features part of the feature collection json, which is only one part of the json needed for a feature collection (you'd also need the feature set schema which comes from the feature service). The FromJson method you're using is mostly meant to be used together with the ToJson method to store feature collections.

Is there a reason you're not using the ServiceFeatureTable class, which will perform all the server rest queries and parsing for you?

MarcHillman
New Contributor III

The reason I'm not using ServiceFeatureTable class is I've never heard of them. Looks like I have some reading to do. Thanks.

0 Kudos