Select to view content in your preferred language

How to use query layers with enterprise geodatabases (hands-on)

432
0
07-30-2024 10:58 PM
How to use query layers with enterprise geodatabases (hands-on)

At first

In this two-part series, we'll show you how to publish query layers and how to use them with ArcGIS Maps SDK for .NET. In the previous article, you introduced what query layers are in enterprise geodatabases and how to publish them. In this article, we will explain how to display the published layer on a map in a client application developed with ArcGIS Maps SDK for .NET, and how to update the reference DB.

In this article, in addition to the previous configuration, we will carry out the following configuration.

*Please refer to this site for how to use the ArcGIS Maps SDK for .NET.

Working Environment

SDK

ArcGIS Maps SDK for .NET 200.3

undefined

Map the layer

Invoke the published layer and display it in the client application.

The process from publishing to map display is identical to that of a regular feature layer.

The first step is to access the service on the server where you published the layer and get the URL of the service, including the layer ID .

undefined

Next, you'll code using the ArcGIS Maps SDK for .NET.

Create a feature table (ServiceFeatureTable) object by specifying the URL (_featureLayerPath) of the feature service based on the URL of the service you obtained earlier. Next, you'll create a feature layer (FeatureLayer) object from the feature table. Finally, you can add a feature layer to the Map object's operational layers (OperationalLayers) so that the layer appears on the map, as shown below.

//サービス URL
public string _featureLayerPath = <サービスURL>;
//フィーチャテーブル
public ServiceFeatureTable serviceFeatureTable;
//フィーチャレイヤー
public FeatureLayer featureLayer;
 
serviceFeatureTable = new ServiceFeatureTable(new Uri(_featureLayerPath));
featureLayer = new FeatureLayer(serviceFeatureTable);

MyMapView.Map.OperationalLayers.Add(featureLayer);

undefined

Add and update operations for each table in the query layer

Since it is not possible to add or update the joined table itself in the query layer, it is added or updated individually to the joined table. In doing so, the layer and the stand-alone table refer to some of the services differently. Also, adding to a table and updating it are handled differently.

Service references (for layers)

Get the URL of the published layer's service, including the layer ID .

undefined

Service reference (for stand-alone tables)

Unlike layers, an empty layer is stored at number 0 of the layer ID, and a stand-alone table is stored after number 1.

Check the standalone table and get the URL , including the layer ID .

undefined

Addition/update processing

Additions and updates are coded differently.

First, a common process for adding and updating is to create a feature table (ServiceFeatureTable) object by specifying the URL (_featureLayerPath) of the feature service based on the URL of the service.

//サービス URL
private string _ featureLayerPath = <サービス URL>
//フィーチャテーブル
public ServiceFeatureTable serviceFeatureTable;

serviceFeatureTable = new ServiceFeatureTable(new Uri(_featureLayerPath));

Next, I will explain how to describe the case of adding data and the case of updating data.

In the case of adding data

Create an empty feature to append the data. Load the features you created and populate the fields with data. Finally, you'll add the features you just created to the table and upload the changes to the feature service.

Feature Feature_Geo = serviceFeatureTable.CreateFeature();
await (Feature_Geo as ArcGISFeature).LoadAsync();
Feature_Geo.SetAttributeValue(<フィールド名>, <>);

await serviceFeatureTable.AddFeatureAsync(Feature_Geo);
await serviceFeatureTable.ApplyEditsAsync();

The following video is an example of what you need to do when you add data.

In this example, a park in Tokyo is symbolized.

In this case, you added a park symbol to the address of ESRI Japan headquarters in Chiyoda-ku by geocoding and confirmed that the display of the layer would change.

データ追加デモ.mp4
Video Player is loading.
Current Time 0:00
Duration 1:21
Loaded: 0%
Stream Type LIVE
Remaining Time 1:21
 
1x
    • Chapters
    • descriptions off, selected
    • captions off, selected
    • default, selected

    In the case of data refresh

    Retrieves the data to be updated by query. First, create an instance of the parameter class and set the conditional clause of the query to search for updates. Execute the query and get the results. Iterate over the acquired data. In the iteration, you'll load individual features, set values for each field, add the updated features to the table, and upload the changes to the feature service.

    QueryParameters param = new QueryParameters(); 
    param.WhereClause = <SQLのWhere句の内容を記述>;
    
    FeatureQueryResult featureResult = await serviceFeatureTable.QueryFeaturesAsync(param);
    
    foreach (Feature feature in featureResult)
    {
        await(feature as ArcGISFeature).LoadAsync();
        feature.SetAttributeValue(<フィールド名>, <>);
        await serviceFeatureTable.UpdateFeatureAsync(feature); 
        await serviceFeatureTable.ApplyEditsAsync();
    }

    The following video is an example of when the data is updated.

    In this example, the average rent for each ward in Tokyo is divided into classes and displayed.

    This time, we changed the average rent in Chiyoda Ward from 110000 yen to 4000 yen and confirmed that the display of the layer would be switched.

    (view in My Videos)

    At last

    In this article, you learned how to map a published layer in a client application developed with the ArcGIS Maps SDK for .NET , and how to update the referencing DB . By adding and updating the referencing DB , you can link with other systems that use the same DB . By linking, you can change layer information in real time and reflect data in other systems, so please give it a try.

    References

    Query layer

    ArcGIS Enterprise

    Enterprise Geodatabase Setup Guide (SQLServer)

    ArcGIS Maps SDK for .NET Library Reference

    ArcGIS Developers 開発リソース集

    ArcGIS Maps SDK for .NET

    Mr./Ms. Code

    Esri may utilize third parties to translate your data and/or imagery to facilitate communication across different languages.

    Version history
    Last update:
    ‎07-30-2024 10:58 PM
    Updated by:
    Contributors