]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.gis/src/main/java/org/argeo/slc/postgis/ImportShapefile.java
1 package org
.argeo
.slc
.postgis
;
5 import org
.apache
.commons
.io
.FilenameUtils
;
6 import org
.argeo
.slc
.SlcException
;
7 import org
.argeo
.slc
.core
.execution
.tasks
.SystemCall
;
8 import org
.argeo
.slc
.gdal
.OgrProcess
;
9 import org
.springframework
.core
.io
.FileSystemResource
;
11 public class ImportShapefile
extends OgrProcess
{
13 private Boolean createIndex
= true;
14 private String mode
= "-d";
15 private String tableName
;
16 private String dbHost
= "localhost";
17 private Integer dbPort
= 5432;
18 private String dbName
;
19 private String dbUser
;
26 shapefile
= File
.createTempFile(
27 FilenameUtils
.getBaseName(getSource().getName()),
28 FilenameUtils
.getExtension(getSource().getName()));
30 // do OGR pre-processing
33 shapefile
= getSource();
36 if (tableName
== null)
37 tableName
= FilenameUtils
.getBaseName(getSource().getName());
39 SystemCall shp2pgsql
= new SystemCall("shp2pgsql");
42 if (getTargetSrs() != null) {
43 if (getTargetSrs().toUpperCase().startsWith("EPSG:")) {
44 String srid
= getTargetSrs().toUpperCase().substring(
46 shp2pgsql
.arg("-s", srid
);
48 throw new SlcException("Cannot interpret SRS "
53 shp2pgsql
.arg(tableName
);
54 shp2pgsql
.arg(shapefile
.getAbsolutePath());
57 File sqlOutput
= File
.createTempFile(
59 + FilenameUtils
.getBaseName(getSource().getName()),
61 shp2pgsql
.setStdOutFile(new FileSystemResource(sqlOutput
));
62 shp2pgsql
.setRedirectStdOut(true);
66 SystemCall psql
= new SystemCall("psql");
67 psql
.arg("-h", dbHost
);
68 psql
.arg("-p", dbPort
.toString());
69 psql
.arg("-d", dbName
);
70 psql
.arg("-U", dbUser
);
71 psql
.setStdInFile(new FileSystemResource(sqlOutput
));
74 } catch (Exception e
) {
75 throw new SlcException("Cannot import " + getSource(), e
);
79 public void setCreateIndex(Boolean createIndex
) {
80 this.createIndex
= createIndex
;
83 public void setMode(String mode
) {
87 public void setTableName(String tableName
) {
88 this.tableName
= tableName
;
91 public void setDbHost(String dbHost
) {
95 public void setDbPort(Integer dbPort
) {
99 public void setDbName(String dbName
) {
100 this.dbName
= dbName
;
103 public void setDbUser(String dbUser
) {
104 this.dbUser
= dbUser
;