如何使用Geotools生成带有Style的KML文件?

时间:2012-06-18 10:57:05

标签: java styles kml geoserver geotools

我围绕这个问题进行了很多搜索,但没有找到任何答案。

在Java程序中,我有一个“SimpleFeatureCollection”(geotools)和一个“StyleLayerDescriptor”(geotools),它包含我的“SimpleFeatureCollection”样式,我需要使用这种样式生成一个KML文件。

我实际上使用我的“SimpleFeatureCollection”对象生成了一个KML文件(没有任何样式),代码如下:

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;
}

我没有找到关于如何添加样式的任何信息,我认为这不可能,你有什么想法吗?

感谢。

1 个答案:

答案 0 :(得分:0)

我最终决定编写一个程序来生成我自己的样式化KML文件

事实上,这并不是很难:

  1. 编写KML标题
  2. 遍历几何图形并将其写入
  3. 写Kml页脚
  4. 可以在此处找到与KML 2.2版中定义的 KML 元素相关的所有信息:

    享受。