ARCGIS Rest API with python addfeatures question

1349
10
Jump to solution
01-31-2019 09:08 AM
Larry
by
New Contributor III

I am uploading some Points and Lines into ArcGIS Online hosted feature services using a python program the ArcGIS Rest Api. The points work fine but I am having trouble getting the correct format for adding the lines.

For the Points:

{
    "features":

            "geometry": {

                  "x": x,
                  "y": y
             },
            "attributes": {
                "RECORD_ID": RECORD_ID,
                "DEVICE_ID": DEVICE_ID,
                "DATE_TIME": DATE_TIME,
                "LONGITUDE": LONGITUDE,
                "LATITUDE": LATITUDE,
            }

 }

Works.

For the lines If have tried:

{
     "features":
            "paths":[
                [x,y],[x1,y1]],
                "spatialReference": {"wkid" : 4326},
                
            "attributes": {
                "RECORD_ID": RECORD_ID,
                "DEVICE_ID": DEVICE_ID,
                "DEVICE_NAME": DEVICE_NAME,
                "DATE_TIME": DATE_TIME,
                "SPEED": SPEED,
                "HEADING": HEADING,
            }
 }

FAILS.

The error I get is:

"No JSON object could be decoded"

Any idea what I am doing wrong?

Thanks

Larry

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RandyBurton
MVP Regular Contributor

I believe for the add query or update (OBJECTID field required) query, the features section is all that is needed.  You shouldn't need "fields" or the other sections.

{
	"features": [{
		"attributes": {
			"RECORD_ID": 1,
			"DATE_TIME": 1546359300000,
			"SPEED": 1,
			"HEADING": 12
		},
		"geometry": {
			"paths": [
				[
					[-5871083.00245447, 6028331.87508284],
					[-5871713.60793782, 6027605.72331413]
				]
			]
		}
	}]
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I did notice that the spatial reference of the line layer returned is 3857 - web mercator (see below).  From your first json example, it looks like you are trying to use 4326 - lon/lat.  You may need to convert your coordinates before the update query with a projectAs.

"spatialReference": {
    "wkid": 102100,
    "latestWkid": 3857
}‍‍‍‍

View solution in original post

10 Replies
JoshuaBixby
MVP Esteemed Contributor

Try adding an extra set of square brackets around your "paths"

Larry
by
New Contributor III

No Luck, same erro.

 {
     "features":
            "paths":[
                [[x,y],[x1,y1]]],
                "spatialReference": {"wkid" : 4326},
                
            "attributes": {
                "RECORD_ID": RECORD_ID,
                "DEVICE_ID": DEVICE_ID,
                "DEVICE_NAME": DEVICE_NAME,
                "DATE_TIME": DATE_TIME,
                "SPEED": SPEED,
                "HEADING": HEADING,
            }
        }

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I should have caught this earlier.  ArcGIS feature objects don't have a "paths" property at the feature level.  You need to have a "geometry" property that contains the path and spatial reference.

See Feature object—Common Data Types | ArcGIS for Developers  and Geometry objects—Common Data Types | ArcGIS for Developers 

RandyBurton
MVP Regular Contributor

When you request a line feature, what does the returned json look like (specifically, the geometry portion)? 

0 Kudos
Larry
by
New Contributor III

I haven't tried looking at the result of requesting a line. I did export a json line layer from AGOL and that had the geojson formatting which I did try to use but without and luck so I went back to the ESRI version of json using the "paths" method.

0 Kudos
RandyBurton
MVP Regular Contributor

Also, checking json with jsonlint.com will also help locate issues.

So, perhaps something like:

{
  "features": {
    "geometry": {
      "paths": [
        [
         [0, 0],
         [1, 1]
        ]
       ],
      "spatialReference": {
        "wkid": 4326
      }
    },
    "attributes": {
      "RECORD_ID": 1,
      "DEVICE_ID": 1,
      "DEVICE_NAME": "NAME",
      "DATE_TIME": 123,
      "SPEED": 1,
      "HEADING": 1
    }
  }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
Larry
by
New Contributor III
I just tried your syntax exactly and I got the same error. I will try your idea of requesting
a json line from AGOL and see what I get back. BTW the record gets inserted each time with all
of the attributes correct, just no line object.


Thanks
 
{
  "features": {
    "geometry": {
      "paths": [
        [
         [0, 0],
         [1, 1]
        ]
       ],
      "spatialReference": {
        "wkid": 4326
      }
    },
    "attributes": {
      "RECORD_ID": 1,
      "DEVICE_ID": 1,
      "DEVICE_NAME": "NAME",
      "DATE_TIME": 123,
      "SPEED": 1,
      "HEADING": 1
    }
  }
}
0 Kudos
Larry
by
New Contributor III

This is the result from a request to AGOL for a line record. The last 2 lines are the features and geometry.

This one I added in the editor on AGOL

{"objectIdFieldName":"OBJECTID","uniqueIdField":{"name":"OBJECTID","isSystemMaintained":true},"globalIdFieldName":"GlobalID",
"geometryProperties":{"shapeLengthFieldName":"Shape__Length","units":"esriMeters"},
"geometryType":"esriGeometryPolyline","spatialReference":{"wkid":102100,"latestWkid":3857},
"fields":[{"name":"RECORD_ID","type":"esriFieldTypeInteger","alias":"RECORD_ID","sqlType":"sqlTypeOther",
"domain":null,"defaultValue":null},{"name":"DATE_TIME","type":"esriFieldTypeDate","alias":"DATE_TIME",
"sqlType":"sqlTypeOther","length":0,"domain":null,"defaultValue":null},{"name":"SPEED","type":"esriFieldTypeDouble",
"alias":"SPEED","sqlType":"sqlTypeOther","domain":null,"defaultValue":null},{"name":"HEADING","type":"esriFieldTypeDouble",
"alias":"HEADING","sqlType":"sqlTypeOther","domain":null,"defaultValue":null}],
"features":[{"attributes":{"RECORD_ID":1,"DATE_TIME":1546359300000,"SPEED":1,"HEADING":12},
"geometry":{"paths":[[[-5871083.00245447,6028331.87508284],[-5871713.60793782,6027605.72331413]]]}}]}

This one I added using python. You will notice that it does not have any geometry.

{"objectIdFieldName":"OBJECTID","uniqueIdField":{"name":"OBJECTID","isSystemMaintained":true},"globalIdFieldName":"GlobalID",
"geometryProperties":{"shapeLengthFieldName":"Shape__Length","units":"esriMeters"},
"geometryType":"esriGeometryPolyline","spatialReference":{"wkid":102100,"latestWkid":3857},
"fields":[{"name":"RECORD_ID","type":"esriFieldTypeInteger","alias":"RECORD_ID","sqlType":"sqlTypeOther",
"domain":null,"defaultValue":null},{"name":"DATE_TIME","type":"esriFieldTypeDate","alias":"DATE_TIME"
,"sqlType":"sqlTypeOther","length":0,"domain":null,"defaultValue":null},{"name":"SPEED","type":"esriFieldTypeDouble",
"alias":"SPEED","sqlType":"sqlTypeOther","domain":null,"defaultValue":null},{"name":"HEADING","type":"esriFieldTypeDouble",
"alias":"HEADING","sqlType":"sqlTypeOther","domain":null,"defaultValue":null}],
"features":[{"attributes":{"RECORD_ID":18790232,"DATE_TIME":1547054436000,"SPEED":9.15513190909996E-07,"HEADING":20.2115876610467}}]}

0 Kudos
RandyBurton
MVP Regular Contributor

I believe for the add query or update (OBJECTID field required) query, the features section is all that is needed.  You shouldn't need "fields" or the other sections.

{
	"features": [{
		"attributes": {
			"RECORD_ID": 1,
			"DATE_TIME": 1546359300000,
			"SPEED": 1,
			"HEADING": 12
		},
		"geometry": {
			"paths": [
				[
					[-5871083.00245447, 6028331.87508284],
					[-5871713.60793782, 6027605.72331413]
				]
			]
		}
	}]
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I did notice that the spatial reference of the line layer returned is 3857 - web mercator (see below).  From your first json example, it looks like you are trying to use 4326 - lon/lat.  You may need to convert your coordinates before the update query with a projectAs.

"spatialReference": {
    "wkid": 102100,
    "latestWkid": 3857
}‍‍‍‍