Skip to main content

Get Line Geometry as a String from QueryTask

Comments

9 comments

  • Permanently deleted user

    What are you trying to achieve overall with your workflow?

    0
  • Permanently deleted user

    Fair question.

    The goal is to produce a string of coordinates representing a linear(or point) feature in a format that we can use in a KML file.  I do not actually want a KML file just a coordinate string, we supply a third party with a custom XML stream who then produces a KML on Google Maps. For example this is what I need....

    "-36.1016773979999,145.442367569 -36.1022217349999,145.44236571 -36.1119289069999,145.442371207 -36.112018883,145.442358316 ...."

    We actually store the data in a local projection and the query task will project it, I just can't extract the coords from the result.  The resultant site is pretty cool and we are very proud of it, have a look at http://alerts.vicroads.vic.gov.au

    Thanks for any help

    0
  • Permanently deleted user

    You can get the geometries into a string variable by looping through the features that are returned. For example, use a ForEach control, where ForEach item in featureset1.Features(), assign string1 = item.Geometry.ToString().

    What is stored in string1 will depend on the geometry type of the features returned from the query, so if you are querying a Points layer, string1 will contain "Point[X=796747.726016322, Y=3326871.84658199, WKID=26915]". You will then have to do some formatting if you only want to store the X and Y values.

    -Victoria

    0
  • Permanently deleted user

    Thanks Victoria for your response but it doesn't work like that or at least I can't make it work like that.  What am I missing?

    The output of a Query Task is of type ESRI.ArcGIS.Client.Tasks.FeatureSet.  ESRI.ArcGIS.Client.Tasks. does not have a Feature as a member although Geocortex.Essentials.Client.Tasks does.  How do I convert between them. Or more likely the way to go about it is,

    How do I loop through an ESRI.ArcGIS.Client.tasks.FeatureSet?

     

    0
  • Nico Burgerhart

    Use the Features property on the FeatureSet (see http://help.arcgis.com/en/webapi/silverlight/1.2/apiref/topic976.html) and use a For Each activity to loop the list of features.

    0
  • Permanently deleted user

    Thanks for that response but unfortunately I can not crack this.  If you could do a quick example that would be great.  I am able to do the formatting, not problem, I just need to work out the mechanism that allows me to see a list of the point coordinates.

    When I use "item.Geometry.ToString()" all I get is "ESRI.ArcGIS.Client.Geometry.Polyline"

    My result FeatureSet is always a single feature. 

    I am really sorry to sound stupid, I just can't understand how I go from a FeatureSet (of n =1) to a Graphic or list of point coords, representing that feature.

     

    0
  • Permanently deleted user

    Hi Robert,

    I'm sorry, the important step I didn't mention in my first post is to cast the geometry to the type that should be returned. What is always returned in the featureset is an Esri.ArcGIS.Client.Geometry.Geometry, and you will have to cast it to either an Esri.ArcGIS.Client.Geometry.MapPoint or Esri.ArcGIS.Client.Geometry.Polyline before you will be able to access the actual points.

    In the case of the polyline, there are a couple of additional loops you will need to get down to the actual X and Y coordinates of each point along the path. (https://support.geocortex.com/Data/Sites/1/polyline.zip) Here is an example that will display the coordinates of a Polyline in a string.

    -Victoria

    0
  • Permanently deleted user

    Breaking down the structure of a single Polyline contained in a FeatureSet object:

    • The polyline itself is contained in a collection of ESRI.ArcGIS.Client.Graphic objects called 'Features'. So a reference to this 'Graphic' can be obtained like so:

    featureSet.Features.FirstOrDefault() or featureSet.Features[0]

    • Given a FeatureSet with a single feature both of the above statements will return the same result, but the statement on the left will not throw an error if the FeatureSet is empty, but will return 'null' instead. Keep this in mind if an empty FeatureSet would ever be expected at this point in your workflow.
    • A 'Graphic' mainly consists of two things -- geometry and an associated attributes table. You are interested in the Geometry, and it can be accessed fairly straightforwardly:

    graphic.Geometry,  or directly from the FeatureSet:  featureSet.Features[0].Geometry.   (you must be absolutely sure there is a Graphic there to do this though)

    • Now there is still further to go -- we don't have a list of points yet, and we don't even have a polyline -- we just have a generic 'Geometry' type which could be any kind of geometry whatsoever. It must be first converted, or 'cast' to the appropriate specific geometry. You can use the 'Cast' task in workflow, or the 'CType()' method in an 'Assign' task as follows. Be sure that it actually is a Polyline though, or this statement will throw an error:

    polyline = CType(graphic.Geometry, ESRI.ArcGIS.Client.Geometry.Polyline)

    • Now you have a polyline, which does have a list of points. In fact, it actually has a collection of lists of points, as this geometry type needs to support all of the complex multipart polylines that can be created in ArcMap. Typically there is only one list of points in the collection, but you still will always need to treat this geometry type as if there could be multiple.
    • The lists of points are called 'Paths'. To iterate through all of the paths and collect all the X,Y point values you will need two nested 'foreach' loops.
    • The first will need to iterate through a collection of type ESRI.ArcGIS.Client.Geometry.PointCollection, so:

    foreach (PointCollection pointcollection in polyline.Paths)  (that's how you'd write it in C#, hopefully it is clear how to translate that to a workflow)\

    • And the second will need to iterate through each PointCollection to get the points:

    foreach (MapPoint point in pointcollection)

    • In the body of the second 'foreach' loop you will now receive each point that makes up the polyline in turn, and you can display or store the X and Y values as you like. Each MapPoint will have these properties stored as floating point numbers:

    point.X  and point.Y

    • For display, or to concatenate values together in a string, you can now use:

    point.X.ToString()  and point.Y.ToString()

    Hope this helps explain things. You'll find the ESRI Silverlight API an invaluable reference when creating workflows, and further information on all of the above can be found here:

    http://help.arcgis.com/en/webapi/silverlight/apiref/api_start.htm

     

    0
  • Permanently deleted user

    thanks heaps guys for your help!

    The example was great and the complete explanation is excellent to aim understanding.

    0

Please sign in to leave a comment.