在VB.NET中编写ArcGIS脚本时出错" HRESULT中的异常:0x80040202"

时间:2014-07-15 15:58:06

标签: vb.net vb.net-2010 arcgis comexception

我在VB.NET脚本中编码ArcGIS时计算运行时错误,以计算两个三维对象之间的距离。

  

“来自HRESULT的异常:0x80040202”

我试图了解问题但失败了。请帮我调试。我正在尝试添加一个屏幕截图,但看起来我需要至少10个声望来发布图像。

实际上,我的工作是创建一个矩形平面,在地球表面下方具有3D顶点,并从地球表面上创建的网格的所有点找到到平面的距离。所有这些工作都将在ArcGIS中完成。所以我在地理坐标系WGS-1984中创建了一个地理数据库。然后我创建了一个网格文件并添加了信封,拉片和长片等。然后我在GCS中创建了两个形状文件,一个点和一个多边形,并将它们投影到UTM系统。然后我使用了一个名为I3DProximity的接口来查找距离。然后它给出了错误。

所以这是我的代码。首先,我在这里创建了Geodatabase并分配了Geographic coodrinate系统:

    Dim wksp As IWorkspace
        wksp = CreateFileGDB(mainPath, GDBName)
        Dim fWS As IFeatureWorkspace
        fWS = CType(wksp, IFeatureWorkspace)

        Dim pSpatialReferenceEnvironment As SpatialReferenceEnvironment
        pSpatialReferenceEnvironment = New SpatialReferenceEnvironment
        Dim pGeographicCoordinateSystem As IGeographicCoordinateSystem
        pGeographicCoordinateSystem = pSpatialReferenceEnvironment.CreateGeographicCoordinateSystem(esriSRGeoCSType.esriSRGeoCS_WGS1984)



        Dim pfeatclass As IFeatureClass
        pfeatclass = CreateFeatureClassWithFields(mainName, fWS)

        'Adding Fields to the GDB file
        newfields()

        'polygons
        Dim pworkedit As IWorkspaceEdit = CType(wksp, IWorkspaceEdit)
        Dim pfeaturebuffer As IFeatureBuffer


        pworkedit.StartEditing(True)
        pworkedit.StartEditOperation()
        pfeaturebuffer = pfeatclass.CreateFeatureBuffer

        Dim pfeature As IFeature = CType(pfeaturebuffer, IFeature)
        Dim nfeatcursor As IFeatureCursor = pfeatclass.Insert(True)


        Dim Xmin As Double
        Dim Ymin As Double
        Dim Xmax As Double
        Dim Ymax As Double

        If ToolStripTextBox10.Text = "Xmin" Then
            Dim player As ILayer = axMapControl1.ActiveView.FocusMap.Layer(0)

            Xmin = player.AreaOfInterest.Envelope.XMin     'longitude of left bottom point
            Ymin = player.AreaOfInterest.Envelope.YMin     'latitude
            Xmax = player.AreaOfInterest.Envelope.XMax     'longitude of top right point
            Ymax = player.AreaOfInterest.Envelope.YMax     'latitude
        Else
            Xmin = Val(ToolStripTextBox10.Text)
            Ymin = Val(ToolStripTextBox11.Text)
            Xmax = Val(ToolStripTextBox12.Text)
            Ymax = Val(ToolStripTextBox13.Text)

        End If


        Dim numgridsLong As Integer = CType((Xmax - Xmin) / gInterval, Integer)
        Dim numgridsLat As Integer = CType((Ymax - Ymin) / gInterval, Integer)

        ReDim gridLong(numgridsLong, numgridsLat)
        ReDim gridLat(numgridsLong, numgridsLat)

        gridLong(0, 0) = Xmin
        gridLat(0, 0) = Ymin

        For j = 0 To (numgridsLat - 1)
            For i = 0 To (numgridsLong - 1)
                gridLong(i, j) = Xmin + i * gInterval
                gridLat(i, j) = Ymin + j * gInterval
                Dim pPolygon As IPolygon = getPolygon(gridLong(i, j), gridLat(i, j))
                'createPolygon(gridLong(i, j), gridLat(i, j), interval1, interval2)

                pfeature.Shape = pPolygon
                nfeatcursor.InsertFeature(pfeaturebuffer)
            Next i
        Next j

        nfeatcursor.Flush()
        pworkedit.StopEditOperation()
        pworkedit.StopEditing(True)

        'Adding lattitude and longitude field values to the mainName fileGDB
        AddLongLat()

        ' Adding a featureclass as a layer to Map Control
        Dim featWS As IFeatureWorkspace = retFWspace(PathName)
        Dim featclass As IFeatureClass = featWS.OpenFeatureClass(mainName)
        Dim gridFLayer As IFeatureLayer = New FeatureLayer
        With gridFLayer
            .FeatureClass = featclass
            .Name = mainName
            .Visible = True
        End With

        axMapControl1.AddLayer(gridFLayer)
        axMapControl1.ActiveView.FocusMap.RecalcFullExtent()


        disp_stat("GDB : " & PathName)
        disp_stat("Grid Interval: " & gInterval)
        disp_stat("Grids: " & numgridsLong & " * " & numgridsLat)
        Count = 0
        disp_stat("Feature count: " & FeatCount())

    Else
        Exit Sub

    End If

    MakeGridTable()
    populategridtableAddcolumn()
    initialization()
    'AddColumn("Latitude")
    'AddColumn("Longitude")
    'AddColumn("Test")
    transfer("Latitude")
    transfer("Longitude")
    mruList.AddItem(mainPath) 'MRU List Loader
    disp_stat("Create GDB Executed")
    'save_log()

    watch.Stop()
    disp_stat(watch.Elapsed.TotalMilliseconds)

在这里,我使用四个3D点创建了一个矩形:

Dim pPoint As IPoint = New PointClass()
    Dim pPointCollection As IPointCollection = New RingClass()
    Dim pGeomCollection As IGeometryCollection = New PolygonClass()



    pPoint.PutCoords(lat2, long2)
    pPoint.Z = Z2
    pPointCollection.AddPoint(pPoint)
    pPoint.PutCoords(lat1, long1)
    pPoint.Z = Z1
    pPointCollection.AddPoint(pPoint)

    pPoint.PutCoords(lat4, long4)
    pPoint.Z = Z4
    pPointCollection.AddPoint(pPoint)
    pPoint.PutCoords(lat3, long3)
    pPoint.Z = Z3
    pPointCollection.AddPoint(pPoint)
    pGeomCollection.AddGeometry(pPointCollection)
    Dim pOutGeometry As IGeometry = CType(pGeomCollection, IGeometry)
    Dim pZaware As IZAware = CType(pOutGeometry, IZAware)
    pZaware.ZAware = True

现在我创建了一个3D点来检查距离计算是否正常

    Dim gpoint As IPoint = New PointClass()
    Dim gridgeometry As IGeometry = CType(gpoint, IGeometry)
    Dim gZaware As IZAware = CType(gridgeometry, IZAware)
    gZaware.ZAware = True
    gpoint.PutCoords(71.558, 21.663)
    gpoint.Z = 0

在这里,我给出了多边形和点的地理坐标系,并将它们投影到UTM坐标系,因为3D算子在投影系统而不是地理坐标系中工作

Dim pSpatRefFact As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory

    pSpatRefFact = New ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment

    Dim pGCS As ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem
    pGCS = pSpatRefFact.CreateGeographicCoordinateSystem(ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984)


    pOutGeometry.SpatialReference = pGCS
    gpoint.SpatialReference = pGCS

    'Now Define the Projected Coordinate System
    Dim projectedcosys As IProjectedCoordinateSystem
    projectedcosys = pSpatRefFact.CreateProjectedCoordinateSystem(esriSRProjCSType.esriSRProjCS_WGS1984UTM_43N)

    'Now We need to project it
    pOutGeometry.Project(projectedcosys)

    gridgeometry.Project(projectedcosys)

现在我使用IProximity3D inerface返回距离

    Dim pProxOp As IProximityOperator3D = CType(gpoint, IProximityOperator3D)
    Dim pReturnDistance As Double = pProxOp.ReturnDistance3D(pOutGeometry)
    MsgBox(pReturnDistance)

这是异常图片: https://lh3.googleusercontent.com/-uy_hpPC7Z1E/U8VkmJNpQTI/AAAAAAAAAYE/djH6m-dWHnw/w1044-h587-no/runtime+error.png

0 个答案:

没有答案