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.

  • shp2psql -w shape.shp > some.sql , then extract WKT from sql script is one option – simplexio Dec 4 '12 at 8:02

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.

  • 1
    Yes, and invoking the method "toString" on each JTS geometry will return directly its WKT representation. – julien May 24 '12 at 9:48

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.