Beginner - can I use the REST API to add points on map?

2534
6
Jump to solution
06-29-2020 10:38 AM
JasonWood
New Contributor II

I am a software developer but am new to mapping & ArcGIS.

My client created a layer in their ArcGIS Online account using a file import. Each point on the map also includes a number of other fields from the database.

Can the REST API be used to individually add a new point or update the information stored in an existing point? Or do I have to reference a URL where the complete table is available to be re-ingested?

Thank you!

1 Solution

Accepted Solutions
Egge-Jan_Pollé
MVP Regular Contributor

Hi Jason Wood,

Yes, you are close. You are new to mapping & ArcGIS, didn't you say so? So, the next topic to study is: the spatial reference of your data...

You added a feature layer and - unless you specify it explicitly - this will get the default spatial reference of 102100 (aka 3857): "spatialReference" : {"wkid" : 102100, "latestWkid" : 3857}

(EPSG:3857 is a Spherical Mercator projection coordinate system popularized by web services such as Google and later OpenStreetMap, and also being used by Esri, with WKID:102100). On the other hand, It looks like your input x and y are in WGS84 (EPSG:4326).

Your input is x:-79.419591 and y:43.647131. In WGS84 this will bring you to a point in Toronto, but in this Web Mercator projection it is close to zero. So, that's why you ended up where you ended up 🙂

I did use this site to transform your input coordinates: https://epsg.io/transform#s_srs=4326&t_srs=3857 and that gives me x: -8840948.43 and y: 5410996.30.

These new values bring me to a building on the corner of Ossington Ave and Argyle St in (downtown?) Toronto, Canada. Is that the location you were after?

HTH,

Egge-Jan

View solution in original post

6 Replies
EduardoFernandez1
Esri Contributor

Hello Jason 

Yes, you can add points to the map using the REST endpoint. See the following link:

 https://developers.arcgis.com/rest/services-reference/add-features.htm

 

Bear in mind that you will have to deal with authentication to get a token before you can access a secured service endpoint:

 

https://developers.arcgis.com/rest/users-groups-and-items/authentication.htm

https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/accessing-arcg...

Hope this helps, Ed

Egge-Jan_Pollé
MVP Regular Contributor

Hi Jason Wood,

Yes, you can use the ArcGIS REST API to add a feature (e.g. a point) directly to a Feature Service through an HTTP POST request. And this point will become visible on the map. Eduardo Fernandez‌ gives some links to useful resources above. I will extend the answer here with a hands-on exercise.

 

IN this exercise you will use the Hazards service from the Editor widget example: https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/Hazards_Uptown_Charlotte/FeatureSe... (This is a public service, maintained by Esri's jsapi_team. You can add records freely to this service, for testing purposes. I guess they remove the records every now and then...)

 

We want to report a hazard, a wild animal: let's pretend we have seen a gorilla in the center of Paris!!

 

Go to https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/Hazards_Uptown_Charlotte/FeatureSe... and enter the feature you want to add:

[
    {
      "attributes" : {
        "HazardType" : "Dangerous Animal",
        "Description" : "We have seen a gorilla in the vicinity of the Effel Tower",
        "SpecialInstructions" : "No Action",
        "Status" : "Active",
        "Priority" : "High"
      },
      "geometry" : {
        "x" : 255422,
        "y" : 6250838
      }
    }
]
 

As soon as you click Add Features, your Gorilla Warning will be added to the service and hence be added to the map.

 

Is this example useful to you?

 

Best regards,

 

Egge-Jan

 

 

JasonWood
New Contributor II

Thank you both. It may take me a day or two to get back into this, but even just knowing that what I was calling a "point" is a "feature" in the API gets me miles ahead. I was looking at the docs for "Items" and getting lost! I will come back soon to report my results. Thanks again!

JasonWood
New Contributor II

I'm close!

I added a feature layer to my developer account and setup some fields. I am able to create features with attributes, BUT the point always goes to 0,0 off the coast of Africa...

Here is my cURL, which I was expecting to place a point in Toronto:

curl -X POST \
-d "f=json" \
-d "token=[theToken]" \
-d "features=[{\"attributes\":{\"Operator\":\"Bob\",\"Location\":123456789},\"geometry\":{\"x\":-79.419591,\"y\":43.647131}}]"‍‍‍‍‍‍
Egge-Jan_Pollé
MVP Regular Contributor

Hi Jason Wood,

Yes, you are close. You are new to mapping & ArcGIS, didn't you say so? So, the next topic to study is: the spatial reference of your data...

You added a feature layer and - unless you specify it explicitly - this will get the default spatial reference of 102100 (aka 3857): "spatialReference" : {"wkid" : 102100, "latestWkid" : 3857}

(EPSG:3857 is a Spherical Mercator projection coordinate system popularized by web services such as Google and later OpenStreetMap, and also being used by Esri, with WKID:102100). On the other hand, It looks like your input x and y are in WGS84 (EPSG:4326).

Your input is x:-79.419591 and y:43.647131. In WGS84 this will bring you to a point in Toronto, but in this Web Mercator projection it is close to zero. So, that's why you ended up where you ended up 🙂

I did use this site to transform your input coordinates: https://epsg.io/transform#s_srs=4326&t_srs=3857 and that gives me x: -8840948.43 and y: 5410996.30.

These new values bring me to a building on the corner of Ossington Ave and Argyle St in (downtown?) Toronto, Canada. Is that the location you were after?

HTH,

Egge-Jan

JasonWood
New Contributor II

Perfect. What I ended up doing is specifying the WKID of my coordinates in the request so I don't need to worry about what the layer is using or do any conversions myself:

[{
	"attributes": {
		"Operator": "Bob",
		"Location": 123456789
	},
	"geometry": {
		"spatialReference": {
			"wkid": 4326
		},
		"x": -79.419591,
		"y": 43.647131
	}
}]

Thanks again!