2

I'm working on a geographic information system project, whose products form shapefiles. I am using the Java programming language and a PostGIS database. Is there a way to generate a shapefile from PostGIS or KML using the Java language?

1
  • 1
    Another thing you could look into is GeoTools. It is another open source package written in Java. It may have a little more than what you need, but it would allow you more freedom to manipulate the data.
    – Branco
    Commented Oct 1, 2014 at 17:07

4 Answers 4

2

Geotools is a powerful library, and can read from PostGIS, for example, and can export to ShapeFile, for example, using the "Feature" object.

I cann't show you a complete "example", but it's easy to find out a way to do it, in Google.

2

You can use geotools to do such actions. You may find here an example converting a java ResultSet to shapefile. Though the example provided is using an oracle ResultSet but you can easily adjust it to accept postgis ResultSet and generate shapefiles.

1

H2GIS is a lightweight (about 5 megabytes) embedded spatial database written in Java and available on Maven Central. It could suit your needs. A short sample of using this library is available.

generate a shp file from PostGIS

H2GIS can import/export SHP files. You can use the SHPDriverFunction by providing a JDBC connection with PostGIS.You should use this connection wrapper in order to bind JTS geometry object to postgis geometry object.

generate a kml file from PostGIS

A KMLDriverFunction is also available.

Please note that the H2GIS library is under the GPLV3 license. In order to use this your software must be open-source.

1

You can search for OpenJUMP it's a GIS Java software, you can use it to display PostGIS files or for developing Plugins. You can read more about this GIS Java software here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.