1

I am getting this Run time Error while coding ArcGIS in VB.NET script to calculate distance between two 3-D objects.

“Exception from HRESULT: 0x80040202”

I tried to understand the problem but failed. Please help me to debug. I am trying to add a screen shot but it looks like i need at least 10 reputation to post images.

Actually my work is to create a Rectangular plane with 3D vertices below earth's surface and to find distance to the plane from all the points of a Grid created on earth's surface. All this work is to be done in ArcGIS. So I created a Geodatabase in Geographic Coordinate System WGS-1984. Then I created a grid file and added envelope, lats and longs etc. Then I created two shape files a point and a polygon in GCS and projected them to UTM system. Then I used an interface called I3DProximity to find the distance. Then it gave the error.

So here's my code. First I created Geodatabase here and assigned Geographic coodrinate system: Though I have given the whole code, I guess the error is somewhere in the last 2 parts, like in spatial referencing and using IProximity3D interface.

        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)

Here I created a rectangle using four 3D points:

    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

Now I created a 3D point to check if the distance calculation works fine

    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

Here I gave Geographic coordinate systems to bothe polygon and point and projected them to UTM coordinate system as 3D operators works in projected systems rather than geographic coordinate systems

    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)

Now I use IProximity3D inerface to return the distance

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

Visual Studio

  • Welcome to GIS SE! For questions like this one I recommend always including an arcobjects tag to help bring it to the attention of people with those skills. – PolyGeo Jul 16 '14 at 7:49
  • Also, you may want to explicitly point out the line that is failing. I can see it in the screenshot, but I almost missed that. For reference, the error you are getting is EVENT_S_NOSUBSCRIBERS, which is a new one to me. – Evil Genius Jul 16 '14 at 11:03
1

Just an idea but you seem to be constructing your rectangle from a ring and the help talks about wrapping rings in higher level geometry.

If it were me and as it looks like you are building a simple rectangle I would have built the polygon this way (not sure it makes a difference but worth a try?)...

Dim pPolygon As IPolygon4
Set pPolygon = New Polygon
Dim pZaware As IZAware
Set pZaware = pPolygon
pZaware.ZAware = True
Dim pPointColl As IPointCollection
Set pPointColl = pPolygon

Dim pPoint As IPoint
Set pPoint = New Point
Set pZaware = pPoint
pZaware.ZAware = True
pPoint.PutCoords 0, 0 ' dummy coordinates to show how to add them
pPoint.Z = 1

pPointColl.AddPoint pPoint

' repeat adding your points
  • :) Glad to have helped. – Hornbydd Jul 16 '14 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.