Question

I'm looking for a way to visualize a piece of GML I'm receiving. What is the best freely available java library to use for this task?

Was it helpful?

Solution

GeoTools provides a library for reading GML files. They also provide UI components for displaying geospatial formats their library supports.

OTHER TIPS

You are warned that GML does not actually define a file format. It provides an abstract starting point for defining your own xml schema. We use the schema to sort out what xml elements to map to what Java class (so dates show up as Date, geometry as a JTS Geometry, etc...).

This causes enough grief with people that have only been provided with a GML "file"; that I have recently added a utility class (called GML) to GeoTools that will assume any undefined element is a String.

Here is an example from test cases::

        URL url = TestData.getResource(this, "states.gml");
        InputStream in = url.openStream();

        GML gml = new GML(Version.GML3);
        SimpleFeatureCollection featureCollection = gml.decodeFeatureCollection(in);

You can take the resulting featureCollection and use JMapPane class as shown in the GeoTools quickstart::

    MapContext map = new DefaultMapContext();
    map.setTitle("Quickstart");
    map.addLayer(featureCollection, null);

    // Now display the map
    JMapFrame.showMap(map);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top