This project has moved and is read-only. For the latest updates, please go here.

Extract coordinates from polygon

Jul 27, 2015 at 1:25 AM
Edited Jul 27, 2015 at 1:47 AM
Hello,

I need to extract the coordinates of a polygon from .KML file.
Following the example below of .kml, need to extract the coordinates of the tag <coordinates>

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
    <name>poligono kml.kml</name>
    <Style id="s_ylw-pushpin">
        <IconStyle>
            <scale>1.1</scale>
            <Icon>
                <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
            </Icon>
            <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
        </IconStyle>
    </Style>
    <StyleMap id="m_ylw-pushpin">
        <Pair>
            <key>normal</key>
            <styleUrl>#s_ylw-pushpin</styleUrl>
        </Pair>
        <Pair>
            <key>highlight</key>
            <styleUrl>#s_ylw-pushpin_hl</styleUrl>
        </Pair>
    </StyleMap>
    <Style id="s_ylw-pushpin_hl">
        <IconStyle>
            <scale>1.3</scale>
            <Icon>
                <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
            </Icon>
            <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
        </IconStyle>
    </Style>
    <Placemark>
        <name>poligono kml</name>
        <styleUrl>#m_ylw-pushpin</styleUrl>
        <Polygon>
            <tessellate>1</tessellate>
            <outerBoundaryIs>
                <LinearRing>
                    <coordinates>
                        -46.72666928318849,-23.52792136167547,0 -46.71975617107682,-23.53737144188922,0 -46.70524161260465,-23.53625596387829,0 
                    </coordinates>
                </LinearRing>
            </outerBoundaryIs>
        </Polygon>
    </Placemark>
</Document>
</kml>
Converting the extracted coordinates to the following format string

"-46.72666928318849 -23.52792136167547, -46.71975617107682 23.53737144188922, -46.70524161260465 -23.53625596387829"

Longitude and latitude separated by whitespace, and separated with commas each point of the polygon.


Is there any solution that I can do this using the SharpKml?

Thank you for attention
Jul 27, 2015 at 7:35 AM
You should be able to use the library to extract that information, take a quick look at the Extracting information from a KML file example that will show you a quick way of finding the Placemarks - from there you will need to cast the Geometry property to a Polygon to get hold of the OuterBoundary that contains the coordinates.

Hope that points you in the right direction,
Sam