You are here: > ESRI Forums > arcgis server forums > Thread Replies

ArcGIS Server Forums

ArcGIS Server: REST API forum

creating a geometry object from json respon...   p. thibault Oct 09, 2009
Re: creating a geometry object from json re...   p. thibault Oct 09, 2009
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject creating a geometry object from json response 
Author p. thibault 
Date Oct 09, 2009 
Message I have a json response created by a REST service (as seen in code sample). How do I take the RING and build a geometry object in javascript? Does anyone have a sample? I have tried a number of interations of the following:

geometry = new esri.geometry.fromJson(curFeature.geometry.rings[0]);

Thanks



 
 
REST service reponse:
showResults({
  "results" : [
    {
      "layerId" : 1, 
      "layerName" : "Parcels *", 
      "displayFieldName" : "PREFIX", 
      "foundFieldName" : "SBL", 
      "value" : "071275", 
      "attributes" : {
        "OBJECTID" : "1917726", 
        "PARCEL_" : "Null", 
        "PARCEL_ID" : "Null", 
        "PREFIX" : "", 
        "SWIS" : "132400", 
        "COUNTY_SBL" : "00636700000712750000", 
        "SBL" : "071275", 
        "SECNO" : "6367.00", 
        "SID" : "0", 
        "MOD_DATE" : "Null", 
        "CHANGE_DATE" : "Null", 
        "KEYCODE" : "0", 
        "FEAT_CODE" : "0", 
        "PARCELGRID" : "13240000636700000712750000", 
        "SECTION" : "006367", 
        "SUBSECTION" : "0000", 
        "LOT" : "071275", 
        "SUFFIX" : "0000", 
        "KEY_" : "13240000636700000712750000", 
        "GlobalID" : "{420E2C8D-1C3D-4C7D-B1DA-9CA812395C9A}", 
        "Shape" : "Polygon", 
        "Shape.area" : "990788.560251", 
        "Shape.len" : "4266.288356"
      }, 
      "geometryType" : "esriGeometryPolygon", 
      "geometry" : 
      {
        "spatialReference" : {
          "wkid" : 2260
        }, 
        "rings" : 
        [
          [
            [667740.115706164, 1097582.42783179], 
            [667670.516986098, 1097587.4557998], 
            [667670.0025541, 1097681.05451988], 
            [667691.86277812, 1098110.37496828], 
            [667699.407610126, 1098208.84165638], 
            [667837.642618254, 1098225.78335239], 
            [668147.615482543, 1098277.95487244], 
            [668835.092987183, 1098694.60191283], 
            [668871.738107219, 1098435.72421659], 
            [668882.748923227, 1098309.53439247], 
            [668921.141371265, 1097968.72568815], 
            [668874.42700322, 1097930.84434412], 
            [668788.245499142, 1097859.62386405], 
            [668741.724667098, 1097820.36677601], 
            [668699.86047506, 1097784.35474398], 
            [668465.353722841, 1097602.38776781], 
            [668335.335802719, 1097502.60818372], 
            [668261.863162652, 1097447.13106367], 
            [668237.942778628, 1097430.19461565], 
            [668213.807866607, 1097414.88005564], 
            [668183.747322578, 1097398.08082362], 
            [668158.913018554, 1097386.16351161], 
            [668143.091578539, 1097379.4858796], 
            [668121.54738652, 1097371.04978359], 
            [668078.655098479, 1097355.82610358], 
            [668051.233530454, 1097347.65663157], 
            [668040.230266444, 1097344.83141557], 
            [668023.755130429, 1097341.25599157], 
            [668006.068474412, 1097338.18616757], 
            [667936.877050348, 1097327.61643956], 
            [667882.154746298, 1097573.70706379], 
            [667740.115706164, 1097582.42783179]
          ]
        ]
      }
    }
  ]
});
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: creating a geometry object from json response 
Author p. thibault 
Date Oct 09, 2009 
Message Solution: add the rings to a geometry object as shown in code below. 
 
var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255,0,0]), 2), new dojo.Color([0,255,0,0.25]));
              alert(curFeature.geometry.rings[0].length);
			  geometry = new esri.geometry.Polygon();
			  var rings;
			  rings = curFeature.geometry.rings;
					for (var r=0, rl=rings.length; r<rl; r++) {
					//add ring to combined polygon
					geometry.addRing(rings[r]);
					}
					   break;
          }

		  
		  
		  
		  //graphic.setSymbol(symbolfind);
          map.graphics.add(new esri.Graphic(geometry,symbol));