Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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.

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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