I have a data file that contains area polygons and sub polygons that I write to a different format. My script works except where there is a sub polygon that contains only 4 xy pairs, I need to add the first or last xy of that group to the beg or end in order for another program to handle a required 5 xy pair polygon.
I also have the problem in that the input data file could have 40,41,etc xy pairs as "SUB 40","SUB 41" not just "SUB 4"
Any suggestions, please.
Thanks,
INPUT:
ADD 5
XY 2233831 349494.08
XY 2233700 349492.86
XY 2233700 349364.25
XY 2233831 349365.46
XY 2233831 349494.08
SUB 5
XY 2233831 349494.08
XY 2233700 349492.86
XY 2233700 349364.25
XY 2233831 349365.46
XY 2233831 349494.08
SUB 6
XY 2226772 339594.57
XY 2226604 339678.39
XY 2226591 339641.26
XY 2226475 339250.52
XY 2226782 339255.27
XY 2226772 339594.57
SUB 4
XY 2226772 339594.57
XY 2226774 339553.71
XY 2226782 339255.27
XY 2226772 339594.57
GAWK SCRIPT:
BEGIN { OFS=","
}
{ fd_1 ="A"
fd_2 = "B"
if ($0 ~ /^H/) next
if ($0 ~ /^ *$/) next
if ($0 ~ /^$/) next
if (match($0, "EOF")) next
if (match($0, "ADD")) {
count=0;type ="AREA";group_id="0";next
}
if (match($0, "SUB ")) {
count=0;type ="SUB";group_id++;next
}
{
count++
x = $2
y = $3
print fd_1,fd_2,type,group_id,x,y,count
}
}
I also have the problem in that the input data file could have 40,41,etc xy pairs as "SUB 40","SUB 41" not just "SUB 4"
Any suggestions, please.
Thanks,
INPUT:
ADD 5
XY 2233831 349494.08
XY 2233700 349492.86
XY 2233700 349364.25
XY 2233831 349365.46
XY 2233831 349494.08
SUB 5
XY 2233831 349494.08
XY 2233700 349492.86
XY 2233700 349364.25
XY 2233831 349365.46
XY 2233831 349494.08
SUB 6
XY 2226772 339594.57
XY 2226604 339678.39
XY 2226591 339641.26
XY 2226475 339250.52
XY 2226782 339255.27
XY 2226772 339594.57
SUB 4
XY 2226772 339594.57
XY 2226774 339553.71
XY 2226782 339255.27
XY 2226772 339594.57
GAWK SCRIPT:
BEGIN { OFS=","
}
{ fd_1 ="A"
fd_2 = "B"
if ($0 ~ /^H/) next
if ($0 ~ /^ *$/) next
if ($0 ~ /^$/) next
if (match($0, "EOF")) next
if (match($0, "ADD")) {
count=0;type ="AREA";group_id="0";next
}
if (match($0, "SUB ")) {
count=0;type ="SUB";group_id++;next
}
{
count++
x = $2
y = $3
print fd_1,fd_2,type,group_id,x,y,count
}
}