Skip to content

Commit

Permalink
Merge pull request #386 from jkey-esri/master
Browse files Browse the repository at this point in the history
Merge Pro SDK Get Better Geoprocessing Tool Error Messages sample and Enterprise SDK FilterFeaturesByFieldSOI sample
  • Loading branch information
tsimons6 authored Dec 13, 2024
2 parents 657db64 + 40389a4 commit de78593
Show file tree
Hide file tree
Showing 18 changed files with 694 additions and 0 deletions.
169 changes: 169 additions & 0 deletions enterprise-sdk/FilterFeaturesByFieldSOI/FilterFeaturesByFieldSOI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
// Copyright 2022 ESRI
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
//
// See the use restrictions at <your Enterprise SDK install location>/userestrictions.txt.
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Server;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto;
using ESRI.Server.SOESupport;
using ESRI.Server.SOESupport.SOI;

//This is SOI template of Enterprise SDK

namespace FilterFeaturesByFieldSOI
{
[ComVisible(true)]
[Guid("c9eaee50-c440-4b5a-b909-40e52e3f138c")]
[ClassInterface(ClassInterfaceType.None)]
[ServerObjectInterceptor("MapServer",
Description = "",
DisplayName = ".NET FilterFeaturesByField SOI",
Properties = "",
SupportsSharedInstances = true)]
public class FilterFeaturesByFieldSOI : IServerObjectExtension, IRESTRequestHandler, IWebRequestHandler, IRequestHandler2
{
private string _soiName;
private IServerObjectHelper _soHelper;
private RestSOIHelper _restSOIHelper;

public FilterFeaturesByFieldSOI()
{
_soiName = this.GetType().Name;
}

public void Init(IServerObjectHelper pSOH)
{
//System.Diagnostics.Debugger.Launch();

_soHelper = pSOH;
_restSOIHelper = new RestSOIHelper(pSOH);
}

public void Shutdown()
{
}

#region REST interceptors

public string GetSchema()
{
IRESTRequestHandler restRequestHandler = _restSOIHelper.FindRequestHandlerDelegate<IRESTRequestHandler>();
if (restRequestHandler == null)
return null;

return restRequestHandler.GetSchema();
}

public byte[] HandleRESTRequest(string Capabilities, string resourceName, string operationName,
string operationInput, string outputFormat, string requestProperties, out string responseProperties)
{
responseProperties = null;

// Find the correct delegate to forward the request too
IRESTRequestHandler restRequestHandler = _restSOIHelper.FindRequestHandlerDelegate<IRESTRequestHandler>();
if (restRequestHandler == null)
return null;

if (operationName == "export" || operationName == "identify" || operationName == "find")
{
var joOperationInput = new JsonObject(operationInput);
var operationInputToJsonTest = joOperationInput.ToJson();

if (joOperationInput.Exists("layerDefs"))
joOperationInput.Delete("layerDefs");

var joLayerDefsFilter = new JsonObject();
// Filter the features by the POP attribute field.
joLayerDefsFilter.AddString("0", "POP > 500000");
joOperationInput.AddJsonObject("layerDefs", joLayerDefsFilter);

operationInput = joOperationInput.ToJson();
}

return restRequestHandler.HandleRESTRequest(
Capabilities, resourceName, operationName, operationInput,
outputFormat, requestProperties, out responseProperties);
}

private JsonObject CreateACircle()
{
string circleJs = "{\"spatialReference\":{\"wkid\":4269}, \"curveRings\": [[[-102, 41],{\"a\":[[-102, 41], [-104, 39], 0, 1]}]]}";
IPolygon poly = ESRI.Server.SOESupport.Conversion.ToGeometry(circleJs, esriGeometryType.esriGeometryPolygon) as IPolygon;
((IPolycurve)poly).Densify(0.1, 0.1); //Densifying as ToJsonObject() can't jsonify any curves
return ESRI.Server.SOESupport.Conversion.ToJsonObject(poly, true);
}

#endregion

#region SOAP interceptors
public byte[] HandleBinaryRequest(ref byte[] request)
{
IRequestHandler requestHandler = _restSOIHelper.FindRequestHandlerDelegate<IRequestHandler>();
if (requestHandler != null)
{
return requestHandler.HandleBinaryRequest(request);
}

//Insert error response here.
return null;
}

public string HandleStringRequest(string Capabilities, string request)
{
IRequestHandler requestHandler = _restSOIHelper.FindRequestHandlerDelegate<IRequestHandler>();
if (requestHandler != null)
{
return requestHandler.HandleStringRequest(Capabilities, request);
}

//Insert error response here.
return null;
}

public byte[] HandleBinaryRequest2(string Capabilities, ref byte[] request)
{
IRequestHandler2 requestHandler = _restSOIHelper.FindRequestHandlerDelegate<IRequestHandler2>();
if (requestHandler != null)
{
return requestHandler.HandleBinaryRequest2(Capabilities, request);
}

//Insert error response here.
return null;
}
#endregion

#region OGC interceptors
public byte[] HandleStringWebRequest(esriHttpMethod httpMethod, string requestURL, string queryString, string Capabilities, string requestData, out string responseContentType, out esriWebResponseDataType respDataType)
{
IWebRequestHandler webRequestHandler = _restSOIHelper.FindRequestHandlerDelegate<IWebRequestHandler>();
if (webRequestHandler != null)
{
return webRequestHandler.HandleStringWebRequest(
httpMethod, requestURL, queryString, Capabilities, requestData, out responseContentType, out respDataType);
}

responseContentType = null;
respDataType = esriWebResponseDataType.esriWRDTPayload;
//Insert error response here.
return null;
}
#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>

<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>mykey.snk</AssemblyOriginatorKeyFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>


<ItemGroup>
<Reference Include="ESRI.Server.SOESupport">
<HintPath>$(ENTDEVKITJAVA)\DotNet\ESRI.Server.SOESupport.dll</HintPath>
<EmbedInteropTypes>false</EmbedInteropTypes>
</Reference>
<Reference Include="ESRI.Server.Carto">
<HintPath>$(ENTDEVKITJAVA)\DotNet\ESRI.Server.Carto.dll</HintPath>
<EmbedInteropTypes>false</EmbedInteropTypes>
</Reference>
<Reference Include="ESRI.Server.DatasourcesFile">
<HintPath>$(ENTDEVKITJAVA)\DotNet\ESRI.Server.DatasourcesFile.dll</HintPath>
</Reference>
<Reference Include="ESRI.Server.DatasourcesGDB">
<HintPath>$(ENTDEVKITJAVA)\DotNet\ESRI.Server.DatasourcesGDB.dll</HintPath>
</Reference>
<Reference Include="ESRI.Server.DatasourcesRaster">
<HintPath>$(ENTDEVKITJAVA)\DotNet\ESRI.Server.DatasourcesRaster.dll</HintPath>
</Reference>
<Reference Include="ESRI.Server.Geodatabase">
<HintPath>$(ENTDEVKITJAVA)\DotNet\ESRI.Server.Geodatabase.dll</HintPath>
</Reference>
<Reference Include="ESRI.Server.GeoDatabaseDistributed">
<HintPath>$(ENTDEVKITJAVA)\DotNet\ESRI.Server.GeoDatabaseDistributed.dll</HintPath>
</Reference>
<Reference Include="ESRI.Server.GeoDatabaseExtensions">
<HintPath>$(ENTDEVKITJAVA)\DotNet\ESRI.Server.GeoDatabaseExtensions.dll</HintPath>
</Reference>
<Reference Include="ESRI.Server.Geometry">
<HintPath>$(ENTDEVKITJAVA)\DotNet\ESRI.Server.Geometry.dll</HintPath>
</Reference>
<Reference Include="ESRI.Server.GISClient">
<HintPath>$(ENTDEVKITJAVA)\DotNet\ESRI.Server.GISClient.dll</HintPath>
</Reference>
<Reference Include="ESRI.Server.Server">
<HintPath>$(ENTDEVKITJAVA)\DotNet\ESRI.Server.Server.dll</HintPath>
</Reference>
<Reference Include="ESRI.Server.System">
<HintPath>$(ENTDEVKITJAVA)\DotNet\ESRI.Server.System.dll</HintPath>
</Reference>
</ItemGroup>


<PropertyGroup>
<ZipFileExtension>soe</ZipFileExtension>
<AddInTargetProduct>Server</AddInTargetProduct>
<AddInTargetVersion>11.0</AddInTargetVersion>
<ServerProvider>ArcObjects11</ServerProvider>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\ESRI\ESRI.ArcGIS.Enterprise.SDK.targets" Condition="Exists('$(MSBuildExtensionsPath)\ESRI\ESRI.ArcGIS.Enterprise.SDK.targets')" />



</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34408.163
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFilterFeaturesByFieldSOI", "NetFilterFeaturesByFieldSOI.csproj", "{611E59A2-E1E4-4ED9-8CB6-D3FC2868A74B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{611E59A2-E1E4-4ED9-8CB6-D3FC2868A74B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{611E59A2-E1E4-4ED9-8CB6-D3FC2868A74B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{611E59A2-E1E4-4ED9-8CB6-D3FC2868A74B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{611E59A2-E1E4-4ED9-8CB6-D3FC2868A74B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {03749842-433E-4CE8-AA0B-4C18A780C712}
EndGlobalSection
EndGlobal
45 changes: 45 additions & 0 deletions enterprise-sdk/FilterFeaturesByFieldSOI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ClipAndSpatialFilterSOI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ClipAndSpatialFilterSOI")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("b71a4fd2-5b82-4a19-8b3b-1d11389c151b")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

[assembly: ESRI.Server.SOESupport.AddInPackage("ClipAndSpatialFilterSOI", "cf479c85-ca82-4ff5-b546-809549c82a93",
Author = "moha5225",
Company = "",
Date = "10/5/2019 1:38:08 PM",
Description = "",
TargetProduct = "Server",
TargetVersion = "11.2",
Version = "1.0")]
51 changes: 51 additions & 0 deletions enterprise-sdk/FilterFeaturesByFieldSOI/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
order: 14
---

# .NET Filter Features By Field SOI

This sample illustrates how to develop an SOI to apply certain field value restrictions on the [Export Map](https://developers.arcgis.com/rest/services-reference/export-map.htm), [Identify](https://developers.arcgis.com/rest/services-reference/identify-map-service-.htm), and [Find](https://developers.arcgis.com/rest/services-reference/find.htm) REST operations of a map service. It contains a sample SOI called FilterFeaturesByFieldSOI. The FilterFeaturesByField SOI uses the ExportMap operation's "layerDefs" parameter to filter the displayed features by attribute field.

>*Note* : This sample SOI is only applicable to map services published from ArcGIS Pro to a 10.8 or later versions of ArcGIS Server. See [what's new in the ArcGIS REST API at 10.8](https://developers.arcgis.com/rest/services-reference/what-s-new.htm).
Deploying the SOI from the .soe file (`..\soe\NetFilterFeaturesByFieldSOI_ent.soe`) does not require you to open Visual Studio. However, you can load the project (`..\NetFilterFeaturesByFieldSOI.csproj`) in Visual Studio to debug, modify, and recompile the SOI code.

## Features

* Preprocess REST requests
* Layer Definitions

## Sample data

This instruction uses the SampleWorldCities service as the sample service to test with the SOI.

## Instructions

### Deploy the SOIs

1. Log in to ArcGIS Server Manager and click the ***Site*** tab.
2. Click ***Extensions***.
3. Click ***Add Extension***.
4. Click ***Choose File*** and choose the ***NetFilterFeaturesByFieldSOI_ent.soe*** file (`..\soe\NetFilterFeaturesByFieldSOI_ent.soe` or `..\bin\Debug\NetFilterFeaturesByFieldSOI_ent.soe`).
5. Click ***Add***.

### Enable the FilterFeaturesByField SOI on a map service

1. Navigate to the SampleWorldCities map service in ArcGIS Server Manager.
3. Select ***.NET FilterFeaturesByField SOI*** in the ***Available Interceptors*** box and click the right arrow button to move it to ***Enabled Interceptors***.
4. Click the ***Save and Restart*** button to restart the service.

### Test the SpatialFilter SOI

1. Open a browser and navigate to the REST services endpoint of the SampleWorldCities map service (URL: `http://<serverdomain>/<webadaptorname>/rest/services/SampleWorldCities/MapServer`).
2. Scroll to the bottom of the above page and click ***Export Map*** in ***Supported Extensions***.

This leads you to the following URL:

```
http://<serverdomain>/<webadaptorname>/rest/services/SampleWorldCities/MapServer/export?bbox=-103.80966151584494,-40.27311509271942,74.63649935920162,66.70933645099878
```

The exported image shows the map with only features that have a population (POP) over 500000. Alternatively, try to view this map service in ***ArcGIS JavaScript*** or ***ArcGIS Online Map Viewer*** and you should see similar result. (If the ***ArcGIS JavaScript*** or ***ArcGIS Online Map Viewer*** page appears blank at first, refresh the page or check sharing settings.)

3. You can play around the ***Export Map***, ***Identify*** and ***Find*** operations to observe the SOI's effects.
Binary file added enterprise-sdk/FilterFeaturesByFieldSOI/mykey.snk
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit de78593

Please sign in to comment.