Thought this might be useful for some people.
What makes it good is that it doesn't add any columns to the tables. It works on the raw variables with any size table and line length.
How to use:
set "tabletoclean" to a table you want to clean
call the sub
What it does:
Finds all the polylines which fold back on themselves eg. 1,2,1,4,5 and deletes 2,1, leaving 1,4,5.
Finds all the polylines with duplicate verticies eg. 1,1,2,3,4 and deletes the second 1 leaving 1,2,3,4
You may not need the metadata bit. (It checks to see if it's already been cleaned once.)
You may only need the fold or duplicate part.
Haven't tested it on tables with multiple object types. ie points and lines.
sub cleanDupVerticies
dim nodesfixed as integer
dim oline as object
dim rid,numberofnodes,counter as integer
dim isclean as integer
isclean=GetMetadata$( tabletoclean, "\cleanedonce")
if isclean=0 then
print "Cleaning folded verticies from "+tabletoclean
commit table tabletoclean
select * from tabletoclean where obj into blah
update blah set obj =CONVERTTOPLINE(obj)
select max(Objectinfo(obj,20))from tabletoclean into blah Hide
numberofnodes=blah.Col1
'fix the folding lines by removing the middle and end vertex
for counter=numberofnodes to 3 step-1
if counter mod 5=0 then
print "Checking for folded lines, node "+counter+ " on " +tabletoclean
end if
Select * from tabletoclean where int(ObjectInfo(Obj,21))=1 and int(Objectinfo(obj,20))>3 and int(Objectinfo(obj,20))>=counter ' object type=1, numnodes>3, numnodes>=counter
into blah noselect hide
if Int(TableInfo(blah,TAB_INFO_NROWS))>0 then
Select * from blah where (ObjectNodeX(obj,1,counter))=(ObjectNodeX(obj,1,(counter-2))) and (ObjectNodey(obj,1,counter))=(ObjectNodey(obj,1,(counter-2))) ' node x=node x-1, node y=nodey-1
into selection hide
if Int(SelectionInfo(3))>0 then
fetch first from selection
do until eot(selection)
oline = selection.obj
Rid = selection.ROWID
nodesfixed=nodesfixed+2
Alter Object oline Node Remove Position 1, counter
Alter Object oline Node Remove Position 1, counter-1
update selection set obj = oline where rowid=rid
print " Fixed folded section "+(counter-2)+","+(counter-1)+","+counter +" from "+ selection.id
fetch next from selection
loop
end if
end if
next
' remove duplicate adjacent verticies
for counter=numberofnodes to 2 step-1
if counter mod 5=0 then
print "Checking for duplicate nodes, node "+counter+ " on " +tabletoclean
end if
Select * from tabletoclean where int(ObjectInfo(Obj,21))=1 and int(Objectinfo(obj,20))>2 and int(Objectinfo(obj,20))>=counter ' object type=1, numnodes>2, numnodes>=counter
into blah noselect hide
if Int(TableInfo(blah,TAB_INFO_NROWS))>0 then
Select * from blah where (ObjectNodeX(obj,1,counter))=(ObjectNodeX(obj,1,(counter-1))) and (ObjectNodey(obj,1,counter))=(ObjectNodey(obj,1,(counter-1))) ' node x=node x-1, node y=nodey-1
into selection hide
if Int(SelectionInfo(3))>0 then
fetch first from selection
do until eot(selection)
oline = selection.obj
Rid = selection.ROWID
nodesfixed=nodesfixed+1
Alter Object oline Node Remove Position 1, counter
update selection set obj = oline where rowid=rid
print " Fixed duplicate vertex "+(counter-1)+","+counter +" from "+ selection.id
fetch next from selection
loop
end if
end if
next
Print "Removed "+ nodesfixed + " duplicate verticies from "+tabletoclean
commit table tabletoclean
metadata table tabletoclean setkey "\cleanedonce" to "1"
else
print tabletoclean +"Already cleaned"
end if
end sub
------------------------------
Myles Corin
Knowledge Community Shared Account
------------------------------