Obtice
Obtice

Reputation: 1269

How to import gis shapefiles into postgis database programatically?

How can I import gis shapefiles into postgis database programatically using java ? I used a program named postgis shapefile import but now I want to do it in my java code.

Upvotes: 0

Views: 2357

Answers (1)

Mike T
Mike T

Reputation: 43672

The most common tool (one of several) is shp2pgsql, which comes with PostGIS. It is normally used from a command prompt, but can be used through Java's ProcessBuilder.

ProcessBuilder pb =
   new ProcessBuilder("/bin/sh", "-c", "shp2pgsql my.shp | psql -d mydb");
Process p = pb.start();

ogr2ogr is another commonly used tool to convert most geospatial vector formats to PostGIS.

Upvotes: 2

Related Questions