如何使用GeoTools以KML编码设置altitudeMode?

时间:2013-06-27 08:38:24

标签: java kml google-earth geotools

我使用GeoTools KML编码器将一组点导出到KML。

它工作正常,但我的点数表示为lat,lon,alt,并且它们都是这样导出的,但Google Earth会将它们固定在曲面上。

我读了here我需要设置altitudeMode属性。我如何使用GeoTools编码器做到这一点?

这是我的代码:

/**
 * Converts the given point array to KML.
 * @param points The array of points to be converted.
 * @param os The target output stream where the resulting KML is to be
 * written. This method does not close the stream.
 */
public static void toKml(Point[] points, OutputStream os) {
    SimpleFeatureTypeBuilder sftb = new SimpleFeatureTypeBuilder();
    sftb.setName("points");
    sftb.add("geomtery", Point.class, DefaultGeographicCRS.WGS84_3D);
    SimpleFeatureType type = sftb.buildFeatureType();

    DefaultFeatureCollection features = new DefaultFeatureCollection();

    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    for (int i = 0; i < points.length; i++) {
        builder.add(points[i]);
        features.add(builder.buildFeature(Integer.toString(i)));
    }

    Encoder encoder = new Encoder(new KMLConfiguration());
    encoder.setIndenting(true);
    try {
        encoder.encode(features, KML.kml, os);
    } catch (IOException e) {
        throw new RuntimeException("While converting " +
                Arrays.toString(points) + " to KML.", e);
    }
}

0 个答案:

没有答案