Create buffer of a complete feature class in memory

2212
2
Jump to solution
07-03-2012 12:03 AM
HectorSanchez_Molinero
New Contributor
Hello, I am beginning to programs with vb.net and c# and of arcobjects do not belong almost anything.

I have created the buffer but creating a new featureclass, with the object itopologicaloperator:

'duplicate featureclass
featureClass2 = fws.CreateFeatureClass("buffer_", _
                                                                        featureClass.Fields, _
                                                                        featureClass.CLSID, _
                                                                        featureClass.EXTCLSID, _
                                                                        featureClass.FeatureType, _
                                                                        featureClass.ShapeFieldName, "")

            'create cursor
            Dim cursor As IFeatureCursor
            cursor = edificios.Search(Nothing, False)
            Dim feature, feature2 As IFeature

                    'duplicate each registry
                    feature2 = featureClass2.CreateFeature()

                    Dim j As Integer
                    For j = 0 To featureClass2.Fields.FieldCount - 1
                        If feature.Fields.Field(j).Editable Then
                            feature2.Value(j) = feature.Value(j)
                        End If
                    Next

                    'buffer to duplicate registry
                    Dim bufferTool As ITopologicalOperator
                    bufferTool = feature2.Shape

                    feature2.Shape = bufferTool.Buffer(Form1._buffer)                   
                    feature2.Store()
                    feature = cursor.NextFeature



there is way of doing it in memory?? (without duplicate featureclass)


I tried it with an ipolygonlist but I have not been capable.

thanks a lot.
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
Here is how I create an in-memory feature class in my projects, using the Geoprocessor.

'pSR is a variable containing a spatial reference 'in this case, I'm creating an in-memory point feature class pFeatureClass = CreateInMemoryFeatureClass2("temporary", ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint, pSR)     Public Function CreateInMemoryFeatureClass2(ByVal Name As String, InShapeType As ESRI.ArcGIS.Geometry.esriGeometryType, InSR As ESRI.ArcGIS.Geometry.ISpatialReference3) As ESRI.ArcGIS.Geodatabase.IFeatureClass          Dim CreateFC As New ESRI.ArcGIS.DataManagementTools.CreateFeatureclass         Dim ShapeType As String         Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2          Try             Using releaser As New ESRI.ArcGIS.ADF.ComReleaser                 releaser.ManageLifetime(CreateFC)                  Select Case InShapeType                     Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint                         ShapeType = "Point"                     Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline                         ShapeType = "Line"                     Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon                         ShapeType = "Polygon"                     Case Else                         Return Nothing                 End Select                  CreateFC.out_path = "in_memory"                 CreateFC.out_name = Name                 CreateFC.geometry_type = ShapeType                 CreateFC.spatial_reference = InSR                  Result = RunTool(CreateFC, Nothing)                 If Result Is Nothing Then                     System.Windows.Forms.MessageBox.Show("Could not create InMemory dataset")                     Return Nothing                 End If                  Return ReturnObjectfromResult(Result, "Feature Class")             End Using          Catch ex As Exception             System.Windows.Forms.MessageBox.Show(ex.ToString, "Create InMemory Featureclass error")             Return Nothing         End Try      End Function     Friend Function ReturnObjectfromResult(ByVal result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2, ByVal Type As String) As Object          Dim GPVal As ESRI.ArcGIS.Geodatabase.IGPValue         Dim InMemFC As String         Dim GPUtil As ESRI.ArcGIS.Geoprocessing.IGPUtilities3 = New ESRI.ArcGIS.Geoprocessing.GPUtilities          Try             GPVal = result.GetOutput(0)             InMemFC = GPVal.GetAsText()              Select Case Type                 Case "Feature Class"                     Return GPUtil.OpenFeatureClassFromString(InMemFC)                 Case "Table"                     Return GPUtil.OpenTableFromString(InMemFC)             End Select          Catch ex As Exception             System.Windows.Forms.MessageBox.Show(ex.ToString, "Return FeatureClass error")             Return Nothing         End Try      End Function      Friend Function RunTool(ByVal Process As ESRI.ArcGIS.Geoprocessor.IGPProcess, ByVal TC As ESRI.ArcGIS.esriSystem.ITrackCancel2) As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2          Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2         Dim GP As New ESRI.ArcGIS.Geoprocessor.Geoprocessor          Try             Result = CType(GP.Execute(Process, Nothing), ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2)             If Result.Status <> ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded Then ReturnMessages(Result, "Geoprocessing Error")          Catch ex As Exception             System.Windows.Forms.MessageBox.Show(ex.ToString, "Run Geoprocessor")         End Try          Return Result      End Function      Private Sub ReturnMessages(ByVal pResult As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2, ByVal Title As String)          Dim ErrorMessage As String          If pResult.MessageCount > 0 Then             For Count As Integer = 0 To pResult.MessageCount - 1                 ErrorMessage += pResult.GetMessage(Count)             Next         End If          System.Windows.Forms.MessageBox.Show(ErrorMessage, Title)      End Sub  

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor
Here is how I create an in-memory feature class in my projects, using the Geoprocessor.

'pSR is a variable containing a spatial reference 'in this case, I'm creating an in-memory point feature class pFeatureClass = CreateInMemoryFeatureClass2("temporary", ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint, pSR)     Public Function CreateInMemoryFeatureClass2(ByVal Name As String, InShapeType As ESRI.ArcGIS.Geometry.esriGeometryType, InSR As ESRI.ArcGIS.Geometry.ISpatialReference3) As ESRI.ArcGIS.Geodatabase.IFeatureClass          Dim CreateFC As New ESRI.ArcGIS.DataManagementTools.CreateFeatureclass         Dim ShapeType As String         Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2          Try             Using releaser As New ESRI.ArcGIS.ADF.ComReleaser                 releaser.ManageLifetime(CreateFC)                  Select Case InShapeType                     Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint                         ShapeType = "Point"                     Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline                         ShapeType = "Line"                     Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon                         ShapeType = "Polygon"                     Case Else                         Return Nothing                 End Select                  CreateFC.out_path = "in_memory"                 CreateFC.out_name = Name                 CreateFC.geometry_type = ShapeType                 CreateFC.spatial_reference = InSR                  Result = RunTool(CreateFC, Nothing)                 If Result Is Nothing Then                     System.Windows.Forms.MessageBox.Show("Could not create InMemory dataset")                     Return Nothing                 End If                  Return ReturnObjectfromResult(Result, "Feature Class")             End Using          Catch ex As Exception             System.Windows.Forms.MessageBox.Show(ex.ToString, "Create InMemory Featureclass error")             Return Nothing         End Try      End Function     Friend Function ReturnObjectfromResult(ByVal result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2, ByVal Type As String) As Object          Dim GPVal As ESRI.ArcGIS.Geodatabase.IGPValue         Dim InMemFC As String         Dim GPUtil As ESRI.ArcGIS.Geoprocessing.IGPUtilities3 = New ESRI.ArcGIS.Geoprocessing.GPUtilities          Try             GPVal = result.GetOutput(0)             InMemFC = GPVal.GetAsText()              Select Case Type                 Case "Feature Class"                     Return GPUtil.OpenFeatureClassFromString(InMemFC)                 Case "Table"                     Return GPUtil.OpenTableFromString(InMemFC)             End Select          Catch ex As Exception             System.Windows.Forms.MessageBox.Show(ex.ToString, "Return FeatureClass error")             Return Nothing         End Try      End Function      Friend Function RunTool(ByVal Process As ESRI.ArcGIS.Geoprocessor.IGPProcess, ByVal TC As ESRI.ArcGIS.esriSystem.ITrackCancel2) As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2          Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2         Dim GP As New ESRI.ArcGIS.Geoprocessor.Geoprocessor          Try             Result = CType(GP.Execute(Process, Nothing), ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2)             If Result.Status <> ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded Then ReturnMessages(Result, "Geoprocessing Error")          Catch ex As Exception             System.Windows.Forms.MessageBox.Show(ex.ToString, "Run Geoprocessor")         End Try          Return Result      End Function      Private Sub ReturnMessages(ByVal pResult As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2, ByVal Title As String)          Dim ErrorMessage As String          If pResult.MessageCount > 0 Then             For Count As Integer = 0 To pResult.MessageCount - 1                 ErrorMessage += pResult.GetMessage(Count)             Next         End If          System.Windows.Forms.MessageBox.Show(ErrorMessage, Title)      End Sub  
0 Kudos
HectorSanchez_Molinero
New Contributor
thank you very much kenbuja
0 Kudos