Local Geoprocessing without packages

4844
47
Jump to solution
11-09-2012 11:26 AM
Labels (1)
GeorgeFaraj
Occasional Contributor III
I'm opening feature layers from map packages and now I need to run tools such as Union, Buffer, Intersect, etc. dynamically on those layers, then add the results as a new layer in the map. What is the best way to do this locally without using pre-modeled packages?
1 Solution

Accepted Solutions
GeorgeFaraj
Occasional Contributor III
I finally got this working. I'll put the code here in case anyone else needs help with this. I needed to specify the correct field type, and especially I needed to correctly identify the OID field too. Thanks for everyone that helped.


  public static ICollection<Field> GetFields(Graphic graphic)   {    var fields = new List<Field>();    foreach (var attribute in graphic.Attributes)    {     var field = new Field()     {      FieldName = attribute.Key,      Alias = attribute.Key     };     if (attribute.Key.ToLower() == "shape")     {      field.Type = Field.FieldType.Geometry;     }     else if (attribute.Key.ToLower() == "fid")     {      field.Type = Field.FieldType.OID;     }     else if (attribute.Key.ToLower() == "objectid")     {      field.Type = Field.FieldType.OID;     }     else if (attribute.Value is int)     {      field.Type = Field.FieldType.Integer;     }     else if (attribute.Value is double)     {      field.Type = Field.FieldType.Double;     }     else if (attribute.Value is float)     {      field.Type = Field.FieldType.Single;     }     else if (attribute.Value is DateTime)     {      field.Type = Field.FieldType.Date;     }     else     {      field.Type = Field.FieldType.String;     }     fields.Add(field);    }    return fields;   }

View solution in original post

0 Kudos
47 Replies
KerrieScholefield
Occasional Contributor
Hi,

Geometry operations such as Union, Buffer, Intersect can be dynamically performed on graphics. Once the operation is complete the results can be rendered on the map in a graphics layer. To perform these operations on local data, the LocalGeometryService should be used in conjunction with the use of a GeometryService Task.

Please see the conceptual documentation on LocalGeometryService for more information and code examples:

http://resources.arcgis.com/en/help/runtime-wpf/concepts/index.html#/How_to_use_the_Geometry_task/01...

Samples using the LocalGeometry Class can be found in the Sample Application under Geometry> Geometry Operations

Cheers

Kerrie
0 Kudos
GeorgeFaraj
Occasional Contributor III
I would like to revive this thread. I'm not sure if the above answer is really what I need. I have one or more layers and want to perform operations such as Buffer, Union, Clip, etc onto those layers. I want it to work like in the ArcObjects SDK, where you use the Geoprocessor and you specify the input feature layers, and it would return the resulting features.

Can someone direct me on the right path?
0 Kudos
GeorgeFaraj
Occasional Contributor III
Is there really no way to run geoprocessing tools without having to pre-package the geometry and tools beforehand? I want to run geoprocessing tools on dynamically added layers (which can be shapefiles) on my map. Is this not possible?
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

I think depends on what you'd like to achieve with the output. If it's for display purposes or for the duration of the user/app session then the LocalGeometryService and the GeometryService task is a valid approach for the types of functions you mentioned (buffer, clip, union). They work with arrays of individual geometries so you'd need to construct a query first to retrieve the geometries. If you want to store these geometries you could add them to a Geodatabase via a FeatureLayer/ArcGISLocalFeatureLayer or you can also serialize the features to JSON.

Alternatively you can use Geoprocessing packages to create a LocalGeoprocessingService and use in conjunction with the Geoprocessor task. This gives you the benefit of being able to create longer workflows as a model or Python script (i.e. Input > Buffer > Clip > Intersect > Output) and calling it as one operation, asynchronously. Typically these GP tools operate on an entire feature class (although you can easily do selection/filtering in the model/script). You'll get the result back as a set of Graphic objects, or alternatively you can request a MapServer to render the results (better for large datasets). If you want to store the output in a Geodatabase you can have the model/script write the output as required, or create an separate model/script to do this piece. Again, you could also write graphics to a Geodatabase via a FeatureLayer/ArcGISLocalFeatureLayer or serialize the features to JSON.


Cheers

Mike
0 Kudos
GeorgeFaraj
Occasional Contributor III
Hi Mike,

With regards to your second approach (Geoprocessor), how do I execute a geoprocessing tool on any layer on the map? Everything I've seen in the documentation suggests that I have to create the geoprocessing package beforehand with the geometry. I want to mimick the Geoprocessing functionality that is provided with ArcMap, where you select the tool you want and then set the input parameters, like which layers to use, etc. After running it, I will add the results as a layer.
0 Kudos
jp
by
New Contributor II
Charles,

Have you checked the code under ArcGIS Runtime SDK for WPF samples (desktop application )?

Under - Geometry -> Geometry operations -> Buffer a point

Similar to what Mike suggested.

Does this help for your requirement?
0 Kudos
GeorgeFaraj
Occasional Contributor III
Charles,

Have you checked the code under ArcGIS Runtime SDK for WPF samples (desktop application )?

Under - Geometry -> Geometry operations -> Buffer a point

Similar to what Mike suggested.

Does this help for your requirement?



I am not sure if this works for me. For example, if I run the Buffer operation on Layer1, I want the results of the operation to contain (clones of) the features from Layer1 that are within that buffer. I need to use the attributes for these resulting features to perform other operations on them.

This was easily done using the Geoprocessor class in the ArcObjects SDK, by providing the input layer and a distance.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You can't directly use the layer as input of a geometry service but most of the geometry service accepts a list of feature as input parameter (ex BufferParameter.Features) so setting the input with all graphicsLayer.Graphics is just a particular case.

Though note that the graphics returned by the service don't include the attributes. However the returned graphics are always in the same order as the input graphics so you can easily retrieve the attributes from the input graphics.

For the intersect service (not sure from your description if you are talking about Buffer or Intersect service), some features may not intersect the input geometry but even in this case graphics with a null geometry are returned in the output graphics so the number of output graphics is always equals to the number of input graphics.
0 Kudos
GeorgeFaraj
Occasional Contributor III

Though note that the graphics returned by the service don't include the attributes. However the returned graphics are always in the same order as the input graphics so you can easily retrieve the attributes from the input graphics.


That doesn't make sense to me. If I want a buffer of N kms around X features, I want the results to also contain features outside of those X features but within the buffer distance. In other words, the results should have X or more features.
0 Kudos