阅读:2379回复:2
无法给FeatureClass预定义坐标系统,求解?是高手给个代码,好心的
这种情况大家可能都碰到过,一个featureclass坐标系统为空,利用arctoolbox中的define projection工具可以给它加入坐标系统 ,但是用C#+AE ,用GP却无法实现,这个问题纠结了我好久,求高手帮帮我啊!代码如下:<br/>Geoprocessor GP = new Geoprocessor();<br/>ESRI.ArcGIS.DataManagementTools.DefineProjection defineProTool = new ESRI.ArcGIS.DataManagementTools.DefineProjection();<br/>defineProTool.in_dataset = @"d:\temp\test.mdb\test40";<br/>defineProTool.out_dataset = @"d:\temp\test.mdb\test40";<br/>defineProTool.coor_system = esriSRProjCS4Type.esriSRProjCS_Xian1980_3_Degree_GK_Zone_40;<br/>GP.Execute(defineProTool, null);<br/><br/>代码可以运行,但是featureclass无任何变化,不知道哪里出错,在arctoolbox里可以解决搬到AE就不行了,不知道有没有其他解决办法,高手帮忙帮帮忙啊!!!
|
|
1楼#
发布于:2011-11-24 08:23
<p>按以下的思路写,可以解决</p>
<p> </p> <p> It fails when I pass the spatial reference directly to DataManagementTools.DefineProjection() but it works fine if I convert the spatial reference to a definition string and pass in the string. <br/></p> <p>Public Sub DefineProjection92(ByVal DatasetPath As String, <br/>ByVal SpatialReference As ESRI.ArcGIS.Geometry.ISpatialReference2)<br/><br/>Dim GP As ESRI.ArcGIS.Geoprocessor.Geoprocessor <br/>GP = New ESRI.ArcGIS.Geoprocessor.Geoprocessor<br/>GP.AddOutputsToMap = False<br/><br/><strong>' Convert the spatial reference to a definition string</strong><br/>Dim pProjectedCoordinateSystem As ESRI.ArcGIS.Geometry.ISpatialReference2GEN = SpatialReference<br/>Dim pParameterExport As ESRI.ArcGIS.Geometry.IESRISpatialReferenceGEN = pProjectedCoordinateSystem<br/>Dim pBytes As Integer<br/>Dim pBuffer As String = New String(" ", pParameterExport.ESRISpatialReferenceSize)<br/>pParameterExport.ExportToESRISpatialReference(pBuffer, pBytes)<br/><br/>' Open the tool<br/>Dim define As ESRI.ArcGIS.DataManagementTools.DefineProjection<br/>define = New ESRI.ArcGIS.DataManagementTools.DefineProjection(DatasetPath, pBuffer)<br/><br/>Dim pTrkCan As ITrackCancel = Me.GetCancelTracker<br/><br/>' Execute the tool<br/>Dim pResult As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult <br/><strong>pResult = GP.Execute(define, pTrkCan)</strong> <strong>'Works on feat classes and feat datasets</strong><br/><br/>If pResult Is Nothing Then<br/>Dim ErrorMessage As String = ""<br/>If GP.MessageCount > 3 Then<br/>ErrorMessage = GP.GetMessage(2) '2 is normally the index of the error message, but not always!<br/>End If<br/>Throw New System.Exception("Define Projection failed: " ; ErrorMessage)<br/>End If<br/><br/>End Sub</p> |
|
|
2楼#
发布于:2011-11-24 08:30
<p>谢谢 我试试看</p>
<p> </p> <p>问题已经解决 ,谢谢 斑竹!</p> [此贴子已经被作者于2011-11-24 11:00:39编辑过]
|
|