Help GIS Tutorial for Python Scripting ex 2.3

3539
4
01-14-2015 09:58 AM
ChantellKrider
New Contributor

I recently purchased David Allen's GIS tutorial and I'm stuck on exercise 2.3. The objective is to buffer multiple paths with variable buffer distances based on the length of the path -step 7 (I'm stuck here). The exercise uses a search cursor to go through each path and buffer accordingly. The data are available with the book here. I know the buffer line is incorrect, it needs to call fcName and wellBuffDist.

  

It would be helpful to see the full script...if anyone has already completed this exercise. Thanks.

try:

  import arcpy

  from arcpy import env

  env.workspace = r"C:\EsriPress\GISTPython\Data\City of Oleander.gdb\Well_Data"

  env.overwriteOutput = True

  fcName = "BC_South_3H_Path"

  wellCursor = arcpy.da.SearchCursor(fcName,["Shape_Length"])

  for row in wellCursor:

    drillLength = row[0]

  def wellBuffDist(drillLenght, wellBuffDist):

    if drillLenght < 3000:

      wellBuffDist = 75

    elif drillLenght >= 3000 and drillLenght < 4000:

      wellBuffDist = 175

    else:

      wellBuffDist = 300

# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script

# The following inputs are layers or table views: "BC_South_3H_Path"

  arcpy.Buffer_analysis(in_features="BC_South_3H_Path",out_feature_class="C:/EsriPress/GISTPython/MyExercises/Scratch/Temporary Storage.gdb/SelectionBuffer",buffer_distance_or_field="300 feet",line_side="FULL",line_end_type="ROUND",dissolve_option="NONE",dissolve_field="#")

  print "great job!"

except:

  print "do over"

0 Kudos
4 Replies
DallasShearer
Occasional Contributor

this should work...

try:

  import arcpy

  from arcpy import env

  env.workspace = r"C:\EsriPress\GISTPython\Data\City of Oleander.gdb\Well_Data"

  env.overwriteOutput = True

  fcName = "BC_South_3H_Path"

  def wellBuffDist(drillLenght):

    if drillLenght < 3000:

      BuffDist = 75

    elif drillLenght >= 3000 and drillLenght < 4000:

      BuffDist = 175

    else:

      BuffDist = 300

    return str(BuffDist) + " feet"

  wellCursor = arcpy.da.SearchCursor(fcName,["Shape_Length"])

  for row in wellCursor:

    drillLength = row[0]

    wBuffDist = wellBuffDist(row[0])

    arcpy.Buffer_analysis(in_features=fcName, out_feature_class="C:/EsriPress/GISTPython/MyExercises/Scratch/Temporary Storage.gdb/SelectionBuffer", buffer_distance_or_field=wBuffDist, line_side="FULL", line_end_type="ROUND", dissolve_option="NONE", dissolve_field="#")

  print "great job!"

except:

  print "do over"

0 Kudos
ChantellKrider
New Contributor

Dallas-

Wow! thank you sooo much. I really appreciate your response. I did run the code you suggested and it almost works. I commented bits out until I discovered the source of the error. It gets hung up in the buffer statement where it calls the wBuffDist. I'll do a little more work to try and figure it out.

Thanks again!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Chantell Krider‌,

When you post code, could you please use the syntax highlighting?

Posting Code blocks in the new GeoNet

In case Dallas answer was helpful you can mark it as Helpfull (below the post you'll find "Helpful Yes | No").

In case Dallas answered your question you can mark his post using the button "Correct Answer".

Kind regards, Xander

0 Kudos
ChantellKrider
New Contributor

Okay. Thanks. I'm new to this. Thanks for the tip.

0 Kudos