Advertisement
Guest User

Untitled

a guest
May 1st, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. import arcpy, traceback, os, sys
  2. gr=(math.sqrt(5)-1)/2
  3.  
  4. try:
  5. def showPyMessage():
  6. arcpy.AddMessage(str(time.ctime()) + " - " + message)
  7. #golden section to find minimum
  8. def gss(a,b,tol):
  9. c=b-gr*(b-a)
  10. d=a+gr*(b-a)
  11. fc=f(c);fd=f(d)
  12. while abs(c-d)>tol:
  13. if fc<fd:
  14. b,d,fd=d,c,fc
  15. c=b-gr*(b-a)
  16. fc=f(c)
  17. else:
  18. a,c,fc=c,d,fd
  19. d=a+gr*(b-a)
  20. fd=f(d)
  21. return (b+a)/2
  22. def f(z):
  23. global two
  24. theP=outline.positionAlongLine (z).firstPoint
  25. splitter=arcpy.Polyline(arcpy.Array([point,theP]),SR)
  26. two=pgon.cut(splitter)
  27. intR=abs(two[0].area-two[1].area)/pgon.area*100
  28. arcpy.AddMessage(intR)
  29. return intR
  30.  
  31. mxd = arcpy.mapping.MapDocument("CURRENT")
  32. layers = arcpy.mapping.ListLayers(mxd)
  33. (outputLR,pointLR,pgonLR) =layers[:3]
  34. g=arcpy.Geometry()
  35. point=arcpy.CopyFeatures_management(pointLR,g)[0].firstPoint
  36. SR = arcpy.Describe(pointLR).spatialReference
  37. pgon=arcpy.CopyFeatures_management(pgonLR,g)[0]
  38. outline=pgon.boundary();L=outline.length
  39. chainage=gss(0,L,0.01)
  40. doit=f(chainage)
  41.  
  42. curT = arcpy.da.InsertCursor(outputLR,"Shape@")
  43. for item in two:
  44. curT.insertRow((item,))
  45.  
  46.  
  47. except:
  48. message = "n*** PYTHON ERRORS *** "; showPyMessage()
  49. message = "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]; showPyMessage()
  50. message = "Python Error Info: " + str(sys.exc_type)+ ": " + str(sys.exc_value) + "n"; showPyMessage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement