Deserialize FeatureSet JSON to Feature Class

4684
4
04-20-2010 11:56 AM
RafaelFerraro
New Contributor II
I am working on some geoprocessing services that will require the use of ArcObjects, no way around that.  I have been playing around with making a custom tool via IGPFunction2, and publishing that as a service.  That whole process seems a bit much if you ask me.

I have been experimenting with sending a feature set's json to a wcf service, where I  deserialize to a feature class, do some ArcObjects magic, and then send back to the client. 

The hack of a deserialization routine that I slapped together is disappointingly slow, but I only worked on it for a few hours.  So, I have a couple of questions for anyone else who has gone this route:

1.  Is there a standard function/library to do the serialization/deserialization on the .NET backend?
2.  Is there some reason why I shouldn't do this?

Any comments or suggestions welcome.

p.s.  I am working in Flex, but imagine the same process would be similar to Silverlight developers as well.
0 Kudos
4 Replies
AdamPfister
Esri Contributor
for #1 i've always used Json .NET with no problems at all.  i've had some fairly complex serializing/de-serializing and it's pretty quick.  check it out: http://james.newtonking.com/pages/json-net.aspx

just curious, what are you doing that requires the IGPFunction2?

Adam
0 Kudos
RafaelFerraro
New Contributor II
Thanks for suggestion about JSON.NET.

I am using IGPFunction2 to create a custom tool (think ArcToolbox tool) that can be published to AGIS as a geoprocessing service.  All of the examples I have seen for .NET tools to AGIS Geoprocessing Services went this route.  If there is a better way, please tell me.
0 Kudos
nicogis
MVP Frequent Contributor
I have written for you a sample from featureSet json to feature class


string jsonfeatureSet = "{\"displayFieldName\":\"\",\"fieldAliases\":{\"OBJECTID\":\"OBJECTID\",\"Indirizzo\":\"Indirizzo\"},\"geometryType\":\"esriGeometryPoint\",\"spatialReference\":{\"wkid\":102100},\"fields\":[{\"name\":\"OBJECTID\",\"type\":\"esriFieldTypeOID\",\"alias\":\"OBJECTID\"},{\"name\":\"Indirizzo\",\"type\":\"esriFieldTypeString\",\"alias\":\"Indirizzo\",\"length\":50}],\"features\":[" +
            "{" +
             "\"geometry\": {" +
                "\"x\": 940411.3699657875," +
                "\"y\": 5643498.120243863," +
                "\"spatialReference\": {\"wkid\": 102100}" +
              "}," +
              "\"attributes\": {" +
                "\"OBJECTID\": 1," +
                "\"Indirizzo\": \"VIA SORDI, 1\"" +
              "}" +
            "}]}";

            IJSONReader jsonReader = new JSONReaderClass();
            jsonReader.ReadFromString(jsonfeatureSet);

            IJSONConverterGdb JSONConverterGdb = new JSONConverterGdbClass();
            IPropertySet ppOriginalToNewFieldMap;
            IRecordSet pRecorset;
            JSONConverterGdb.ReadRecordSet(jsonReader, null, null, out pRecorset, out ppOriginalToNewFieldMap);

            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
            IWorkspace workspace = workspaceFactory.OpenFromFile(@"C:\Temp\testsd\sd.gdb", 0);
            IRecordSet2 recordSet2 = pRecorset as IRecordSet2;
            recordSet2.SaveAsTable(workspace, "Test");


0 Kudos