Hi and thanks for looking at my post. I am wanting to do spatial join on a point layer and a polygon layer in VB.net. I am getting this done one piece at a time.
I have created both layers from the database to new layers on my C: drive so I can try whatever and cause no problems.
When I get to the join portion is when it errors. This is how I am attempting to do it and it may not be the right way so I can use some pointers.
This is the error message that I get:
Can’t create output feature class.
Database user name and current schemas do not match
[Data.User.JoinLayer]
The field is not nullable.
The field is not nullable.
DBMS table not found.
My Code:
Dim pFLayer As IFeatureLayer
Dim pFParLayer As IFeatureLayer
Dim pFc As IFeatureClass
Dim pINFeatureClassName As IFeatureClassName
Dim pInDsName As IDatasetName
Dim pWS As IFeatureWorkspace = openSDEWorkspace("DATA")
Dim pAddressesLayer As ESRI.ArcGIS.Carto.IFeatureLayer = gp.FindMapLayer("ADDRESSES")
If (pAddressesLayer Is Nothing) Then
pAddressesLayer = New FeatureLayer
pAddressesLayer.FeatureClass = pWS.OpenFeatureClass("DATA.ADDRESSES")
End If
'*******************************************************************************
Dim pParcelLayer As ESRI.ArcGIS.Carto.IFeatureLayer = gp.FindMapLayer("Parcels")
Dim pParcelWS As IFeatureWorkspace
If (pParcelLayer Is Nothing) Then
pParcelLayer = New FeatureLayer
pParcelWS = openSDEWorkspace("PARCELS")
pParcelLayer.FeatureClass = pParcelWS.OpenFeatureClass("PARCELS.PARCELS")
End If
'*******************************************************************************
pFLayer = pAddressesLayer
pFParLayer = pParcelLayer
Dim pFLDef As IFeatureLayerDefinition = pFLayer
Dim pFLParDef As IFeatureLayerDefinition = pFParLayer
Dim pFeatureSelection As ESRI.ArcGIS.Carto.IFeatureSelection = pAddressesLayer
Dim pFeatureQueryFilter As ESRI.ArcGIS.Geodatabase.IQueryFilter = New QueryFilter
Dim pSelFLayer As IFeatureLayer
pFeatureSelection.SelectionChanged()
pSelFLayer = pFLDef.CreateSelectionLayer("Address PIN", True, vbNullString, vbNullString)
'*******************************************************
Dim pParFeatureSelection As ESRI.ArcGIS.Carto.IFeatureSelection = pParcelLayer
Dim pSelParFLayer As IFeatureLayer
pParFeatureSelection.SelectFeatures(Nothing, ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultNew, False)
pParFeatureSelection.SelectionChanged()
pSelParFLayer = pFLParDef.CreateSelectionLayer("Parcel PIN", True, vbNullString, vbNullString)
'*******************************************************
Dim pDataset As IDataset = pSelFLayer.FeatureClass
Dim pWkSpDataset As IDataset = pDataset.Workspace
Dim pWkSpName As IWorkspaceName = pWkSpDataset.FullName
pFc = pFLayer.FeatureClass
pDataset = pFc
pINFeatureClassName = pDataset.FullName
pInDsName = pINFeatureClassName
'*********************************************************
Dim pGxLayer As ESRI.ArcGIS.Catalog.IGxLayer = New ESRI.ArcGIS.Catalog.GxLayer
Dim pGxFile As ESRI.ArcGIS.Catalog.IGxFile = pGxLayer
pGxFile.Path = "C:\Temp\" & pSelFLayer.Name & ".lyr"
pGxLayer.Layer = pSelFLayer
pGxFile.Path = "C:\Temp\" & pSelParFLayer.Name & ".lyr"
pGxLayer.Layer = pSelParFLayer
'*****************************************************************************************
'Join by location that joins the attributes of the
'first point contained within each polygon.
'*****************************************************************************************
Dim pSpJoin As ISpatialJoin = New SpatialJoin
Dim pFCNew As IFeatureClass
With pSpJoin
.JoinTable = pSelFLayer.FeatureClass
.SourceTable = pSelParFLayer.FeatureClass
.LeftOuterJoin = True
End With
'*****************************************************************************************
'Setting maxMapDist to 0 means that only points within
'each each polygon will be considered
'*****************************************************************************************
Dim pFCName As IFeatureClassName = New FeatureClassName
Dim pOutDSName As IDatasetName = pFCName
With pOutDSName
.Name = "JoinLayer"
.WorkspaceName = pWkSpName
End With
'****************************************************
This is where it goes out
Dim pName As IName = pOutDSName
pFCNew = pSpJoin.JoinNearest(pName, 0)
'****************************************************
If Not pFCNew Is Nothing Then
Dim pNewFLayer As IFeatureLayer
pNewFLayer = New FeatureLayer
pNewFLayer.FeatureClass = pFCNew
pNewFLayer.Name = "Sample Join by Location"
m_pMap.AddLayer(pNewFLayer)
m_pMXDOC.UpdateContents()
End If
Thanks again for your time. Dale,