ArcGIS Online displaying attributes wrong

150
9
01-26-2022 12:33 PM
Labels (2)
DonaldBrown
Occasional Contributor

I have a static geojson file that I add to my map in ArcGIS Online. Everything displays fine. The issue is:  AGOL is not honoring the type of attributes specified in the geojson file. I'm attaching what the data looks like in the geojson file and what it looks like in the the table or 'identify' in AGOL. Take a look at the 'SiteNumber' or 'ParameterCode' attributes. AGOL is treating them like numbers instead of strings. Cutting off the leading zeros in the 'ParameterCode' is not good :(. The data type in the geojson file are honored when I add the same dataset to a QGIS session or consume it with other apps.

Anyone else seen this and have a solution?

I eventually want to turn the geojson into a URL service and add it to a map that way. Will the same issue happen if I do this?

0 Kudos
9 Replies
HuubZwart
Occasional Contributor

Check publishing a geoJSON file as hosted feature layer, step 7:

Review the fields included and make changes as needed.

If the field types can be identified, they are set automatically. You can remove fields, change the display name of the field, and change the field type.

0 Kudos
DonaldBrown
Occasional Contributor

Thank you for that information. I tried that and specifically set the 'ParameterCode' field to string. However, after the dataset is added and I look at the table/fields, that field is denoted as a number... not a string. Why is AGOL changing it? I'll upload the geojson file so you can try/see for yourself.

0 Kudos
DonaldBrown
Occasional Contributor
 
0 Kudos
HuubZwart
Occasional Contributor

Thank you for sharing, that is interesting indeed. It looks like the REST API call behind the publish function doesn't actually include the selected field type parameters. Also changing the field names doesn't do anything... Sounds like a bug!

0 Kudos
jcarlson
MVP Frequent Contributor

When you add a layer like that to the map, it's really just reading it in as text. You see this a bunch with CSVs with things like parcel numbers, ZIP codes, etc. When AGOL reads the attributes in and sees a series of numbers, it makes its best guess, and occasionally gets it wrong.

The best solution is to have a layer with defined datatypes, but you can't always do that. You might consider going the Excel approach, which is to prepend "text numbers" with some character that will be ignored. That is, store the value "'0060" instead of "0060".

Would it be possible to create a layer in AGOL and simply have it sync with the GeoJSON periodically? Perhaps using a Python script?

 

- Josh Carlson
Kendall County GIS
0 Kudos
DonaldBrown
Occasional Contributor

A json file DOES have defined datatypes:

Double quotes means text.

No quotes means number.

Why is AGOL making a guess? Other applications seem to have no problem honoring the defined datatypes in the json file. Also, I'm specifically telling it 'text' in the procedure mentioned above and it's changing it back to number.

0 Kudos
jcarlson
MVP Frequent Contributor

I mean like a database layer, i.e., a hosted layer, sorry. I'm not disagreeing with you, I know that geojsons and the like have data types, they're just not as explicit/rigid as in a DB.

When you add a file to your map, the map makes a call to /rest/features/generate to cobble together a Feature Collection. Somewhere in the process, it's seeing all digits and saying "oh, that's a number field", regardless of the rest of the file's formatting.

None of that really answers the main question of "why does it do this?", though.

- Josh Carlson
Kendall County GIS
0 Kudos
jcarlson
MVP Frequent Contributor

If you host the file at a URL and add it to the new map viewer, it respects your data types!

jcarlson_1-1643237272517.png

 

jcarlson_0-1643237206920.png

Why the difference? Who knows!

 

- Josh Carlson
Kendall County GIS
0 Kudos
DonaldBrown
Occasional Contributor

Ooooh, that is good news! Thanks for taking the time to create the geojson service and testing it. My goal is to create a geojson service (and NOT use a static geojson file) anyway, so I'm less concerned now. Anyway. it would be nice if ESRI could fix the static geojson upload issue.

0 Kudos