ArcGIS 的空间校正算法只有4种,无法满足数据处理的要求,尝试自己写ArcGIS插件。
参考链接:
通过空间调整调整要素位置-Adjusting feature locations with spatial adjustment
ITransformationMethod Interface
通过空间调整调整要素位置 |
概要本主题讨论使用空间调整方法定义位移链接和调整要素几何。
在这个主题中
关于使用空间调整方法调整要素
在ArcMap用户界面(UI)中,通过定义位移链接,将要调整的要素以及将应用的变换方法来执行空间调整。
在应用程序编程接口(API)中,将链接定义为表示位移链接的起点和终点的两个点数组。所需的位移链接数基于要应用的转换类型。每个转换都定义了这个数字,可以通过ITransformationMethod.MinNumDisplacementPoints访问。
然后通过ITransformationMethod上的方法和属性定义转换。要执行转换,请调用ITransformationMethod.Transform传递要调整的要素的要素光标。
ArcGIS支持以下转换:
- AffineTransformationMethod
- ConformalTransformationMethod(相似转换)
- EdgeSnapTransformationMethod
- PiecewiseTransformationMethod(用于橡皮布)
- ProjectiveTransformationMethod
以下代码显示了这些步骤的示例:
确保根据您的数据更改控制点的x,y坐标和查询过滤器的WHERE子句。
[C#] [VB.NET]
// This method performs an affine transformation on features.
//Create control points for the transformation.
//Normally, these come from the from/to ends of displacement links.
List < IPoint > fromPoints = new List < IPoint > ();
fromPoints.Add(CreatePoint(5566626.728, 4948245.103));
fromPoints.Add(CreatePoint(5566858.655, 4948246.713));
fromPoints.Add(CreatePoint(5566686.32, 4948088.874));
IPoint[] fromPointsArray = fromPoints.ToArray();
List < IPoint > toPoints = new List < IPoint > ();
toPoints.Add(CreatePoint(5566895.699, 4948111.423));
toPoints.Add(CreatePoint(5566744.302, 4947960.026));
toPoints.Add(CreatePoint(5567013.273, 4947989.017));
IPoint[] toPointsArray = toPoints.ToArray();
//Define control points.
ITransformationMethodGEN transformMethod = new AffineTransformationMethodClass();
IMxDocument mxDoc = m_application.Document as IMxDocument;
try
{
transformMethod.DefineFromControlPoints(ref fromPointsArray, ref toPointsArray,
null, mxDoc.ActiveView.Extent);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Define Control Points failed.");
}
//Create a feature cursor based on the predefined query.
IFeatureLayer featureLayer = mxDoc.FocusMap.get_Layer(0)as IFeatureLayer;
if (featureLayer == null)
{
System.Windows.Forms.MessageBox.Show(
"Please load a feature layer as the first layer in TOC.");
return ;
}
IFeatureClass featureClass = featureLayer.FeatureClass;
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.WhereClause = "diameter = 10";
IFeatureCursor featureCursor = featureClass.Search(queryFilter, false);
//Transform features.
IWorkspaceEdit workspaceEdit = featureClass.FeatureDataset.Workspace as
IWorkspaceEdit;
workspaceEdit.StartEditOperation();
transformMethod.Transform(featureCursor, null);
workspaceEdit.StopEditOperation();
//Refresh the active view.
mxDoc.ActiveView.Refresh();
private IPoint CreatePoint(double xVal, double yVal)
{
//This function creates a point.
IPoint point = new PointClass();
point.X = xVal;
point.Y = yVal;
return point;
}
'Perform an affine transformation on features.
'Create control points for the transformation.
'Normally, these come from the from/to ends of displacement links.
Dim fromPoints As List(Of IPoint) = New List(Of IPoint)
fromPoints.Add(CreatePoint(5566626.728, 4948245.103))
fromPoints.Add(CreatePoint(5566858.655, 4948246.713))
fromPoints.Add(CreatePoint(5566686.32, 4948088.874))
Dim fromPointsArray() As IPoint = fromPoints.ToArray()
Dim toPoints As List(Of IPoint) = New List(Of IPoint)
toPoints.Add(CreatePoint(5566895.699, 4948111.423))
toPoints.Add(CreatePoint(5566744.302, 4947960.026))
toPoints.Add(CreatePoint(5567013.273, 4947989.017))
Dim toPointsArray() As IPoint = toPoints.ToArray()
'Define control points.
Dim transformMethod As ITransformationMethodGEN = New AffineTransformationMethodClass()
Dim mxDoc As IMxDocument = TryCast(m_application.Document, IMxDocument)
Try
transformMethod.DefineFromControlPoints(fromPointsArray, _
toPointsArray, Nothing, mxDoc.ActiveView.Extent)
Catch ex As Exception
System.Windows.Forms.MessageBox.Show("Define Control Points failed.")
End Try
'Create a feature cursor based on the predefined query.
Dim featureLayer As IFeatureLayer = TryCast(mxDoc.FocusMap.Layer(0), IFeatureLayer)
If (featureLayer Is Nothing) Then
System.Windows.Forms.MessageBox.Show("Please load a feature layer as the first layer in TOC.")
Return
End If
Dim featureClass As IFeatureClass = featureLayer.FeatureClass
Dim queryFilter As IQueryFilter = New QueryFilterClass()
queryFilter.WhereClause = "diameter = 10"
Dim featureCursor As IFeatureCursor = featureClass.Search(queryFilter, False)
'Transform features.
Dim workspaceEdit As IWorkspaceEdit = TryCast(featureClass.FeatureDataset.Workspace, IWorkspaceEdit)
workspaceEdit.StartEditOperation()
transformMethod.Transform(featureCursor, Nothing)
workspaceEdit.StopEditOperation()
'Refresh the active view.
mxDoc.ActiveView.Refresh()
Private Function CreatePoint(ByVal xVal As Double, ByVal yVal As Double) As IPoint
'This function creates a point.
Dim point As IPoint = New PointClass()
point.X = xVal
point.Y = yVal
Return point
End Function
创建置换链接
在某些情况下,处理大量已知坐标以编程方式定义位移链接而不是手动输入一对坐标可能是有利的。
以下代码示例演示如何创建置换链接:
[C#] [VB.NET]
public void CreateDisplacementLink()
{
//Create a displacement link from two points.
//Get the map and reset graphics container.
IMxDocument mxDocument = m_application.Document as IMxDocument;
IMap map = mxDocument.FocusMap;
IGraphicsContainer graphicsContainer = map as IGraphicsContainer;
graphicsContainer.Reset();
//Get the link symbol from the adjustment extension.
IAdjustment adjustment = m_application.FindExtensionByName(
"ESRI Adjustment Tools")as IAdjustment;
IAdjustProperties adjustmentProperties = adjustment as IAdjustProperties;
ILineSymbol linkSymbol = adjustmentProperties.DisplacementLinkSymbol;
//Create the polyline from two points.
IPoint fromPoint = new PointClass();
fromPoint.PutCoords(115, - 32);
IPoint toPoint = new PointClass();
toPoint.PutCoords(116, - 31);
IPolyline polyLine = new PolylineClass();
polyLine.FromPoint = fromPoint;
polyLine.ToPoint = toPoint;
//Instantiate a new displacement link and set symbology.
IDisplacementLinkElement link = new DisplacementLinkElementClass();
link.Symbol = linkSymbol;
IElement element = link as IElement;
//Set the geometry and add to the graphics container.
element.Geometry = polyLine;
graphicsContainer.AddElement(element, 0);
//Refresh the graphics.
mxDocument.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null,
null);
}
'Create a displacement link from two points
'Get the map and graphics container
Dim pMxDoc As IMxDocument = My.ArcMap.Document
Dim pMap As IMap = pMxDoc.FocusMap
Dim pGraCon As IGraphicsContainer = pMap
pGraCon.Reset()
'Get the link symbol from the adjustment extension
Dim pAdjust As IAdjustment = My.ArcMap.Application.FindExtensionByName("ESRI Adjustment Tools")
Dim pAdjustProp As IAdjustProperties = pAdjust
Dim pLinkSymbol As ILineSymbol = pAdjustProp.DisplacementLinkSymbol
'Create the polyline from two points
Dim pFromPoint As IPoint
pFromPoint = New Point
pFromPoint.PutCoords(115, -32)
Dim pToPoint As IPoint
pToPoint = New Point
pToPoint.PutCoords(116, -31)
Dim pPolyLine As IPolyline
pPolyLine = New Polyline
pPolyLine.FromPoint = pFromPoint
pPolyLine.ToPoint = pToPoint
'Instantiate a new displacement link and set symbology
Dim pLink As IDisplacementLinkElement
pLink = New DisplacementLinkElement
pLink.Symbol = pLinkSymbol
Dim pElement As IElement = pLink
'Set the geometry and add to the graphics container
pElement.Geometry = pPolyLine
pGraCon.AddElement(pElement, 0)
'Refresh the graphics
pMxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, Nothing, Nothing)
若要使用本主题中的代码,请在Visual Studio项目中引用以下程序集。在代码文件中,您需要对相应的命名空间使用(C#)或Imports(VB .NET)指令(如果与程序集名称不同,则在下面的括号中给出):
- ESRI.ArcGIS.Framework
- ESRI.ArcGIS.ArcMapUI
- ESRI.ArcGIS.Geodatabase
- ESRI.ArcGIS.Carto
- ESRI.ArcGIS.Geometry
- ESRI.ArcGIS.EditorExt
- System.Collections.Generic
开发许可 | 部署许可 |
---|---|
ArcView的 | ArcView的 |
ArcEditor中 | ArcEditor中 |
ArcInfo的 | ArcInfo的 |
ArcObjects库参考(EditorExt) |
ITransformationMethod接口
提供对转换方法的访问。
产品供货
适用于ArcGIS Desktop。
何时使用
使用此界面定义和执行空间调整。使用ITransformationMethod :: DefineFromControlPoints定义调整参数。使用其中一种变换方法调整实体。
会员
所有 属性 方法 | 描述 | |
---|---|---|
DefineFromControlPoints | 定义一组点之间的最佳转换。 | |
我们提醒位移点 | 此转换方法所需的最小位移点数。 | |
Name | 转换方法的名称。 | |
SupportsIdentityLinks | 指示转换方法是否支持标识链接。 | |
转变 | 转换给定的功能。 | |
TransformElement | 转换给定元素。 | |
TransformShape | 转换给定的几何体。 |
实现ITransformationMethod的CoClasses
CoClasses和Classes | 描述 |
---|---|
AffineTransformationMethod | 仿射变换方法。 |
ConformalTransformationMethod | 保形变换方法。 |
EdgeSnapTransformationMethod | 边缘捕捉变换方法。 |
PiecewiseTransformationMethod | 分段(橡胶片)转化方法。 |
ProjectiveTransformationMethod | 投影变换方法。 |