About adding feature from JSON input with group or nested attribute.

5428
2
04-22-2014 01:35 AM
MeshariAlsawat
New Contributor
I have some issues regarding using poll JSON from website and then add a feature class. I just want to add feature class from the result of this json website http://api.metro.net/agencies/lametro/routes/207/vehicles/ . I tried field mapper but still there is a problem with in polling events in JSON array "items".

Any help ... thanks
0 Kudos
2 Replies
RJSunderman
Esri Regular Contributor
Hello -

I had some problems reaching out to the URL you provided (http://api.metro.net/agencies/lametro/routes/207/vehicles). I was seeing some HTTP 503 "Service Unavailable" errors returned. However, I was able, intermittently, to obtain JSON from the site and I've included a sample below.

You are using the correct input connector - Poll an external website for JSON. Notice in the sample JSON below that the response contains a number of items in a list. If you specify items for the input's JSON Object Name parameter, GeoEvent Processor will parse the JSON and ingest a separate GeoEvent for each "item" in the list returned from the external site.

{
    "items": [
        {
            "seconds_since_report": 6,
            "run_id": "207_240_0",
            "longitude": -118.308899,
            "heading": 360,
            "route_id": "207",
            "predictable": true,
            "latitude": 34.003338,
            "id": "9479"
        },
        {
            "seconds_since_report": 244,
            "run_id": "207_240_0",
            "longitude": -118.309067,
            "heading": 360,
            "route_id": "207",
            "predictable": true,
            "latitude": 34.065708,
            "id": "9556"
        },
        {
            "seconds_since_report": 6,
            "run_id": "207_236_1",
            "longitude": -118.309166,
            "heading": 180,
            "route_id": "207",
            "predictable": true,
            "latitude": 34.056084,
            "id": "9543"
        },
        {
            "seconds_since_report": 6,
            "run_id": "207_236_1",
            "longitude": -118.309296,
            "heading": 180,
            "route_id": "207",
            "predictable": true,
            "latitude": 34.091366,
            "id": "9425"
        },
        {
            "seconds_since_report": 6,
            "run_id": "207_240_0",
            "longitude": -118.309036,
            "heading": 330,
            "route_id": "207",
            "predictable": true,
            "latitude": 34.021954,
            "id": "9431"
        },
        {
            "seconds_since_report": 64,
            "run_id": "207_240_0",
            "longitude": -118.308998,
            "heading": 360,
            "route_id": "207",
            "predictable": true,
            "latitude": 33.965965,
            "id": "9554"
        },
        {
            "seconds_since_report": 6,
            "run_id": "207_236_1",
            "longitude": -118.309036,
            "heading": 180,
            "route_id": "207",
            "predictable": true,
            "latitude": 34.00177,
            "id": "9504"
        },
        {
            "seconds_since_report": 65,
            "run_id": "207_240_0",
            "longitude": -118.308968,
            "heading": 220,
            "route_id": "207",
            "predictable": true,
            "latitude": 33.932251,
            "id": "9438"
        },
        {
            "seconds_since_report": 6,
            "run_id": "207_236_1",
            "longitude": -118.309395,
            "heading": 220,
            "route_id": "207",
            "predictable": true,
            "latitude": 34.104317,
            "id": "9427"
        },
        {
            "seconds_since_report": 6,
            "run_id": "207_236_1",
            "longitude": -118.308998,
            "heading": 315,
            "route_id": "207",
            "predictable": true,
            "latitude": 33.931149,
            "id": "9424"
        }
    ]
}


You will have to work some to first generate, and possibly refine, a GeoEvent Definition for the event data you expect to receive. For example, if you do not specify a node name in the JSON Object Name parameter, and you configure the input to generate a GeoEvent Definition, GeoEvent Processor will generate an event definition which looks something like the illustration below (click the thumbnail to see a larger view):
[ATTACH=CONFIG]33251[/ATTACH]

When the input is reconfigured with items specified as the input's JSON Object Name, the generated GeoEvent Definition does not include a 'Group' element since each "item" is ingested as a separate event:
[ATTACH=CONFIG]33252[/ATTACH]

Now that you have a GeoEvent Definition which specifies the format of each vehicle report, you need to reconfigure the input to Construct Geometry From Fields. The events you are receiving contain latitude and longitude values, and if you want to update a feature class through a feature service you will need to construct a Geometry. To do that you must tell the input which fields (specified in the event definition) contain the coordinate values.

My final configuration of the Poll an external website for JSON is illustrated below. Notice that I've changed the Create GeoEvent Defintion parameter to 'False' and selected the previously created GeoEvent Definition as the one to use to interpret the received events. (This is assuming, of course, that the structure of the data is not going to change...) I've also specified that my X Geometry Field value should be taken from 'longitude' and my Y Geometry Field should be taken from 'latitude'. Because I am requesting the input build a Geometry for me, I need a field in which the Geometry can be placed, so I also needed to edit the generated LA-Metro-Vehicle-Report event definition to include a new field of type Geometry.

[ATTACH=CONFIG]33254[/ATTACH]

[ATTACH=CONFIG]33253[/ATTACH]

Hope this information helps -
RJ
0 Kudos
MeshariAlsawat
New Contributor
Thank you so much... This is really what I need.
😄
0 Kudos