Extracting Geometry Coordinates from JSON String

4502
11
06-11-2014 04:54 PM
TomFlahive
New Contributor III
With the GeoEvent Processor, is there a way to extract the coordinates from a JSON field when the coordinates are embedded in a single string?:

"CREATED_LOCATION":"31.555114:-117.458182:12.792526:10.000000:3.000000:0.000000:-1.000000:1402525011.385171"


I'm just trying to pull out the 31.555114 and -117.458182 to be used in creating Geometry for a feature service.  I asked a similar question recently (http://forums.arcgis.com/threads/109721-Converting-Lat-Long-Coordinates-in-JSON-Feed-to-Geometry?p=3...), but this case is a little trickier since the coordinates are now embedded in a single string.
0 Kudos
11 Replies
RJSunderman
Esri Regular Contributor
Hello Tom -

I apologize for not being able to respond to your post earlier.

The easiest way to do what I think you are trying to do will be to leverage the Field Calculator and Java string functions available with the 10.2.2 product release.

Given a block of JSON input:

{
    "Attributes": {
        "name": "Some name...",
        "date": "2/17/2014 15:31:45"
    },
    "Location": "31.555114:-117.458182:12.792526:10.000000:3.000000:0.000000"
}


You could design a GeoEvent Service something like the one illustrated below to find the index of the ':' delimiters within the event attribute string and then pull the substring found between those index values.

[ATTACH=CONFIG]34963[/ATTACH]
(Click to Enlarge)

This is going to depend on your "latitude" and "longitude" always being found within the first two substring values of the Location attribute string. The output you should expect would look something like:

[
    {
        "Attributes": {
            "name": "Some name...",
            "date": 1392679905000
        },
        "Location": "31.555114:-117.458182:12.792526:10.000000:3.000000:0.000000",
        "IdxA": 9,
        "IdxB": 21,
        "Latitude": 31.555114,
        "Longitude": -117.458182
    }
]


Hope that helps -
RJ
0 Kudos
SaraAbasi
New Contributor III

Hi RJ,

Will you be able to help me with creating a calculated field for the following input?

I am polling an external website for a json, here is the format of the input and the geodefinition that created by default.

I've created a flat geoevent definition but I am not sure how to map the data to the new definition and the expression in the calculated field to build the geometry.

Thank you!

0 Kudos
Stefan_Jung
Esri Contributor

Hi Sara Abasi‌,

the easiest way would be to use "Construct Geometry From Fields" in your input connector. This will work pretty fine if you always have the same JSON structure that contains a geometry.

Just add a new field to your geoevent definition with the Type Geometry and the Tag GEOMETRY 

In the Advanced section if your input configuration you can try this:

That should work

Best,

Stefan

0 Kudos
SaraAbasi
New Contributor III

Thanks, I will try that.

Do you recommend creating a flat geoevent definition and using a field mapper?

Which output connector works the best? I used "Update a Feature in a Spatiotemporal Big Data Store" .

0 Kudos
Stefan_Jung
Esri Contributor

Creating a flat geoevent definition is always a good idea if the data will be used in a relational table. 

Just be careful if you have fields with Cardinality many.

And which output connector works best depends on what are you planning to do with the data. There is not just one correct answer.

If you want to save all the incoming data for analysis and if you receive a lot of data than the Spatiotemporal Big Data Store might be best for you. If you want save and update the last location of your incoming vehicles the Standard Data Store might be enough. If you want to have a smooth visualization of the current position of each vehicle maybe Stream Service is your choice.

Best Stefan

0 Kudos
SaraAbasi
New Contributor III

Stefan,

I used the output: "Add a Feature to a Spatiotemporal Big Data Store", count is increasing in Geoevent manger/ monitor, but there is no data when I view the feature class in portal/ content page.

0 Kudos
Stefan_Jung
Esri Contributor

First of all i would check the log-files if you find any error trying to write to the output. Maybe there is a missmatch of the geoevent defnition that has been used for publishing the service and is now used to write.

For debugging I would also suggest you to create a new output connector: Push Text to an External TCP Socket and use the GeoEvent Logger (installed with GeoEvent Server) to see what data is send to the output.

SaraAbasi
New Contributor III

It's captured in logs for both outputs I created, Spatiotemporal and stream service:

"The GeoEvent received contains an incompatible GeoEvent Definition (Bird-Status-Changes-Created) than the schema of the destination Spatiotemporal Big Data Store Service (BirdAPI-StatusChanges-Flat)."

0 Kudos
Stefan_Jung
Esri Contributor

So you might forgot to map the GeoEvent Definition. The Definition that is received by the Ouput must match the one that has been used for publishing the service.

0 Kudos