<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Has anyone used the arcgis.realtime.StreamLayer? in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/has-anyone-used-the-arcgis-realtime-streamlayer/m-p/797475#M1880</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to build a Python script to pull off features from a GeoEvent streaming service but I have not found ANY examples of how to use the StreamLayer class. Not even Esri has samples for how to use it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Jun 2019 15:39:33 GMT</pubDate>
    <dc:creator>WeldonWiyninger</dc:creator>
    <dc:date>2019-06-20T15:39:33Z</dc:date>
    <item>
      <title>Has anyone used the arcgis.realtime.StreamLayer?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/has-anyone-used-the-arcgis-realtime-streamlayer/m-p/797475#M1880</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to build a Python script to pull off features from a GeoEvent streaming service but I have not found ANY examples of how to use the StreamLayer class. Not even Esri has samples for how to use it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jun 2019 15:39:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/has-anyone-used-the-arcgis-realtime-streamlayer/m-p/797475#M1880</guid>
      <dc:creator>WeldonWiyninger</dc:creator>
      <dc:date>2019-06-20T15:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: Has anyone used the arcgis.realtime.StreamLayer?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/has-anyone-used-the-arcgis-realtime-streamlayer/m-p/797476#M1881</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Weldon,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You're in luck - I actually wrote on article on this exact topic not too long ago. I believe our content team is still working to make it public-facing, but I'll paste a copy for you below. This is a simple example that utilizes one of our sample GeoEvent Servers. The events are printed for illustrative purposes, but you may of course modify the function to process the received events however you wish:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE style="color: #222222; background-color: #ffffff; font-size: 12px;"&gt;&lt;TBODY&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;In order to use the subscribe method, you must have the following packages installed: &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;autobahn&lt;/SPAN&gt;, &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;twisted&lt;/SPAN&gt;, &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;pyOpenssl&lt;/SPAN&gt;, and &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;service_identity&lt;/SPAN&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you already have the ArcGIS API for Python installed, then you may already have some of the packages installed and just need to install twisted and autobahn:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;conda install twisted&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;conda -c conda-forge install autobahn&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The subscribe method expects at minimum a callback function. The below sample illustrates how you can define a callback function that print events (JSON) as they come in. This is a very basic example - you could further manipulate the JSON to view only certain information or even perform additional processing/data analysis if desired.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; arcgis &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; GIS
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; arcgis&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;realtime &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; StreamLayer
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; ssl&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; json
 
ssl&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;_create_default_https_context &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; ssl&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;_create_unverified_context
url &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"https://geoeventsample1.esri.com:6443/arcgis/rest/services/AirportTraffics/StreamServer"&lt;/SPAN&gt;
streamLayer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; StreamLayer&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;url&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;callback&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;event&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    event_as_json &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; json&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;loads&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;event&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;event_as_json&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
streamLayer&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;subscribe&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;callback&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note:&lt;/STRONG&gt; This script may not run well in a Jupyter Notebook - if you run the code and decide to stop the script, the next time you attempt to run the script you may encounter errors like these:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;--------------------------------------------------------------------------- ReactorNotRestartable                     Traceback (most recent call last) &amp;lt;ipython-input-2-7cd591176ebd&amp;gt; in &amp;lt;module&amp;gt;      10     print(event)      11  ---&amp;gt; 12 streamLayer.subscribe(callback)

&lt;/PRE&gt;&lt;P&gt;When this happens, restart the kernel and you should be able to re-execute. Otherwise, the script runs consistently from the command line.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Earl&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:13:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/has-anyone-used-the-arcgis-realtime-streamlayer/m-p/797476#M1881</guid>
      <dc:creator>EarlMedina</dc:creator>
      <dc:date>2021-12-12T09:13:16Z</dc:date>
    </item>
  </channel>
</rss>

