Publish a feature service
In this tutorial, you’ll create a hosted feature layer in ArcGIS Online to display near real-time reservoir data for Texas. First, you’ll download reservoir data for Texas. Next, you’ll use this information to publish a hosted feature layer and configure a view of it. You'll configure a Python script to update the feature layer and set up a Windows task to run it. The Texas reservoirs data feature layer will be overwritten as new data becomes available, so any web maps based on the feature view will always display the latest information.
Access near real-time reservoir data for Texas
First, you'll access reservoir information from the Water Data for Texas website. Then, you'll download the data in GeoJSON format and store it locally.
- In a browser, go to the Water Data for Texas website. Scroll down and under the Statewide Conservation Storage chart, click Recent Averaged Storage Conditions and choose GeoJSON.

The website redirects you to https://www.waterdatafortexas.org/reservoirs/statewide/recent-conditions.geojson, which contains the near real-time reservoir data for Texas. This is a GeoJSON file. For each reservoir in Texas, it contains information such as location (coordinates), name, conservation capacity, percent full, and last updated time (time stamp).

Note:
The Water Data for Texas website is dynamic. It is frequently updated, as soon as new data is available. The time stamp value for each reservoir displays the time of the last update. - Click on the page and press Ctrl + A to select all of the text on the recent conditions page, then right-click and click Copy. You can also press Ctrl + C to copy the text.

- Open a text editor such as Notepad++ and press Ctrl + V to paste the text into a new file.
- Save the file to your local computer. In the Save as window, browse to a folder on your computer such as C:\Temp\. For File name, type recent-conditions.geojson and for Save as type choose All types. Click Save.

Note:
Check the file in your local folder after you save it to verify that the file extension is .geojson and not .geojson.txt.
Add an item to ArcGIS Online
You'll use the local GeoJSON file of reservoir data for Texas to create a hosted feature layer in ArcGIS Online.
- Sign in to your ArcGIS organizational account.
Note:
If you don't have an organizational account, see options for software access.
- If necessary, click Content, and click My Content.

- Click New item.

- Drag the recent-conditions.geojson file that you just saved onto the upload pane or click Your device and browse to the file.
- For How would you like to add this file?, accept the default option of Add recent-conditions.geojson and create a hosted feature layer and click Next.
- On the next page of the New item page, enter the following:
- For Title, type TX_reservoirs_recent_ followed by your name or initials (for example TX_reservoirs_recent_(yourname).
- For Tags, type Texas, Reservoirs, Recent Conditions and press Enter after each tag.
- For Summary, type Near real-time reservoir information for Texas.
Note:
You cannot create two layers in an ArcGIS organization with the same name. Adding your initials to a layer name ensures that other people in your organization can also complete this tutorial. Once a layer has been created, you can rename it in the map to remove your initials, which will not affect the name of the underlying data layer.
- Click Save.
The process will take a few moments. After it completes, the Overview page for the TX_reservoirs_recent_(yourname) hosted feature layer appears. In addition to this layer, a copy of the TX_reservoirs_recent GeoJSON file is added to your My Content section.
You accessed near real-time reservoir information for Texas and created a hosted feature service in ArcGIS Online. Next, you'll use the feature service to create a feature view. This feature view can be customized, shared publicly, and added to your apps. Creating the feature view allows the feature service to be updated without disrupting the symbology and pop-ups configured for the view. This simplifies the process of updating the data later.
Create a hosted feature layer view
Now you'll create a hosted feature layer view from the hosted feature layer, share the hosted feature layer view publicly, update its symbology, and configure its pop-up.
Create the hosted feature layer view
The Texas reservoirs hosted feature layer that you created will be overwritten when new information is available. The overwrite process will remove any custom symbology and pop-up settings and restore it to the default settings. To avoid changing how the data is displayed in your web maps and apps, you will create a hosted feature layer view in ArcGIS Online and configure its symbology and pop-up settings. These will remain the same and display the latest data after the hosted feature layer is overwritten.
- On the TX_reservoirs_recent_(yourname) feature layer Overview page, click Show more.

- Click the Create view layer drop-down menu and choose View layer.

- On the Create view layer page, in the TX_reservoirs_recent_(yourname) pane, the TX_reservoirs_recent_(yourname) point layer is selected by default. Click Next twice.
In the Included layers pane you can set layer definitions. To learn more about these options, view the Create hosted feature layer views documentation.
- In the Create pane, enter the following:
- For Title, type Texas Reservoirs Recent Conditions (Your Name).
- For Folder, you can optionally specify a folder where you want to save the view layer.
- For Tags, type Water, Environment, Natural Resources, Live Feeds, livefeeds, pressing Enter after each tag.
- For Summary, you can optionally provide additional text about the view layer.
- Click Create. Once the view has been created a Success window appears. Close this window.
A new hosted feature layer view item is created from the hosted feature layer and the item details page for the new feature layer view appears.
- On the Overview page, click Share, choose Everyone (public), and click Save.
The hosted feature layer view is now public and accessible to everyone.
- On the ribbon, click Content.
There are now three items in your My Content page: the GeoJSON file, the hosted feature layer, and the view.

Note:
It is a good practice to use a hosted feature layer view to share a hosted feature layer, keeping the original hosted feature layer private. You can change the pop-up and the symbology of the hosted feature layer view without modifying the original hosted feature layer. During an update process, the hosted feature layer can be overwritten, and the new values will be reflected in the hosted feature layer view. The symbology of the hosted feature layer view is saved with it and is not affected when the original hosted feature layer is overwritten.
Change symbology
The hosted feature layer view has the reservoir data for Texas. You'll customize its symbology to better represent the information in the layer using the reservoirs' capacity for different feature sizes and using the current percent-full level for different colors.
- Click the Texas Reservoirs Recent Conditions_(Your Name) feature layer to open the hosted feature layer view item page.
The item page for Texas Reservoirs Recent Conditions_(Your Name) appears on the Overview tab.
- Click Open in Map Viewer.

- If necessary, in the Layers pane, click the Texas Reservoirs Recent Conditions layer to activate it.
Note:
You may choose to remove your name from the Texas Reservoirs Recent Conditions (Your Name) layer display name by clicking the layer's Options button and choosing Rename.
- On the Settings (light) toolbar, click Styles.

- Under Choose attributes, click the Field button.

- In the Select fields window that appears, choose percent_full and conservation_capacity and click Add.

The attributes are added to the Styles pane.
- For percent_full, click the Reposition button and drag it above conservation_capacity.

- Under Pick a style, for Color and Size, click Style options.

- For Counts and Amounts (Color), click Style options.

- In the Style options pane, for Data range, on the histogram, click the minimum value break, type 50 and press Enter.

Note:
Your Data range values may be different, as you are using more recent data.
- For Symbol style, click the color ramp.

- In the Symbol style window, for Colors, click the color ramp.
- In the Ramp window, choose Blue 10 and click Done.

To see the name of a color ramp, point to the color ramp.
- In the Style options pane, click Done.
- For Counts and Amounts (size), click Style options.

- For Symbol style, click the symbol. In the Symbol style window, for Outline color, click the Edit button.

- For #, delete the current value and replace with 283849 and press Done.
- In the Style options pane, click Done, and click Done two more times.
The symbology for the layer is now set.
- On the Contents (dark) toolbar, click Basemap and click Light Gray Canvas.

The symbology for the basemap is now set.

The final map shows the recent conditions of reservoirs in Texas. The color of each point represents the percentage full of each reservoir, and the size of the point represents the total reservoir capacity. Next, you'll configure the map and save it.
Configure the pop-up
You will improve the pop-up for the layer to display only the relevant information. You'll show the name, capacity, and percent full for each reservoir.
- On the Settings toolbar, click Pop-ups.

- On the Pop-ups pane, expand Title, delete the existing text, and click the Add Field button.

The Add field window appears.
- For Fields list, choose full_name.
The pop-up title will now show the contents of the attribute full_name.
- For Fields list, click the Options button and choose Delete.

- Click the Add Content button and click Text


A text box appears.
- In the text box, type or paste {percent_full}% full as of {timestamp} and click OK.

The attribute field names in curly braces will be replaced with the values from those fields when the pop-up is opened by clicking a feature.
The pop-up will now show the title and text you configured when a feature is clicked.

You can still improve the format of the fields by configuring how each of the fields is displayed.
- On the Settings toolbar, click the Fields tab and click the percent_full field.
- In the Manage field window, change the Display name to Percent Full (%). For Significant digits, change both the Minimum and Maximum to 0.

- Click Done.
- On the Contents toolbar, click Save and open and click Save as.
- In the Save map window, enter the following:
- For Title, type Texas Reservoirs
- For Tags, type Water, Texas, and Reservoirs. Press Enter after each tag.
- For Summary, type A near real-time map of Texas reservoirs showing percent full and capacity.
- Click Save.
- Click a reservoir on the map.
The pop-up displays the name of the reservoir, the percent full, and the date last updated.
You've created a hosted feature layer view in ArcGIS Online from the reservoirs hosted feature layer. The hosted feature layer view allows you to customize the display of the Texas reservoir layer and retain these customizations even when the hosted feature layer is overwritten. Next, you'll overwrite the Texas reservoirs hosted feature layer using a simple Python script. The updated information will be reflected automatically in the hosted feature layer view.
Update a hosted feature layer
Next, you'll configure a short script to overwrite the Texas reservoirs hosted feature layer. First, you'll download the overwrite script from ArcGIS Online. Then, you'll retrieve the hosted feature layer parameters such as item title and item ID. Finally, you'll run the script locally using the Python Command Prompt. The overwrite process allows you to update the hosted feature layer with the latest information.
Download the overwrite script
First, you'll download the script for overwriting a hosted feature layer in ArcGIS Online.
- Download the OverwriteFS.zip file to your computer.
The .zip file contains several items, including the Python script (OverwriteFS.py) and a document (ReadMe.pdf).
- Extract the contents of the .zip file to a folder on your computer, for example, C:\Temp\.
- Open a text editor such as Notepad or Notepad++ to a new, blank text file.
- On the map ribbon, click the navigation button and click Content.

- In ArcGIS Online, under My Content, click the TX_reservoirs_recent_(yourname) hosted feature layer.
You will need to know the title and the item ID for this hosted feature layer in order to update it. You will save this information in a text document for reference.
- On the TX_reservoirs_recent_(yourname) item Overview page, copy the item title and paste it into the text file.

- Copy the item ID at the end of the item's URL and paste it into your text file. Save the file, but keep it open, you will need this information soon.
In this example, the item title is TX_reservoirs_recent_(yourname) and the item ID is b99000442d0742c6aa503d5be5c1aad1. The item ID is unique for each item in ArcGIS Online. Your item ID will be different.
Store ArcGIS Online credentials locally
ArcGIS Online requires login credentials to overwrite items. You'll store ArcGIS credentials locally in a secure profile. This profile will be used in the Python script to overwrite the reservoirs hosted feature layer.
- Open the Windows Start menu, search for Python Command Prompt, and open it.
Note:
If you have installed ArcGIS API for Python separately from an ArcGIS Pro installation, use your package manager to activate the environment in which you installed ArcGIS API for Python and then open the Python command prompt (see the Esri Developer page for help setting up Python and the ArcGIS API for Python).
- Type cd, add a space, and type the path to the folder where you extracted the OverwriteFS.py script and press Enter.
For example, if you extracted the script to C:\Temp, you would type cd C:\Temp.

- Type python and press Enter.

This starts the Python console in the Python Command Prompt window. The Python version is noted in the console and the input prompt changes to >>>.
Next, you'll import the arcgis Python module.
- In the Python console, type import arcgis and press Enter.

Note:
The Python command prompt and the arcgis Python module are included with the ArcGIS Pro installation.
Next, you'll store your ArcGIS Online credentials locally by adding a profile.
- Type the command gis = arcgis.GIS(profile='learn_user', username= '<account>', password= '<pass>'), replace <account> with your username account and <pass> with your password. Press Enter.

Note:
Your ArcGIS Online credentials will be securely saved in the learn_user profile. You can learn more about storing ArcGIS Online credentials locally in a profile by visiting the Working with different authentication schemes page.
- Type exit() and press Enter to close the Python console and return to the command prompt.
Overwrite the hosted feature layer
Now use the overwrite Python script, the ArcGIS Online profile, and the hosted feature layer parameters (item ID and title) to update the reservoirs hosted feature layer.
- In the Python command prompt, in the C:\Temp\ folder that contains the OverwriteFS.py script, type the following command: python OverwriteFS.py learn_user <item id> <item title> <GeoJSON URL>, replacing <item id> and <item title> with the parameters of the hosted feature layer you saved in your text file. You'll replace <GeoJSON URL> with the URL of the data source with the updated data, https://www.waterdatafortexas.org/reservoirs/statewide/recent-conditions.geojson.
In this code, learn_user is the ArcGIS Online profile saved locally.
Note:
Because you've already created the hosted feature layer using the most recent data, the script won't make any changes. Instead, you can temporarily use this file, which contains a snapshot of the recent-conditions.geojson file for December 26, 2019.
If you run it with the GeoJSON URL to the live Texas water site, the command will resemble the following (the item ID will be different):
python OverwriteFS.py learn_user b99000442d0742c6aa503d5be5c1aad1 TX_reservoirs_recent_(yourname) https://www.waterdatafortexas.org/reservoirs/statewide/recent-conditions.geojson
If you download the snapshot of the recent-conditions.geojson file for December 26, 2019, save it to the C:\Temp\ folder that you are working in (replace the existing file), the command will resemble the following (the item ID will be different, and the path will be a local file path instead of a URL):
python OverwriteFS.py learn_user b99000442d0742c6aa503d5be5c1aad1 TX_reservoirs_recent_(yourname) c:\Temp\recent-conditions.geojson
- Press Enter to run the command.
The command prompt displays the results. The Elapsed Time for Overwrite Process message at the end means that the script correctly updated the hosted feature layer.

- In a browser, open your Texas Reservoirs map in Map Viewer. Click any reservoir to view its pop-up.
The pop-up shows the updated date and percent-full values. The symbology of the hosted feature layer view remains as you set it.
You ran a Python script to overwrite a hosted feature layer in ArcGIS Online. Next, you'll create and schedule a task in Windows to automatically run the overwrite script at regular intervals.
Create and schedule a task
You ran a Python script to update a hosted feature layer. Now, you'll automate running the script by scheduling a task in Windows. First, you'll create a .bat file. Then, you'll create a task in Windows Task Scheduler. The task will regularly run the .bat file, which will run the overwrite Python script, which will check for updates and overwrite the hosted feature layer if new data is available.
Create a .bat file
Windows .bat files are simple text files with a set of instructions to be run by the command line interpreter.
- Open a text editor such as Notepad or Notepad++.
- Copy and paste the following text into the text editor:
"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe" "C:\Temp\OverwriteFS.py" learn_user 3b2b385c923147349dec02025e10aa55 TX_reservoirs_recent_(yourname) https://www.waterdatafortexas.org/reservoirs/statewide/recent-conditions.geojsonYou can also type the text it as a single line.
- Change the item ID from 3b2b385c923147349dec02025e10aa55 to the item ID of your hosted feature layer.
- Change TX_reservoirs_recent_(yourname) to the name of your item.
- Save the file in your C:\Temp\ folder, and type TXreservoirs_overwrite.bat for the file name. In the Save as type drop-down menu, choose All types (or if you are using Notepad++, choose Batch file).

Next, you'll create a task to run the .bat file.
Create a basic task
Now that you have a .bat file, you’ll schedule a task to run it at regular intervals.
- Open the Windows Start menu. Search for and open Task Scheduler.
- In the Actions panel, click Create Basic Task.

The Create Basic Task Wizard window appears and starts on the Create a Basic Task tab.
- In the Create Basic Task Wizard window, for Name, type TX reservoirs, and for Description type Task to run the TXreservoirs_overwrite.bat file to update the feature service.

- Click Next.
The Task Trigger tab appears.
- For When do you want the task to start?, confirm Daily is selected and click Next.

The wizard updates to the Daily tab.
- For Start date, choose today’s date. Set the start time to be one hour after the current time (4:35 p.m. in the example).

- For Recur every, type 1 to make the task run every day and click Next.
- On the Action page, confirm that Start a Program is selected as the task action and click Next.
- On the Start a Program page, in the Program/script text box, type C:\Temp\TXreservoirs_overwrite.bat and click Next.
Note:
If you saved the .bat file in another folder, ensure you enter the correct path to the .bat file. You can also click the browse button and browse to the location of the file.

The Finish tab appears in the wizard.
- Check the box for Open the properties dialog for this task when I click Finish box and click Finish.

The TX reservoir Properties (Local Computer) window appears.
- On the General tab, under Security options, check the box for Run whether user is logged on or not and check Do not store password. Click OK.

The task will run at the scheduled time, updating the hosted feature layer with the latest information from the Water Data for Texas website. The hosted feature layer view will show the updated information from the hosted feature layer while retaining the same symbology and pop-up configuration.
In this tutorial, you downloaded data from the Water Data for Texas website and created a hosted feature layer. You created, customized, and shared a hosted feature layer view of the hosted feature layer to isolate the public item from the update process. You adapted, downloaded, and used a Python script to obtain the latest data from the website and update the hosted feature layer. You also created a .bat file and scheduled a Windows task to run the Python script. When the task runs, the overwrite Python script will update the hosted feature layer. You configured the task to run daily, so any web maps or apps that display the hosted feature layer view will show the latest data each day.
