Best Practices - changing types
You frequently have to change data types in workflow to transition from one activity to another. I am not really clear on how to do that consistently.
so...
What's the best or preferred way to get geometry from a esri.arcgis.clinet.tasks.featureset that contained many features.
What's the best or preferred way to get esri.arcgis.client.graphics from the geometry or from the feature set.
and the reverse is true, whats the best way to convert graphics to geometry or to a featureset?
Sice i am no programmer, some samples or links to samples would be great.
Jeff
-
Hi Jeff
I think one place to broaden your knowledge without necessarily turning you into a programmer is understanding what some of these types are and when you actually are changing datatypes.
Have a browse to http://resources.arcgis.com/en/help/silverlight-api/apiref/api_start.htm (note that this is the Silverlight API and not necessarily applicable or equivalent to all other ESRI api's but it will be a good start)
click on ESRI.ArcGIS.Client in the hierarchy tree on the left
click on ESRI.ArcGIS.Client.Tasks
find Featureset
click on Featureset Members etc
Anyway have any explore. You should find that a FeatureSet is a collection of Features and a Feature is a Graphic that may or may not have attributes or Geometry
So sometimes it is not a conversion that you are doing but rather getting a property of an object or part of an object.
Hope that helps
Ralph
0 -
FeatureSet to Geometry:
- If you want the Geometry of the whole thing, use a Union Task, which takes a FeatureSet as input, and gives you a Geometry back.
- If you want the Geometry of each feature, use ForEach loop to loop through each 'feature' in FeatureSet.Features (this is a foreach loop of type 'Graphic'). Then you can access the Geometry of each feature like this: feature.Geometry
Graphics from a FeatureSet is as above, but you don't have to access any property of the feature, as the feature itself is a Graphic.
A FeatureSet has many different constructors. You can make a FeatureSet from a Geometry:
myFeatureSet = new ESRI.ArcGIS.Client.Tasks.FeatureSet(myGeometry)
or a list of Geometries:
myGeometryList = new List(of Geometry) From { myGeometry1, myGeometry2, etc... }
myFeatureSet = new ESRI.ArcGIS.Client.Tasks.FeatureSet(myGeometryList)
You can also make a FeatureSet from a list of Graphics in the same manner.
There's no constructor for a single Graphic, however nothing is stopping you from having a List with only one element. The following is totally valid:
?myFeatureSet = new ESRI.ArcGIS.Client.Tasks.FeatureSet( new List(of Graphic) From { myGraphic } )
Just remember that FeatureSet.Features is a collection of Graphics, and each Graphic has a Geometry attribute (containing the spatial representation), and a Attributes dictionary (containing the table data).
Hope this helps.
0
Please sign in to leave a comment.
Comments
2 comments