How to Generate KML file with Style using Geotools?
문제
I performed a lot of search around this question, and do not find any answer.
In a Java Program, I have a "SimpleFeatureCollection"(geotools) and a "StyleLayerDescriptor"(geotools) which contain my "SimpleFeatureCollection" style, and I need to generate a KML file using this style.
I actually generate successfully a KML file (without any style) using my "SimpleFeatureCollection" object with the following code:
static public boolean collectionToKMLFile(File iKMLFile, SimpleFeatureCollection iPolygonsCollection, StyledLayerDescriptor iStyle) throws IOException
{
Encoder lEncoder = new Encoder(new KMLConfiguration());
FileOutputStream lFileOutputStream = new FileOutputStream(iKMLFile);
lEncoder.setIndenting(true);
lEncoder.encode(iPolygonsCollection, KML.kml, lFileOutputStream);
lFileOutputStream.close();
return false;
}
I do not find any information on how to add style, I do not think it is impossible, do yo have an idea ?
Thanks.
해결책
I finally decided to write a program to generate my own Styled KML File.
In fact, it is not really hard:
- Write KML Header
- Loop over your geometries and Write them
- Write Kml Footer
All information relative to KML elements defined in KML Version 2.2 could be found here :
Enjoy.
제휴하지 않습니다 StackOverflow