I am trying to change the color of a specific object, by ID (or another feature). Currently I am able to extract data about an shapefile and display that data. However, I want to be able to change the color of a specific feature (all features that match X ID) based on the ID of the feature (assuming it has one).


private void changeLineColor() {

    ArrayList tempArray = new ArrayList();

    SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
    typeBuilder.add("geom-attr-name", MultiLineString.class);
    typeBuilder.add("id", Integer.class);
    typeBuilder.add("id", Integer.class);

    SimpleFeatureType type = typeBuilder.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    DefaultFeatureCollection features = new DefaultFeatureCollection();

    try (FeatureIterator<SimpleFeature> iterator = collection.features()) {
        while (iterator.hasNext()) {

            SimpleFeature feature = iterator.next();

            tempArray.add(feature); // all features

    } catch (Exception ex) {

        Logger.getLogger(ShapefileExporter.class.getName()).log(Level.SEVERE, null, ex);

    }finally {

        for (int j = 0; j < tempArray.size(); j++) {
                System.out.println("Attribute: " + tempArray.get(j) );


It would look something like this, but only for one MultiPolygon, or MultilineString

Image with codes

I would most likely want to make a dialog like this, but the color would only be for matching codes


  • You need a style that has a filter in it – Ian Turton Oct 23 '15 at 15:23
  • I'm aware of that much, I've went through the Map Style tutorial (even though it didn't work) and looked through the styling tutorials and making the style + filter isn't the issue. The question is, how do I select, or pass to the style, the correct feature? I can pass the information I need into a SimpleFeature, but after that i am lost as to what to do with the style/filter. – Lloyd Smith Oct 23 '15 at 19:47
  • did you get any solution for the above requirement. i'm exactly looking for the same issue. If you found any solution please let me know. – Chandrika Medapati Mar 5 at 13:25
  • This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review – Taras Mar 5 at 14:26

Your Answer

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

Browse other questions tagged or ask your own question.