I tryed once more (sorry about non english notes):
import arcpy
arcpy.env.overwriteOutput = True
#input:
line_upper = arcpy.GetParameterAsText(0) #input shape # Shapefile
line_lower = arcpy.GetParameterAsText(1) #input shape # Shapefile
step = arcpy.GetParameter(2) #step #double
step = int(step)
max_distance_plus = arcpy.GetParameter(3) #step #double
max_distance_plus = int(max_distance_plus)
#input edited
max_distance_minus = max_distance_plus *(-1)
desc_linie_upper = arcpy.Describe(line_upper)
line_upper_path = desc_linie_upper.path + "\\"
## temp
pracovni_path = line_upper_path + "__pracovni_smazat" + "\\"
if not arcpy.Exists(pracovni_path):
arcpy.CreateFolder_management(line_upper_path, "__pracovni_smazat")
Route_ID = "ID"
txt_plus_path = pracovni_path + "_test_plus.txt"
txt_minus_path = pracovni_path + "_test_minus.txt"
PointsAlongLines_fc = "_PointsAlongLines.shp"
PointsAlongLines = pracovni_path + "_PointsAlongLines.shp"
RouteEvent_merge = pracovni_path + "_RouteEvent_merge.shp"
PointsToLine = pracovni_path + "_PointsToLine.shp"
IntersectPoints = pracovni_path + "_IntersectPoints.shp"
PointsMerge = pracovni_path + "_pointsMerge.shp"
IntersectPoints_single_fc = "_IntersectPoints_single.shp"
IntersectPoints_single = pracovni_path + "_IntersectPoints_single.shp"
MergeIntersectPpal = pracovni_path + "_MergeIntersectPpal.shp"
#fin output file
svah_feature_fc = "svahove_linie.shp"
svah_feature = line_upper_path + svah_feature_fc
#txt
PlusWrite = open(txt_plus_path,"w")
hlavicka_sloupcu = "Location" + "\t" + "Offset" +"\t"+ "Route_ID"
PlusWrite.writelines(hlavicka_sloupcu + "\n")
MinusWrite = open(txt_minus_path,"w")
hlavicka_sloupcu = "Location" + "\t" + "Offset" +"\t"+ "Route_ID"
MinusWrite.writelines(hlavicka_sloupcu + "\n")
#Position along lines
ppal_all = []
with arcpy.da.SearchCursor(line_upper, ["SHAPE@",Route_ID]) as ppcur:
for pprow in ppcur:
length = int(pprow[0].length)
for i in xrange(0, length + step, step):
ppal = pprow[0].positionAlongLine(i)
ppal_all.append([ppal,i])
#zapis do textaku
PlusWrite.writelines(str(i) + "\t" + str(max_distance_plus) + "\t" + str(pprow[1]) +"\n")
MinusWrite.writelines(str(i) + "\t" + str(max_distance_minus) + "\t" + str(pprow[1]) +"\n")
del ppcur
PlusWrite.close()
MinusWrite.close()
#points along line new shp
arcpy.CreateFeatureclass_management(pracovni_path,PointsAlongLines_fc,"POINT")
arcpy.AddField_management(PointsAlongLines,"Location","DOUBLE")
with arcpy.da.InsertCursor(PointsAlongLines, ["SHAPE@","Location"]) as icur:
for i in ppal_all:
icur.insertRow(i)
del icur
#create line from points along line buffer
arcpy.MakeRouteEventLayer_lr(line_upper, Route_ID, txt_plus_path,"Route_ID POINT Location","RouteEvent_Plus", "Offset")
arcpy.MakeRouteEventLayer_lr(line_upper, Route_ID, txt_minus_path,"Route_ID POINT Location","RouteEvent_Minus", "Offset")
arcpy.Merge_management(["RouteEvent_Minus","RouteEvent_Plus"],RouteEvent_merge)
arcpy.PointsToLine_management(RouteEvent_merge,PointsToLine,"Location")
#Intersect
arcpy.Intersect_analysis([PointsToLine,line_lower],IntersectPoints,"ALL",0.01,"POINT")
IntersectPoints_list = []
with arcpy.da.SearchCursor(IntersectPoints, ["SHAPE@","Location"]) as iscur:
for isrow in iscur:
for part in isrow[0]:
IntersectPoints_list.append([part,part.M])
del iscur
#multi to single points
arcpy.CreateFeatureclass_management(pracovni_path,IntersectPoints_single_fc,"POINT")
arcpy.AddField_management(IntersectPoints_single,"Location","DOUBLE")
with arcpy.da.InsertCursor(IntersectPoints_single, ["SHAPE@","Location"]) as icur:
for i in IntersectPoints_list:
icur.insertRow(i)
del icur
arcpy.CreateFeatureclass_management(line_upper_path,IntersectPoints_single_fc,"POINT")
arcpy.AddField_management(IntersectPoints_single,"Location","DOUBLE")
#fin line
exp = arcpy.AddFieldDelimiters(IntersectPoints_single,"Location")
InterPal_list =[]
with arcpy.da.SearchCursor(IntersectPoints_single,["SHAPE@","Location"]) as iscur:
for isrow in iscur:
isrowgeom = isrow[0]
with arcpy.da.SearchCursor(PointsAlongLines,["SHAPE@","Location","FID"], exp + " = " + str(isrow[1])) as pscur:
for psrow in pscur:
psrowgeom = psrow[0]
if psrow[2] % 2 ==0:
InterPal_list.append(arcpy.Polyline(arcpy.Array([isrowgeom.firstPoint,psrowgeom.firstPoint])))
else:
npnt = arcpy.Point()
npnt.X = ((isrowgeom.firstPoint.X - psrowgeom.firstPoint.X)/4+psrowgeom.firstPoint.X)
npnt.Y = ((isrowgeom.firstPoint.Y - psrowgeom.firstPoint.Y)/4+psrowgeom.firstPoint.Y)
InterPal_list.append(arcpy.Polyline(arcpy.Array([npnt,psrowgeom.firstPoint])))
del iscur
del pscur
##new/existing shape
if arcpy.Exists(svah_feature):
arcpy.Append_management(InterPal_list,svah_feature,"NO_TEST")
arcpy.AddMessage("\n" + "shape: " + svah_feature + "\n")
else:
arcpy.CopyFeatures_management(InterPal_list, svah_feature)
arcpy.AddMessage("\n" + "novy shape: " + svah_feature + "\n")