Reputation: 49
My question is very simple: is it possible to fill a polygon in Google Earth with an image file (bmp, jpeg, gif,...), instead of a color?
Thank you!
Upvotes: 4
Views: 3169
Reputation: 13
Yes,You can. Refer this program given by Google KML interactive sampler.
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>SketchUp Model of Macky Auditorium</name>
<description>University of Colorado, Boulder; model created by Noël Nemcik.</description>
<LookAt>
<longitude>-105.2727379358738</longitude>
<latitude>40.01000594412381</latitude>
<altitude>0</altitude>
<heading>-27.70337734057933</heading>
<tilt>65.74454495876547</tilt>
<range>127.2393107680517</range>
</LookAt>
<Model id="model_4">
<altitudeMode>relativeToGround</altitudeMode>
<Location>
<longitude>-105.272774533734</longitude>
<latitude>40.009993372683</latitude>
<altitude>0</altitude>
</Location>
<Orientation>
<heading>0</heading>
<tilt>0</tilt>
<roll>0</roll>
</Orientation>
<Scale>
<x>1</x>
<y>1</y>
<z>1</z>
</Scale>
<Link>
<href>http://kml-samples.googlecode.com/svn/trunk/resources/CU-Macky.dae</href>
</Link>
<ResourceMap>
<Alias>
<targetHref>textures/CU-Macky---Center-StairsnoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky---Center-StairsnoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-4sideturretnoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-4sideturretnoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-Back-NorthnoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-Back-NorthnoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-BrickwallnoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-BrickwallnoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-East-WingnoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-East-WingnoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-EastdetaildoornoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-EastdetaildoornoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-EastnoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-EastnoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-EntrancenoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-EntrancenoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-Front--TurretnoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-Front--TurretnoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-FrontbrickwallnoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-FrontbrickwallnoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-FrontnoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-FrontnoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-FrontofTowernoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-FrontofTowernoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-NortheastUnivnoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-NortheastUnivnoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-NorthnoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-NorthnoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-RoofnoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-RoofnoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-Tower-SidenoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-Tower-SidenoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-TowerBasenoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-TowerBasenoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-TowernoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-TowernoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/CU-Macky-_Side_BrickwallnoCulling.jpg</targetHref>
<sourceHref>../files/CU-Macky-_Side_BrickwallnoCulling.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>textures/roofnoCulling.jpg</targetHref>
<sourceHref>../files/roofnoCulling.jpg</sourceHref>
</Alias>
</ResourceMap>
</Model>
</Placemark>
</kml>
Upvotes: 0
Reputation: 51
I had the same issue and found the model solution suggested by Pablo Reyes to be the best. The problem with Ground Overlays is that they expect the image to be a plate carrée projection. If your image is an orthographic projection, trying to compensate using <gx:LatLonQuad>
distorts the image because it applies a non-affine transformation. Plus the altitude coordinate of the <gx:LatLonQuad>
is ignored anyway, so the image curves with the globe maintaining a constant altitude.
The KML sample provided by Pablo Reyes is good. Without the need for SketchUp, the model.dae file for a flat plane looks like:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
<asset>
<unit meter="1" name="meter" />
<up_axis>Z_UP</up_axis>
</asset>
<library_visual_scenes>
<visual_scene id="ID1">
<node>
<instance_geometry url="#ID2">
<bind_material>
<technique_common>
<instance_material symbol="Material2" target="#ID3">
<bind_vertex_input semantic="UVSET0" input_semantic="TEXCOORD" input_set="0" />
</instance_material>
</technique_common>
</bind_material>
</instance_geometry>
</node>
</visual_scene>
</library_visual_scenes>
<library_geometries>
<geometry id="ID2">
<mesh>
<source id="ID8">
<float_array id="ID12" count="24">500.0 500.0 0 -500.0 -500.0 0 -500.0 500.0 0 500.0 -500.0 0 500.0 -500.0 0 500.0 500.0 0 -500.0 -500.0 0 -500.0 500.0 0</float_array>
<technique_common>
<accessor count="8" source="#ID12" stride="3">
<param name="X" type="float" />
<param name="Y" type="float" />
<param name="Z" type="float" />
</accessor>
</technique_common>
</source>
<source id="ID9">
<float_array id="ID13" count="24">0 0 -1 0 0 -1 0 0 -1 0 0 -1 -0 -0 1 -0 -0 1 -0 -0 1 -0 -0 1</float_array>
<technique_common>
<accessor count="8" source="#ID13" stride="3">
<param name="X" type="float" />
<param name="Y" type="float" />
<param name="Z" type="float" />
</accessor>
</technique_common>
</source>
<source id="ID11">
<float_array id="ID14" count="8">1 1 0 0 0 1 1 0</float_array>
<technique_common>
<accessor count="4" source="#ID14" stride="2">
<param name="S" type="float" />
<param name="T" type="float" />
</accessor>
</technique_common>
</source>
<vertices id="ID10">
<input semantic="POSITION" source="#ID8" />
<input semantic="NORMAL" source="#ID9" />
</vertices>
<triangles count="4" material="Material2">
<input offset="0" semantic="VERTEX" source="#ID10" />
<input offset="1" semantic="TEXCOORD" source="#ID11" />
<p>0 0 1 1 2 2 1 1 0 0 3 3 4 3 5 0 6 1 7 2 6 1 5 0</p>
</triangles>
</mesh>
</geometry>
</library_geometries>
<library_materials>
<material id="ID3" name="MaterialName">
<instance_effect url="#ID4" />
</material>
</library_materials>
<library_effects>
<effect id="ID4">
<profile_COMMON>
<newparam sid="ID6">
<surface type="2D">
<init_from>ID5</init_from>
</surface>
</newparam>
<newparam sid="ID7">
<sampler2D>
<source>ID6</source>
</sampler2D>
</newparam>
<technique sid="COMMON">
<lambert>
<diffuse>
<texture texture="ID7" texcoord="UVSET0" />
</diffuse>
<transparent opaque="RGB_ZERO">
<color>0.3 0.3 0.3 1</color>
</transparent>
<transparency>
<float>1</float>
</transparency>
</lambert>
</technique>
</profile_COMMON>
</effect>
</library_effects>
<library_images>
<image id="ID5">
<init_from>images/2Dimage.png</init_from>
</image>
</library_images>
<scene>
<instance_visual_scene url="#ID1" />
</scene>
Where the plane is 1000 meters square with the model coordinate system origin in the center. This is defined by:
<float_array id="ID12" count="24">500.0 500.0 0 -500.0 -500.0 0 -500.0 500.0 0 500.0 -500.0 0 500.0 -500.0 0 500.0 500.0 0 -500.0 -500.0 0 -500.0 500.0 0</float_array>
The image will be applied to the plane edge-to-edge. If the image is not square, the dimensions of the plane must be modified accordingly. The plane can be re-sized and rotated in GE using the <Scale>
and <Orientation>
KML settings. And the opacity of the image is set by:
<color>0.3 0.3 0.3 1</color>
This allows me to use the same model file with multiple images that have different sizes, locations, and orientations (as long as they all have the same shape: square in this case). And it properly renders orthographic projections that are tangent to the globe in the center.
Upvotes: 3
Reputation: 3123
You can create a collada 3D object where you define, for instance, a plane that has an image as the texture of the plane. Once created, you use it as a model in your kml file, where you can place it in a certain (longitude, latitude, altitude) and with the scale and orientation that you want. The easiest way to do this is using the software SketchUp to create your plane with an image as texture, and export the collada *.dae file. Then you go to the menu of Google Earth and ADD the model you just created and place it. You can save this as a *.kmz file. That file will contain compressed the collada *.dae file and the texture image. A more elaborated way to do this can be achieved using python pycollada library to create the collada *.dae file. There are some tools to create the *.kml file using python too [e.g. pyKML, simplekml, or fastkml], or you can write it yourself like the piece of kml file that I'm posting here. In this code the collada model file name is "model.dae", That file uses the image file name "2Dimage.png" as included in the part of the kml file.
...
<Placemark>
<styleUrl>#default0</styleUrl>
<Model id="ID">
<altitudeMode>relativeToGround</altitudeMode>
<Location>
<longitude>167.469167</longitude>
<latitude>9.397944000000001</latitude>
<altitude>12</altitude>
</Location>
<Orientation>
<heading>0</heading>
<tilt>0</tilt>
<roll>0</roll>
</Orientation>
<Scale>
<x>1</x>
<y>1</y>
<z>1</z>
</Scale>
<Link>
<href>model.dae</href>
</Link>
<ResourceMap>
<Alias>
<targetHref>2Dimage.png</targetHref>
<sourceHref>images/2Dimage.png</sourceHref>
</Alias>
</ResourceMap>
</Model>
</Placemark>
Upvotes: 2
Reputation: 23738
You cannot fill a polygon with an image but you can use a Ground Overlay (aka Image Overlay).
The normal Ground Overlay only allows a square boundary that you can rotate.
<kml xmlns="http://www.opengis.net/kml/2.2">
<GroundOverlay>
<name>GroundOverlay.kml</name>
<Icon>
<href>http://www.google.com/intl/en/images/logo.gif</href>
</Icon>
<LatLonBox>
<north>37.83234</north>
<south>37.832122</south>
<east>-122.373033</east>
<west>-122.373724</west>
<rotation>45</rotation>
</LatLonBox>
</GroundOverlay>
</kml>
However, if you want full control over the image overlay then you could use a Google Earth extension <gx:LatLonQuad>
. The LatLonQuad specifies the coordinates of the four corner points of a quadrilateral defining the overlay area rather than just two points that define the north, south, east, and west boundary.
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<GroundOverlay>
<name>Quad Image Overlay</name>
<Icon>
<href>http://www.google.com/intl/en/images/logo.gif</href>
<viewBoundScale>0.75</viewBoundScale>
</Icon>
<gx:LatLonQuad>
<coordinates>
31.13309787341621,29.97820855337135,0 31.13521972695729,29.97822570382352,0 31.13414174103354,29.97910121868758,0 31.13378951869572,29.97910728214542,0
</coordinates>
</gx:LatLonQuad>
</GroundOverlay>
</kml>
References:
Upvotes: 1