I'm trying to create an identify tool that will return all of the features that intersect the geometry of a particular parcel. For example, a user clicks (or draws a rectangle on) a parcel and then can get information on utilities, contours, zoning, etc. that cross that and only that property. I'm using the geometry of the selected parcel(s) (GeometryType.Polygon) as the input geoemtry for my IdentifyParameters. The first problem is that adjacent parcels are also selected in addition to the parcel(s) that are actually selected. It's almost like it's overiding the Polygon geometry of each parcel and using an envelope instead. I can get around this by specifying a LayerDefinition in the IdentifyParameters that only uses the Parcel ID number of the selected parcel(s). This kind of leads into the other problem... I need to submit the geometry of the selected parcel(s) to the IdentifyTask and since it's a Polygon, the URL can exceed the maximum URL length (2083 chars, I think) pretty easily. Put this together with my LayerDefinition and the URL quickly becomes too long. Especially considering I want to use a Rectangle to select one or many parcels to Identify on at once. Is there a better, more effective way to do this?
StringBuilder definitionString = new StringBuilder("PID in ("); //PID = Unique Parcel ID #
pidList.ForEach(pid => { definitionString.Append("'" + pid + "',"); });
if (definitionString.ToString().EndsWith(","))
definitionString.Remove(definitionString.Length - 1, 1);
if (!definitionString.ToString().EndsWith(")"))
definitionString.Append(")");
LayerDefinition layerDefinition = new LayerDefinition();
layerDefinition.Definition = definitionString.ToString();
layerDefinition.LayerID = 2;
List<LayerDefinition> layerDefinitions = new List<LayerDefinition>();
layerDefinitions.Add(layerDefinition);
IdentifyParameters identifyParams = new IdentifyParameters();
identifyParams.Geometry = geometry; //geometry = Parcel (polygon) geometry returned in from another method.
identifyParams.MapExtent = Target.Extent; //-10405823.111712,5607318.33490769,-10405351.611712,5607522.08490769
identifyParams.Width = (int)Target.ActualWidth; //1886
identifyParams.Height = (int)Target.ActualHeight; //815
identifyParams.LayerOption = LayerOption.all;
identifyParams.LayerDefinitions = layerDefinitions; //ex: PID in ('2811722310044', '2811722310043')
identifyParams.Tolerance = 0;
IdentifyTask identifyTask = new IdentifyTask(IdentifyService.Url);
identifyTask.ExecuteCompleted += new EventHandler<IdentifyEventArgs>(identifyTask_ExecuteCompleted);
identifyTask.Failed += new EventHandler<TaskFailedEventArgs>(identifyTask_Failed);
identifyTask.ExecuteAsync(identifyParams);