svn-gvsig-desktop / tmp / trunk / servidor / WorkSpace_Servidor / Callejero / src / es / logex / callejero / core / Callejero.java @ 26486
History | View | Annotate | Download (4.43 KB)
1 |
/**
|
---|---|
2 |
*
|
3 |
*/
|
4 |
package es.logex.callejero.core; |
5 |
|
6 |
import java.awt.geom.Rectangle2D; |
7 |
import java.sql.Connection; |
8 |
import java.util.*; |
9 |
|
10 |
import org.apache.commons.logging.Log; |
11 |
import org.apache.commons.logging.LogFactory; |
12 |
import es.logex.utils.*; |
13 |
|
14 |
import java.sql.ResultSetMetaData; |
15 |
import java.sql.SQLException; |
16 |
import java.sql.Statement; |
17 |
import java.sql.ResultSet; |
18 |
import org.tigris.frogs.commons.*; |
19 |
|
20 |
import es.logex.callejero.modelo.*; |
21 |
|
22 |
import org.w3c.dom.Document; |
23 |
import org.w3c.dom.DOMException; |
24 |
import org.w3c.dom.Element; |
25 |
import org.gvsig.gpe.GPEDefaults; |
26 |
import org.gvsig.gpe.GPERegister; |
27 |
import org.gvsig.gpe.writers.GPEWriterHandler; |
28 |
|
29 |
import org.postgis.PGbox2d; |
30 |
import org.postgis.PGgeometry; |
31 |
import org.postgis.PGboxbase; |
32 |
|
33 |
/* logEx. Lógica Extrema s.l.*
|
34 |
* Copyright (C) 2007 Lógica Extrema and Generalitat Valenciana.
|
35 |
*
|
36 |
* This program is free software; you can redistribute it and/or
|
37 |
* modify it under the terms of the GNU General Public License
|
38 |
* as published by the Free Software Foundation; either version 2
|
39 |
* of the License, or (at your option) any later version.
|
40 |
*
|
41 |
* This program is distributed in the hope that it will be useful,
|
42 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
43 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
44 |
* GNU General Public License for more details.
|
45 |
*
|
46 |
* You should have received a copy of the GNU General Public License
|
47 |
* along with this program; if not, write to the Free Software
|
48 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
49 |
*
|
50 |
* For more information, contact:
|
51 |
*
|
52 |
* Generalitat Valenciana
|
53 |
* Conselleria d'Infraestructures i Transport
|
54 |
* Av. Blasco Ibañez, 50
|
55 |
* 46010 VALENCIA
|
56 |
* SPAIN
|
57 |
*
|
58 |
* +34 963862235
|
59 |
* gvsig@gva.es
|
60 |
* www.gvsig.gva.es
|
61 |
*
|
62 |
* or
|
63 |
*
|
64 |
* Lógica Extrema s.l.
|
65 |
* Avda. Cortes Valencianas
|
66 |
* 46015 Valencia
|
67 |
* Spain
|
68 |
*
|
69 |
* logic@logex.es
|
70 |
*/
|
71 |
|
72 |
/**
|
73 |
* @author kike
|
74 |
*
|
75 |
*/
|
76 |
public class Callejero implements ICallejero { |
77 |
|
78 |
Log log = LogFactory.getLog(this.getClass());
|
79 |
|
80 |
private static List<String> municipios = new ArrayList<String>(); |
81 |
public Connection conn = null; |
82 |
|
83 |
public Callejero(Connection conn) { |
84 |
this.conn = conn;
|
85 |
} |
86 |
|
87 |
private ResultSet EjecutaSql(String query) { |
88 |
ResultSet r= null; |
89 |
|
90 |
try {
|
91 |
Statement s = conn.createStatement();
|
92 |
r = s.executeQuery(query); |
93 |
|
94 |
}catch (Exception e){ |
95 |
log.error(e.getMessage()); |
96 |
} |
97 |
|
98 |
return r;
|
99 |
} |
100 |
|
101 |
/**
|
102 |
* Devuelve una lista con los nombres de todos los municipios de la base de datos
|
103 |
*
|
104 |
* @return una lista de municipios
|
105 |
*/
|
106 |
public List<String> getMunicipios() { |
107 |
try{
|
108 |
if (this.municipios.isEmpty() ) { |
109 |
log.debug("Municipios vacío. Se llena por primera vez");
|
110 |
|
111 |
ResultSet r = this.EjecutaSql("select * from municipios"); |
112 |
while (r.next()) {
|
113 |
municipios.add(r.getString("ine_denomina"));
|
114 |
} |
115 |
log.debug("Añadidos " + r.getRow() + "municipios a Callejero.municipios"); |
116 |
} |
117 |
}catch (Exception e) { |
118 |
log.error("Error en getMunicipios()");
|
119 |
log.error(e.getMessage());} |
120 |
finally{
|
121 |
return municipios;}
|
122 |
} |
123 |
|
124 |
/**
|
125 |
* Dado el nombre de un municipio devuelve los 10 mejores
|
126 |
* candidatos. Si se encuentra un municipio con el mismo nombre
|
127 |
* sólo se devuelve el municipio encontrado.
|
128 |
*/
|
129 |
public List<String> getMunicipiosLV(String municipio){ |
130 |
LevenshteinDistance lv = new LevenshteinDistance();;
|
131 |
List<String> lista = new ArrayList<String>(); |
132 |
|
133 |
return lv.getTopX(municipio, getMunicipios(),10); |
134 |
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* Devuelve el mapa con sus layers, cada layer tendrá su gmldocument
|
139 |
*/
|
140 |
public IMap getMapFromExtent(BoundingBox box) {
|
141 |
IMap map = null;
|
142 |
|
143 |
return map;
|
144 |
} |
145 |
|
146 |
/**
|
147 |
* Devuelve el extent máximo del callejero. En principio mira en la tabla de parcelas, pero quizás sería más riguroso mirar en todas las tablas
|
148 |
* y devolver los máximos...
|
149 |
* @return
|
150 |
* @throws Exception
|
151 |
*/
|
152 |
public Rectangle2D getMaxExtent() throws Exception{ |
153 |
ResultSet r = null; |
154 |
Statement s = null; |
155 |
PGbox2d pgBox = null;
|
156 |
|
157 |
try {
|
158 |
s = conn.createStatement(); |
159 |
r = s.executeQuery("SELECT EXTENT(the_GEOM) as bbox FROM parcelas");
|
160 |
|
161 |
if (r.next() ) {
|
162 |
pgBox = (PGbox2d) r.getObject("bbox");
|
163 |
} |
164 |
|
165 |
Rectangle2D rec = new Rectangle2D.Double(pgBox.getLLB().x,pgBox.getLLB().y, pgBox.getURT().x, pgBox.getURT().y) ; |
166 |
return rec;
|
167 |
|
168 |
} catch (SQLException e) { |
169 |
// TODO Auto-generated catch block
|
170 |
e.printStackTrace(); |
171 |
throw e;
|
172 |
} |
173 |
|
174 |
} |
175 |
|
176 |
} |
177 |
|