javageometrygpspointgeotools

Java GeoTools Feature Information Window not correctly loading Feature information


So I have tried a few different ways to create SimpleFeatures for a single data point, from various different samples of code, with no success.

I can successfully create a FeatureCollection that contains the information such that the point is drawn on the map in the display. The issue i'm having is when I click on the point using the information tool, rather than displaying the ACTUAL data for the Point, it instead displays the word "Point" (which i believe is telling me it's of type Point.class rather than the Points data).

Fairly simple setup:

SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
typeBuilder.setName("test point information");
typeBuilder.setSRC(COORDINATE_REFERENCE_SYSTEM); // WGS84
typeBuilder.add("geom", Point.class);
typeBuilder.add("name", String.class);
typeBuilder.add("number", Integer.class);

SimpleFeatureType TYPE = typeBuilder.buildFeatureType();

DefaultFeatureCollection featureCollection = new DefaultFeatureCollection("internal",TYPE);
WKTReader2 wkt = new WKTReader2();

double longitude = positionCoordinate.getX();
double latitude = positionCoordinate.getY();

String pointString = "POINT("+longitude+" "+latitude+")";
String name = "Position"
int ID = 0;

featureCollection.add( SimpleFeatureBuilder.build(TYPE, new Object[]{ wkt.read(pointString), name, ID }, "PlatformPos"));
Style style = SLD.createPointStyle(...)
return new FeatureLayer(featureCollection, style);

The name in the information panel appears correctly, along with the number. But the Point displays "geom: Point". I have ensured it is not using awt Point anywhere and every reference to Point is the org.locationtech.jts.geom.Point.

Thanks


Solution

  • The infoTool is designed to not overwhelm the user with excessively large geometry strings. See FeatureLayerHelper line 129 where only the name of the geometry class is stored to be returned to the user.

                       if (value != null) {
                            if (value instanceof Geometry) {
                                result.setFeatureValue(name, value.getClass().getSimpleName());
                            } else {
                                result.setFeatureValue(name, value);
                            }
                        } else {
                            result.setFeatureValue(name, "null");
                        }
    

    If you want to get the point's coordinates back then you will need to override that class and change the way it handles that.

    Alternatively, if you can live with having the geom: Point show up as well, you could add the WKT of the geometry to your point as a String with some code like:

    typeBuilder.add("Location", String.class);
     ...
    String pointString = "(" + point.getX() + " " + point.getY() + ")"; 
     ...
    featureCollection.add( SimpleFeatureBuilder.build(TYPE, new Object[]{ point, pointString, name, ID }, "PlatformPos"));