1

I am trying to export features(polygons) in to a KML file. I am able to get KML file with the given features. Here all lines are coming in a white color. How can i give different colors to different polygons. Please suggest me.

Here my code

    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setName(plotName);
    builder.setCRS(DefaultGeographicCRS.WGS84);
    builder.add(sPolygon, Polygon.class);
    builder.length(32).add("AreaLocation", String.class);
    final SimpleFeatureType featureType = builder.buildFeatureType();

getting Feature Collection from featureList

    SimpleFeatureCollection collection = new ListFeatureCollection(builder.getFeatureType(), featureList); //featureList list of all polygons

exporting as a kml

            OutputStream stream = new FileOutputStream("my.kml");
            Encoder encoder = new Encoder(new KMLConfiguration());
            encoder.setIndenting(true);
            encoder.encode(collection, KML.kml, stream);
  • What should control the colour of the polygons? – Ian Turton Apr 9 '16 at 17:54
  • When I am opening the KML file it is appearing that whole polygons are in white background here the link to image drive.google.com/file/d/0B5Vh2tWJlQW_QzAzQ0pXRHpHTmM/… in this image there are 7 polygons but not showing since all are in while Color. – Suri Apr 10 '16 at 5:43
1

To the best of my knowledge there is no code to do this on GeoTools as GeoTools confines itself to reading and writing data formats and handles styling as a separate matter.

You could look at (and probably use) the code in GeoServer that handles writing out KML with a style.

  • But what might be the reason in my code at least the boundary lines of the polygons should be visible but not appearing in the resultant KML. – Suri Apr 10 '16 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.