Is there an expression for converting values of longtitude and latitude into a point

9038
10
05-11-2014 08:19 AM
KerenCohen
Esri Contributor
I need to calculate a shape from an input of json.
Is there an expression that I can use to convert the longtitude and latitude values into a point geometry to feed a shape field?
0 Kudos
10 Replies
MarkBramer
Occasional Contributor II
Which input connector are you using?  If you are using an input connector that has a "build geometry from fields" property, you specify which "fields" contain your x and y coordinates in your inbound messages and GeoEvent Processor will automatically build the shape using the values in those two fields. 

Keep in mind:
1. The GeoEvent Definition you will be using for your inbound messages needs a field to contain this automatically-built geometry.  So you may need to add a field to your GeoEvent Definition, which is a common scenario if you told GeoEvent Processor to automatically create the GeoEvent Definition based on incoming data.
2. If the x and y values are not at the top level of your JSON, you will need to fully qualify the location of your x and y.  For example, if your inbound JSON looks like this:

{

  [INDENT][/INDENT]"iss_position": {

  [INDENT][INDENT][/INDENT][/INDENT]  "latitude": 44.16374704120857,

  [INDENT][INDENT][/INDENT][/INDENT]  "longitude": -127.63242554809165

[INDENT][/INDENT] },

[INDENT][INDENT][/INDENT][/INDENT] "message": "success",

  [INDENT][INDENT][/INDENT][/INDENT]"timestamp": 1400010196

}

You would need to tell your input that the x value is in "iss_position.longitude" and y value in "iss_position.latitude" (not just "longitude" and "latitude").

Mark
0 Kudos
RJSunderman
Esri Regular Contributor
Hello Keren -

An example of the functionality to which Mark is referring, Build Geometry From Fields can be found in 'Module 2' of the recently updated Introduction to GeoEvent" rel="nofollow" target="_blank">http://www.arcgis.com/home/item.html?id=265c334a47994dcc95e... Processor tutorial. Look on pages 26 and 27 in the exercise "Making Features Come Alive".

If your coordinates are expressed as attributes within a group, as in Mark's example, you retrieve them from the JSON structure by name. If the coordinates are in a list, as illustrated below, you need to specify the list index from which the coordinate value can be obtained.

{
    "iss_position": {
        "coordinates": [
            -127.632425,
            44.163747
        ]
    },
    "message": "success",
    "timestamp": 1400010196
}


Given the JSON above, you would specify the X Geometry Field be taken from iss_position.coordinates[0] and the Y Geometry Field from iss_position.coordinates[1].

Hope this information helps -
RJ
SindreEngh
New Contributor III

Hi RJ.

I have just upgraded to 10.3.

I have a GEP service which uses a Field Calculator to convert coordinates from minute degrees to decimal degrees and then use a Field Mapper to to cast the the string to a Geometry type, like explained in the "Using a Field Calculator Processor to compute a Geometry" example. Like this:

longitude and latitude are converted coorinates.

'{' + ' "x":' + longitude + ',' + ' "y":' + latitude + ',' + ' "spatialReference":{"wkid":4326} }'

This worked just fine in 10.2.2, but now this is not working. I get the follwing error:

com.esri.ges.adapter.genericJson.JsonInboundParserJson parser could not find the field 'location.longitude' in the incoming data. This field is needed to populate the 'x' value in the Geometry.
com.esri.ges.adapter.genericJson.JsonInboundParserJson parser could not find the field 'location.latitude' in the incoming data. This field is needed to populate the 'y' value in the Geometry.

So something have changed in 10.3, I guess it's trying to read the String with nested fields as a Geometry type, and not just converting the string to a geometry object?

How can I fix this?

Best regards

Sindre

0 Kudos
SindreEngh
New Contributor III

I fugured this one out.

In 10.3 when you calculate the geometry with the Field Calculator the New Field Type should be Geomtry, not String. This have changed from 10.2.2. When you then Field Map it to the Shape field of the output Feature Class it works!

FieldCalc.png

RJSunderman
Esri Regular Contributor

I've just verified for the 10.3.1 product release that this has been fixed. You will again be able to use a Field Calculator to produce a JSON String representation of a Geometry and write the result to a New Field Type:  String.

When using the 10.3.0 product release, you will need to write your Field Calculator output to a Geometry field of type Geometry as illustrated above. You will probably also have to use a Field Mapper to make sure the 'Geometry' the processor has calculated is cast to a proper Geometry before attempting to update features through a feature service.

The workflow outlined in the appendix of the product introduction tutorial works as documented for the 10.3.1 product release. Apologies for the frustration over this issue.

- RJ

0 Kudos
BradleyHardesty
New Contributor II

Great news. Thanks RJ.

-Brad

0 Kudos
DavidStajan
New Contributor III

Hi All,

I'm trying the opposite.  I have a geometry tag but I'm trying to use the x or y value in the field calculator expression.  Anyone know how to to this?

0 Kudos
RJSunderman
Esri Regular Contributor

Hello David -

If the field type within your GeoEvent is already of type Geometry, then no, you cannot use a Field Calculator processor (for example) to reach into the Geometry object and extract out coordinate values.

You might want to take a look at the Extent Enricher Processor available on the Gallery. The source code for this custom processor is available on GitHub here.

As I understand it, the processor allows you to enrich an event with fields providing the minimum and maximum X and Y values. The processor can optionally enrich the event with a second Geometry representing the center point of the original geometry.

I believe the processor, given a Point geometry, will return to you identical minimum X and maximum X values ... the minimum Y and maximum Y would likewise be the same.

Hope this information helps -

RJ

0 Kudos
DavidStajan
New Contributor III

Thanks for the response RJ.  I was hoping for an easier solution than a custom processor.  I'll have to rethink my approach.

Cheers,

David

0 Kudos