Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multigeometry with two points and different names in the points

Tags:

kml

I have a Multigeometry in KML but when I assign a name to the placemark, both points in my placemark have the same name. Is there any possibility to have different names for points in any placemark?

Here is an example of my code:

<Placemark>
    <name>TEST</name>
<description></description>
    <visibility>1</visibility>
    <tessellate>1</tessellate>
    <styleUrl>#StyTEST</styleUrl>
<MultiGeometry>
    <Point>
        <coordinates>-3.6655,40.4364</coordinates>
    </Point>
    <Point>
        <coordinates>-3.6726,40.4308</coordinates>
    </Point>
    <LineString>
        <tessellate>1</tessellate>
            <coordinates>
                -3.6655,40.4364
                -3.6726,40.4308
            </coordinates>
    </LineString>
</MultiGeometry>
</Placemark>
like image 821
Jonathan Raul Tapia Lopez Avatar asked Dec 08 '25 13:12

Jonathan Raul Tapia Lopez


2 Answers

KML does not allow multiple names/labels for geometries within a single Feature even using a Multi-geometry. If you have multiple points in a MultiGeometry then the same name of the feature will appear over all points. One Placemark point == one label so if you want different labels on map using KML then must have two Placemarks one at each end of the line.

Simple solution is to structure your KML with multiple Placemarks which you can hide in a Document/Folder using the checkHideChildren listItemType. Then it appears in the Places panel in Google Earth as a single "feature" but multiple name labels display on the map as you want. The trick here is that the Folder name appears in the Places Panel and the Placemark names appear as labels on the map.

The following example illustrates such a KML file.

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
    <Document>            
        <name>Example</name>
        <open>1</open>

        <Style id="hide">
            <ListStyle>
                <listItemType>checkHideChildren</listItemType>
            </ListStyle>
        </Style>

        <Folder>
          <name>TEST1</name>
          <styleUrl>#hide</styleUrl>

          <Placemark>
            <name>TEST1</name>
            <MultiGeometry>
                <Point>
                    <coordinates>-3.6726,40.4308</coordinates>
                </Point>
                <LineString>
                    <tessellate>1</tessellate>
                    <coordinates>
                     -3.6655,40.4364
                     -3.6726,40.4308
                    </coordinates>
                </LineString>
            </MultiGeometry>
          </Placemark>

          <Placemark>
            <name>TEST2</name>
            <Point>
                <coordinates>-3.6655,40.4364</coordinates>
            </Point>
          </Placemark>

        </Folder>
    </Document>
</kml>
like image 144
CodeMonkey Avatar answered Dec 10 '25 02:12

CodeMonkey


A Placemark has only one name. If you need to have each Point have its own name, they need to be separate Placemarks.

From the referenced documentation:

<Placemark>
Syntax

<Placemark id="ID">
<!-- inherited from Feature element -->
<name>...</name> <!-- string -->
<visibility>1</visibility> <!-- boolean -->
<open>0</open> <!-- boolean -->
<atom:author>...<atom:author> <!-- xmlns:atom -->
<atom:link href=" "/> <!-- xmlns:atom -->
<address>...</address> <!-- string -->
<xal:AddressDetails>...</xal:AddressDetails> <!-- xmlns:xal -->
<phoneNumber>...</phoneNumber> <!-- string -->
<Snippet maxLines="2">...</Snippet> <!-- string -->
<description>...</description> <!-- string -->
<AbstractView>...</AbstractView> <!-- Camera or LookAt -->
<TimePrimitive>...</TimePrimitive>
<styleUrl>...</styleUrl> <!-- anyURI -->
<StyleSelector>...</StyleSelector>
<Region>...</Region>
<Metadata>...</Metadata> <!-- deprecated in KML 2.2 -->
<ExtendedData>...</ExtendedData> <!-- new in KML 2.2 -->

<!-- specific to Placemark element -->
<Geometry>...</Geometry>
</Placemark>

like image 20
geocodezip Avatar answered Dec 10 '25 03:12

geocodezip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!