Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Sort a series of X Y (Lat, Lon) data points into line segments

Subject: Sort a series of X Y (Lat, Lon) data points into line segments

From: Charlie

Date: 23 Feb, 2011 21:31:05

Message: 1 of 3

Hello Everyone.

I have a series of about 3000 coordinate pairs of Latitude,Longitude
from a scientific cruise I was recently (I can very easily convert
this into X,Y points). When plotted, they are basically a jumble, but
I can see that at some points the ship was travelling in straight
transects.

I would like to write a loop that breaks the series of points up so
that the pairs forming fairly straight lines can be grouped together
(so I can do some contour plotting of the data obtained underneath the
vessel).

I cannot think of an easy way to do this. Perhaps a loop that checks
that slope of the first two points, and then compares the slope of the
first and third points, and the first and fourth points, and groups
together ones that have a slope within a certain tolerance? There can
be a little "bending" in the line segments, it doesn't have to be
perfectly straight.

Can anyone help me think of a simple algorithm that will do this?

cheers,

Subject: Sort a series of X Y (Lat, Lon) data points into line segments

From: someone

Date: 23 Feb, 2011 21:59:22

Message: 2 of 3

Charlie <charliebishop@gmail.com> wrote in message <5624e30e-bd50-4bf5-b982-ec28167ac162@q40g2000prh.googlegroups.com>...
> Hello Everyone.
>
> I have a series of about 3000 coordinate pairs of Latitude,Longitude
> from a scientific cruise I was recently (I can very easily convert
> this into X,Y points). When plotted, they are basically a jumble, but
> I can see that at some points the ship was travelling in straight
> transects.
>
> I would like to write a loop that breaks the series of points up so
> that the pairs forming fairly straight lines can be grouped together
> (so I can do some contour plotting of the data obtained underneath the
> vessel).
>
> I cannot think of an easy way to do this. Perhaps a loop that checks
> that slope of the first two points, and then compares the slope of the
> first and third points, and the first and fourth points, and groups
> together ones that have a slope within a certain tolerance? There can
> be a little "bending" in the line segments, it doesn't have to be
> perfectly straight.
>
> Can anyone help me think of a simple algorithm that will do this?
>
> cheers,

I'm not sure how your data was collected,
but it would seem to me that rather than work
with slopes it would make more sense to work
with minimum distances from one point to the next.

You could start with the first point and compute the distance
to every other point using something like:

sqrt((x-x1).^2 + (y-y1).^2); % actually no need for sqrt

then find which one of those is the minimum distance point,
call that the second point and continue until all the points are used up.

The resulting order should plot somewhat neatly.

Just a thought.

Subject: Sort a series of X Y (Lat, Lon) data points into line segments

From: TideMan

Date: 23 Feb, 2011 22:41:51

Message: 3 of 3

On Feb 24, 10:31 am, Charlie <charliebis...@gmail.com> wrote:
> Hello Everyone.
>
> I have a series of about 3000 coordinate pairs of Latitude,Longitude
> from a scientific cruise I was recently (I can very easily convert
> this into X,Y points). When plotted, they are basically a jumble, but
> I can see that at some points the ship was travelling in straight
> transects.
>
> I would like to write a loop that breaks the series of points up so
> that the pairs forming fairly straight lines can be grouped together
> (so I can do some contour plotting of the data obtained underneath the
> vessel).
>
> I cannot think of an easy way to do this. Perhaps a loop that checks
> that slope of the first two points, and then compares the slope of the
> first and third points, and the first and fourth points, and groups
> together ones that have a slope within a certain tolerance? There can
> be a little "bending" in the line segments, it doesn't have to be
> perfectly straight.
>
> Can anyone help me think of a simple algorithm that will do this?
>
> cheers,

3000 points is not very many.
You could do some of the work by eye.
Plot the points up, then do:
[xx,yy]=ginput;
and pick off the start and finish coordinates of each transect.
Now, locate the indexes of the actual coordinates:
nt=length(xx);
imn=zeros(nt,1);
for it=1:nt
[zmn,imn(it)]=min((xx(it)-x).^2+(yy(it)-y).^2);
end

So, now you have the start and finish indexes of each transect and you
can process the sequences of data.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us