Hi José

Thanks for your nice words. Praise is always gratefully accepted :-)

For KML, the gt-xsd-kml module is your friend.  Here's a little
example that works directly with a JTS Geometry object...

import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.io.WKTReader;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.geotools.kml.KML;
import org.geotools.kml.KMLConfiguration;
import org.geotools.xml.Encoder;

public class KMLExample {

    public static void main(String[] args) throws Exception {
        /*
         * Create a triangular polygon
         */
        GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(null);
        WKTReader reader = new WKTReader(gf);
        Geometry triangle = reader.read("POLYGON((0 0, 10 20, 20 0, 0 0))");

        /*
         * Encode the polygon as KML and dump it to the console
         */
        Encoder encoder = new Encoder(new KMLConfiguration());
        encoder.setIndenting(true);
        encoder.encode(triangle, KML.Polygon, System.out);
    }
}

You should see the following output:

<?xml version="1.0" encoding="UTF-8"?>
<kml:Polygon xmlns:kml="http://earth.google.com/kml/2.1";>
    <kml:outerBoundaryIs>
        <kml:LinearRing>
            <kml:coordinates>0.0,0.0 10.0,20.0 20.0,0.0
0.0,0.0</kml:coordinates>
        </kml:LinearRing>
    </kml:outerBoundaryIs>
</kml:Polygon>

Hope that helps.

Michael

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to