[GIS] Convert list of Java objects with JTS geom to GeoJson

geojsonjavajts-topology-suite

I have a list of Java POJOs that all have a JTS geometry associated with them (Point) – a list of POIs, basically.

I want to output them as GeoJson (FeatureCollection, Feature etc.)

jackson-datatype-jts (https://github.com/bedatadriven/jackson-datatype-jts) will encode JTS Points into GeoJSON, but not a list of objects.

geojson-jackson (https://github.com/opendatalab-de/geojson-jackson) will let me make FeatureCollections and Features with geometries, but uses it's own classes for Geometries so I'd have to convert all of JTS to theirs.

That's not that complicated, but is there any Java library that will let me create proper GeoJson documents out of Java objects with JTS geometries? I started looking at GeoTools but can't really find any example that does that.

Best Answer

If you look at GeometryJSON from GeoTools you will see the write method which should do what you need.