0

I'm trying to create a KMZ with Photooverlays, so the pictures I take will show up where I took them in Google Earth. I already have my program georeferencing the photos successfully and wanted to add this KMZ functionality. I did the task manually, opening the photos, creating the overlays, and then saving the place to a KMZ. Then I used the KML in the KMZ as a template for creating the photooverlays manually. I am expecting that when I open the KMZ (or even just the KML with the pictures referenced relative to the file) and it should look like what I did manually. But instead the pictures are just red X's enter image description here

I've compared the programmed KML with the original, and I can't find any difference besides the filenames and gps locations. But the GPS locations are correct, just the Icons are showing up... Any ideas what I'm doing wrong?

public void WriteKML_manually()
    {
        using (StreamWriter writer = new StreamWriter(Path.Combine(_rootpath, "doc.kml"), false, System.Text.Encoding.UTF8))
        {
            // Start document with kml element
            writer.WriteLine(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
            writer.WriteLine(@"<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"">");
            writer.WriteLine(@"<Folder>");

            writer.WriteLine(@"<name>Pictures</name>");
            writer.WriteLine(@"<open>1</open>");

            foreach (Picture picture in _process.pictures)
            {
                writer.WriteLine("<PhotoOverlay>");
                writer.WriteLine("<name>" + picture.name + picture.extension + "</name>");

                //Camera
                writer.WriteLine("<Camera>");
                writer.WriteLine("<longitude>" + picture.gpslong.ToString() + "</longitude>");
                writer.WriteLine("<latitude>" + picture.gpslat.ToString() + "</latitude>");
                writer.WriteLine("<altitude>" + picture.gpsalt.ToString()+"</altitude>");
                writer.WriteLine("<heading>"+picture.heading.ToString()+"</heading>");
                writer.WriteLine("<tilt>"+picture.tilt.ToString()+"</tilt>");
                writer.WriteLine("<roll>"+picture.roll.ToString()+"</roll>");
                writer.WriteLine("<gx:altitudeMode>relativeToGround</gx:altitudeMode>");
                writer.WriteLine("</Camera>");

                //Style
                writer.WriteLine("<Style>");
                writer.WriteLine("<IconStyle>");
                writer.WriteLine("<Icon>");
                writer.WriteLine("<href>files/camera_mode.png</href>");
                writer.WriteLine("</Icon>");
                writer.WriteLine("</IconStyle>");
                writer.WriteLine("<ListStyle>");
                writer.WriteLine("<listItemType>check</listItemType>");
                writer.WriteLine("<ItemIcon>");
                writer.WriteLine("<state>open closed error fetching0 fetching1 fetching2</state>");
                writer.WriteLine("<href>http://maps.google.com/mapfiles/kml/shapes/camera-lv.png</href>");
                writer.WriteLine("</ItemIcon>");
                writer.WriteLine("<bgColor>00ffffff</bgColor>");
                writer.WriteLine("<maxSnippetLines>2</maxSnippetLines>");
                writer.WriteLine("</ListStyle>");
                writer.WriteLine("</Style>");

                //Icon
                writer.WriteLine("<Icon>");
                writer.WriteLine("<href>files/" + picture.name + picture.extension + "</href>");
                writer.WriteLine("</Icon>");

                //ViewVolume
                writer.WriteLine("<ViewVolume>");
                writer.WriteLine("<leftFov>-25</leftFov>");
                writer.WriteLine("<rightFov>25</rightFov>");
                writer.WriteLine("<bottomFov>-19.275</bottomFov>");
                writer.WriteLine("<topFov>19.275</topFov>");
                writer.WriteLine("<near>15630.2</near>");
                writer.WriteLine("</ViewVolume>");

                //Point
                writer.WriteLine("<Point>");
                writer.WriteLine("<gx:altitudeMode>relativeToGround</gx:altitudeMode>");
                writer.WriteLine("<coordinates>" + picture.gpslong.ToString() + "," + picture.gpslat.ToString() + "," + picture.gpsalt.ToString() + "</coordinates>");
                writer.WriteLine("</Point>");

                writer.WriteLine("</PhotoOverlay>");
            }

            writer.WriteLine(@"</Folder>");
            writer.WriteLine(@"</kml>");


            // Write the document to file
            writer.Flush();
        }

Output:

<?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">
<Folder>
<name>Pictures</name>
<open>1</open>
<PhotoOverlay>
<name>DJI_0002.JPG</name>
<Camera>
<longitude>-101.844902194444</longitude>
<latitude>54.74660125</latitude>
<altitude>0</altitude>
<heading>0</heading>
<tilt>0</tilt>
<roll>0</roll>
<gx:altitudeMode>relativeToGround</gx:altitudeMode>
</Camera>
<Style>
<IconStyle>
<Icon>
<href>files/camera_mode.png</href>
</Icon>
</IconStyle>
<ListStyle>
<listItemType>check</listItemType>
<ItemIcon>
<state>open closed error fetching0 fetching1 fetching2</state>
<href>http://maps.google.com/mapfiles/kml/shapes/camera-lv.png</href>
</ItemIcon>
<bgColor>00ffffff</bgColor>
<maxSnippetLines>2</maxSnippetLines>
</ListStyle>
</Style>
<Icon>
<href>files/DJI_0002.JPG</href>
</Icon>
<ViewVolume>
<leftFov>-25</leftFov>
<rightFov>25</rightFov>
<bottomFov>-19.275</bottomFov>
<topFov>19.275</topFov>
<near>15630.2</near>
</ViewVolume>
<Point>
<gx:altitudeMode>relativeToGround</gx:altitudeMode>
<coordinates>-101.844902194444,54.74660125,0</coordinates>
</Point>
</PhotoOverlay>

<... Lot's more photos here ...>

  • Did you try passing System.Text.Encoding.UTF8 to the StreamWriter constructor? – Kirk Kuykendall Aug 23 '16 at 16:05
  • I've done this now, but it didn't change anything. Updated the code to reflect the new constructor – cndnflyr Aug 23 '16 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.