1

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

它工作正常,但我的点表示为 lat、lon、alt,并且它们是这样导出的,但 Google Earth 将它们显示在表面上。

我在这里读到我需要设置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);
    }
}
4

0 回答 0