Select to view content in your preferred language

LayerItemViewModel.GeometryType

1661
8
12-09-2010 06:46 AM
AndrewWhite
Emerging Contributor
Am I right in saying that the layer GeometryType is not available anywhere in the LayerItemViewModel object model?

This is too bad.  I've added the ability for users to toggle a layer in the legend, then when they click a location on the map, it performs an identifyquery at that point.  We've got some layers that are polygons, some that are points, and others that are polyline.  We change the IdentifyQuery.Geometry based on the GeometryType of the layer selected.  A point works great for polygon layers, and a small polygon extent works better for polyline and point layers -- otherwise the user has to click exactly on the line or point.

If GeometryType is not available to me through the object model, can you think of a workaround?  And if not, can I request that it be added in the next version?

Thank you.
0 Kudos
8 Replies
DominiqueBroux
Esri Frequent Contributor
You are right, the geometryType is not available in the LayerItemViewModel.

That's mostly because the geometry type is not tied to a legend item but to the layer or sublayer itself (as an example, the GeometryType would have few sense for a GraphicsLayer that can contain any geometry type).

That being said, I guess the target of your question is an ArcGISDynamicMapServiceLayer.
From the LayerItemViewModel you can get the Layer and the subLayerID associated to the legend layer item. So your question becomes, how can I get the geometry type of an ArcGSDynamicMapServiceLayer sublayer.

Answer is:
- you cannot:( with out of the box method
- but you can 🙂 by requesting by yourself the sublayer rest end point which is providing the info (e.g . http://services.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Diversity_US_2D/MapServer//0)
0 Kudos
DaveTimmins
Deactivated User
Hi Andrew,

why not just specify the tolerance value for the IdentifyTask?

Cheers,
0 Kudos
AndrewWhite
Emerging Contributor
Hi Andrew,

why not just specify the tolerance value for the IdentifyTask?

Cheers,


Thank you for the feedback.  Using Tolerance is probably what I should use instead of Geometry in the QueryParameters.  However, that doesn't address the problem that I need one tolerance for PolyLine and Point layers, and another tolerance for Polygon layers.  Isn't that correct?  Or, will ArcServer just handle that for me?
0 Kudos
DaveTimmins
Deactivated User
Hi Andrew,

I've found that it doesn't really matter about adjusting the Tolerance value for differing geometry types, and really you are only that concerned with point or polyline features as polygon is more likely to succeed. I only specify a Tolerance of 2 usually and this is enough to be able to correctly identify the expected features.

I'm not 100% sure how AGS handles the Tolerance value but I would guess that it does a buffer based on the Tolerance value and also the extent so it has a sliding ratio applied to the input geometry. The easiest thing is to just test it out for your scenario and see if it meets your needs.

Cheers,
0 Kudos
AndrewWhite
Emerging Contributor


The easiest thing is to just test it out for your scenario and see if it meets your needs.



Okay, I tested it out...

First, I had to change from a QueryTask to an IdentifyTask, since the Query doesn't have Tolerance and the IdentifyParameters does.  Not a big deal though.

Second, I still have the same problem -- specifically, I have a Parcels layer (polygons) and I click right next to a line between two parcels I get both parcels in the results because the parcel on the other side of the line is within the Tolerance.  This is not really acceptable.  In this situation I want a Tolerance of 0.  However, we also have point and polyline layers, and for those we do want a bit of a tolerance.

So, I guess I'm left with doing a quick REST call to get the GeometryType of the layer being queried.  😞

Thanks much for your input though.  😄  Using Tolerance is a much better choice for those times when I want to use a bit of a buffer.
0 Kudos
JenniferNery
Esri Regular Contributor
This may not be the most efficient way to do this but maybe it will help:
   FeatureLayer l = new FeatureLayer() { Url = "http://services.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Diversity_US_2D/MapServer/0" };
   EventHandler<EventArgs> handler = null;
   GeometryType geometryType;
   handler = (s, e) =>
   {
     l.Initialized -= handler;
     geometryType = l.LayerInfo.GeometryType;
    };
   l.Initialized += handler;
   l.Initialize();
0 Kudos
AndrewWhite
Emerging Contributor
Thank you!

Your code example came too late, as my code is complete.  🙂

I'm just doing a quick REST call using a WebClient and parsing the results into a DataContract using a DataContractJsonSerializer.  Works great and is fast.
0 Kudos
JenniferNery
Esri Regular Contributor
Okay. WebClient request is the most efficient way, anyway where you can parse JSON string and decide GeometryType from there.  "geometryType" : "esriGeometryPolygon",
0 Kudos