Read geometry from JSON object

4469
3
Jump to solution
11-24-2012 06:51 AM
Highlighted
Occasional Contributor II
In Flex 3, I convert a featureset (including several simple polygons) to JSON object: var geomJSON:Object = myFeatureSet.toJSON();

Then I pass the geomJSON as a parameter to a web service (developed using VS2010 C# language). Now the problem is: how to read the polygons inside the C# web service? What kinds of ESRI classes should I use?

Many thanks in advance!
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Occasional Contributor III
Hy,
you should ask this question in the ArcObjects forum.

But here my solution in Java:

import com.esri.arcgis.geometry.Polygon; import com.esri.arcgis.system.JSONReader; import com.esri.arcgis.geodatabase.JSONDeserializerGdb;   JSONReader reader = new JSONReader(); reader.readFromString(jsonTxt); JSONDeserializerGdb ds = new JSONDeserializerGdb(); ds.initDeserializer(reader, null); Polygon polygon = (Polygon) ds.readGeometry(esriGeometryType.esriGeometryPolygon);


This should be similar in C++.

Tom

View solution in original post

Reply
0 Kudos
3 Replies
Highlighted
Occasional Contributor III
Hy,
you should ask this question in the ArcObjects forum.

But here my solution in Java:

import com.esri.arcgis.geometry.Polygon; import com.esri.arcgis.system.JSONReader; import com.esri.arcgis.geodatabase.JSONDeserializerGdb;   JSONReader reader = new JSONReader(); reader.readFromString(jsonTxt); JSONDeserializerGdb ds = new JSONDeserializerGdb(); ds.initDeserializer(reader, null); Polygon polygon = (Polygon) ds.readGeometry(esriGeometryType.esriGeometryPolygon);


This should be similar in C++.

Tom

View solution in original post

Reply
0 Kudos
Highlighted
Occasional Contributor

I was trying this in C#. However when I cast that to IPolygon (which should be the .NET-equivalent to the Polygon-interface in your Java-solution), I get an InvalidCastException, as seen here https://community.esri.com/thread/215252-jsonconvertergeometryclass-creates-invalid-geometries 

Reply
0 Kudos
Highlighted
Occasional Contributor II
Hy,
you should ask this question in the ArcObjects forum.

But here my solution in Java:

import com.esri.arcgis.geometry.Polygon;
import com.esri.arcgis.system.JSONReader;
import com.esri.arcgis.geodatabase.JSONDeserializerGdb;


JSONReader reader = new JSONReader();
reader.readFromString(jsonTxt);
JSONDeserializerGdb ds = new JSONDeserializerGdb();
ds.initDeserializer(reader, null);
Polygon polygon = (Polygon) ds.readGeometry(esriGeometryType.esriGeometryPolygon);


This should be similar in C++.

Tom


Thanks a lot! It is very helpful! I will try in my C# project and then get back. Thank you again!
Reply
0 Kudos