I am writing a windows console app in VS 2010 to perform an overlay using the ArcGIS Rest API.

My first REST query returns information about the geometry for a specific feature. I then want to send that geometry to another feature class, to return data about the shared area.

I am using the DeserializeObject method to convert the query results to a Dictionary. How do I take the geometry from that result set and post it to a new query?


What if I user the JavaScriptSerializer.Serialize method on the geometry string? Is there a way to pass the resulting JSON string to the REST service call? I already tried just assigning it to the "geometry" value in the querystring, but that failed.

  • "send that to another feature class" ... is that local or through another REST call? – Kirk Kuykendall May 13 '11 at 14:23
  • Another REST call – Britt Wescott May 13 '11 at 14:32
  • 1
    Would dependencies on Esri's WPF SDK assemblies be acceptable? – Kirk Kuykendall May 13 '11 at 14:42
  • I've considered that, I wanted to see if there was a way to do it just with REST calls before I opted for that route. – Britt Wescott May 13 '11 at 14:56
  • 1
    Have you tried Vish's GeoJson.NET ? – Kirk Kuykendall May 13 '11 at 15:00

The code below works for me.

using System;
using System.Text;
using System.Net;
using Newtonsoft.Json;
using System.IO;
using Newtonsoft.Json.Linq;

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
                string baseUrl = @"http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer";
                string jsonGeom = GetStateGeom(baseUrl,1, "Colorado");
                string featuresJson = QueryHighways(baseUrl, 0, jsonGeom);
            catch (Exception ex)

        private static string GetStateGeom(string baseUrl, int layerID,string state)
            string url = String.Format("{0}/{1}/query?text={2}&f=pjson",baseUrl,layerID,state);

            var wc = new WebClient();
            var strm =  wc.OpenRead(new Uri(url));
            var strmReader = new StreamReader(strm);
            var json = strmReader.ReadToEnd();
            var jObj = JsonConvert.DeserializeObject(json) as JObject;
            JArray features = (JArray)jObj["features"];
            if (features.Count == 0)
                Console.WriteLine("state of {0} not found", state);
                return null;
            string jsonGeom = ((JObject)features[0])["geometry"].ToString();
            return jsonGeom;

        private static string QueryHighways(string baseUrl, int layerID,string jsonGeom)
            string url = String.Format("{0}/{1}/query", baseUrl, layerID);
            var wc = new WebClient();
            wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            StringBuilder sb = new StringBuilder();
            var bytes = Encoding.ASCII.GetBytes(sb.ToString());
            var respBytes = wc.UploadData(url, "POST", bytes);
            return Encoding.ASCII.GetString(respBytes);

There is some JSON helpers i ArcObjects that you might be able to use, but I'm not sure if they are supported on the client side though: SOESupport.JsonObject

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.