public void addPoligonGeorefrenced(IFeatureLayer featureLayer, IFeatureWorkspace featureworkspace)
{
try
{
//Define vertices
if (_rasterInfo.rasterType != "Unknown")
convertPolygon();
IMap map = ArcMap.Document.FocusMap;
AddGraphicToMap(map);
IWorkspaceEdit editWorkspace = featureworkspace as IWorkspaceEdit;
editWorkspace.StartEditing(true);
editWorkspace.StartEditOperation();
int count = 0;
if (_rasterInfo.rasterType != "Unknown")
count = lngLatSet.Length;
else
count = pointSet.Length;
for (int j = 0; j < count; j++)
{
IPoint pPoint1 = new ESRI.ArcGIS.Geometry.Point();
IPoint pPoint2 = new ESRI.ArcGIS.Geometry.Point();
IPoint pPoint3 = new ESRI.ArcGIS.Geometry.Point();
IPoint pPoint4 = new ESRI.ArcGIS.Geometry.Point();
if (_rasterInfo.rasterType != "Unknown")
{
pPoint1.PutCoords(lngLatSet[j].leftTopX, lngLatSet[j].leftTopY);
pPoint2.PutCoords(lngLatSet[j].rightTopX, lngLatSet[j].rightTopY);
pPoint3.PutCoords(lngLatSet[j].rightDownX, lngLatSet[j].rightDownY);
pPoint4.PutCoords(lngLatSet[j].leftDownX, lngLatSet[j].leftDownY);
}
else
{
// if (pointSet[j].leftTopY < 0)
{
pPoint1.PutCoords(pointSet[j].leftTopX, pointSet[j].leftTopY);
pPoint2.PutCoords(pointSet[j].rightTopX, pointSet[j].rightTopY);
pPoint3.PutCoords(pointSet[j].rightDownX, pointSet[j].rightDownY);
pPoint4.PutCoords(pointSet[j].leftDownX, pointSet[j].leftDownY);
}
//else if (_rasterInfo.ratserNegative<0)
//{
// pPoint1.PutCoords(pointSet[j].leftTopX, pointSet[j].leftTopY *-1);
// pPoint2.PutCoords(pointSet[j].rightTopX, pointSet[j].rightTopY*-1);
// pPoint3.PutCoords(pointSet[j].rightDownX, pointSet[j].rightDownY*-1);
// pPoint4.PutCoords(pointSet[j].leftDownX, pointSet[j].leftDownY*-1);
//}
}
IPointCollection pPolygon = new Polygon();
IPointCollection pPointCollection = pPolygon as IPointCollection;
//Add the vertices of the polygon
pPointCollection.AddPoints(1, ref pPoint1);
pPointCollection.AddPoints(1, ref pPoint2);
pPointCollection.AddPoints(1, ref pPoint3);
pPointCollection.AddPoints(1, ref pPoint4);
((IPolygon)pPolygon).Close();
IFeature iFeature = featureLayer.FeatureClass.CreateFeature();
iFeature.Shape = (IPolygon)pPolygon;
iFeature.Store();
//Feature cursor used to loop through all features in feature class, optionally a query filter can be used.
if (_rasterInfo.rasterType != "Unknown")
{
int num = featureLayer.FeatureClass.FindField("URI");
iFeature.set_Value(num, lngLatSet[j].URI.ToString());
}
iFeature.Store();
}
IFeatureCursor fcCursor = featureLayer.FeatureClass.Update(null, true);
//Stop the operation and provide a name to add to the operation stack.
editWorkspace.StartEditOperation();
//Stop editing and save the edits.
editWorkspace.StopEditing(true);
map.AddLayer(featureLayer);
}
catch (Exception e)
{
Log.WriteLine("AddPolygon: " + e.Message);
}
}