嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
空间分析应用程序,包括建立缓冲区,边界线等十种空间分析方法
private void loadMapDocument()
{
System.Windows.Forms.OpenFileDialog openFIleDialog;
openFIleDialog = new OpenFileDialog();
openFIleDialog.Title = "打开地图文档";
openFIleDialog.Filter = "map document(*.mxd)|*.mxd";
openFIleDialog.ShowDialog();
string filePath = openFIleDialog.FileName;
if (axMapControl1.CheckMxFile(filePath))
{
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass;
axMapControl1.LoadMxFile(filePath, 0, Type.Missing);
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
else
{
MessageBox .Show (filePath "不是有效文档");
}
}
//获取简单线符号
private ISymbol getSimpleLineSymbol()
{
ISimpleLineSymbol SimpleLineSymbol = new SimpleLineSymbolClass();
SimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot;
SimpleLineSymbol.Width = 10;
IRgbColor rgbColor = getRgb (255, 0, 0);
SimpleLineSymbol.Color = rgbColor;
ISymbol symbol = SimpleLineSymbol as ISymbol;
symbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
return symbol;
}
//获取简单面填充符号
private ISimpleFillSymbol getSimpleFillSymbol(int fillColor, int lineColor)
{
ISimpleFillSymbol SimpleFillSymbol = new SimpleFillSymbolClass();
SimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
SimpleFillSymbol.Color = getRgb(255, 0, 0);
//创建边线符号
ISimpleLineSymbol SimpleLineSymbol = new SimpleLineSymbolClass();
SimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot;
SimpleLineSymbol.Color = getRgb(0, lineColor, 0);
SimpleLineSymbol.Width = 5;
ISymbol symbol = SimpleLineSymbol as ISymbol;
symbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
SimpleFillSymbol.Outline = SimpleLineSymbol;
return SimpleFillSymbol;
}
//创建颜色带
private IColorRamp CreatAlogrithmicColorRamp(int count)
{
//创建一个新CreatAlogrithmicColorRamp对象
IAlgorithmicColorRamp algColorRamp = new AlgorithmicColorRampClass();
IRgbColor fromColor = new RgbColorClass();
IRgbColor toColor = new RgbColorClass();
//创建起始颜色对象
fromColor.Red = 255;
fromColor.Green = 0;
fromColor.Blue = 0;
//创建终止颜色对象
toColor.Red = 0;
toColor.Green = 0;
toColor.Blue = 255;
//设置 AlgorithmicColorRampClass的起止属性
algColorRamp.ToColor = fromColor;
algColorRamp.FromColor = toColor;
//设置梯度类型
algColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
//设置颜色带颜色数量
algColorRamp.Size = count;
//创建颜色带、
bool bture = true;
algColorRamp.CreateRamp(out bture);
return algColorRamp;
}
private void Form1_Load(object sender, EventArgs e)
{
loadMapDocument();
}
//boundery
private void button1_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer;
IFeatureCursor featureCursor;
featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
featureCursor = featureLayer.FeatureClass.Search(null, true);
IFeature feature;
IGeometry geometry;
ISymbol symbol;
IActiveView activeView = this.axMapControl1.ActiveView;
feature = featureCursor.NextFeature();
while (feature != null)
{
if (feature.get_Value(feature.Fields.FindField("Continent")).ToString() == "Europe")
{
IPolygon polygon;
polygon = feature.Shape as IPolygon;
ITopologicalOperator topo = polygon as ITopologicalOperator;
topo.Simplify();
geometry = topo.Boundary;
if (geometry != null)
{
if (geometry.GeometryType == esriGeometryType.esriGeometryPolyline)
{
symbol = getSimpleLineSymbol() as ISymbol;
activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
activeView.ScreenDisplay.SetSymbol(symbol);
activeView.ScreenDisplay.DrawPolyline(geometry);
activeView.ScreenDisplay.FinishDrawing();
activeView.ScreenDisplay.FinishDrawing();
}
}
}
feature = featureCursor.NextFeature();
}
}
//装换像素到地图单位
private double ConvertPixelsToMapUnits(IActiveView pActiveView, double pixelUnits)
{
tagRECT pRect = pActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame();
int piexlExtent = pRect.right - pRect.left;
double realWorldDisplayExtent = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width;
double sizeOfOnePixel = realWorldDisplayExtent / piexlExtent;
return pixelUnits * sizeOfOnePixel;
}
//buffer
private void button2_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
IFeatureCursor featureCursor;
IFeature feature;
IGeometry geometry;
IActiveView activeView = this.axMapControl1.ActiveView;
ITopologicalOperator topo;
featureCursor = featureLayer.FeatureClass.Search(null, false);
feature = featureCursor.NextFeature();
ISpatialFilter spatialFilter = new SpatialFilterClass();
IFeatureSelection featureSelection;
ISymbol symbol = getSimpleFillSymbol(255, 125) as ISymbol;
if (feature != null)
{
topo = feature.Shape as ITopologicalOperator;
double bufferLength = ConvertPixelsToMapUnits(activeView, 2);
geometry = topo.Buffer(bufferLength);
activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
activeView.ScreenDisplay.SetSymbol(symbol);
activeView.ScreenDisplay.DrawPolygon(geometry);
activeView.ScreenDisplay.FinishDrawing();
//spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
//spatialFilter.Geometry = geometry;
//spatialFilter.GeometryField = featureLayer.FeatureClass.ShapeFieldName;
//spatialFilter.SubFields = "continent";
//spatialFilter.WhereClause = "";//
//featureSelection = featureLayer as IFeatureSelection;
//featureSelection.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
//ISelectionSet selectionSet = featureSelection.SelectionSet;
//ICursor cursor;
//selectionSet.Search(null, true, out cursor);
//feature = featureCursor.NextFeature();
//while (feature != null)
//{
// this.axMapControl1.Map.SelectFeature(featureLayer, feature);
// feature = featureCursor.NextFeature();
//}
activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
}
}
private void button3_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
IFeatureCursor featureCursor;
IFeature feature;
IGeometry geometry;
IActiveView activeView = this.axMapControl1.ActiveView;
ITopologicalOperator topo;
featureCursor = featureLayer.FeatureClass.Search(null, false );
feature = featureCursor.NextFeature();
ISpatialFilter spatialFilter = new SpatialFilterClass();
IFeatureSelection featureSelection;
IEnvelope env = new EnvelopeClass();
if (feature != null)
{
topo = feature.Shape as ITopologicalOperator;
env = feature.Shape.Envelope;
double width, height;
width = env.XMax - env.XMin;
height = env.YMax - env.YMin;
env.XMin = env.XMin width / 3;
env.YMin = env.YMin height / 3;
env.XMax =env .XMax -width /3;
env.YMax = env.YMax - height / 3;
geometry = new PolygonClass();
topo.QueryClipped(env, geometry);
ISymbol symbol = getSimpleFillSymbol(255, 255) as ISymbol;
activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
activeView.ScreenDisplay.SetSymbol(symbol);
activeView.ScreenDisplay.DrawPolygon(geometry);
activeView.ScreenDisplay.FinishDrawing();
activeView.ScreenDisplay.FinishDrawing();
}
}
//construction
private void button4_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
IFeature feature;
IActiveView activeView = this.axMapControl1.ActiveView;
ITopologicalOperator topo;
object missing = Type.Missing;
IGeometryCollection geometryCollection = new GeometryBagClass();
for (int i = 0; i < 3; i )
{
feature = featureLayer.FeatureClass.GetFeature(i);
geometryCollection.AddGeometry(feature.Shape, ref missing, ref missing);
}
IPolygon newPolygon = new PolygonClass();
topo = newPolygon as ITopologicalOperator;
topo.ConstructUnion(geometryCollection as IEnumGeometry);
ISymbol symbol = getSimpleFillSymbol(255, 255) as ISymbol;
activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
activeView.ScreenDisplay.SetSymbol(symbol);
activeView.ScreenDisplay.DrawPolygon(newPolygon as IGeometry);
activeView.ScreenDisplay.FinishDrawing();
activeView.ScreenDisplay.FinishDrawing();
}
private void button5_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
IFeature feature;
IActiveView activeView = this.axMapControl1.ActiveView;
ITopologicalOperator topo;
IGeometry geometry;
feature = featureLayer.FeatureClass.GetFeature(0);
topo = feature.Shape as ITopologicalOperator;
geometry = topo.ConvexHull();
ISymbol symbol = getSimpleLineSymbol();
activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
activeView.ScreenDisplay.SetSymbol(symbol);
activeView.ScreenDisplay.DrawPolyline (geometry);
activeView.ScreenDisplay.FinishDrawing();
activeView.ScreenDisplay.FinishDrawing();
}
private void button6_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
IFeature feature;
IActiveView activeView = this.axMapControl1.ActiveView;
ITopologicalOperator topo;
IGeometry leftGeometry, rightGeometry;
feature = featureLayer.FeatureClass.GetFeature(0);
topo = feature.Shape as ITopologicalOperator;
IEnvelope env = feature.Shape.Envelope;
IPolyline polyline = new PolylineClass();
IPoint point = new PointClass();
point.PutCoords(env.XMax, env.YMax);
polyline.FromPoint = point;
point.PutCoords(env.XMax, env.YMax);
polyline.ToPoint = point;
topo.Cut(polyline, out leftGeometry, out rightGeometry);
ISymbol symbol = getSimpleFillSymbol(255, 255) as ISymbol;
activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
activeView.ScreenDisplay.SetSymbol(symbol);
activeView.ScreenDisplay.DrawPolygon(leftGeometry );
activeView.ScreenDisplay.FinishDrawing();
}
private void button7_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
IFeature feature;
IActiveView activeView = this.axMapControl1.ActiveView;
ITopologicalOperator topo;
IGeometry geometry;
feature = featureLayer.FeatureClass.GetFeature(0);
topo = feature.Shape as ITopologicalOperator;
IEnvelope env = feature.Shape.Envelope;
double width, height;
width = env.XMax - env.XMin;
height = env.YMax - env.YMin;
object Missing = Type.Missing;
IPolygon polygon = new PolygonClass();
IPointCollection pointCollection = polygon as IPointCollection;
IPoint point = new PointClass();
point.PutCoords(env.XMin width / 3, env.YMin height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
point.PutCoords(env.XMin width / 3, env.YMin - height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
point.PutCoords(env.XMax - width / 3, env.YMax - height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
point.PutCoords(env.XMax - width / 3, env.YMax height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
geometry = topo.Difference(polygon as IGeometry);
ISymbol symbol = getSimpleFillSymbol(255, 255) as ISymbol;
activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
activeView.ScreenDisplay.SetSymbol(symbol);
activeView.ScreenDisplay.DrawPolygon(geometry );
activeView.ScreenDisplay.FinishDrawing();
}
private void button8_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
IFeature feature;
IActiveView activeView = this.axMapControl1.ActiveView;
ITopologicalOperator topo;
IGeometry geometry;
feature = featureLayer.FeatureClass.GetFeature(0);
topo = feature.Shape as ITopologicalOperator;
IEnvelope env = feature.Shape.Envelope;
double width, height;
width = env.XMax - env.XMin;
height = env.YMax - env.YMin;
object Missing = Type.Missing;
IPolygon polygon = new PolygonClass();
IPointCollection pointCollection = polygon as IPointCollection;
IPoint point = new PointClass();
point.PutCoords(env.XMin width / 3, env.YMin height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
point.PutCoords(env.XMin width / 3, env.YMin - height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
point.PutCoords(env.XMax - width / 3, env.YMax - height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
point.PutCoords(env.XMax - width / 3, env.YMax height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
polygon.SimplifyPreserveFromTo();
geometry = topo.Intersect(polygon as IGeometry, esriGeometryDimension.esriGeometry2Dimension);
ISymbol symbol = getSimpleFillSymbol(255, 255) as ISymbol;
activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
activeView.ScreenDisplay.SetSymbol(symbol);
activeView.ScreenDisplay.DrawPolygon(geometry);
activeView.ScreenDisplay.FinishDrawing();
}
private void button9_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
IFeature feature;
IActiveView activeView = this.axMapControl1.ActiveView;
ITopologicalOperator topo;
IGeometry geometry;
feature = featureLayer.FeatureClass.GetFeature(0);
topo = feature.Shape as ITopologicalOperator;
IEnvelope env = feature.Shape.Envelope;
double width, height;
width = env.XMax - env.XMin;
height = env.YMax - env.YMin;
object Missing = Type.Missing;
IPolygon polygon = new PolygonClass();
IPointCollection pointCollection = polygon as IPointCollection;
IPoint point = new PointClass();
point.PutCoords(env.XMin width / 3, env.YMin height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
point.PutCoords(env.XMin width / 3, env.YMin - height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
point.PutCoords(env.XMax width / 3, env.YMax - height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
point.PutCoords(env.XMax width / 3, env.YMax height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
polygon.SimplifyPreserveFromTo();
geometry = topo.SymmetricDifference(polygon as IGeometry);
ISymbol symbol = getSimpleFillSymbol(255, 255) as ISymbol;
activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
activeView.ScreenDisplay.SetSymbol(symbol);
activeView.ScreenDisplay.DrawPolygon(geometry);
activeView.ScreenDisplay.FinishDrawing();
}
private void button10_Click(object sender, EventArgs e)
{
IFeatureLayer featureLayer = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer;
IFeature feature;
IActiveView activeView = this.axMapControl1.ActiveView;
ITopologicalOperator topo;
IGeometry geometry;
feature = featureLayer.FeatureClass.GetFeature(0);
topo = feature.Shape as ITopologicalOperator;
IEnvelope env = feature.Shape.Envelope;
double width, height;
width = env.XMax - env.XMin;
height = env.YMax - env.YMin;
object Missing = Type.Missing;
IPolygon polygon = new PolygonClass();
IPointCollection pointCollection = polygon as IPointCollection;
IPoint point = new PointClass();
point.PutCoords(env.XMin width / 3, env.YMin height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
point.PutCoords(env.XMin width / 3, env.YMin - height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
point.PutCoords(env.XMax width / 3, env.YMax - height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
point.PutCoords(env.XMax width / 3, env.YMax height / 3);
pointCollection.AddPoint(point, ref Missing, ref Missing);
polygon.SimplifyPreserveFromTo();
geometry = topo.Union(polygon as IGeometry);
ISimpleFillSymbol simpleFillSymbol = getSimpleFillSymbol(255, 255);
activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
activeView.ScreenDisplay.SetSymbol(simpleFillSymbol as ISymbol );
activeView.ScreenDisplay.DrawPolygon(geometry as IGeometry );
activeView.ScreenDisplay.FinishDrawing();
}
}
}