Hi,
I want to perform a spatial search on ArcMap 10.2, cannot find proper sample for vb.net, what I found is the code from VBA. When I trying to convert it to vb.net, I encounter reference problem, the code is as following:
Public Function SpatialQuery(pFeatureClassIN As esriGeoDatabase.IFeatureClass, _
searchGeometry As esriGeometry.IGeometry, _
spatialRelation As esriGeoDatabase.esriSpatialRelEnum, _
Optional whereClause As String = "" _
) As esriGeoDatabase.IFeatureCursor
Dim pSpatialFilter As esriGeoDatabase.ISpatialFilter
Dim strShpFld As String
Dim pFeatCursor As esriGeoDatabase.IFeatureCursor
Dim pQueryFilter As esriGeoDatabase.IQueryFilter
' create a spatial query filter
pSpatialFilter = New esriGeoDatabase.SpatialFilter
' specify the geometry to query with
pSpatialFilter.Geometry = searchGeometry
' specify what the geometry file is called on the Feature Class that we will be querying against
strShpFld = pFeatureClassIN.ShapeFieldName
pSpatialFilter.GeometryField = strShpFld
' specify the type of spatial operation to use
pSpatialFilter.SpatialRel = spatialRelation
' create the where statement
pSpatialFilter.whereClause = whereClause
' perform the query and use a cursor to hold the results
pQueryFilter = pSpatialFilter
pFeatCursor = pFeatureClassIN.Search(pQueryFilter, False)
SpatialQuery = pFeatCursor
End Function
Then I got the following errors:
Not sure is it because the library difference of ArcGIS version? or what kind of library missing in my vb file? what shoukd I do to make it work?
Thanks for your time.
Solved! Go to Solution.
Hi Li Yao,
If you have added the ESRI references already then the types in your code would change from
pFeatureClassIN As esriGeoDatabase.IFeatureClass
To this:
Imports ESRI.ArcGIS.Geodatabase
...
pFeatureClassIN As IFeatureClass
or (without the Imports statement):
pFeatureClassIN As ESRI.ArcGIS.Geodatabase.IFeatureClass
Regards,
Owen
You will need to reference the appropriate DLL files and then import the namespaces in your code file.
For example in Visual Studio - Add Reference:
Then in your code file import the required namespaces:
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Geodatabase
Public Class ExampleClass
Public Function SpatialQuery(pFeatureClassIN As IFeatureClass, _
searchGeometry As IGeometry, _
spatialRelation As esriSpatialRelEnum, _
Optional whereClause As String = "" _
) As IFeatureCursor
Dim pSpatialFilter As ISpatialFilter
Dim strShpFld As String
Dim pFeatCursor As IFeatureCursor
Dim pQueryFilter As IQueryFilter
' etc ...
End Function
End Class
Check out the ArcObjects namespaces page to find the appropriate DLLs to reference as well as the namespaces to import.
Hope this helps,
Owen
Hi Owen,
Thanks for your quick reply. But I have already imported the necessary reference in the namespaces.
Hi Li Yao,
If you have added the ESRI references already then the types in your code would change from
pFeatureClassIN As esriGeoDatabase.IFeatureClass
To this:
Imports ESRI.ArcGIS.Geodatabase
...
pFeatureClassIN As IFeatureClass
or (without the Imports statement):
pFeatureClassIN As ESRI.ArcGIS.Geodatabase.IFeatureClass
Regards,
Owen
Hi Owen,
Yes you are right. Thank you very much for the patient to a beginner.