Erik -
I ran across a post from Maarten Tromp in the following thread: Swap coordinate pairs in a Polygon. Taking what he suggested, here is an approach you can follow using GeoEvent out-of-the-box without having to resort to developing a custom processor.
Given: A portion of an input stream with comma separated pairs of coordinate values and a space between each pair of coordinates.
Example: 57.711279,12.523986 57.635773,12.459618 57.576614,12.436624 57.711279,12.523986
First you need to reverse each coordinate pair. I used an Receive JSON on a REST Endpoint input to HTTP/POST the following JSON to a GeoEvent Service:
{
"trackid": "AA-1234",
"coordinates": "57.711279,12.523986 57.635773,12.459618 57.576614,12.436624 57.711279,12.523986"
}
Use a Field Calculator processor with the following expression to accomplish this:
Expression: replaceAll(coordinates,'([-]*[0-9]+\.[0-9]+?),([-]*[0-9]+(\.[0-9]+)?)','$2,$1')
Notice that the regular expression I used supports an optional negative sign in front of each coordinate value. A site you might want to bookmark to learn about and experiment with regular expressions is: regex101.com
Next you need to replace the literal space between each coordinate pair with a literal string ],[ to format the coordinate values as a set of nested JSON arrays and bracket the beginning and end of the string with [[ and ]]. Note that the RegEx pattern matching the beginning of a line is ^. The RegEx pattern for matching the end of a line is $.
Expression: replaceAll(coordinates,' ','],[')
Expression: replaceAll(coordinates,'^','[[')
Expression: replaceAll(coordinates,'$',']]')
Your GeoEvent Service so far looks like:
And is producing output which looks like:
Now you need to complete the formatting of your coordinate string to create a string representation of a Geometry. For this step I chose to copy the GeoEvent Definition used by the PolygonCoordinatesFeed input and add a field named GeomString. A Field Maper processor maps the existing coordinates and trackid into the new event structure leaving GeomString unmapped. Another Field Calculator processor will write its result into this new field. I do this so that the Field Calculator can write to an existing field without having to create an event defintion on-the-fly in order to write to a new field.
Here is the expression used in this most recent Field Calculator processor:
'{"rings":[' + coordinates + '],"spatialReference":{"wkid":4326}}'
What I'm doing here is prepending a literal string {"rings":[ to the coordinates value and appending a literal string ],"spatialReference":{"wkid":4326}} to the end of the string.
A final Field Mapper takes the event structure with the string representation of the Geometry and maps it to a field named Geometry. I now have an event with a field named trackid and a field named Geometry which I can send to a stream service to display the Geometry I've computed from the coordinate values received from the original feed. Here's my final GeoEvent Service:
I've attached an XML export of this configuration for both the 10.3.1 and 10.4 product releases. You will, of course, need to fix any validation errors by publishing your own stream service or switching to use a different output connector if you want to import this configuration.
Hope this information in helpful -
RJ