ArcGIS engineeC#演示点从一个坐标移动向另一个坐标的轨迹
时间: 2023-09-16 07:12:53 浏览: 52
好的,这个问题我可以回答。下面是一个简单的示例,演示如何将一个点从一个坐标移动到另一个坐标的轨迹。在这个示例中,我们使用ArcGIS Engine的AxMapControl控件来显示地图,使用AxMapControl控件的DrawPoint方法来绘制点,使用IPoint接口来表示点,使用IPointCollection接口来表示点集合,使用IPoint.Move方法来移动点。
```csharp
private ESRI.ArcGIS.Controls.AxMapControl axMapControl1;
private ESRI.ArcGIS.Geometry.IPoint point;
private void Form1_Load(object sender, EventArgs e)
{
// 初始化地图
axMapControl1.Map.ClearLayers();
axMapControl1.LoadMxFile(@"C:\path\to\your\map.mxd");
// 初始化点
point = new ESRI.ArcGIS.Geometry.PointClass();
point.PutCoords(-118.15, 34.02);
point.SpatialReference = axMapControl1.SpatialReference;
// 绘制点
axMapControl1.DrawPoint(point, null);
}
private void button1_Click(object sender, EventArgs e)
{
// 移动点
ESRI.ArcGIS.Geometry.IPoint newPoint = new ESRI.ArcGIS.Geometry.PointClass();
newPoint.PutCoords(-118.12, 34.04);
newPoint.SpatialReference = axMapControl1.SpatialReference;
// 计算移动轨迹
ESRI.ArcGIS.Geometry.IPointCollection path = new ESRI.ArcGIS.Geometry.PathClass();
path.AddPoint(point);
path.AddPoint(newPoint);
ESRI.ArcGIS.Geometry.ITransform2D transform = (ESRI.ArcGIS.Geometry.ITransform2D)path;
transform.RotateAt(45, point);
// 绘制移动轨迹
ESRI.ArcGIS.Display.ISimpleLineSymbol lineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
lineSymbol.Color = new ESRI.ArcGIS.Display.RgbColorClass() { Red = 255 };
lineSymbol.Width = 2;
ESRI.ArcGIS.Display.ISymbol symbol = (ESRI.ArcGIS.Display.ISymbol)lineSymbol;
axMapControl1.DrawPolyline(path, symbol);
// 移动点并清除轨迹
for (int i = 0; i < path.PointCount; i++)
{
point.Move(path.get_Point(i).X - point.X, path.get_Point(i).Y - point.Y);
axMapControl1.DrawPoint(point, null);
System.Threading.Thread.Sleep(100);
if (i > 0) axMapControl1.DrawPolyline(new ESRI.ArcGIS.Geometry.PathClass() { path.get_Point(i - 1), path.get_Point(i) }, null);
}
}
```
在这个示例中,我们在窗体加载时初始化了一个点,并使用AxMapControl控件的DrawPoint方法将其绘制在地图上。在单击按钮时,我们创建了一个新的点,并使用IPoint.Move方法将原始点移动到新位置。然后,我们计算出移动轨迹,并使用AxMapControl控件的DrawPolyline方法将其绘制在地图上。最后,我们移动点并清除轨迹,以实现移动动画效果。
希望这个示例对你有所帮助!