public void MainMethodCode() { Uri arcgisOnlineURL = new Uri("http://services1.arcgis.com/47GG2ga246DGaLwa/arcgis/rest/services/FeatureServiceName/FeatureServer"); ServiceConnectionProperties arcGISOnline = new ServiceConnectionProperties(arcgisOnlineURL); using (Geodatabase featureService = new Geodatabase(arcGISOnline)) { using (FeatureClass featureClass = featureService.OpenDataset <FeatureClass>("0")) { // Use the feature class opened from layer ID 0. } using (Table table = featureService.OpenDataset <Table>("4")) { // Use the table opened from layer ID 4. } using (AttributedRelationshipClass attributedRelationshipClass = featureService.OpenDataset <AttributedRelationshipClass>("5")) { // Use the attributed relationship class opened from layer ID 5. } try { string idOfLayerWhichIsNotTable = "3"; featureService.OpenDataset <Table>(idOfLayerWhichIsNotTable); } catch (InvalidOperationException) { // Handle Exception. } } }
protected override void OnClick() { // Approach 1 // open feature service by known URL ServiceConnectionProperties svcsProperties = new ServiceConnectionProperties( new Uri("http://services.arcgis.com/6DIQcwlPy8knb6sg/arcgis/rest/services/Openstreetmap/FeatureServer")); QueuedTask.Run(() => { using (FeatureService featureService = new FeatureService(svcsProperties)) { var footprints = featureService.OpenDataset <FeatureClass>(0); var featureClassDefinition = footprints.GetDefinition(); var oidField = featureClassDefinition.GetObjectIDField(); } }); // Approach 2 // open feature service from layer var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(); QueuedTask.Run(() => { using (FeatureService featureService = featureLayer.GetFeatureClass().GetDatastore() as FeatureService) { var footprints = featureService.OpenDataset <FeatureClass>(0); var footprintsFeatureClass = featureLayer.GetFeatureClass(); var featureClassDefinition = footprints.GetDefinition(); var oidField = featureClassDefinition.GetObjectIDField(); using (var featureCursor = footprints.Search(new QueryFilter() { WhereClause = "building = 'yes'" }, false)) { while (featureCursor.MoveNext()) { var currentFeature = featureCursor.Current as Feature; System.Diagnostics.Debug.WriteLine(currentFeature["osmuser"]); } } } }); }
public void MainMethodCode() { Uri arcgisOnlineURL = new Uri("http://services1.arcgis.com/47GG2ga246DGaLwa/arcgis/rest/services/FeatureServiceName/FeatureServer"); ServiceConnectionProperties arcGISOnline = new ServiceConnectionProperties(arcgisOnlineURL); using (Geodatabase featureService = new Geodatabase(arcGISOnline)) { //These are the relationship clases where the origin layer ID is 0 and destination layer ID is 1 IReadOnlyList <RelationshipClass> relationshipClasses = featureService.OpenRelationshipClass("0", "1"); //These are the relationship clases where the origin layer ID is 1 and destination layer ID is 0 //Note that these will be different from the relationship classes above. IReadOnlyList <RelationshipClass> reverseRrelationshipClasses = featureService.OpenRelationshipClass("1", "0"); } }
public void MainMethodCode() { Uri nonFederatedServerURL = new Uri("https://arcgis.server.example.com:6443/arcgis/rest/services/FeatureServiceName/FeatureServer"); // Note that for non-federated ArcGIS Server hosted feature services, the username and password have to be specified always. ServiceConnectionProperties nonFederatedArcGISServer = new ServiceConnectionProperties(nonFederatedServerURL) { User = "******", Password = "******" }; using (Geodatabase nonFederatedServerFeatureService = new Geodatabase(nonFederatedArcGISServer)) { // Use the feature service geodatabase. } Uri federatedServerURL = new Uri("http://arcgis.server.federated.with.portal.example.com/server/rest/services/Hosted/FeatureServiceName/FeatureServer"); // Note that for feature services hosted on ArcGIS Server federated with ArcGIS Portal, the username and password cannot be specified through the API. // Even if the username and password were specified, they will be disregarded. // Instead the Portal authorization has to be configured by adding the Portal to ArcGIS Pro with the user with which the connection should be established. // To connect to a Portal from a CoreHost application, use the ArcGIS.Core.SystemCore.ArcGISSignOn class to authenticate with the Portal. ServiceConnectionProperties federatedArcGISServer = new ServiceConnectionProperties(federatedServerURL); using (Geodatabase federatedServerFeatureService = new Geodatabase(federatedArcGISServer)) { // Use the feature service geodatabase. } Uri arcgisOnlineURL = new Uri("http://services1.arcgis.com/47GG2ga246DGaLwa/arcgis/rest/services/FeatureServiceName/FeatureServer"); // Similar to Federated Feature Services, note that for feature services hosted on ArcGIS Online, the username and password cannot be specified through the API. // Even if the username and password were specified, they will be disregarded. // Instead the connection will be established based on the ArcGIS Online user credentials used to login to ArcGIS Pro at startup. ServiceConnectionProperties arcGISOnline = new ServiceConnectionProperties(arcgisOnlineURL); using (Geodatabase arcGISOnlineFeatureService = new Geodatabase(arcGISOnline)) { // Use the feature service geodatabase. } }
public void MainMethodCode() { Uri serviceUrl = new Uri("https://arcgis.server.example.com:6443/arcgis/rest/services/FeatureServiceName/FeatureServer"); ServiceConnectionProperties arcGisServer = new ServiceConnectionProperties(serviceUrl) { User = "******", Password = "******" }; using (Geodatabase serverFeatureService = new Geodatabase(arcGisServer)) { FeatureClassDefinition featureClassDefinition = serverFeatureService.GetDefinition <FeatureClassDefinition>("0"); string shapeField = featureClassDefinition.GetShapeField(); IReadOnlyList <Field> fields = featureClassDefinition.GetFields(); TableDefinition tableDefinition = serverFeatureService.GetDefinition <TableDefinition>("4"); string objectIDField = tableDefinition.GetObjectIDField(); } }
/// <summary> /// Query a feature service for a single value /// </summary> /// <param name="oWebServiceUri">example: "https://services.arcgis.com/SXbDpmb7xQkk44JV/arcgis/rest/services/stations_USGS_ACTIVE/FeatureServer"</param> /// <param name="layerNumber">The ordinal of the feature layer. Example: 0</param> /// <param name="fieldName"></param> /// <param name="queryFilter"></param> /// <returns></returns> public async Task <string[]> QueryServiceForValuesAsync(Uri oWebServiceUri, string layerNumber, string[] fieldNames, QueryFilter queryFilter) { string[] returnValues = new string[fieldNames.Length]; await QueuedTask.Run(() => { try { ServiceConnectionProperties serviceConnectionProperties = new ServiceConnectionProperties(oWebServiceUri); using (Geodatabase geodatabase = new Geodatabase(serviceConnectionProperties)) { Table table = geodatabase.OpenDataset <Table>(layerNumber); using (RowCursor cursor = table.Search(queryFilter, false)) { cursor.MoveNext(); Feature onlyFeature = (Feature)cursor.Current; if (onlyFeature != null) { for (int i = 0; i < fieldNames.Length; i++) { int idx = onlyFeature.FindField(fieldNames[i]); if (idx > -1) { returnValues[i] = Convert.ToString(onlyFeature[idx]); } } } } } } catch (Exception e) { Module1.Current.ModuleLogManager.LogError(nameof(QueryServiceForValuesAsync), "Exception: " + e.Message); } }); return(returnValues); }
public void MainMethodCode() { Layer selectedLayer = MapView.Active.GetSelectedLayers()[0]; if (selectedLayer is FeatureLayer) { FeatureLayer featureLayer = selectedLayer as FeatureLayer; using (Table table = featureLayer.GetTable()) using (Datastore datastore = table.GetDatastore()) { ServiceConnectionProperties serviceConnectionProperties = datastore.GetConnector() as ServiceConnectionProperties; if (serviceConnectionProperties == null) { return; } Uri url = serviceConnectionProperties.URL; // Will be the URL to the Feature Service. string user = serviceConnectionProperties.User; // The username property will only be populated for feature service hosted on non-federated ArcGIS Server. string password = serviceConnectionProperties.Password; // Will always be empty. } } }