REST API /updatefeatures geometry attribute (x, y) not displaying in correct projection

1170
1
Jump to solution
05-18-2020 11:55 PM
JackSilburn
New Contributor III

In attempting to dynamically move the location of points on a map, I am using the /updatefeatures endpoint of the arcGIS REST API.

My POST data looks like the following:

[{

"geometry":{"x": 702078.1622769168, "y": 8625267.799537977},

"attributes":{\'device_id\': 1234, \'objectid\': 20...},

...

}]

The update works successfully, when I use the /query endpoint, the data has changed as expected.

However the map has no points visible when I open the layer in Map viewer. They have disappeared.

Am I mistaken? Does the "geometry" attribute in the request not influence where the point is located?

I even plugged the X and Y coordinate into an online converter and it finds the location successfully.

Thanks

0 Kudos
1 Solution

Accepted Solutions
JackSilburn
New Contributor III

Ok it turns out there is another attribute you need to POST with the "geometery" attribute:

{
"attributes":{
"device_id":1,
"objectid":17,
"longitude":<insert longitude here>,
"latitude":<insert longitude here>,
},
"geometry":{
"x":<insert utm converted coord here>,
"y":<insert utm converted coord here>,
"spatialReference":{
"wkid":<insert WKID here>
}
}
},

"attributes":{
"device_id":2,
"objectid":18,

...

...

.

Realising I needed a 'wkid' (well known ID) for the 'spatialReference' key, I did a google for <my city> WKID.

Using this resource, I was able to find the corresponding WKID for my city's Coordinate Projection System, and send it in the POST request.

FYI, to convert lat long coordinates to X Y (UTM) coordinates, I used the Python "utm" module and the 'from_latlon' function, see:

import utm
#Here I loop through my "device list" and convert Lat/long to X/Y utm coords:
latitude, longitude, zone, var = utm.from_latlon(float(<insert latitude>), float(<insert longitude>))
#Insert the X Y coords into the /updateFeatures "data" (payload) string for the request

Just thought I would update my post for anyone that stumbles upon the same issue. This is the culmination of two days troubleshooting.

Thanks

View solution in original post

0 Kudos
1 Reply
JackSilburn
New Contributor III

Ok it turns out there is another attribute you need to POST with the "geometery" attribute:

{
"attributes":{
"device_id":1,
"objectid":17,
"longitude":<insert longitude here>,
"latitude":<insert longitude here>,
},
"geometry":{
"x":<insert utm converted coord here>,
"y":<insert utm converted coord here>,
"spatialReference":{
"wkid":<insert WKID here>
}
}
},

"attributes":{
"device_id":2,
"objectid":18,

...

...

.

Realising I needed a 'wkid' (well known ID) for the 'spatialReference' key, I did a google for <my city> WKID.

Using this resource, I was able to find the corresponding WKID for my city's Coordinate Projection System, and send it in the POST request.

FYI, to convert lat long coordinates to X Y (UTM) coordinates, I used the Python "utm" module and the 'from_latlon' function, see:

import utm
#Here I loop through my "device list" and convert Lat/long to X/Y utm coords:
latitude, longitude, zone, var = utm.from_latlon(float(<insert latitude>), float(<insert longitude>))
#Insert the X Y coords into the /updateFeatures "data" (payload) string for the request

Just thought I would update my post for anyone that stumbles upon the same issue. This is the culmination of two days troubleshooting.

Thanks

0 Kudos