Select to view content in your preferred language

Processing GeoJSON sent to a REST Endpoint

1589
5
12-22-2020 03:58 PM
RobertMarros
Frequent Contributor

We followed Receive GeoJSON on a REST Endpoint to send weather data to ArcGIS as feature data. Unfortunately, the data is parsed they way we hope or expect. We've tried to have features updated or created when the data is received, and also just converted to csv in a file.

Here's what we're sending:

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -93.265,
                    44.9778
                ]
            },
            "properties": {
                "loc": {
                    "lat": 44.9778,
                    "long": -93.265
                },
                "place": {
                    "name": "minneapolis",
                    "state": "mn",
                    "country": "us"
                },
                "periods": [
                    {
                        "timestamp": 1608324300,
                        "dateTimeISO": "2020-12-18T14:45:00-06:00",
                        "tempC": 5.44,
                        "tempF": 41.79,
                        "feelslikeC": 4.31,
                        "feelslikeF": 39.77,
                        "dewpointC": -0.59,
                        "dewpointF": 30.93,
                        "humidity": 65,
                        "pressureMB": 1014,
                        "pressureIN": 29.94,
                        "windDir": "SSW",
                        "windDirDEG": 194,
                        "windSpeedKTS": 3.5,
                        "windSpeedKPH": 6.48,
                        "windSpeedMPH": 4.03,
                        "windGustKTS": 12.12,
                        "windGustKPH": 22.45,
                        "windGustMPH": 13.95,
                        "precipMM": 0,
                        "precipIN": 0,
                        "snowCM": 0,
                        "snowIN": 0,
                        "visibilityKM": 24.135,
                        "visibilityMI": 14.997,
                        "sky": 100,
                        "cloudsCoded": "OV",
                        "weather": "Cloudy",
                        "weatherCoded": "::OV",
                        "weatherPrimary": "Cloudy",
                        "weatherPrimaryCoded": "::OV",
                        "icon": "cloudy.png",
                        "solradWM2": 49,
                        "uvi": 0,
                        "isDay": true
                    }
                ],
                "profile": {
                    "tz": "America/Chicago",
                    "tzname": "CST",
                    "tzoffset": -21600,
                    "isDST": false,
                    "elevFT": null,
                    "elevM": null
                }
            }
        }
    ]
}

Here are the fields that got created the first time that we sent a post to the endpoint: 

RobertMarros_0-1608680504584.jpeg

Unfortunately, only Geometry actually gets populated with data when a post is sent. The data is the lat and long, in quotes, separated by commas. None of the other fields shown above show any data. Do we need to define fields manually (using the "New Field" button in the screen capture above), perhaps whatever of the subfields in the geoJSON we want, e.g., tempF in the periods array? I'm now also noticing the Tags column in the above, but don't know what they mean.

The geoJSON as shown above is coming from another API, unaltered, so not having to process/reformat it ourselves before sending it on to ArcGIS would make everything simpler, though we can do that, if necessary.

 

0 Kudos
5 Replies
DavidPike
MVP Frequent Contributor

are you specifying f=geojson in the header? Is this done in postman?

0 Kudos
RobertMarros
Frequent Contributor

Hi, thanks for the reply. I have been using Postman. I have not been specifying f=geojson. I just added that now, but it's not changing the result.  

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

My guess is that GIS Server doesn't know how to handle your properties because they are not simple data types, i.e., string, integer, double, etc....  For example, how do you expect the following to get stored in a table?

                "place": {
                    "name": "minneapolis",
                    "state": "mn",
                    "country": "us"
                },

 

RobertMarros
Frequent Contributor

HI,

Thanks for the reply. I'm not sure how the server handles the GeoJSON it receives, and I think that's part of the problem. The initial post request caused the fields in the screenshot of the GeoEvent definition to be created. I suppose my expectation would be that there'd be server-side code to traverse the JSON and pull out the individual key-value pairs, though that still leaves the question of how it would represent the hierarchy in the structure, e.g., if "name" is a column heading in the csv file and "minneapolis" a value in that column, where does "place" go?

My question now is, do I have to modify the GeoJSON to flatten it out, or specify the fields I want in the GeoEvent definition differently to get what I want, or will either, both, or neither be required to achieve what I want? There's example GeoJSON in the page to which I linked, but it's a lot simpler than what I'm sending. Are there other examples I can look at that you're aware of? I was able to stick arbitrary key-value pairs in a "properties" section of GeoJSON and have those get populated in the generated csv (after a new GeoEvent definition was generated with the first post request with the new GeoJSON), so I know that works, but again, I'd prefer not to have to do a lot of reconstructing or reformatting of the GeoJSON, unless it's necessary.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I was able to stick arbitrary key-value pairs in a "properties" section of GeoJSON and have those get populated in the generated csv

I think you just answered your original question.  Posting GeoJSON to a REST endpoint won't flatten nested JSON, and ArcGIS Server appears to have no means of storing the JSON as an object type, although I doubt you would want that anyways. 

0 Kudos