The code is copied from a standalone so ignore obvious typos
my $co-ord-String;
For my $pNum (sort keys %{$hash{$key}}
{
my @points = (sort{$a<=> $b} keys %{$hash{$key}));
my ($long_H,$long_L,$Lat_H,$Lat_L);
Foreach my $pt (@points)
{
my $long = $hash{$key}{$pNum}{Long};
my $lat = $hash{$key}{$pNum}{Lat};
if(($long_H eq "") and ($long_L eq ""))
{
#set higher & lower linits
$long_H = $long + 10;
$long_L = $long – 10;
Repeat for $Lat
}
else
{
# check if $long is within 10 of last piont
if($long >=$long_L && $long <= $long_H)
{
$long_H = $long + 10;
$long_L = $long – 10;
}
else
{
# long is in error
$long = ‘E’;
}
Repeat for $Lat
}
Unless (($long eq ‘E’) or ($lat = ‘E’)
{
$co-ord-String = $co-ord-String . $long . " " . $lat . ",";
}
}
}
$co-ord-String =~ s/,$//g
What you are checking is:
Starting with the second point:
p[i+1] >= p[i]-10 && p[i+1] <= && p[i]+10
That is, the next point must be in a range of +-10 of the point before.
If this is true, p[i+1] is not an error.
The problem is clear with the first point being the real error.
A solution would be:
Starting with the first point:
Check for
p[i+1]+10 > p[i] && p[i+1]-10 < p[i]
In this case the check logic is something else. Imagin the second point in the middle of the range:
i o
i+1 |--------o--------|
From the left to right every position is allowed.
If the position is the most left one which is p[i]-10 = p[i+1]
than p[i] not to be an error
p[i] < p[i+1]+10 must be true.
And if the position is the most right one which is p[i]+10 = p[i+1]
than p[i] not to be an error
p[i] > p[i+1]-10 must be true.
All together:
p[i] is not an error if
p[i+1]+10 > p[i] && p[i+1]-10 < p[i]
is true.
But thats still not all, because now the second last point can be an error, but the real error is the
last one. A new problem.
Solution:
For all points except the first one and the last one, check both conditions:
1 is the index of the first point, m is the index of the last point, k is the current point to check:
for 1<k<m
conditions:
( p[k] <= p[k-1]+10 and p[k] >= p[k-1]-10 )
or
( p[k] < p[k+1]+10 and p[k] > p[k+1]-10 )
must be true, for p[k] not to be an error.
for k=1 (the first point):
( p[k] < p[k+1]+10 and p[k] > p[k+1]-10 )
must be true, for p[k] not to be an error.
for k=m (the last point):
( p[k] <= p[k-1]+10 and p[k] >= p[k-1]-10 )
must be true, for p[k] not to be an error.
Implementing it now should be straight forward.
There is still a problem: say some point in the middle is an error in comparison
to the points before but not in comparison to the points after it. Which means you
have to lists where all points would be ok if the two lists would be separated.
Checking like described will not find an error. But this condition is not defined
in your explanation. Its an undefined condition of the list of points in your
scenario. Add another condition, called "break of lists" = b.
p[k] is of type b, if
( p[k] <= p[k-1]+10 and p[k] >= p[k-1]-10 )
XOR
( p[k] < p[k+1]+10 and p[k] > p[k+1]-10 )
is true.
Regards,
Oli
PS: long explanation but I developed it during writing :-)
Short version: check in both directions for each points, for the first point check against next one only, for the last point check against the second last only. Scenarion "break of list" maybe unpossible in your case or use the XOR rule to find out.
so when testing the first point I'm testing it agents the last and second and the last point against first & second last
although i am testing the points in numerical order they may not be nearest to each other if plotted on a map but this is dealt with later while inserting into my database
say point 3 is in error 2 & 4 are ok then all 3 points are erroring because I'm testing
for 1<k<m
conditions:
( p[k] <= p[k-1]+10 and p[k] >= p[k-1]-10 )
or
( p[k] < p[k+1]+10 and p[k] > p[k+1]-10 )
must be true, for p[k] not to be an error.
For k=3 this results in false, because k-1=2 and k+1=4 are outside the +-10 range, 0 or 0 = 0.if (last point +- 10 of Point && Next point +- 10 of Point) on both the x and y axis (Long and Latitude) rather like a 10 degree circle around each point both it's neighbors are within it's circle.
points 1-4, no error point, the convex hull is trivial a polygon through all points
+ +
+ +
the same with an additional "error" point called e, the others 1,2,3,4 from left to right:
+
+ +
+ +
The convex hull would be a triangle defined by the first 1, the last 4 and the new "error" point e.
The two other points (2,3) are inside the convex hull.
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Filtering a file to table | 9 | 101 | |
Linux rename files by reordering dates in the file name | 6 | 34 | |
PERL - Find newest folder | 12 | 139 | |
Perl - Passing cookies received with CGI::Cookie through to and from LWP::UserAgent->Post | 5 | 99 |
Join the community of 500,000 technology professionals and ask your questions.