copy personal backup from
http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/encodeForm.html
Polyline/polygon encoding utility

An encoding utility for polyline and polygon data

The form below can be used to encode complex latitude/longitude data for use in Google Maps. If your data is stored in a KML file, you can paste the KML into the text area. Alternatively, your data may be entered as a sequence of latitude/longitude pairs in the input text field. The syntax for doing so is described below and there are several illustrative examples built in to the form.

Please keep in mind that some web browsers are a little finicky when it comes to cutting and pasting large amounts of text. Furthermore, this page depends on popup windows to display code and information. Sometimes code is in a window, even if you can't see it! This page seems to work very well with Firefox on Windows and Mac OS X, although the display of large textual data seems worst with Mac Firefox. The page seems to work moderately well with Internet Explorer and Safari.

The form

You can paste your TomTom Tripmaster recorded *.KML or *.CSV log file here
and you can directly view the polyline overlayed on the google map
or get the encoded polyline data source for your webpage

Input text:

Lat/lng order: lat/lng lng/lat

Set Example:
Example commentary: On Off

verySmall:
numLevels:
zoomFactor:

The Map

Details on the input

KML

The KML support is fairly minimal. The program reads KML LineString and Polygon elements and encodes them using GPolyline.fromEncoded and GPolygon.fromEncoded respectively. All LineStrings within the same Placemark element will be grouped together and colored the same. All other elements are ignored. This includes all style elements; thus, the colors generated by this form do not correspond to colors in the KML file.

Input Text

You can also enter data by pasting a sequence of latitude/longitude pairs into the "Input Text" field. There should be one such pair per line and you can see a simple example input by selecting "Mt. Mitchell" from the "Set Examples" menu.

Data is read from the "Input Text" field in a fairly forgiving way. The latitude and longitude may be separated by either a comma, white space, or a comma and white space. Blank lines are ignored. Anything after the latitude and longitude (perhaps an elevation) on a line is ignored. While the latitude and longitude are expected to be the first two elements on a line, the order in which they occur may be specified using the "Lat/lng order" radio buttons.

There is also a syntax for entering a collection of polylines and polygons. This syntax is inspired by the generic vector file format used by LandSerf, a freely available GIS program written in Java. LandSerf can read a wide variety of formats, including ShapeFile, which can then be saved in generic vector format for use in the form here. If, for example, you choose "The Pentagon" from the "Set Examples" menu, the following will appear in the "Input Text" window.


A Pentagon
-77.05788457660967,38.87253259892824,100
-77.05465973756702,38.87291016281703,100
-77.05315536854791,38.87053267794386,100
-77.05552622493516,38.868757801256,100
-77.05844056290393,38.86996206506943,100
-77.05788457660967,38.87253259892824,100 

A Pentagon
-77.05668055019126,38.87154239798456,100
-77.05542625960818,38.87167890344077,100
-77.05485125901024,38.87076535397792,100
-77.05577677433152,38.87008686581446,100
-77.05691162017543,38.87054446963351,100
-77.05668055019126,38.87154239798456,100

L Pentagram
-77.05668055019126,38.87154239798456,100
-77.05485125901024,38.87076535397792,100
-77.05691162017543,38.87054446963351,100
-77.05542625960818,38.87167890344077,100
-77.05577677433152,38.87008686581446,100
-77.05668055019126,38.87154239798456,100

L MyPath
-77.05197 38.86809
-77.05234 38.86819
-77.05318 38.86808
-77.05341 38.86759
-77.05367 38.86746
-77.05427 38.86753
-77.05534 38.86788
-77.05575 38.86824
-77.0568 38.86873
-77.05852 38.86953
-77.05914 38.8697

Each line starting with an "A" (area) or "L" (line) indicates that the following data describes a polygon or a polyline respectively. The last collection of non-white space characters in such a line is used as a descriptor; in particular, consecutive area elements with the same descriptor are placed in the same encoded polygon, affecting the way they are rendered. Consecutive line elements with the same descriptor will be colored the same.

You can look at a somewhat more complicated example involving polygons by selecting "The Carolinas". There are six polygons labeled North and two labeled South. This data is not very detailed, but there is somewhat more detailed data in carolinas.txt and there is mildly detailed data for all 50 states in StateShapes.txt. If you use these, be sure to set the Lat/lng order to lng/lat. Also, keep in mind that this page does the actual encoding of the lines, as well as the display. A map with a pre-encoded line will load faster than the map here. You can get a feel for this by using the "Show Code" button first, then generating the map.

Encoding Parameters

The form accepts three parameters: verySmall, numLevels, and zoomFactor. These are explained in further detail along with my description of the encoding algorithm. The default values should be fine for most purposes.