py addin: buffer error

685
3
08-11-2014 01:13 PM
KevinBell
Occasional Contributor III

I have a python addin that has a tool, and a combo box.  the combo is quarter mile increments, so 0.25, 0.5, 0.75, 1, 1.25 etc.  The tool is just a map click.  This code creates the buffer where the user clicks, but it's 17 inches, not 1 Mile...  I'm going nuts.

def buildWebPage(x, y, cmboDistance):

   

    print 'in buildWebPage def!'

   

    inpoint = arcpy.Point(X=x, Y=y)

    ptGeometry = arcpy.PointGeometry(inpoint)   

    sr = arcpy.SpatialReference(3566)

    arcpy.DefineProjection_management(ptGeometry, sr)

    print 'define prj'

 

    arcpy.Buffer_analysis(ptGeometry, "buffer", str(cmboDistance) + ' Miles')

    print 'buffer complete'

Tags (1)
0 Kudos
3 Replies
KevinBell
Occasional Contributor III

I tried hard coding '1 Mile' instead of passing the distance in w/ the combo box.  Same result.  If I hardcode '5280 Feet' then it works.  hmmm.

0 Kudos
AdamCox1
Occasional Contributor II

You could just take the cmboDistance variable and multiply it by 5280 in the function.  For example:

cmboDistanceFEET = float(cmboDistance)*5280

......

arcpy.Buffer_analysis(ptGeometry, "buffer",cmboDistanceFEET)

Feeding the buffer tool the same units as the point spatial reference (ft) seems like good practice anyway.

If you have trouble with the math conversion, or want to put text (like 1/4, 1/2, 3/4, etc.) in the combobox, you can always use a dictionary to link those values to real numbers in feet.  For example:

def buildWebPage(x, y, cmboDistance):

    val_dict = {"1/4":5280*.25,

                    "1/2":5280*.5,

                    "3/4":5280*.75}

   arcpy.Buffer_analysis(ptGeometry, "buffer",val_dict[cmboDistance])

KevinBell
Occasional Contributor III

Ya, did that but without the dictionary.  I'm not tagging your reply as the correct answer because I'm more reporting the issue.  The correct answer may be that this is a bug that needs to be fixed...

thanks!

0 Kudos