Revision 1691 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/DEMO/PruebasGT2.java
PruebasGT2.java | ||
---|---|---|
48 | 48 |
import java.awt.event.ActionListener; |
49 | 49 |
import java.io.FileNotFoundException; |
50 | 50 |
import java.io.IOException; |
51 |
import java.sql.Connection; |
|
52 |
import java.sql.DriverManager; |
|
53 |
import java.sql.SQLException; |
|
51 | 54 |
import java.util.HashMap; |
52 | 55 |
import java.util.Map; |
53 | 56 |
|
54 |
import java.net.URL; |
|
55 |
import javax.swing.JFileChooser; |
|
56 | 57 |
import javax.swing.JOptionPane; |
57 | 58 |
|
58 | 59 |
import org.geotools.data.DataSourceException; |
59 | 60 |
import org.geotools.data.DataStore; |
60 | 61 |
import org.geotools.data.FeatureSource; |
61 |
// import org.geotools.data.arcsde.ArcSDEDataStoreFactory;
|
|
62 |
import org.geotools.data.postgis.PostgisDataStoreFactory;
|
|
62 | 63 |
import org.geotools.map.DefaultMapLayer; |
63 | 64 |
import org.geotools.map.MapLayer; |
64 | 65 |
import org.geotools.styling.Style; |
65 | 66 |
import org.geotools.styling.StyleBuilder; |
66 | 67 |
|
67 | 68 |
import com.iver.cit.gvsig.fmap.FMap; |
69 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
|
70 |
import com.iver.cit.gvsig.fmap.drivers.postgis.PostGisDriver; |
|
68 | 71 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
72 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
69 | 73 |
import com.iver.cit.gvsig.fmap.layers.FLyrGT2; |
74 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
|
70 | 75 |
import com.vividsolutions.jts.geom.LineString; |
71 | 76 |
import com.vividsolutions.jts.geom.MultiLineString; |
72 | 77 |
import com.vividsolutions.jts.geom.MultiPoint; |
73 | 78 |
import com.vividsolutions.jts.geom.Point; |
74 |
/* import org.geotools.data.postgis.PostgisDataStoreFactory; |
|
75 |
import org.geotools.data.shapefile.ShapefileDataStore; */ |
|
76 | 79 |
|
77 | 80 |
/** |
78 | 81 |
* Pruebas de capas GT2 (ArcSDE, etc), hechas por Fran, sacadas del |
... | ... | |
80 | 83 |
* @author Luis W. Sevilla (sevilla_lui@gva.es) |
81 | 84 |
*/ |
82 | 85 |
public class PruebasGT2 implements ActionListener { |
83 |
// static PostgisDataStoreFactory postGisFactory = new PostgisDataStoreFactory();
|
|
86 |
static PostgisDataStoreFactory postGisFactory = new PostgisDataStoreFactory(); |
|
84 | 87 |
// static ArcSDEDataStoreFactory arcSdeFactory = new ArcSDEDataStoreFactory(); |
85 | 88 |
|
86 | 89 |
Map remote; |
... | ... | |
116 | 119 |
} |
117 | 120 |
} */ |
118 | 121 |
} |
122 |
protected void addLayer_PostGIS() |
|
123 |
{ |
|
124 |
String nomTabla = JOptionPane.showInputDialog(null, "?Nombre de la tabla a cargar?", "provin"); |
|
125 |
VectorialDatabaseDriver driver = new PostGisDriver(); |
|
126 |
String dburl = "jdbc:postgresql://localhost/latin1"; |
|
127 |
String dbuser = "postgres"; |
|
128 |
String dbpass = "aquilina"; |
|
129 |
String fields = "ASTEXT(force_2d(the_geom)) as geom, area, nd_4, nom_provin"; |
|
130 |
String whereClause = ""; |
|
131 |
|
|
132 |
|
|
133 |
Connection conn; |
|
134 |
try { |
|
135 |
Class.forName("org.postgresql.Driver"); |
|
136 |
conn = DriverManager.getConnection(dburl, dbuser, dbpass); |
|
137 |
conn.setAutoCommit(false); |
|
138 |
driver.setData(conn, nomTabla, fields, whereClause); |
|
139 |
FLayer lyr = LayerFactory.createDBLayer(driver, nomTabla, null); |
|
140 |
m_Mapa.getLayers().addLayer(lyr); |
|
141 |
} catch (SQLException e) { |
|
142 |
// TODO Auto-generated catch block |
|
143 |
e.printStackTrace(); |
|
144 |
} catch (ClassNotFoundException e) { |
|
145 |
// TODO Auto-generated catch block |
|
146 |
e.printStackTrace(); |
|
147 |
} |
|
148 |
|
|
149 |
} |
|
119 | 150 |
protected void addLayerGT2_PostGIS() |
120 | 151 |
{ |
121 |
/* remote = new HashMap(); |
|
152 |
String nomTabla = JOptionPane.showInputDialog(null, "?Nombre de la tabla a cargar?", "provin"); |
|
153 |
|
|
154 |
remote = new HashMap(); |
|
122 | 155 |
remote.put("dbtype","postgis"); |
123 |
remote.put("host","213.172.37.189"); //Jos? Miguel
|
|
156 |
remote.put("host","localhost"); //Jos? Miguel
|
|
124 | 157 |
remote.put("port", new Integer(5432)); |
125 |
remote.put("database", "geomarketing");
|
|
126 |
remote.put("user", "Geomarketing");
|
|
127 |
remote.put("passwd", "geomarketing");
|
|
158 |
remote.put("database", "latin1");
|
|
159 |
remote.put("user", "postgres");
|
|
160 |
remote.put("passwd", "aquilina");
|
|
128 | 161 |
remote.put("charset", ""); |
129 | 162 |
remote.put("namespace", ""); |
130 | 163 |
|
131 | 164 |
DataStore store; |
132 | 165 |
try { |
133 | 166 |
store = postGisFactory.createDataStore(remote); |
134 |
loadLayer(store, "ferrocarril");
|
|
167 |
loadLayer(store, nomTabla);
|
|
135 | 168 |
|
136 | 169 |
} catch (IOException e) { |
137 | 170 |
// TODO Auto-generated catch block |
138 | 171 |
e.printStackTrace(); |
139 |
} */ |
|
140 |
|
|
141 |
|
|
172 |
} |
|
142 | 173 |
} |
174 |
|
|
175 |
|
|
143 | 176 |
/** |
144 | 177 |
* Load the data from the specified dataStore and construct a {@linkPlain Context context} with |
145 | 178 |
* a default style. |
... | ... | |
153 | 186 |
*/ |
154 | 187 |
protected void loadLayer(DataStore store, String layerName) |
155 | 188 |
throws IOException, DataSourceException { |
189 |
long t1 = System.currentTimeMillis(); |
|
156 | 190 |
final FeatureSource features = store.getFeatureSource(layerName); |
157 |
|
|
191 |
long t2 = System.currentTimeMillis(); |
|
192 |
System.out.println("t2-t1= " + (t2-t1)); |
|
158 | 193 |
// Create the style |
159 | 194 |
final StyleBuilder builder = new StyleBuilder(); |
160 | 195 |
final Style style; |
... | ... | |
212 | 247 |
m_Mapa = map; |
213 | 248 |
} |
214 | 249 |
public void actionPerformed(ActionEvent e) { |
250 |
|
|
251 |
if (e.getActionCommand() == "ADD_GT2_POSTGIS_PROPIO") { |
|
252 |
addLayer_PostGIS(); |
|
253 |
} |
|
254 |
|
|
215 | 255 |
if (e.getActionCommand() == "ADD_GT2_POSTGIS") { |
216 | 256 |
addLayerGT2_PostGIS(); |
217 | 257 |
} |
Also available in: Unified diff