How to consume KML feed in operations dashboard?

1232
5
11-07-2018 01:45 PM
BobBistrais
New Contributor III

 I have a web map that I am building into an Operations Dashboard.  One of the layers is a KML feed.  I know that the O.D. widgets don't support this, but wondering if anyone knows of a workaround to get KML feed/data to work with an Ops Dashboard widget?

Tags (1)
0 Kudos
5 Replies
EricShreve
Occasional Contributor II

Bob, KML's are extremely difficult to work with because of how the architecture of the the data is written which creates limitations for displaying in ArcGIS Online. A solution if you are familiar with Python that you could pursue is do a transformation of the data from KML -> GeoJSON -> Overwriting a Feature Service through Python. Give this documentation a look over overwriting_feature_layers | ArcGIS for Developers

The code below is one I have successfully implemented to update a Feature Service through a KML Feed.

# coding: utf-8

# In[21]:


# Import libraries
import urllib.request
import kml2geojson
import urllib.request, json
import os
from arcgis.gis import GIS
from arcgis import features


# In[22]:


url = 'http://www.wildcadmap.net/WildCAD_CA-CNF.kml'


# In[23]:


urllib.request.urlretrieve(url, 'C:/Python_Testing/KML2GeoJSON/KML/WildCAD_CA_CNF.kml')
print("Successful Retrival")


# In[24]:


kml2geojson.main.convert('C:/Python_Testing/KML2GeoJSON/KML/WildCAD_CA_CNF.kml', 'C:/Python_Testing/KML2GeoJSON/GeoJSON')


# In[25]:


# Connect to the GIS
gis = GIS("https://www.arcgis.com", "Your Username", "Your Password")
print("Logged in as " + str(gis.properties.user.username))


# In[26]:


CNF_incidents_json_file='C:/Python_Testing/KML2GeoJSON/GeoJSON/WildCAD_CA_CNF.geojson'

# ## Overwrite the feature layer
# Let us overwrite the feature layer using the new csv file we just created. To overwrite, we will use the `overwrite()` method.


# In[27]:


#item id of the feature layer in AGOL Organization
CNF_incidents_featureLayer_item = gis.content.get('Feature Service ID')


# In[28]:


from arcgis.features import FeatureLayerCollection
CNF_incidents_flayer_collection = FeatureLayerCollection.fromitem(CNF_incidents_featureLayer_item)


# In[29]:


from arcgis.features import FeatureLayer
CNF_incidents_flayer = FeatureLayer.fromitem(CNF_incidents_featureLayer_item, layer_id=0)


# In[30]:


#get the count of the features in the geojson
json_data = open(CNF_incidents_json_file)
data2 = json.load(json_data)
print(len(data2['features']))


# In[31]:


#if there are features then overwrite the layer with the new data. If no features then truncate the database.
if len(data2['features'])>0:
CNF_incidents_flayer_collection.manager.overwrite(CNF_incidents_json_file)
else:
CNF_incidentsflayer.manager.truncate()


# In[32]:


dirPath = "C:/Python_Testing/KML2GeoJSON/KML"
fileList = os.listdir(dirPath)
for fileName in fileList:
os.remove(dirPath+"/"+fileName)
print("file deleted")

Let me know if you have any questions.

-Eric Shreve

BobBistrais
New Contributor III

Thanks Eric.  I will try this.  Does it absolutely require use of Jupyter Notebooks?

0 Kudos
EricShreve
Occasional Contributor II

Bob. It does not require Jupyter Notebook but you do need the necessary packages installed within Python 3.

0 Kudos
BobBistrais
New Contributor III

I see it works with feature services on ArcGIS Online.  Will this general method work with map services on our ArcGIS Server/Portal? 

0 Kudos
EricShreve
Occasional Contributor II

You should be able to configure it through ArcGIS Server/Portal given the fact that it is already a rest service. All you would need to do is change the "Connect to GIS URL" to your Portal URL. Let me know if that helps.

0 Kudos