HOW TO
Polylines with very few vertices can look blocky. You can smooth the appearance of these lines by creating more gentle curves; this is know as a spline operation. Spline adds more vertices at places where the line changes direction. This article provides two Avenue scripts that spline selected polyline or polylinez features of the first active theme of the active view.
Code:
'-- SPLINE POLYLINE FEATURES
'
'-- spline_polyline.ave
'
'-- This script uses a basic combination of densifying the
'-- polyline and implementing the Bezier's spline
'-- method on the polyline. This script needs a view
'-- and the target theme active.
'-- A combination of these two variables will produce different
'-- results depending on the nature and scale of the Polyline.
densityfactor = 0.025 '-- 0.000 to 1.000 only
iterations = 15 '-- 1 to 100 works best
v = av.getactivedoc
vg = v.getgraphics
thm = v.getactivethemes.get(0)
ftb = thm.getftab
if(ftb.getshapeclass.getclassname <> "PolyLine") then
msgbox.error("We can only spline PolyLine features.","")
return nil
end
for each selrec in ftb.getselection
thepolyline = ftb.returnvalue(ftb.findfield("Shape"),selrec)
howdense = thepolyline.returnlength*densityfactor
oldplist = thepolyline.returndensified(howdense).aslist
newplist = {}
for each apart in oldplist
for each ap in apart
newplist.add(ap)
end
end
for each x in 1..iterations
newerplist = {}
for each i in 0..(newplist.count-1)
if(i = 0) then
newerplist.add(newplist.get(i))
elseif(i = (newplist.count-1)) then
newerplist.add(newplist.get(i))
break
end
newp = line.make(newplist.get(i),newplist.get(i+1)).returncenter
newerplist.add(newp)
end
newplist = newerplist.deepclone
end
newpolyline = polyline.make({newplist})
gs = graphicshape.make(newpolyline)
asymbol = symbol.make(#SYMBOL_PEN)
asymbol.setsize(2)
asymbol.setcolor(color.getred)
gs.setsymbol(asymbol)
vg.add(gs)
end
v.invalidate
Note:
For polylinez features, use the same steps above, except turn on the 3D Analyst extension and use the code below.
Code:
'-- SPLINE POLYLINE OR POLYLINEZ FEATURES:
'
'-- spline_polylinez.ave
'
'-- This script uses a basic combination of densifying the
'-- polyline and implementing the Bezier's spline
'-- method on the polyline. This script needs a view
'-- and the target theme active.
'-- Note: The 3D Analysis Extension must be loaded
'
'-- A combination of these two variables will produce
'-- different results depending on the nature and scale of the Polyline.
densityfactor = 0.025 '-- 0.000 to 1.000 only
iterations = 15 '-- 1 to 100 works best
v = av.getactivedoc
vg = v.getgraphics
thm = v.getactivethemes.get(0)
ftb = thm.getftab
if(ftb.getshapeclass.getclassname = "PolyLine") then
hasz = false
elseif(ftb.getshapeclass.getclassname = "PolyLineZ") then
hasz = true
else
msgbox.error("We can only spline PolyLine of PolyLineZ features.","")
return nil
end
for each selrec in ftb.getselection
thepolyline = ftb.returnvalue(ftb.findfield("Shape"),selrec)
howdense = thepolyline.returnlength*densityfactor
oldplist = thepolyline.returndensified(howdense).aslist
newplist = {}
for each apart in oldplist
for each ap in apart
newplist.add(ap)
end
end
for each x in 1..iterations
newerplist = {}
for each i in 0..(newplist.count-1)
if(i = 0) then
newerplist.add(newplist.get(i))
elseif(i = (newplist.count-1)) then
newerplist.add(newplist.get(i))
break
end
if(hasz) then
newp = linez.make(newplist.get(i),newplist.get(i+1)).returncenter
else
newp = line.make(newplist.get(i),newplist.get(i+1)).returncenter
end
newerplist.add(newp)
end
newplist = newerplist.deepclone
end
if(hasz) then
newpolyline = polylinez.make({newplist})
else
newpolyline = polyline.make({newplist})
end
gs = graphicshape.make(newpolyline)
asymbol = symbol.make(#SYMBOL_PEN)
asymbol.setsize(2)
asymbol.setcolor(color.getred)
gs.setsymbol(asymbol)
vg.add(gs)
end
v.invalidate
Article ID:000003978
Get help from ArcGIS experts
Download the Esri Support App