Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import arcpy, traceback, os, sys
- gr=(math.sqrt(5)-1)/2
- try:
- def showPyMessage():
- arcpy.AddMessage(str(time.ctime()) + " - " + message)
- #golden section to find minimum
- def gss(a,b,tol):
- c=b-gr*(b-a)
- d=a+gr*(b-a)
- fc=f(c);fd=f(d)
- while abs(c-d)>tol:
- if fc<fd:
- b,d,fd=d,c,fc
- c=b-gr*(b-a)
- fc=f(c)
- else:
- a,c,fc=c,d,fd
- d=a+gr*(b-a)
- fd=f(d)
- return (b+a)/2
- def f(z):
- global two
- theP=outline.positionAlongLine (z).firstPoint
- splitter=arcpy.Polyline(arcpy.Array([point,theP]),SR)
- two=pgon.cut(splitter)
- intR=abs(two[0].area-two[1].area)/pgon.area*100
- arcpy.AddMessage(intR)
- return intR
- mxd = arcpy.mapping.MapDocument("CURRENT")
- layers = arcpy.mapping.ListLayers(mxd)
- (outputLR,pointLR,pgonLR) =layers[:3]
- g=arcpy.Geometry()
- point=arcpy.CopyFeatures_management(pointLR,g)[0].firstPoint
- SR = arcpy.Describe(pointLR).spatialReference
- pgon=arcpy.CopyFeatures_management(pgonLR,g)[0]
- outline=pgon.boundary();L=outline.length
- chainage=gss(0,L,0.01)
- doit=f(chainage)
- curT = arcpy.da.InsertCursor(outputLR,"Shape@")
- for item in two:
- curT.insertRow((item,))
- except:
- message = "n*** PYTHON ERRORS *** "; showPyMessage()
- message = "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]; showPyMessage()
- message = "Python Error Info: " + str(sys.exc_type)+ ": " + str(sys.exc_value) + "n"; showPyMessage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement