trevor1940
asked on
Find random points from a list out side a range
Hi
I’m trying to find the random point from a set of Longitude Latitude coordinates so I can create a co-ordinate string from the cluster
The Longitude values can be between -180 + 180 and Latitude between -90 and +90 degrees
each point needs to be with +or- 10 degrees of the last point
The code I’ve come up with works unless the first point is the one that is wrong causing every other point to be in error and $co-ord-String ony equels the firsst point.
I’m trying to find the random point from a set of Longitude Latitude coordinates so I can create a co-ordinate string from the cluster
The Longitude values can be between -180 + 180 and Latitude between -90 and +90 degrees
each point needs to be with +or- 10 degrees of the last point
The code I’ve come up with works unless the first point is the one that is wrong causing every other point to be in error and $co-ord-String ony equels the firsst point.
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oli thanx
May be i need to explain the situation a little more
If for instance you had a square you need a minimum of 4 points to make a square
Point co-ords X,Y
1 1,1
2 1,2
3 2,1
4 1,2
5 1,1
(You actually need 5 because the first and last points need to be the same to close the square)
In my data I’ve maybe 50 unique points at a seemingly random pattern and order within that same square they are numbered 1 to 50 but point 5 may not be adjacent geographically to points 4 or 6 hence my 10 degree error margin (The UK is about 6.5 degrees at it widest point) some of these points are not within this square. That’s why I need to test all points in both directions (as they are numbered) ie point 1 is with a 10d radius of both point 2 and 50 thus reducing the probability of point 1 being in error.
If I could I’d test every point against every other point but that’s not going to happen
May be i need to explain the situation a little more
If for instance you had a square you need a minimum of 4 points to make a square
Point co-ords X,Y
1 1,1
2 1,2
3 2,1
4 1,2
5 1,1
(You actually need 5 because the first and last points need to be the same to close the square)
In my data I’ve maybe 50 unique points at a seemingly random pattern and order within that same square they are numbered 1 to 50 but point 5 may not be adjacent geographically to points 4 or 6 hence my 10 degree error margin (The UK is about 6.5 degrees at it widest point) some of these points are not within this square. That’s why I need to test all points in both directions (as they are numbered) ie point 1 is with a 10d radius of both point 2 and 50 thus reducing the probability of point 1 being in error.
If I could I’d test every point against every other point but that’s not going to happen
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I used a square to illustrate the issue
Maybe if you look at http://en.wikipedia.org/wiki/Convex_hull it may help you understand my problem.
My database is PostGis it has a Convex_hull it creates a polygon from a cluster of points like in the diagram on the wiki page.
In my data set some of these points are in error creating spikes in the polygon that covers half the world unfortunately there isn't a postGis command that identifies these points so I’m attempting it in Perl first
I appreciate your help on this as it is making me focus on the problem so I can explain it.
Maybe if you look at http://en.wikipedia.org/wiki/Convex_hull it may help you understand my problem.
My database is PostGis it has a Convex_hull it creates a polygon from a cluster of points like in the diagram on the wiki page.
In my data set some of these points are in error creating spikes in the polygon that covers half the world unfortunately there isn't a postGis command that identifies these points so I’m attempting it in Perl first
I appreciate your help on this as it is making me focus on the problem so I can explain it.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oli
FYI postGis is a bolt on to PostGresSQL giving it Geo (maps) analytical capabilities
using a insert command with Convex_hull will create what is known as a Geo blob of all its given points usually a polygon or if all points are straight a line.
unfortunately you can't tell it to ignore the spikes.
i think I've come up with a solution
loop through each point
if the point is within the last point +-10d on both Long & Lat axis add 1 to $count
repeat for it's next point
if the $count >=1 it must be good
the only issue is if two wrong points are together (points 3 & 4) they both have a count of 1 so pass the test
I need to investigate my data to see if this actually occurs or not.
thanx
FYI postGis is a bolt on to PostGresSQL giving it Geo (maps) analytical capabilities
using a insert command with Convex_hull will create what is known as a Geo blob of all its given points usually a polygon or if all points are straight a line.
unfortunately you can't tell it to ignore the spikes.
i think I've come up with a solution
loop through each point
if the point is within the last point +-10d on both Long & Lat axis add 1 to $count
repeat for it's next point
if the $count >=1 it must be good
the only issue is if two wrong points are together (points 3 & 4) they both have a count of 1 so pass the test
I need to investigate my data to see if this actually occurs or not.
thanx
ASKER
Oli
thanx for your hellp not solved the issue yet but ta any way
thanx for your hellp not solved the issue yet but ta any way
ASKER
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
BUT
say point 3 is in error 2 & 4 are ok then all 3 points are erroring because I'm testing
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.
So each point can be in error 0 or 1 time but not 2
so some how i need to test this