InMemory shapefile or featureclass creation

Option Explicit
Sub TestInMemory()
Dim pFC As IFeatureClass
Set pFC = OpenFC(“C:\Projects\SAWS\water3.gdb”, _

Dim pFLayer As IFeatureLayer
Set pFLayer = New FeatureLayer
pFLayer.Name = pFC.AliasName
Set pFLayer.FeatureClass = CacheToMemory(pFC, “Shape_Length 0 Then
Set pQF = New QueryFilter
pQF.WhereClause = sWhere
End If

Dim pInFCur As IFeatureCursor
Set pInFCur = pFC.Search(pQF, False)

Dim pFeat As IFeature
Set pFeat = pInFCur.NextFeature
Do Until pFeat Is Nothing
Dim pOutFeat As IFeature
Set pOutFeat = pInMemFC.CreateFeature

Dim l As Long
For l = 0 To pOutFeat.Fields.FieldCount – 1
‘ todo maybe search by field alias to find match
If pOutFeat.Fields.Field(l).Editable Then
pOutFeat.Value(l) = pFeat.Value(l)
End If
Next l
Set pFeat = pInFCur.NextFeature

End Sub

Function Clone(pClone As IClone) As IClone
Set Clone = pClone.Clone
End Function

Function OpenFC(sPath As String, sName As String) As IFeatureClass
Dim pWSF As IWorkspaceFactory
Set pWSF = New FileGDBWorkspaceFactory
Dim pFWS As IFeatureWorkspace
Set pFWS = pWSF.OpenFromFile(sPath, 0)

Set OpenFC = pFWS.OpenFeatureClass(sName)
End Function

Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: