polyline - how to display it

2765
2
Jump to solution
03-04-2012 08:05 AM
AlexanderWolf
New Contributor III
I've been reading about how to display a Polyline and I'm getting nowhere. As I understand it, using the dynamic display means the drawn items will disappear when the layer is reloaded or redrawn which might happen when zooming, moving, clicking or similar events that cause the mapcontrol to refresh.
I am thinking I should create a layer from the Polyline so that it is persistent when refreshing.
I believe I have enough code to create the Polyline but don't know how to create a layer out of it.
Could you show me how?

Thanks,
Alex
0 Kudos
1 Solution

Accepted Solutions
EdgarBejarano
Occasional Contributor
Usually, when you create a Polyline and you want to display it in ArcMap or the MapControl of an ArcGIS Engine application, you do one of the following:

1.  Assign that the Polyline (geometry) to an existing or a new Feature in a FeatureClass.  If the Feature exists already in a FeatureClass, you get the existing Feature.  If you will assign it to a new Feature, you create a the new Feature with IFeatureClass::CreateFeature.  New or exisint, you will get a reference to IFeature, which has the Shape property, i.e. IFeature::Shape. 

Then one one usually display all or specified features in that FeatureClass by creating a new FeatureLayer and assigning it the FeatureClass as its FeatureClass source:
IFeatureLayer::FeatureClass.

With this approach, it would be the renderer (aka legend) that would dictate the color of the Polyline.

2.  You add the Polyline to a new LineElement.  You assign that LineElement a symbol (color, width, etc.) with ILineElement::Symbol.  Then you add that LineElement to a new GraphicsContainer which corresponds to your Map object in your code.  Essentially, you are adding a graphic element to an ArcMap map or MapControl map.  The below code snippet shows how to add various graphic elements.  Note the Else If statement that specifically shows how to add a line graphic element, specifically:
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Add_Graphic_to_Map_Snipp...

With this 2nd approach, you would not be able to add attributes to the Polyline.  For that, you would have to go the IFeature > IFeatureClass route using the 1st approach.

The approach you take depends on whether you want to display your polyline as a graphic element or if you want to add and store it in a FeatureClass (in this case, FeatureClass can mean a Shapefile or a Geodatabase FeatureClass).

I did not understand the part about dynamic display--perhaps you came across an article that made mention of dynamic display with respect to polylines.

View solution in original post

0 Kudos
2 Replies
EdgarBejarano
Occasional Contributor
Usually, when you create a Polyline and you want to display it in ArcMap or the MapControl of an ArcGIS Engine application, you do one of the following:

1.  Assign that the Polyline (geometry) to an existing or a new Feature in a FeatureClass.  If the Feature exists already in a FeatureClass, you get the existing Feature.  If you will assign it to a new Feature, you create a the new Feature with IFeatureClass::CreateFeature.  New or exisint, you will get a reference to IFeature, which has the Shape property, i.e. IFeature::Shape. 

Then one one usually display all or specified features in that FeatureClass by creating a new FeatureLayer and assigning it the FeatureClass as its FeatureClass source:
IFeatureLayer::FeatureClass.

With this approach, it would be the renderer (aka legend) that would dictate the color of the Polyline.

2.  You add the Polyline to a new LineElement.  You assign that LineElement a symbol (color, width, etc.) with ILineElement::Symbol.  Then you add that LineElement to a new GraphicsContainer which corresponds to your Map object in your code.  Essentially, you are adding a graphic element to an ArcMap map or MapControl map.  The below code snippet shows how to add various graphic elements.  Note the Else If statement that specifically shows how to add a line graphic element, specifically:
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Add_Graphic_to_Map_Snipp...

With this 2nd approach, you would not be able to add attributes to the Polyline.  For that, you would have to go the IFeature > IFeatureClass route using the 1st approach.

The approach you take depends on whether you want to display your polyline as a graphic element or if you want to add and store it in a FeatureClass (in this case, FeatureClass can mean a Shapefile or a Geodatabase FeatureClass).

I did not understand the part about dynamic display--perhaps you came across an article that made mention of dynamic display with respect to polylines.
0 Kudos
AlexanderWolf
New Contributor III
Thank you edga6340 for your detailed explanation. I have now gone with the second approach but may change it to go with the first approach. This explanation really makes the concept clear for me so thank you very much.
0 Kudos