GeoJSON Hosted Layer Error

4396
11
01-13-2020 09:23 AM
TaylorKravits
New Contributor II

I'm attempting to publish a geojson file as a hosted layer to ArcGIS Online but it gives me "There was an error". However, if I add it as a layer to an already created map, it shows just fine.

I have the permissions of a creator and publisher under my organization.

The type is a Feature Collection, crs is set, I'm not really sure what else it could be.

Has anyone had this error before?

0 Kudos
11 Replies
AnttiKajanus3
New Contributor III

I have seen similar issue with other datatypes at some point and if i remember correctly it was due using wrong item type or similar on the publish method. 

Some documentation that solved my issue:

arcgis.gis module — arcgis 1.7.0 documentation  

Publish Item—ArcGIS REST API: Users, groups, and content | ArcGIS for Developers 

If you can share the code, I could have a better look on it.

TaylorKravits
New Contributor II

Apologies for not sharing the code. I wasn't sure if there was a bug out there but it pulls a created .geojson and here is a sample

from arcgis.gis import GIS
import os
import json
username = "username"
password = "password"
gis = GIS("arcgis online organization website", username, password)


data_path = os.path.join(r"C:\Users\taylor\Desktop\rentals.geojson")
item_properties = {'type': 'geojson',
                'title':'Rental Properties',
                'description':'Rental Properties',
                'tags':'rental'}

Rentals = gis.content.add(item_properties, data_path)
published_service = Rentals.publish(file_type='FeatureCollection')

{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "OBJECTID": 1218029, "Parcel Number": "1461", "LICENSENUMBER": "RHL20", "Address": "42 WAY", "LICENSESTATUS": "Issued", "APPLIEDDATE": "2017-09-29T00:00:00", "ISSUEDDATE": "2017-09-29T00:00:00", "EXPIRATIONDATE": "2021-09-29T00:00:00", "LASTRENEWALDATE": null, "SUBCOMMUNITY": "North", "RENTALTYPE": "Standard Rental", "COMPLEXNAME": null, "BUILDINGTYPE": "Single Family Dwelling", "ENERGYCOMPLIANT": "Yes", "BUILDINGIDENTIFICATION": "RHL2015-00466", "DWELLINGUNITSONCASE": 1, "ROOMINGUNITSONCASE": 0.0, "MAXIMUMUNRELATEDOCCUPANTS": 3, "OCCUPANCYBEFOREREZONING": "NO", "PROFESSIONALLICENSEHOLDERNAME": "null", "PROFESSIONALLICENSEHOLDERCMPNY": null, "PROFESSIONALLICENSEYEAR": 2017.0, "SHAPEAREA": 70551.149319832402, "SHAPELEN": 1194.74474079076, "strap_x": "R00368 ", "strap_y": "R00968 ", "eff": "1974", "remodel": 0.0, "status_cd": "A ", "code": "RES" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -105.282824422242228, 40.050975815768872 ], [ -105.282243756596387, 40.050975449135876 ], [ -105.282248337352939, 40.05217015748709 ], [ -105.282825708018564, 40.052170943882906 ], [ -105.282825425662821, 40.051946591042061 ], [ -105.282825176117441, 40.051711208021224 ], [ -105.28282492234834, 40.051479357327715 ], [ -105.282824676197606, 40.051245852152 ], [ -105.282824422242228, 40.050975815768872 ] ] ] } },

}

There's about 1846 records in my code, this is only one of them

0 Kudos
AnttiKajanus
New Contributor III

I tried your geojson file (i fixed it to be valid though) with following code and it seems to work for me.

I checked what agol will add to the json metadata when adding things manually to agol and copied the exact formats from there. 

rentals_item = gis.content.add(
        item_properties = {
            'type': 'GeoJson',
            'title':'Rental Properties',
            'typeKeywords': ['Coordinates Type', 'CRS', 'Feature', 'FeatureCollection', 'GeoJSON', 'Geometry', 'GeometryCollection'], # this seems to be what manual add will add, works without this as well 
            'description':'Rental Properties',
            'tags':'rental'
        }, 
        data = r'./example-data/example.geojson')
rentals_item

published_service = rentals_item.publish(file_type='GeoJson') # file_type is not needed since seems to work without it as well
published_service‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
TaylorKravits
New Contributor II

Thank you Antii! I'll try out this code. What did you fix in the geojson to make it valid? Maybe it's something within my geojson file when it's created using geopandas?

0 Kudos
AnttiKajanus
New Contributor III

No worries. let us know if that fixes your issue.

I just made sure that it's valid Json since you posted only one item and the format if broken due that.  

0 Kudos
TaylorKravits
New Contributor II

This is the error code I get when I attempt to publish

published_service = rentals_item.publish()
File "C:\Users\tkravits\Desktop\Rentals\interpreter_3.7\lib\site-packages\arcgis\gis\__init__.py", line 8865, in publish
serviceitem_id = self._check_publish_status(ret, folder)
File "C:\Users\tkravits\Desktop\Rentals\interpreter_3.7\lib\site-packages\arcgis\gis\__init__.py", line 9092, in _check_publish_status
raise Exception("Job failed.")
Exception: Job failed.

However it shows up as a hosted layer and a geojson file within my content, but when I view the hosted layer in the Map Viewer it zooms to the extent of the area, but there is no data found in the rental property map. I tested the geojson using geojson.io and it displays perfectly with the data intact. Here's a snippet of what shows up below. 

0 Kudos
AnttiKajanus3
New Contributor III

I got the feature visible that was in your example. Maybe there is something wrong on some of the features? Can you get them visible if you publish everything manually? Not to the map directly but add as content file and then publish it as a service? Does that service has all the features? 

I assume that you cannot share the data publicly for me to test. 

0 Kudos
TaylorKravits
New Contributor II

So if I add the geojson file manually (upload a file) to the map, it works. If I add them as content and host it as a feature layer (manually), it also fails. Same "There was an error" message that goes up. The field names populate correctly, but there is no data attached to it. Similar to that picture posted above.

 

Unfortunately, I can't really share this data but I greatly appreciate you helping me.

0 Kudos
AnttiKajanus
New Contributor III

That sounds like that there might be something wrong in the publish part of the ArcGIS REST services for the GeoJson since it works for the webmaps but not for the manual or automated publishing workflow. Since the python Api is basically just a wrapper around the same services used with the ArcGIS Online UI, its highly pointing that way. Maybe folks from the Python API / REST API could clarify that...