I have read some posts and looked at a few different examples but I am still having a problem. My problem seems to lay with the location of the IFeature's shape, they are coming back as x= 590241.41279208846, y= 6284509.0955051426 (looks kind of like a UTM) but in order to see anything in that area they need to be more like x = -12831100.742200622; y = 7674669.7012844728.
This does not seem like a simple mouse point to map point location conversion.
This is my translation code:
public void MoveVisibleContouringLayersToDrawingLayer()
{
IElement pElement = null;
string polylineFeatureLayerBaseName = "Contour lines";
IGraphicsContainer graphicsContainer = GetGraphicsContainer();
graphicsContainer.DeleteAllElements();
IEnumLayer layerEnumerator = MapController.Map.Layers;
if (layerEnumerator != null)
{
try
{
ILayer layer = layerEnumerator.Next();
while (null != layer)
{
if (layer.Name == polylineFeatureLayerBaseName)
{
IFeatureLayer featureLayer = layer as IFeatureLayer;
IGeoFeatureLayer fl = (IGeoFeatureLayer)featureLayer;
if (null != featureLayer.FeatureClass)
{
if (featureLayer.Visible)
{
IFeatureCursor cursor = featureLayer.Search(null, false);
IFeature feature = cursor.NextFeature();
while (feature != null)
{
// Noticing coordinates are no where near the coordinates I use to get
// shapes to show up in my area. x = -12831100.742200622; y = 7674669.7012844728
// but the shape I am getting back is x= 590241.41279208846, y= 6284509.0955051426. Could the shape be in UTM?
var a = feature.Shape.GeometryType.ToString();
var b = feature.Shape.Envelope.UpperLeft.X;
var c = feature.Shape.Envelope.UpperLeft.Y;
var d = feature.Shape.Envelope.LowerRight.X;
var e = feature.Shape.Envelope.LowerRight.Y;
if (feature.Shape.GeometryType ==
ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
{
if (graphicsContainer != null)
{
IColor color = EsriConversionUtility.ConvertToRgbColor(Colors.Red);
ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass();
simpleLineSymbol.Color = color;
simpleLineSymbol.Width = 3;
// The IFeature shape it setting the lines geometry.
IGeometry geometry = feature.Shape;
ILineElement lineElement = new LineElementClass();
lineElement.Symbol = simpleLineSymbol;
IElement elementToAdd = lineElement as IElement;
elementToAdd.Geometry = geometry;
graphicsContainer.AddElement(elementToAdd, 0);
}
}
feature = cursor.NextFeature();
}
}
}
}
layer = layerEnumerator.Next();
}
}
finally
{
Marshal.ReleaseComObject(layerEnumerator);
RefreshView();
}
}
}