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:
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)
Here is the exception image: https://lh3.googleusercontent.com/-uy_hpPC7Z1E/U8VkmJNpQTI/AAAAAAAAAYE/djH6m-dWHnw/w1044-h587-no/runtime+error.png
User contributions licensed under CC BY-SA 3.0