How to return a FeatureClass or FeatureDataset from an SOE?

4803
3
Jump to solution
12-24-2014 06:54 AM
JustinShepard
Occasional Contributor II

I'm using arcobjects to build an SOE and need to return a feature collection. The examples that I've found online focus on returning a single geometry result in json format. Since my result will potentially have hundreds of features and I'll need the attributes as well as the geometry I'm wondering if there is a standard way of returning a FeatureClass. Ultimately this SOE will likely be used in a .NET Runtime application so I want to make sure that the results are easy to import into an application.

I will also have a couple of informational results to return, so I would like to set up the results something like:

      informationalResult1={}

      informationalResult2={}

      featureClassResult={}

Right now I'm thinking that I'll have to create JsonObjects for each result category and have each exist within a larger results JsonObject. If that is the case is there a recommended way to convert an entire FeatureClass to a JsonObject?

Thanks.

0 Kudos
1 Solution

Accepted Solutions
GregMcQuat
New Contributor III

Hi, Justin. I think your approach using the Convert would probably be fine as long as the client knows what format to expect. You might consider converting the Feature Class to a Record Set and then converting it to JSON using SOESupport. I've put the example together from a couple of different sources though I haven't tried it. Good luck!

public static string FeatureClassToJSON(IFeatureClass pFeatureClass)

{

     ITable table = (ITable)pFeatureClass;

     IRecordSetInit rsInit = new RecordSetClass();

     IQueryFilter2 qf = new QueryFilterClass();

     rsInit.SetSourceTable(table, qf); // Load fc

     IRecordSet rs = rsInit as IRecordSet;

     byte[] jsonBytes = ESRI.ArcGIS.SOESupport.Conversion.ToJson(rs);

     return Encoding.UTF8.GetString(jsonBytes, 0, jsonBytes.Length);

}

Ref: bcdc spatial: Some random ArcObjects that make writing Server Object Extensions easier...(C#)

View solution in original post

3 Replies
GregMcQuat
New Contributor III

Hi, Justin. I think your approach using the Convert would probably be fine as long as the client knows what format to expect. You might consider converting the Feature Class to a Record Set and then converting it to JSON using SOESupport. I've put the example together from a couple of different sources though I haven't tried it. Good luck!

public static string FeatureClassToJSON(IFeatureClass pFeatureClass)

{

     ITable table = (ITable)pFeatureClass;

     IRecordSetInit rsInit = new RecordSetClass();

     IQueryFilter2 qf = new QueryFilterClass();

     rsInit.SetSourceTable(table, qf); // Load fc

     IRecordSet rs = rsInit as IRecordSet;

     byte[] jsonBytes = ESRI.ArcGIS.SOESupport.Conversion.ToJson(rs);

     return Encoding.UTF8.GetString(jsonBytes, 0, jsonBytes.Length);

}

Ref: bcdc spatial: Some random ArcObjects that make writing Server Object Extensions easier...(C#)

JustinShepard
Occasional Contributor II

It did throw an error when I tested it but it kept me with a few tweaks. I'm guessing that the silence from the rest of the community means that you and I are on the right track.

0 Kudos
GregMcQuat
New Contributor III

Fantastic! I'd appreciate seeing the working solution when you have it nailed down.

0 Kudos