This is a continuation of another blog post where I described how to compute aggregated results such as totals and averages from a time series table and show them at the point locations where those values were measured. These results are helpful in many analyses. But there are cases where it is required to visualize them using polygon features. For example, if you are an emergency management professional, you may want to know which counties have the most rainfall; whereas if you’re a scientist, you may want to see the same result but aggregated into watershed boundaries/catchment areas instead.

When it comes to transforming results from points to polygons, naturally we think of a simple spatial operation—such as a Contains or a Within operation—to (a) find all points that fall within a polygon feature and (b) use those features to compute the result. This simple approach works well with discrete data, such as computing total sales from all point locations at the state or county level. But this does not work for analyses with sampled data such as rainfall measurements. If you were to do that, you’d get a map, like the one below, where counties with no rainfall stations are not even drawn on the map — basically the map says there were no rain in those counties! That is not true, right?

To avoid that problem and produce an accurate map, we will use Thiessen polygons to compute the rainfall distribution in our area of interest. Such result can be achievable by executing some geoprocessing tools, but that produces result only for one time slice. Every time you want to see result for a different time slice, you need to rerun those tool. This blog post provides step-by-step instructions that overcomes geoprocessing tools limitations – makes the result map reactive to time slider’s current time and still computes aggregated results, such as total rainfall dynamically from a time series table.
Prepare the Data
Let’s get started:
- Download an ArcGIS Pro package to get started with sample data.
- Double-click on the package file you downloaded to open in ArcGIS Pro.
The Rainfall Data map contains a table and a couple of layers:- The two intermediate layers, found in a group layer, are the results of overlay operation between (a) Thiessen polygons (from point features representing rainfall stations) and county boundaries, and (b) Thiessen polygons and watershed boundaries.
- Create a new database connection to your enterprise database.
- Go to the Catalog pane, then navigate to Databases\Rainfall_IL.gdb.
- Copy all feature class and tables from the file geodatabase to your enterprise database.
Visualize Weighted Total Rainfall at the County Level
Next, we’ll add a query layer:
- Click the Query Layer option from the Add Data command on the Map tab.
- Select your database connection.
- Give it a name such as Weighted Total Rainfall by County.
- Copy the following query and paste it in the Query text box:
SELECT c.objectid, c.Name, c.shape, c.POP2010, fo.Rainfall AS Weighted_Total_Rainfall
FROM COUNTIES_IL c
INNER JOIN
(
SELECT t.fips, (sum(r.rainfall_inch * t.area) / sum(t.area)) AS rainfall
FROM COUNTIES_THSN_INTSCT_IL t
INNER JOIN
(
SELECT site_no, Sum(rainfall_inch) AS rainfall_inch
FROM USGS_RAINFALL_TIMESERIES_IL
WHERE ::r:dateRange
GROUP BY site_no
) r
ON r.site_no = t.site_no
GROUP BY t.FIPS
) fo
ON c.fips = fo.fips - Click the blue pencil icon next to the ::r:dateRange parameter to bring up an inline editor to define the parameter.

- Fill in all necessary information as seen in the following screenshot.
- Field or Expression—Type “date_time”.
- Data Type —Choose Date.
- Default value—Uncheck the check box.
- Name of the table the field belongs to—Type “USGS_RAINFALL_TIMESERIES_IL”.

- Click Done.
- Click the Validate button.
- Click the Next button if there is no error.
On the next page, Unique Identifier Field(s), Geometry Type, and Spatial Reference should get determined automatically. - Click Finish.
A query layer gets added to the map. - Symbolize the layer with unclassed symbology using the Weighted_Total_Rainfall attribute.
Since a range parameter is used in the query layer’s source SQL, the layer is automatically made time aware.
The Time Slider appears on the map. - Enable the time slider from the Time tab.
- Set the time span to 1 month.
Counties with computed rainfall for that month will appear. - Use the time slider to go to a different month, or change the time settings to view the aggregated result by week or for any other time duration.

Visualize Weighted Total Rainfall for Watersheds
If you want to visualize the weighted total rainfall for watersheds instead of county boundaries, all you need to do is to repeat steps from the previous section but with a watershed layer. Let’s create another query layer with the following SQL query:
SELECT w.objectid, w.huc8, w.Shape, rh.rainfall_w AS Weighted_Total_Rainfall
FROM USGS_HUC8_WATERSHEDS_IL w
INNER JOIN
(
SELECT huc8, (sum(r.rainfall_inch * c.areasqkm) / sum(c.areasqkm)) as rainfall_w
FROM USGS_HUC8_thsn_intsct_il c
INNER JOIN
(
SELECT site_no, Sum(rainfall_inch) AS rainfall_inch
FROM USGS_RAINFALL_TIMESERIES_IL
WHERE ::r:dateRange
GROUP BY site_no
) AS r
ON r.site_no = c.site_no
GROUP BY c.huc8
) AS rh
ON w.huc8 = rh.huc8

Share and Consume Data in Web Maps
You can share the map as a map image layer (or map service).
- Consume the service on a web application such as ArcGIS Online or a portal map viewer or a Web AppBuilder for ArcGIS application.
- Use the time slider to see the same results.
This script is going to be such a huge help but I am running into an error when I run the script as coped: it says that: name “GetParameter” is not defined. Is it because I am running ArcGIS Pro 2.4 perhaps? Thanks!
Hi Carissa,
This article discusses creating a script tool in ArcGIS Pro 2.8. For best results, please consider upgrading to the latest ArcGIS Pro version.
Best,
Jonah
Anyone try this? I can’t get the Time Zone to set correctly. After publishing, the feature service reflects UTC for our data’s date fields even though I set the “timezone” parameter to “Pacific Standard Time”.
Hi there,
I have created the publish web feature layer, but the input is “map”. What I want to select and publish is a “layer” in the content pane. Could you please tell me how to solve the problem? Thanks in advance.
Best
Leo
Hi Leo, please see this code sample: https://pro.arcgis.com/en/pro-app/latest/arcpy/sharing/featuresharingdraft-class.htm#GUID-8E27A3ED-A705-4ACF-8C7D-AA861327AD26
Hi Jonah, you sent me to this blog from another post last week (thank you!) and I’ve been working through the above and have come across the same problem as Leo. I’ve had a look at the code sample you supplied, is there a way to create a script tool using that code or does it need to be run as a standalone Python script? Or is there a way to alter the code for this blog to look at features rather than map files? Many thanks in advance
Hi James,
The code provided in this blog should be able to be modified with the sample code provided in the FeatureSharingDraft help topic. You’ll need to modify the script tool (code and script tool parameters). If you run into issues, I recommend posting in Esri Community or reaching out to Technical Support.
Best,
Jonah
This is great but I can only get it to work if I leave share_groups blank or just use one group name. Otherwise I get 0x800 “This value is not a member of” Any ideas? I’m separating group names with commas. I’m running ArcGIS Pro 2.9.
Hi Robert,
Good question. Since you have multiple groups, you will need to modify the share_groups parameter to accept multiple values. To do this, check the Multiple values check box when specifying the Parameter Data Type.
Best,
Jonah
That was all I needed, thanks.
Thank you very much for posting this! Is there a way to set the Portal connection where the data will publish to? It looks like it defaults to whatever Portal you are/were signed in to last. I have several Portal/ArcGIS Online connections in Pro but would like to specify which one it publishes too. I plan on setting this up as a scheduled task so I need to make sure it publishes to the right Portal. Thank you!
Hi Nicholas,
Yes, you can use the SignInToPortal ArcPy function: https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/signintoportal.htm
Best,
Jonah
Thank you for posting this article. I am having an issue with seeing my Portal connection in the output folder though. Is there a workaround for this? If I add the SignInToPortal ArcPy function, will this allow me to view the Portal Connection in my output folder?
Hello, I implemented this script tool and generally it works well. We do have a weird issue where if we try to use it to overwrite an existing hosted table, it works, but converts the item to a hosted feature layer. We need these items to persist in AGO as hosted tables. Any thought to adding a parameter to tell it to overwrite as a table rather than a service? or choose no geometry type? thanks!
I’ve downloaded and used the model as it is used in the demonstration map and it uploaded the layer directly to my AGOL content pane, however, when I attempt to run the Publish Web Feature Layer in my own map, the tool runs for a very extended period of time seemingly without end. Is there an option I should be selecting that is different? I selected to run the tool exactly how I had it in the demo as well.
I’ve downloaded the script and got the Model working with one exception, I have a date field and I can’t get it to publish in Eastern Time Zone. What should I be putting in the Time zone parameter? I’ve tried EDT and Eastern_Daylight_Time, but the date field in the web layer is showing UTC. As a side note, when I query the AGOL rest the date field is in EDT.
Thank
Steve
Hi Steve,
If you try “Eastern Standard Time”, I think it should work.
Best,
Jonah
I’ve tried running this script but I get a traceback error to lines 30, 68, and 122 and a ValueError: Missing target server. I copied the script over directly and used the correct inputs/configurations, so I’m not sure what the issue is. Any ideas?
I have successfully run this script within a model in a project, but I have not yet had success running it as a scheduled task. Here’s the error that I see in the log after attempting to run it as a scheduled task:
I have checked and re-checked the script and parameters, but all appears to be set up correctly.
@Michael Olkin did you ever fix this issue? I am experiencing the same thing. I can run the model fine and it publishes but when I schedule it I get this same error. @Jonah Lay Thank you!
Hello Jonah,
Thanks for sharing this script, it’s still “golding” to me. I have adapted it and tried to set the time zone to Eastern Standard Time or ET,EST and all the ways I can imagine the eastern standard time; yet, the time aware data after publishing still shows UTC time values. I have read others comments on the same issue. Are you able to look into that or any other work around. I really appreciate the effort put in.
Thanks,
Amin
Hi Amin, Good question. If you set “Eastern Standard Time”, it should work. Choosing EST means you are saying your data is stored in EST prior to publishing. If you see that time values appear in UTC, this is expected because the data is converted to and stored in UTC in the database. In Pro 3.1, we added support for “Preferred time zone for display”. A preferred time zone ensures that ArcGIS Pro displays data in the time zone of your choice when working with the web layer in the application. I don’t currently have any sample codes for setting… Read more »
Thanks Jonah, it worked at last. Any thought on overwriting a stand alone hosted feature layer in AGOL? This did not set the time zone but the feature was overwritten when I tried on a hosted feature layer not in a web map.
Dear Jonah,
Thanks for this great and absolutely useful tutorial!
I have a model which ends with a feature layer as output. How can I connect my model with the model in your tutorial to publish (only) my output feature to AGOL?
Thanks in advance!
Carlos
Hi Carlos,
You will need to modify the code to publish a layer rather than the map. Please see this sample code: https://pro.arcgis.com/en/pro-app/latest/arcpy/sharing/featuresharingdraft-class.htm#GUID-8E27A3ED-A705-4ACF-8C7D-AA861327AD26
Dear Jonah, Thank you. This is an excellent article. I’m having some difficulty publishing a single feature via a model I’ve created. I’ve modified the code to select my layer with “selected_layer = m.listLayers()[0]” and provided this variable within a list as a parameter in the m.getWebLayerSharingDraft() function however I am getting the error: Error 001272: Analzer errors were encountered ([{"code":"00102", "message":"Selected layer does not contain a required layer type for web feature layer", "object":"Map"}]). I can manually publish the layer to AGOL without any analyser errors though. Can you offer any insight as to why this is happening? Thanks… Read more »
Jonah,
This is a great tool and I am hoping to use it with some of our data. I have one question…How would the code be modified to overwrite a layer with attachments? The steps in the model work fine to add the attachments to the feature class, but I’m having trouble trying to overwrite the AGO layer with the updated attachments. Any help would be greatly appreciated. Thanks