0

I want to to use an array to create 3 buffer files with different buffer distances. The code should produce 3 buffer files in one step. Additionally, the code below runs already after using an ArcGIS Add-in, but I have no idea on how to build in the array and to save this 3 different buffer files.

Can somebody please point me in right direction, as I have no idea where to start? My system is ArcGIS10.2, VB.net, Visual Studio2012

Here is the code without array:

Imports ESRI.ArcGIS.Geoprocessor
Imports ESRI.ArcGIS.Framework
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.ArcMapUI
Imports ESRI.ArcGIS.AnalysisTools

Public Class BufferButton1
    Inherits ESRI.ArcGIS.Desktop.AddIns.Button

  Public Sub New()
  End Sub

  Protected Overrides Sub OnClick()

    Dim m_application = My.ArcMap.Application
    Dim mxDocument As IMxDocument = m_application.Document
    Dim map As IMap = mxDocument.FocusMap

    Dim strInputFC As String
    Dim strOutputFC As String
    Dim intOutputBufferSize As Integer

    Dim gp As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor()
    gp.OverwriteOutput = 1

    strInputFC = map.Layer(0).Name
    strOutputFC = "E:\" ' in this path I would like to save the 3 buffer files
    intOutputBufferSize = 1000 ' here I would like to handle three buffer sizes eg 1000, 2000 and 3000

    Dim bufferTool As ESRI.ArcGIS.AnalysisTools.Buffer = New ESRI.ArcGIS.AnalysisTools.Buffer()
    bufferTool.in_features = strInputFC
    bufferTool.out_feature_class = strOutputFC
    bufferTool.buffer_distance_or_field = intOutputBufferSize
    gp.Execute(bufferTool, Nothing)
    My.ArcMap.Application.CurrentTool = Nothing
  End Sub

  Protected Overrides Sub OnUpdate()
      Enabled = My.ArcMap.Application IsNot Nothing
  End Sub
End Class
5
  • Please make sure all your code fits in the code block. Greetings and thanks are not necessary in GIS SE.
    – Vince
    Commented Aug 6, 2015 at 15:40
  • Are you seeking to use an array? I'm not aware of any technique which will let ArcGIS create buffers in parallel -- You just need to iterate (and that wouldn't require the use of an array).
    – Vince
    Commented Aug 6, 2015 at 15:46
  • Thank you vince! I didn't succedd before to put the code in one block!
    – Susan
    Commented Aug 6, 2015 at 15:48
  • Thank you for quick reply! I think I would need an array and a for..each loop?
    – Susan
    Commented Aug 6, 2015 at 15:54
  • Use of arrays in programming is more of a programming theory issue, addressed by Stack Overflow, not GIS SE.
    – Vince
    Commented Aug 6, 2015 at 15:58

1 Answer 1

1

Adjusting with what @Vince was saying... Buffer does not accept an array in its out_feature_class property. However, you're kind of on the right track with a for each loop. Taking part of your code, here one way to do it. I am using a List instead of an Array because I don't care about memory usage and initializing my Array properly. There are numerous ways to achieve this task, even running it in parallel (threading, etc).

Dim gp As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor()
gp.OverwriteOutput = 1

strInputFC = map.Layer(0).Name
strOutputFC = "E:\" ' in this path I would like to save the 3 buffer files
'intOutputBufferSize = 1000 ' here I would like to handle three buffer sizes eg 1000, 2000 and 3000

Dim buffers As New List(Of Integer)
buffers.Add(1000)
buffers.Add(2000)
buffers.Add(3000)

For Each buff As Integer In buffers
    'each iteration creates a new tool
    Dim bufferTool As ESRI.ArcGIS.AnalysisTools.Buffer = New ESRI.ArcGIS.AnalysisTools.Buffer()
    'uses the same input
    bufferTool.in_features = strInputFC
    'creates a unique name so it isn't overwritten (at least on the initial run)
    bufferTool.out_feature_class = strOutputFC & "_buffer_" & buff.ToString()
    'uses the list integer as the distance
    bufferTool.buffer_distance_or_field = buff
    'executes the tool
    gp.Execute(bufferTool, Nothing)
Next

My.ArcMap.Application.CurrentTool = Nothing

As a side note you should review programming in VB.Net a little more. Once you're comfortable with the syntax and logic flow, then move into programming in ArcObjects. Also, be sure to check the API documentation on ESRI's website to understand what parameters each object takes and how to pass the parameters properly. Arrays, lists, collections, etc are all basic VB.Net/C# data structures, and you should have a grasp on them before trying to implement them. Logical flow, loops etc, are also a very integral part of .Net development. One last thing to look at with ArcObjects is releasing of COM resources. Without doing it properly, you'll end up having memory leaks, locks, unwanted behavior. I didn't adjust your code for it, but it is definitely something you should review, too.

3
  • Dear Branco, thank you a lot for your help, your explanations and advices!!! May I ask something more, please?
    – Susan
    Commented Aug 6, 2015 at 17:33
  • If it is part of this question, edit your question to reflect the change. If not, ask another question.
    – Branco
    Commented Aug 6, 2015 at 17:41
  • Dear Branco, thank you a lot again!! I just wanted to ak you how to get out a message about running process. I found it after a while in using gp.getMessages. Thank you for your help! You are great!!
    – Susan
    Commented Aug 6, 2015 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.