[GIS] Write out a WKT file from a loaded shapefile

geotoolsjavashapefilewell-known-text

We are looking to load and display a shapefile, simple polygons, then write out a WKT string of that shapefile and have the user save it somewhere.

Does anyone have some code snippets of that very function or a link to a site that covers this need?

I imagine we will be using Geotools and java to do this.

Best Answer

You could use the JTS WKTWriter to convert geometries read in from the Shapefile to WKT and then save the strings to a file the user chose. Reading in a Shapefile and accessing the geometries are covered in the CRS tutorial.