Tutorial: Perform web editing using data from a database
In this topic
- Before beginning this tutorial
- Prepare the data
- Author a map document to support feature services and web editing
- Publish a map service with feature access enabled
- Consume the feature service in a web application
- Further reading
Web-based editing allows a larger group of people to add to and improve on your data. These include fieldworkers, analysts in other departments of your company, or perhaps even crowdsourced volunteers who may be able to make valuable contributions to your data given a user-friendly editing interface.
In this tutorial, you will load data to your database, grant privileges on the data, register your database with ArcGIS Server, author a map document, publish a feature service, and consume the feature service through the ArcGIS.com map viewer to edit the data.
Before beginning this tutorial
If you want to publish a feature service from a database, it is assumed that you have a database that can store spatial data. If you do not, you must install database management software and create a database. In some cases, you must also install a spatial type or enable the database to store spatial data. You can publish feature services from one of the following database management systems:
- ALTIBASE HDB
- IBM DB2 (requires DB2 Spatial Extender)
- IBM Informix (requires Informix Spatial Data Blade)
- Oracle (install the ST_Geometry type or use Oracle's SDO_Geometry type)
- PostgreSQL (install the ST_Geometry type or PostGIS)
- SAP HANA
- Teradata
You will need two users to complete this tutorial: one user who has privileges to create tables and feature classes in the database (a data owner) and one who initially only has connect privileges to the database (a data editor). You will grant the data editor privileges to edit the data to be published as a feature service.
If you are the database administrator, you can use the database management system's tools to create both users and grant the required privileges. Alternatively, you can use the Create Database User geoprocessing tool to create the data owner user, but you will still need to use database management system tools to create the data editor user. If you are not the database administrator, ask him or her to create a data owner and data editor for you to use to complete this tutorial.
If you've just installed ArcGIS Server, consider reading the following before you begin this tutorial:
- For details on how to configure your ArcGIS Server site, see Getting started after installation in the help.
- If you don't have prior experience with feature services, see What is a feature service?
- To publish data to ArcGIS Server, you must register the data. How you register the data depends on whether you want your feature service accessing the data in your source database or whether you want the feature service to access a copy of the data. For the purposes of this tutorial, the feature service will access the data in your database. However, you should understand what this means and what other options are available. See Make your data accessible to ArcGIS Server and Determining how the server will access service data to help you determine which method is best for your situation.
Prepare the data
This tutorial contains instructions to copy feature classes into your database through ArcGIS. Data copied in through ArcGIS meets the following criteria, which is required to publish data as a feature service:
- Feature classes you publish to a feature service to be edited must contain a not null integer field that is automatically populated with unique values by the database. This field will be used as an ObjectID field.
Tip:
If your data is added to the database using ArcGIS, a qualifying ObjectID field is automatically added to the table. If you have existing feature classes stored in DB2, Oracle, or PostgreSQL that you want to publish, you can use the Add Incrementing ID Field tool to add a not null integer field that is populated by the database to your table.
- ArcGIS only recognizes one spatial column, one spatial reference, and one geometry type (that is, points, lines, or polygons) for a feature class. If your feature class contains more than one spatial column, ArcGIS will use the first one it comes to when reading the table from left to right. If your feature class contains records with different spatial references, geometries, or dimensionalities, ArcGIS will read the value of the first record in the feature class and use that. Records that do not correspond to that value will not be used.
- All feature classes published to a feature service must have a spatial reference. Feature classes with unknown spatial references cannot be published.
- ArcGIS recognizes specific data types. If your feature class contains data types not supported by ArcGIS, they cannot be viewed by ArcGIS clients and cannot be accessed through the feature service. See DBMS data types supported in ArcGIS for a list of the data types with which ArcGIS can work.
To create a feature class in ArcGIS that meets all these requirements, complete the next section of the tutorial.
Add feature classes to the database
Connect to the database as the data owner (the user who has privileges sufficient to create tables in the database) and copy feature classes from a file geodatabase installed with ArcGIS for Server.
Connect to the ArcGIS Server sample data
A file geodatabase (tree_maintenance.gdb) is installed with ArcGIS for Server. Connect to it from ArcGIS for Desktop.
If you installed ArcGIS for Server on a Linux machine, copy or ftp the tree_maintenance.gdb to a directory on your ArcGIS for Desktop computer. The default location of the data on Linux is <home directory of installing user>/arcgis/server/help/samples/data.
- Start ArcCatalog or ArcMap and open the Catalog window.
- Click Connect To Folder .
- Choose the sample data folder, located in the directory where you installed ArcGIS for Server (Windows) or copied from your ArcGIS for Server (Linux) installation.
By default, the Windows data is installed to C:\Program Files\ArcGIS\Server\help\samples\data.
- Click OK to add the folder to the Folder Connections in the Catalog tree.
Connect to the database as the data owner
Connect to the database as the data owner user so you can copy data into the database.
- Expand the Database Connections node in the Catalog tree of the Catalog window.
- Double-click Add Database Connection and connect to the database as the data owner user.
See Database connections in ArcGIS Desktop for information on connecting to a database.
- Name the connection file so that you can identify it as the data owner's connection.
For example, right-click the new connection, point to Rename, then type dataowner@mydatabase.sde.
Copy data to your database
Copy the trees, villages, and streets feature classes from the tree_maintenance file geodatabase and paste them into your database.
- Open the sample data folder.
- Double-click the tree_maintenance geodatabase to connect to it.
- Press and hold the Shift key and choose the streets, trees, and villages feature classes in the tree_maintenance geodatabase.
You must click on the feature classes in the Contents tab (ArcCatalog) or Contents pane (ArcMap) to choose multiple feature classes at the same time.
- Right-click the highlighted feature classes and click Copy.
- Right-click your database connection and click Paste.
Copies of the streets, trees, and villages feature classes are in your database.
Grant privileges on the data
The user who will access the data you publish must be granted privileges sufficient to edit the data. For example, if you want people to insert new features and update existing features in the feature classes you publish, you must grant the connecting user select, insert, and update privileges on the data. If you only want people to update existing records, grant the connecting user select and update privileges on the data.
You can publish the data as the data owner if you are publishing to a test site or are completing this tutorial merely for educational purposes. However, if you are publishing data to a production site, the connection used to access the data should have the least privileges required.
If you use database-authenticated users, grant privileges on the data to the database user. If you use Windows authentication to connect to the database, you must grant the privileges to the ArcGIS Server account.
The following steps grant select, insert, and update privileges on the feature classes to be included in your feature service. If you are using your own data, follow the same basic steps to grant privileges on your data.
- Right-click the trees feature class under the database connection in the Catalog tree, point to Manage and click Privileges.
The Privileges dialog box opens.
- If the data editor database user or ArcGIS Server account is already in the list, check the boxes to grant select, insert, and update privileges on the trees feature class.
- If the data editor database user or ArcGIS Server account is not already in the list, do the following:
- Click Add to open the User/Role dialog box.
- If you have privileges in the database to view the system table that lists all users and roles in the database, you can choose the database user or role you want to add from the list by checking the box next it; otherwise, type the name of the database user, database role, operating system login, or Windows group to which you want to grant privileges.
- Click OK to close the User/Role dialog box.
The Select box is already checked.
- Check the Insert and Update boxes and click OK to apply the privileges and close the dialog box.
- Repeat these steps for the villages and streets feature classes.
Author a map document to support feature services and web editing
Once you have the data you want to publish and have granted privileges so ArcGIS Server can access the data, you can author a map document to support the feature service you will use for web editing.
Connect to the database as a data editor
If you are using database authentication, connect to the database as the data editor user. Follow the same procedure to connect to the database as you did to connect as the data owner, only, this time, connect as the data editor. Be sure to save the user name and password with the connection by checking Save user name and password.
If you are using operating system authentication, you can connect with a login that has at least select privileges on the data. The feature service will access the data as the ArcGIS Server account, which you have already granted privileges to edit the data, not the login you are using to create and publish the map.
To help you find the connection file, rename it to be dataeditor@mydatabase. You will need this connection file when registering the database with the server.
Register the database with the server
To publish to ArcGIS Server, you must create a publisher connection to your GIS server and register your database with it. For this tutorial, you will register the database so that the publisher database is the same as the server database. That means the published feature service will access the data directly in the source database.
- First, connect to the server to publish data. Follow the instructions in Making a publisher connection to ArcGIS Server in ArcGIS for Desktop to make this type of connection.
- Once you are connected to the server, you can register the database. Right-click the GIS server connection and click Server Properties.
- On the Data Store tab, click the Add button next to Registered Databases.
The Register Database dialog box opens.
- Enter a unique name for the registered database.
- Click Import and browse to and select the database connection file you created in the last section (the editor's connection to the database).
- Make sure the box is checked next to Same as publisher database connection.
- Click OK to close the Register Database dialog box.
- Click OK to close the ArcGIS Server Properties dialog box.
Tip:
For more information on registering specific databases, see the following topics:
Add data to the map and set properties
You can drag the feature classes you want to publish from the editor's database connection in the Catalog window to the map. ArcMap checks for the properties it requires, such as an ObjectID field and spatial reference. If it cannot determine these properties, you will be prompted to specify the required information.
When you add a database table to ArcMap, a query layer is defined to access that table. You can alter the query layer that defines what data is displayed in ArcMap. See Modifying a query layer for instructions on changing the query layer definition.
Note:
The query definition cannot join tables; query layers can only contain data from one table if you want to publish a feature service.
When you have finished configuring the map, save your map document.
- Start ArcMap if it is not already started.
- Double-click the data editor connection in the Catalog window to connect to the database.
- One at a time, choose the feature classes from the database connection and drag them onto the map.
If you are using the tutorial data, choose the villages, trees, and streets feature classes.
ArcMap calculates the spatial extent of the data and displays the features on the map.
- Make sure the layers are drawn in the correct order. For the tutorial data, the order should be trees, streets, villages. If the layers are in the wrong order, click List By Drawing Order and drag the layers into the right order in the table of contents.
Once the data has been added to the map, you can set field properties, symbology, and a layer description. You can also configure HTML pop-up windows. See Author feature services for more information on setting map properties.
Set properties for the trees layer
Set general properties for the trees layer.
- Right-click the trees layer in the ArcMap table of contents and click Properties.
The Layer Properties dialog box opens.
- On the General tab, change the Layer Name to Public Trees.
- Type the following for the Description: An inventory of trees in public spaces, which are maintained by the Parks Department.
- Set a minimum scale beyond which the trees layer will not draw.
- Under Scale Range, click Don't show layer when zoomed.
- Set the minimum scale to 1:500,000.
- Leave the maximum scale set to <None>.
- Click Apply to set the property changes you've made so far.
Set field aliases.
- Click the Fields tab.
- Assign aliases to the fields as follows:
- Choose tree_planted from the fields list, and type Date Planted in the Alias field.
- Choose eg_decid from the fields list, and type Evergreen or Deciduous for the alias.
- Choose last_trimmed from the fields list, and type Date Trimmed for the alias.
- Click Apply to set field aliases.
Next, change the symbology for the trees layer.
- Click the Symbology tab of the Layer Properties dialog box.
- Click Categories.
The Unique values category is selected by default.
- Choose Evergreen or Deciduous from the Value Field drop-down list.
- Click Add All Values.
The values d and e are added to the list with default symbols and colors.
- Change the symbol for the deciduous (d) trees.
- Double-click the default symbol for d to open the Symbol Selector dialog box.
- Click Style References and check the box next to Civic.
- Click OK to add the Civic symbols to the Symbol Selector.
- Choose the Tree 3 symbol.
You will need to scroll down to find the symbol.
- Click OK to apply your change.
- Change the symbol for the evergreen (e) trees.
- Double-click the default symbol for e to open the Symbol Selector dialog box.
- Choose the Tree 2 symbol.
- Click OK to apply your symbol change.
- Click OK to apply all symbology changes and close the Layer Properties dialog box.
Set properties for the villages layer
Set general properties for the villages layer.
- Right-click the villages layer in the ArcMap table of contents and click Properties.
The Layer Properties dialog box opens.
- On the General tab, change the Layer Name to Villages.
- Type the following for the Description: Boundaries of the villages of Osokopf.
- Set a minimum scale for drawing the villages layer.
- Under Scale Range, click Don't show layer when zoomed.
- Set the minimum scale to 1:10,000,000.
- Leave the maximum scale set to <None>.
- Click Apply to set the property changes you've made so far.
Set field aliases.
- Click the Fields tab.
- Assign aliases to the fields as follows:
- Choose village_name from the fields list, and type Name for the alias.
- Choose population from the fields list, and type Population (2010) for the alias.
- Click Apply.
Change the color used to symbolize the villages layer.
- Click the Symbology tab.
- Click Categories.
Unique values is selected by default.
- Choose Name from the Value Field drop-down list.
- Click Add All Values.
- Choose a different color for each village.
- Once all your symbology changes are made, click OK to apply all your changes and close the Layer Properties dialog box.
Set properties for the streets layer
The recommended practice is to publish a separate map service for reference data. However, to reduce the number of steps needed to complete this tutorial, the streets layer will be part of your feature service even though it is only used as reference data.
- Follow the same procedures that you did for the other layers to set general properties, symbology, and field aliases for the streets layer.
- Click the Labels tab.
- Check Label features in this layer.
- Make sure the Label Field is set to the st_name field.
- Set a scale range for the labels.
- Under Other Options, click Scale Range.
- Click Don't show labels when zoomed, and set the minimum scale to 1:250,000.
- Click OK to close the Scale Range dialog box.
- Click Apply to apply your changes.
By default, HTML pop-up windows are enabled for all feature classes. However, you won't be editing the streets layer, so you can disable HTML pop-up windows.
- Click the HTML Popup tab in the Layer Properties dialog box.
- Uncheck Show content for this layer using the HTML Popup tool.
- Click OK to apply your changes and close the Layer Properties dialog box.
Publish a map service with feature access enabled
Now that your data and map are ready, you can publish a map service with feature access enabled.
- From the main menu in ArcMap, choose File > Share As > Service.
- In the Share as Service window, choose Publish a service. Click Next.
- In the Publish a Service dialog box, choose the publisher connection to ArcGIS Server you set up earlier in the tutorial.
- By default, the name of the map document is used for the service name. Instead of using the default, type TreeMaintenance.
- By default, services are published to the root folder (root) of ArcGIS Server. Accept the default location and click Continue.
The Service Editor dialog box displays. Use Service Editor to choose what users can do with your feature service and take fine-grained control of how the server exposes your feature service.
- Click the Capabilities tab.
- By default, mapping and KML are enabled. Choose Feature Access. Enabling this option creates an associated feature service with your map service that allows clients to perform feature editing over the web.
- In the left pane of the Service Editor dialog box, click Feature Access and review the URLs to be used for the service.
- Under Operations allowed, uncheck Delete.
Remember, you did not grant the connecting user privileges to delete features.
- In the left pane of the Service Editor dialog box, click Item Description and type the following:
- For Summary, type Service used to update the inventory of public trees.
- For Tags, type trees,maintenance,parks.
- For Description, type The Tree Maintenance feature service can be used to update the inventory of public trees.
- Click Analyze to be sure you will be able to publish your features.
If any error messages are returned, you must correct those before you can publish. You can correct warning or informational messages, but you do not have to; they are provided to improve the performance and usability of your resultant service but are not required for the service to function. You can ignore warning 24041, since you can only use default templates when editing database data through a feature service.
- Click Publish .
Your feature service is published to ArcGIS Server. Now you can consume your feature service in a web application and make edits.
Consume the feature service in a web application
In this section of the tutorial, you'll use the ArcGIS.com map viewer to add, update, and edit features in your database over the web. The map viewer is hosted on ArcGIS.com and is deployable directly through the ArcGIS Server Service Directory. It does not require any configuration or programming work to use the map viewer.
To get started, follow these steps:
- Open a web browser and browse to the ArcGIS Server Services Directory. Typically, this is located at http://gisserver.domain.com:6080/arcgis/rest/services. You can also access the Services Directory by opening the shortcut installed with ArcGIS Server.
- In the services list, click TreeMaintenance (Feature Server).
- On the TreeMaintenance (FeatureServer) page, the trees, streets, and villages feature classes are listed, as well as the supported operations for the feature service. Review these parameters to be sure they are correct.
- Click View In: ArcGIS.com Map at the top of the page.
A new window (or tab) opens, displaying the ArcGIS.com map viewer.
- At the top of the map viewer, click Edit.
The Add Features dialog box opens.
- Zoom in to different areas of the map and edit attributes of existing features. To edit an attribute:
- Click on a feature.
The HTML pop-up window opens.
- Type a new value in a field. For dates, choose a date from the calendar.
- Click Close to apply your edits and close the HTML pop-up window.
- Click on a feature.
- Also, add new features to the trees layer. To do this:
- Click either the d (deciduous) or e (evergreen) symbol in the Add Features pane.
- Click the point on the map where you want to place the tree.
- Select the tree you added and add attributes through the HTML pop-up window.
- Click Close to apply your edits and close the HTML pop-up window.
- Verify that edits to your features are reflected in your database.
You can do this by switching back to your ArcMap document and refreshing the map display. The features you added to your web map appear in the map display. To see edits to the attributes, open the attribute table for the trees layer in ArcMap.
- If you want, you can sign in to ArcGIS Online and save your map.
Further reading
Now that you've successfully tested your feature service using the ArcGIS.com map viewer, you might want to consider how you can use and share your feature service in other ArcGIS clients. For example
- In ArcGIS Online and Portal for ArcGIS, you can create a customized web mapping application using the application templates. These templates can be deployed on your organization's web server.
- ArcGIS API for JavaScript offers the most advanced web mapping capabilities and customization options. If you're comfortable programming using this API, you can create a rich editing experience for your users on the web by utilizing a feature service identical to the one you created in this tutorial.
Remember that web-based editing allows external users to add to and improve on your data. By exploring one or all of the ArcGIS clients listed above, you give yourself additional options that can help you tailor your editing scenario for a specific purpose, goal, or organizational strategy.