About Google Earth kml, automatic coding design and generation

Source: Internet
Author: User

We know that in googleearth, we can share our own coordinate information, using kml.

What is kml? Kml stands for keyhole markup language. It is a markup language (markup) based on the XML (Extensible Markup Language) syntax standard.
Language), using the tag structure, containing nested elements and attributes. I will not talk much about the kml writing standards. For details, refer:Kml interactive sampler (kml display): Http://kml-samples.googlecode.com/svn/trunk/interactive/index.html.Google kml Tutorial:Https://developers.google.com/kml/documentation/kml_tut? Hl = ZH-CN.

First, the data I use is the geographic information data read from the Oracle database. The data format is: simple polygon: [[], [], [], [], [], double ring: [[], [], [], [], [], [], [4, 4], three-ring and above: [[], [], []...].

The idea of implementation is:

1. Read the data in the database and process it in the form of, and 3 (you can refer to the following code. Of course, it would be better to use the regular law ).

2. Write three templates: The information style template in the pop-up box, the template with two or three rings, and the normal polygon template.

3. Use Io to write data to a file.

4. Note: if the data size is too large, please write less data each time (for example, write 1000 data each time). At first I encountered this problem: the prompt is insufficient memory.

The kml template is used, and the added data is written in the red area:

<? Xmlversion = "1.0" encoding = "Utf-8"?>
<Kml xmlns = "http://earth.google.com/kml/2.1">
<Document>
<Name> project </Name>
<Style id = "pointstyle">
<Iconstyle>
<Color> ffff0000 </color>
<Size> 0.8 </scale>
<Icon>
<Href> http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png </Icon>
</Iconstyle>
<Labelstyle>
<Color> ffffffff </color>
<Size> 0.7 </scale>
</Labelstyle>
</Style>
<! -- Format the data as a template class. This is a style template. Place the style about the appearance description of the polygon in it. I only change its color value. -->
<Style id = "polygonstyle1">
<Iconstyle>
<Size> 1.1 </scale>
<Icon>
<Href> http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png </Icon>
<Hotspotx = "20" Y = "2" xunits = "pixels" yunits = "pixels"/>
</Iconstyle>
<Polystyle>
<Color> ffb0e0e6 </color>
</Polystyle>
</Style>
<! -- Format the data as a template class. This is a file template. Place the polygon and ring classes in it. -->

<Folder>
<Name> XXXXX </Name>

Xxxxxxxxxxxxxx

</Folder>

 

<Folder>
<Name> XXXXX </Name>

Xxxxxxxxxxxxxx

</Folder>

 

</Kml>

Open kml in Google Earth as follows:

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.