THE SETUP
I have a table which contains linestrings. Linestrings are made up of multiple geographic points. Each point is made up of a latitude and longitude. Note: the linestring value is stored as TEXT in the database.
So one row in the table might look like this:
id: an integer
linestring: x1, y2, x2, y2, x3, y3, x4, y4
THE PROBLEM
Google Maps only allows up to 1000 elements to be displayed at a time. In my case, I'm displaying 850 linestrings and will need to add many more in the future.
THE QUESTION
Quite a few of the linestrings connect with one or more other linestrings, meaning that they start and/or end at the same coordinates. What I'd look to do is find the best way to optimize the dataset so linestrings which connect at the ends are merged in the DB table. This will reduce the total element count when I parse the DB table and create the display file for google maps.
EXAMPLE
In this example, imagine, the alpha (A,B,C) values represent geographic points. The unoptimized table might look like this:
before optimization:
id linestring
1 A, B, C
2 C, D
3 B, A
4 F, G, H
5 G, I
6 H, J
After optimization:
1 A, B, C, D
2 F, G, H, J
3 G, I
So what is the best way to optimize the data? Is there a particular algorithm which works best? I have some ideas for solutions which I will formulate and add, but they seem verbose and convulated.
I am not a CS major so excuse the sloppy terminology and let me know if clarification is needed anywhere. Thanks!
FYI.. I am using a MySQL DB. I am not using the spatial extensions. If you have an embarrassingly simple solution that uses the spatial extensions I would love to hear about it anyway.