Moving a 3D model on Google Earth - kml

I'm working on a KML file for moving a model in space with interpolation (smoothly).
I developed the following code, but it doesn't work. Any suggestion?
<?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">
<Placemark>
<name>SketchUp Model</name>
<description>University.</description>
<LookAt>
<longitude>12.491456</longitude>
<latitude>41.889687</latitude>
<altitude>6</altitude>
<range>127.2393107680517</range>
<tilt>65.74454495876547</tilt>
<heading>-27.70337734057933</heading>
</LookAt>
</Placemark>
<Folder>
<name>Arrivals</name>
<Placemark>
<name>Modello</name>
<description>University of Colorado</description>
<gx:Track>
<altitudeMode>relativeToGround</altitudeMode>
<when>2010-05-01T13:00:00-05</when>
<when>2010-05-01T13:00:04-05</when>
<when>2010-05-01T13:00:08-05</when>
<when>2010-05-01T13:00:12-05</when>
<when>2010-05-01T13:00:16-05</when>
<gx:coord>12.491436 41.889687 0</gx:coord>
<gx:coord>12.491456 41.889657 0</gx:coord>
<gx:coord>12.491446 41.889667 0</gx:coord>
<gx:coord>12.491426 41.889617 0</gx:coord>
<gx:coord>12.491466 41.889627 0</gx:coord>
<gx:angles>20 0 0</gx:angles>
<gx:angles>20 0 0</gx:angles>
<gx:angles>20 0 0</gx:angles>
<gx:angles>20 0 0</gx:angles>
<gx:angles>20 0 0</gx:angles>
<Model>
<altitudeMode>relativeToGround</altitudeMode>
<Location>
<longitude>12.491456</longitude>
<latitude>41.889687</latitude>
<altitude>2</altitude>
</Location>
<Orientation>
<heading>0</heading>
<tilt>0</tilt>
<roll>0</roll>
</Orientation>
<Scale>
<x>1.0</x>
<y>1.0</y>
<z>1.0</z>
</Scale>
<Link>
<href>models/Citizen Extras_Male 03.dae</href>
</Link>
</Model>
</gx:Track>
</Placemark>
</Folder>
</kml>
When I load the html file with fetchKml(...) nothing happens. I only see the globe in space...

If you want to animate any model in Google Earth, you should see these examples:
http://www.barnabu.co.uk/geapi/bounce/
http://earth-api-samples.googlecode.com/svn/trunk/examples/event-frameend.html
The only way to animate models I know is using KML Tours or working with frameend event

Related

KML google earth <gx:Track><gx:coord> does not match <LineString><coordinates>

I'm using KML and Google Earth to show spacecraft orbiting the earth with gx:Track gx:coord that seems to work fine. I thought it would be cool to not only to show the crafts .dae model orbiting but also show the orbital path with a line. So I'm using LineString and coordinates and that seems to work well too. My problem is the line plotted with LineString/coordinates and the animated craft model path plotted with gx:Track/gx:coord are different. They both use the same values, in the same order(done by C program). They are both using relativeToGround for altitudeMode.
It appears that the model is running to the east a few hundred miles from the path here's my code. What am I missing?
<?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>orbit tracker</name>
<Style id="yellowLine">
<LineStyle>
<color>7f00ffff</color>
<width>4</width >
</LineStyle>
</Style>
<Folder>
<name>intercept</name>
<open>1</open >
<StyleMap id="default">
<Pair>
<key>normal</key>
<styleUrl>#default0</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#hl</styleUrl>
</Pair>
</StyleMap>
<Style id="default0">
<IconStyle>
<scale>0 </scale >
</IconStyle>
<LabelStyle>
<scale>0 </scale >
</LabelStyle>
<LineStyle>
<width>0 </width >
</LineStyle>
</Style>
<Style id="hl">
<IconStyle>
<scale>0</scale >
</IconStyle>
<LabelStyle>
<scale>0</scale >
</LabelStyle>
<LineStyle>
<width>0</width >
</LineStyle>
</Style>
<Placemark>
<name>relativeToGround</name>
<description>yellow path</description>
<styleUrl>#yellowLine</styleUrl>
<LineString>
<!-- <extrude>1</extrude >
<tessellate>1</tessellate> -->
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>
249.736573,-0.000023,376056.154875
251.843021,3.145995,375522.230739
253.963971,6.286935,375138.772855
256.113750,9.417027,374905.321591
258.307182,12.530269,374819.227168
260.559828,15.620296,374875.733743
262.888242,18.680247,375068.101533
265.310220,21.702611,375387.764236
267.845052,24.679046,375824.518196
270.513739,27.600180,376366.739198
</coordinates>
</LineString>
</Placemark>
<Placemark>
<name>satellite_0</name>
<Style id="default">
<IconStyle>
<scale>0</scale >
</IconStyle>
<LabelStyle>
<scale>0</scale >
</LabelStyle>
<LineStyle>
<width>0</width >
</LineStyle>
</Style>
<styleUrl>#default</styleUrl>
<gx:Track kml:id="ID_0">
<altitudeMode>relativeToGround</altitudeMode>
<when>2022-10-02T00:00:00</when>
<when>2022-10-02T00:01:00</when>
<when>2022-10-02T00:02:00</when>
<when>2022-10-02T00:03:00</when>
<when>2022-10-02T00:04:00</when>
<when>2022-10-02T00:05:00</when>
<when>2022-10-02T00:06:00</when>
<when>2022-10-02T00:07:00</when>
<when>2022-10-02T00:08:00</when>
<when>2022-10-02T00:09:00</when>
<gx:coord> 249.736573 -0.000023 376056.154875 </gx:coord>
<gx:coord> 251.843021 3.145995 375522.230739 </gx:coord>
<gx:coord> 253.963971 6.286935 375138.772855 </gx:coord>
<gx:coord> 256.113750 9.417027 374905.321591 </gx:coord>
<gx:coord> 258.307182 12.530269 374819.227168 </gx:coord>
<gx:coord> 260.559828 15.620296 374875.733743 </gx:coord>
<gx:coord> 262.888242 18.680247 375068.101533 </gx:coord>
<gx:coord> 265.310220 21.702611 375387.764236 </gx:coord>
<gx:coord> 267.845052 24.679046 375824.518196 </gx:coord>
<gx:coord> 270.513739 27.600180 376366.739198 </gx:coord>
<gx:angles>0 0 0</gx:angles>
<gx:angles>0 0 0</gx:angles>
<gx:angles>0 0 0</gx:angles>
<gx:angles>0 0 0</gx:angles>
<gx:angles>0 0 0</gx:angles>
<gx:angles>0 0 0</gx:angles>
<gx:angles>0 0 0</gx:angles>
<gx:angles>0 0 0</gx:angles>
<gx:angles>0 0 0</gx:angles>
<gx:angles>0 0 0</gx:angles>
<Model id="model_5">
<altitudeMode>relativeToGround</altitudeMode>
<Location>
<longitude>-152.12475 </longitude >
<latitude>52.4241697 </latitude >
<altitude>321869 </altitude >
</Location>
<Orientation>
<heading>0 </heading >
<tilt>0 </tilt >
<roll>0 </roll >
</Orientation>
<Scale>
<x>30000.0000000</x>
<y>30000.0000000</y>
<z>30000.0000000</z>
</Scale>
<Link>
<href>_work/kml/test1/models/spacecraft.dae</href>
</Link>
<ResourceMap>
<Alias> <targetHref>/_work/C++/genkml/models/spacecraft/solarpanel.jpg</targetHref>
<sourceHref>spacecraft/solarpanel.jpg</sourceHref>
</Alias>
</ResourceMap>
</Model>
</gx:Track>
</Placemark>
</Folder>
</Document>
</kml>
ok I figured it out. My issue wasn't in the kml at all. My issue was the .dae file I was using for my model was not centered on the origin. Imported it into blender, reset the origin, and I'm good to go.

calculate centorid of the polygon kml [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
How to calculate centre of polygon when points are distributed unevenly ?
In below kml file 30% of lat/lons are on one side hence average does not produce a good result. Does any one knows any good libraries to achieve it ?
<?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:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/kml/2.2
http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd
http://www.google.com/kml/ext/2.2
http://code.google.com/apis/kml/schema/kml22gx.xsd">
<Document id="DLS_Parcels">
<name>DLS_Parcels</name>
<Snippet/>
<Folder id="FeatureLayer0">
<name>DLS_Parcels</name>
<Snippet/>
<Placemark id="ID_00000">
<name>189</name>
<Snippet/>
<description><![CDATA[<html><body><table border="1"><tr><th>Field Name</th><th>Field Value</th></tr><tr><td>OBJECTID</td><td>240106</td></tr><tr><td>SBPI_ID_NO</td><td>1076078</td></tr><tr><td>District Code</td><td>6</td></tr><tr><td>Municipality/Community Code</td><td>343</td></tr><tr><td>Quarter Code</td><td>1</td></tr><tr><td>Block Code</td><td>0</td></tr><tr><td>Parcel Number</td><td>189</td></tr><tr><td>Sheet</td><td>26</td></tr><tr><td>Plan</td><td>50</td></tr><tr><td>SRC_SL_CODE</td><td>5</td></tr><tr><td>SOURCE</td><td>DCDB</td></tr><tr><td>Parcel Area</td><td>2516</td></tr><tr><td>CadastralPlan</td><td>Null</td></tr></table></body></html>]]></description>
<styleUrl>#PolyStyle00</styleUrl>
<MultiGeometry>
<Polygon>
<extrude>0</extrude>
<altitudeMode>clampToGround</altitudeMode>
<tessellate>1</tessellate>
<outerBoundaryIs>
<LinearRing>
<coordinates> 32.394743,35.040539,0.000000
32.394946,35.040474,0.000000 32.395228,35.040376,0.000000
32.395274,35.040366,0.000000 32.395306,35.040379,0.000000
32.395318,35.040406,0.000000 32.395308,35.040847,0.000000
32.394855,35.040830,0.000000 32.394861,35.040659,0.000000
32.394642,35.040669,0.000000 32.394506,35.040674,0.000000
32.394505,35.040673,0.000000 32.394505,35.040672,0.000000
32.394505,35.040671,0.000000 32.394504,35.040670,0.000000
32.394504,35.040669,0.000000 32.394504,35.040668,0.000000
32.394503,35.040667,0.000000 32.394503,35.040666,0.000000
32.394503,35.040666,0.000000 32.394503,35.040665,0.000000
32.394502,35.040664,0.000000 32.394502,35.040663,0.000000
32.394502,35.040662,0.000000 32.394502,35.040661,0.000000
32.394502,35.040660,0.000000 32.394502,35.040659,0.000000
32.394501,35.040658,0.000000 32.394501,35.040657,0.000000
32.394501,35.040656,0.000000 32.394501,35.040655,0.000000
32.394501,35.040654,0.000000 32.394501,35.040653,0.000000
32.394501,35.040652,0.000000 32.394501,35.040651,0.000000
32.394501,35.040650,0.000000 32.394501,35.040649,0.000000
32.394502,35.040649,0.000000 32.394502,35.040648,0.000000
32.394502,35.040647,0.000000 32.394502,35.040646,0.000000
32.394502,35.040645,0.000000 32.394502,35.040644,0.000000
32.394503,35.040643,0.000000 32.394503,35.040642,0.000000
32.394503,35.040641,0.000000 32.394503,35.040640,0.000000
32.394504,35.040639,0.000000 32.394504,35.040638,0.000000
32.394504,35.040637,0.000000 32.394505,35.040636,0.000000
32.394505,35.040636,0.000000 32.394505,35.040635,0.000000
32.394506,35.040634,0.000000 32.394506,35.040633,0.000000
32.394507,35.040632,0.000000 32.394507,35.040631,0.000000
32.394508,35.040630,0.000000 32.394508,35.040629,0.000000
32.394509,35.040629,0.000000 32.394509,35.040628,0.000000
32.394510,35.040627,0.000000 32.394510,35.040626,0.000000
32.394511,35.040625,0.000000 32.394512,35.040624,0.000000
32.394512,35.040624,0.000000 32.394513,35.040623,0.000000
32.394514,35.040622,0.000000 32.394514,35.040621,0.000000
32.394515,35.040621,0.000000 32.394516,35.040620,0.000000
32.394516,35.040619,0.000000 32.394517,35.040618,0.000000
32.394518,35.040618,0.000000 32.394519,35.040617,0.000000
32.394519,35.040616,0.000000 32.394520,35.040616,0.000000
32.394521,35.040615,0.000000 32.394522,35.040614,0.000000
32.394523,35.040614,0.000000 32.394524,35.040613,0.000000
32.394624,35.040579,0.000000 32.394743,35.040539,0.000000</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
</Folder>
<Style id="PolyStyle00">
<LabelStyle>
<color>00000000</color>
<scale>0.000000</scale>
</LabelStyle>
<LineStyle>
<color>ff0000e6</color>
<width>3.000000</width>
</LineStyle>
<PolyStyle>
<color>00000000</color>
<outline>1</outline>
</PolyStyle>
</Style>
</Document>
</kml>
You can utilize geoPHP
Here is an example
$kml = '<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>The Pentagon</name>
<Polygon>
<extrude>1</extrude>
<altitudeMode>relativeToGround</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-77.05788457660967,38.87253259892824,100
-77.05465973756702,38.87291016281703,100
-77.05315536854791,38.87053267794386,100
-77.05552622493516,38.868757801256,100
-77.05844056290393,38.86996206506943,100
-77.05788457660967,38.87253259892824,100
</coordinates>
</LinearRing>
</outerBoundaryIs>
<innerBoundaryIs>
<LinearRing>
<coordinates>
-77.05668055019126,38.87154239798456,100
-77.05542625960818,38.87167890344077,100
-77.05485125901024,38.87076535397792,100
-77.05577677433152,38.87008686581446,100
-77.05691162017543,38.87054446963351,100
-77.05668055019126,38.87154239798456,100
</coordinates>
</LinearRing>
</innerBoundaryIs>
</Polygon>
</Placemark>
</kml>';
$polygon = geoPHP::load($kml, 'kml');
$centroid = $polygon->getCentroid();
$centX = $centroid->getX();
$centY = $centroid->getY();

Share a placemark description

I've created a geologic units map. Each geologic unit is composed of multiple placemark polygons. I currently have the same geologic unit description repeated in each placemark composing the geologic unit in order to get the functionality I want (click on the polygon and get a description).
Is there a way to include the geologic unit description once in the KML file and use it on multiple polygons?
Here's an example of what I currently have:
<?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>Geologic Units</name>
<open>1</open>
<Style id="style22">
<LineStyle>
<color>40000000</color>
</LineStyle>
<PolyStyle>
<color>996ca66c</color>
</PolyStyle>
</Style>
<Folder>
<name>Cokeville Formation (Lower Cretaceous)</name>
<Placemark>
<name>Cokeville Formation</name>
<description><![CDATA[<p>UNITSYMBOL: Kc</p><p>UNITNAME: Cokeville Formation</p><p>AGE: Lower Cretaceous</p><p>Description: Interbedded dark-gray, carbonaceous, shaly mudstone and siltstone, tan-weathering sandstone, and gray to tan limestone and coquina containing gastropod (Pyrgulifera) and pelecypod fauna. hickness about 650 m. Mapped only along southeastern edge of map area</p>]]></description>
<styleUrl>#style22</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<tessellate>1</tessellate>
<coordinates>
-111.001621832,41.6548237803,0 -111.000744207,41.6560784513,0 -111.00074419,41.6548059965,0 -111.001123716,41.6547959594,0 -111.001621832,41.6548237803,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Placemark>
<name>Cokeville Formation</name>
<description><![CDATA[<p>UNITSYMBOL: Kc</p><p>UNITNAME: Cokeville Formation</p><p>AGE: Lower Cretaceous</p><p>Description: Interbedded dark-gray, carbonaceous, shaly mudstone and siltstone, tan-weathering sandstone, and gray to tan limestone and coquina containing gastropod (Pyrgulifera) and pelecypod fauna. hickness about 650 m. Mapped only along southeastern edge of map area</p>]]></description>
<styleUrl>#style22</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<tessellate>1</tessellate>
<coordinates>
-111.010074925,41.6544088836,0 -111.009817106,41.6540759648,0 -111.009537791,41.6538429717,0 -111.009365835,41.6535267043,0 -111.009150955,41.6532271007,0 -111.008914576,41.653010725,0 -111.008549317,41.6527943596,0 -111.00861367,41.6521452029,0 -111.008506241,41.6516790986,0 -111.008466501,41.6515573391,0 -111.009350608,41.6513600036,0 -111.01081154,41.6510769006,0 -111.011498939,41.6510102244,0 -111.011406521,41.6517787096,0 -111.011019912,41.6519285808,0 -111.010590221,41.6523613799,0 -111.01028951,41.6528275229,0 -111.010246703,41.6535765651,0 -111.010160817,41.6540093659,0 -111.010074925,41.6544088836,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Folder>
</Document>
</kml>
I figured out how to do it with BalloonStyle Text. Is this the only way or is there another/better way?
<?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>Geologic Units</name>
<open>1</open>
<Style id="style22">
<BalloonStyle>
<text><![CDATA[<p>UNITSYMBOL: Kc</p><p>UNITNAME: Cokeville Formation</p><p>AGE: Lower Cretaceous</p><p>Description: Interbedded dark-gray, carbonaceous, shaly mudstone and siltstone, tan-weathering sandstone, and gray to tan limestone and coquina containing gastropod (Pyrgulifera) and pelecypod fauna. hickness about 650 m. Mapped only along southeastern edge of map area</p>]]></text>
</BalloonStyle>
<LineStyle>
<color>40000000</color>
</LineStyle>
<PolyStyle>
<color>996ca66c</color>
</PolyStyle>
</Style>
<Folder>
<name>Cokeville Formation (Lower Cretaceous)</name>
<Placemark>
<name>Cokeville Formation</name>
<styleUrl>#style22</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<tessellate>1</tessellate>
<coordinates>
-111.001621832,41.6548237803,0 -111.000744207,41.6560784513,0 -111.00074419,41.6548059965,0 -111.001123716,41.6547959594,0 -111.001621832,41.6548237803,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Placemark>
<name>Cokeville Formation</name>
<styleUrl>#style22</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<tessellate>1</tessellate>
<coordinates>
-111.010074925,41.6544088836,0 -111.009817106,41.6540759648,0 -111.009537791,41.6538429717,0 -111.009365835,41.6535267043,0 -111.009150955,41.6532271007,0 -111.008914576,41.653010725,0 -111.008549317,41.6527943596,0 -111.00861367,41.6521452029,0 -111.008506241,41.6516790986,0 -111.008466501,41.6515573391,0 -111.009350608,41.6513600036,0 -111.01081154,41.6510769006,0 -111.011498939,41.6510102244,0 -111.011406521,41.6517787096,0 -111.011019912,41.6519285808,0 -111.010590221,41.6523613799,0 -111.01028951,41.6528275229,0 -111.010246703,41.6535765651,0 -111.010160817,41.6540093659,0 -111.010074925,41.6544088836,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Folder>
</Document>
</kml>
For your use-case, a shared Style with a BalloonStyle containing a balloon template is probably the best way to go. You can take this a step further and include placeholder variables in the BalloonStyle template, which get replaced by contents of the ExtendedData section in each Placemark. That said, another way it can be done is to combine the relevant polygons into one Placemark, using a MultiGeometry, but only if you want the combined polygons to act as one on the map.

KML - Polygon Fill not needed, but still happens

I have KML code that will fill a polygon. I do not want the polygon filled. I have 0 and 1 but still displays a filled polygon. The polygon is approximately 10m radius. Is this so small that the line width of 1.5 is actually causing the polygon to be filled?
Here is the KML (I stripped it to only 1 point rather than the multiple of the original source)(this is operational so you should be able to copy it and see what I mean):
<?xml version='1.0' encoding='UTF-8'?>
<kml xmlns='http://earth.google.com/kml/2.1'>
<Document>
<name>
CO0xxxxxx
</name>
<open>1</open>
<Style id='a'>
<IconStyle>
<Icon>
http://maps.google.com/mapfiles/kml/paddle/grn-blank.png
</Icon>
</IconStyle>
</Style>
<Folder>
<open>0</open>
<name>Names</name>
<Placemark>
<name>WELL NO 2</name>
<description><![CDATA[]]></description>
<Point>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>-107.676117, 39.586253,0</coordinates>
</Point>
</Placemark>
<open>0</open>
<name>Polygons on-off</name>
<Placemark>
<Style>
<IconStyle>
<Icon>
<href>root://icons/palette-s.png</href>
<x>224</x>
<y>224</y>
<w>32</w>
<h>32</h>
</Icon>
</IconStyle>
<PolyStyle>
<Fill>0</Fill>
<Outline>1</Outline>
</PolyStyle>
<LineStyle>
<Color>ff0000ff</Color>
<Width>1.5</Width>
</LineStyle>
</Style>
<Polygon>
<extrude>0</extrude>
<altitudeMode>clampToGround</altitudeMode>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-107.676029,39.586323,0
-107.675996,39.586227,0
-107.676085,39.586158,0
-107.676205,39.586183,0
-107.676238,39.586279,0
-107.676149,39.586348,0
-107.676029,39.586323,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Folder>
</Document>
</kml>
KML is a dialect of XML. Tags are case sensitive.
(from the posted KML)
<PolyStyle>
<Fill>0</Fill>
<Outline>1</Outline>
</PolyStyle>
is not the same as:
<PolyStyle>
<fill>0</fill>
<outline>1</outline>
</PolyStyle>
(updated KML)
KML Reference

how to fill color in sld with the feature's attribute

for example:
here is a grass feature like this:
id,area, level
1,geometry, 24
2,geometry, 56
...
i wount to write a sld file that display color according to the attribute level, like this :
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
<NamedLayer>
<Name>grass</Name>
<UserStyle>
<Name>grass</Name>
<Title>grass polygon</Title>
<Abstract>grass fill with level</Abstract>
<FeatureTypeStyle>
<Rule>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">rgb(**level**, 0, 255)</CssParameter>
</Fill>
<Stroke />
</PolygonSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
Have a look at the categorize and interpolate functions:
http://docs.geoserver.org/latest/en/user/styling/sld-tipstricks/transformation-func.html

Resources