Revision 26631
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/callejero/modelo/Feature.java | ||
---|---|---|
1 |
package es.logex.callejero.modelo; |
|
2 |
|
|
3 |
import java.util.*; |
|
4 |
import org.postgis.PGgeometry; |
|
5 |
|
|
6 |
public class Feature { |
|
7 |
|
|
8 |
private List<DataElement> data; |
|
9 |
private GeometryElement geometry; |
|
10 |
private String name; |
|
11 |
|
|
12 |
public Feature(String name) { |
|
13 |
this.name = name; |
|
14 |
} |
|
15 |
public List<DataElement> getData() { |
|
16 |
return data; |
|
17 |
} |
|
18 |
public void setData(List<DataElement> data) { |
|
19 |
this.data = data; |
|
20 |
} |
|
21 |
public GeometryElement getGeometryElement() { |
|
22 |
return geometry; |
|
23 |
} |
|
24 |
public void setGeometry(GeometryElement geometry) { |
|
25 |
this.geometry = geometry; |
|
26 |
} |
|
27 |
public PGgeometry getGeometryObject() { |
|
28 |
return geometry.getGeometry(); |
|
29 |
} |
|
30 |
|
|
31 |
public void setGeometry(Object geometry) { |
|
32 |
this.geometry.setGeometry(geometry); |
|
33 |
} |
|
34 |
public String getName() { |
|
35 |
return name; |
|
36 |
} |
|
37 |
public void setName(String name) { |
|
38 |
this.name = name; |
|
39 |
} |
|
40 |
} |
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/callejero/modelo/BoundingBox.java | ||
---|---|---|
1 |
package es.logex.callejero.modelo; |
|
2 |
|
|
3 |
public class BoundingBox { |
|
4 |
|
|
5 |
private double[] lowersBoundingBox; |
|
6 |
private double[] uppersBoundingBox; |
|
7 |
private String crsBoundingBox; //en formato epsg.xml#XXXXX donde XXXXX=SRID |
|
8 |
|
|
9 |
public BoundingBox() { |
|
10 |
|
|
11 |
} |
|
12 |
public BoundingBox(double[] lowersBoundingBox,double[] uppersBoundingBox,String crsBoundingBox){ |
|
13 |
this.crsBoundingBox = crsBoundingBox; |
|
14 |
this.lowersBoundingBox = lowersBoundingBox; |
|
15 |
this.uppersBoundingBox = uppersBoundingBox; |
|
16 |
} |
|
17 |
|
|
18 |
public BoundingBox(Double[] lowersBoundingBox,Double[] uppersBoundingBox,String crsBoundingBox){ |
|
19 |
this.crsBoundingBox = crsBoundingBox; |
|
20 |
this.lowersBoundingBox = new double[2]; |
|
21 |
for (int i = 0; i < lowersBoundingBox.length; i++){ |
|
22 |
this.lowersBoundingBox[i] = (double)lowersBoundingBox[i]; |
|
23 |
} |
|
24 |
|
|
25 |
this.uppersBoundingBox = new double[2]; |
|
26 |
for (int j = 0; j < uppersBoundingBox.length; j++){ |
|
27 |
this.uppersBoundingBox[j] = (double)uppersBoundingBox[j]; |
|
28 |
} |
|
29 |
} |
|
30 |
|
|
31 |
public String getCrsBoundingBox() { |
|
32 |
return crsBoundingBox; |
|
33 |
} |
|
34 |
|
|
35 |
public void setCrsBoundingBox(String crsBoundingBox) { |
|
36 |
this.crsBoundingBox = crsBoundingBox; |
|
37 |
} |
|
38 |
|
|
39 |
public double[] getLowersBoundingBox() { |
|
40 |
return lowersBoundingBox; |
|
41 |
} |
|
42 |
public void setLowersBoundingBox(double[] lowersBoundingBox) { |
|
43 |
this.lowersBoundingBox = lowersBoundingBox; |
|
44 |
} |
|
45 |
public double[] getUppersBoundingBox() { |
|
46 |
return uppersBoundingBox; |
|
47 |
} |
|
48 |
public void setUppersBoundingBox(double[] uppersBoundingBox) { |
|
49 |
this.uppersBoundingBox = uppersBoundingBox; |
|
50 |
} |
|
51 |
|
|
52 |
public String toString(){ |
|
53 |
return "(" + this.lowersBoundingBox[0] + " " + this.lowersBoundingBox[1] + "," + |
|
54 |
this.uppersBoundingBox[0] + " " + this.uppersBoundingBox[1] + ")"; |
|
55 |
} |
|
56 |
|
|
57 |
/*** |
|
58 |
* Devuelve el SRID del bounding box. |
|
59 |
* @throws Exception |
|
60 |
* |
|
61 |
*/ |
|
62 |
public String getSRID() throws Exception { |
|
63 |
int index = this.crsBoundingBox.lastIndexOf("#"); //para formatos epsg.xml# |
|
64 |
if (index > 0 && index < this.crsBoundingBox.length() -1) { |
|
65 |
return this.crsBoundingBox.substring(index +1 , this.crsBoundingBox.length()); |
|
66 |
} else { |
|
67 |
index = this.crsBoundingBox.lastIndexOf(":"); |
|
68 |
if (index > 0 && index < this.crsBoundingBox.length() -1) |
|
69 |
return this.crsBoundingBox.substring(index +1 , this.crsBoundingBox.length()); |
|
70 |
|
|
71 |
} |
|
72 |
throw new Exception("El formato del sistema de referencia no es OGC compliant(ejemplo: epsg.xml#23030)"); |
|
73 |
} |
|
74 |
} |
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/callejero/modelo/DataElement.java | ||
---|---|---|
1 |
package es.logex.callejero.modelo; |
|
2 |
|
|
3 |
public class DataElement { |
|
4 |
|
|
5 |
private String name; |
|
6 |
private String value; |
|
7 |
|
|
8 |
public DataElement(String name, String value){ |
|
9 |
setName(name); |
|
10 |
setValue(value); |
|
11 |
} |
|
12 |
|
|
13 |
public String getName() { |
|
14 |
return name; |
|
15 |
} |
|
16 |
public void setName(String name) { |
|
17 |
this.name = name; |
|
18 |
} |
|
19 |
public String getValue() { |
|
20 |
return value; |
|
21 |
} |
|
22 |
public void setValue(String value) { |
|
23 |
this.value = value; |
|
24 |
} |
|
25 |
|
|
26 |
} |
|
27 |
|
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/callejero/modelo/GeometryElement.java | ||
---|---|---|
1 |
package es.logex.callejero.modelo; |
|
2 |
|
|
3 |
import org.postgis.PGgeometry; |
|
4 |
|
|
5 |
public class GeometryElement { |
|
6 |
|
|
7 |
private String name; |
|
8 |
|
|
9 |
public String getName() { |
|
10 |
return name; |
|
11 |
} |
|
12 |
|
|
13 |
public void setName(String name) { |
|
14 |
this.name = name; |
|
15 |
} |
|
16 |
|
|
17 |
private PGgeometry geometry; |
|
18 |
|
|
19 |
public PGgeometry getGeometry() { |
|
20 |
return geometry; |
|
21 |
} |
|
22 |
|
|
23 |
public void setGeometry(PGgeometry geometry) { |
|
24 |
this.geometry = geometry; |
|
25 |
} |
|
26 |
|
|
27 |
public void setGeometry(Object geometry) { |
|
28 |
this.geometry = (PGgeometry) geometry; |
|
29 |
} |
|
30 |
} |
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/callejero/exceptions/LayerBoundingBoxNulo.java | ||
---|---|---|
1 |
package es.logex.callejero.exceptions; |
|
2 |
|
|
3 |
public class LayerBoundingBoxNulo extends Exception { |
|
4 |
|
|
5 |
/** |
|
6 |
* |
|
7 |
*/ |
|
8 |
private static final long serialVersionUID = -5106823702548439322L; |
|
9 |
|
|
10 |
public LayerBoundingBoxNulo() { |
|
11 |
super(); |
|
12 |
// TODO Auto-generated constructor stub |
|
13 |
} |
|
14 |
|
|
15 |
/** |
|
16 |
* DOCUMENT ME! |
|
17 |
* |
|
18 |
* @param message |
|
19 |
*/ |
|
20 |
public LayerBoundingBoxNulo(String message) { |
|
21 |
super(message); |
|
22 |
|
|
23 |
// TODO Auto-generated constructor stub |
|
24 |
} |
|
25 |
|
|
26 |
/** |
|
27 |
* DOCUMENT ME! |
|
28 |
* |
|
29 |
* @param message |
|
30 |
* @param cause |
|
31 |
*/ |
|
32 |
public LayerBoundingBoxNulo(String message, Throwable cause) { |
|
33 |
super(message, cause); |
|
34 |
|
|
35 |
// TODO Auto-generated constructor stub |
|
36 |
} |
|
37 |
|
|
38 |
/** |
|
39 |
* DOCUMENT ME! |
|
40 |
* |
|
41 |
* @param cause |
|
42 |
*/ |
|
43 |
public LayerBoundingBoxNulo(Throwable cause) { |
|
44 |
super(cause); |
|
45 |
|
|
46 |
// TODO Auto-generated constructor stub |
|
47 |
} |
|
48 |
} |
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/callejero/exceptions/LayerConnectionNula.java | ||
---|---|---|
1 |
package es.logex.callejero.exceptions; |
|
2 |
|
|
3 |
public class LayerConnectionNula extends Exception{ |
|
4 |
|
|
5 |
/** |
|
6 |
* |
|
7 |
*/ |
|
8 |
private static final long serialVersionUID = 3961618904459405883L; |
|
9 |
|
|
10 |
public LayerConnectionNula() { |
|
11 |
super(); |
|
12 |
// TODO Auto-generated constructor stub |
|
13 |
} |
|
14 |
|
|
15 |
/** |
|
16 |
* DOCUMENT ME! |
|
17 |
* |
|
18 |
* @param message |
|
19 |
*/ |
|
20 |
public LayerConnectionNula(String message) { |
|
21 |
super(message); |
|
22 |
|
|
23 |
// TODO Auto-generated constructor stub |
|
24 |
} |
|
25 |
|
|
26 |
/** |
|
27 |
* DOCUMENT ME! |
|
28 |
* |
|
29 |
* @param message |
|
30 |
* @param cause |
|
31 |
*/ |
|
32 |
public LayerConnectionNula(String message, Throwable cause) { |
|
33 |
super(message, cause); |
|
34 |
|
|
35 |
// TODO Auto-generated constructor stub |
|
36 |
} |
|
37 |
|
|
38 |
/** |
|
39 |
* DOCUMENT ME! |
|
40 |
* |
|
41 |
* @param cause |
|
42 |
*/ |
|
43 |
public LayerConnectionNula(Throwable cause) { |
|
44 |
super(cause); |
|
45 |
|
|
46 |
// TODO Auto-generated constructor stub |
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
} |
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/callejero/exceptions/CallejeroGPEErrorHandler.java | ||
---|---|---|
1 |
package es.logex.callejero.exceptions; |
|
2 |
|
|
3 |
import org.gvsig.gpe.GPEErrorHandler; |
|
4 |
|
|
5 |
public class CallejeroGPEErrorHandler extends GPEErrorHandler { |
|
6 |
|
|
7 |
} |
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/callejero/core/Callejero.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package es.logex.callejero.core; |
|
5 |
|
|
6 |
import java.awt.geom.Rectangle2D; |
|
7 |
import java.sql.Connection; |
|
8 |
import java.sql.ResultSet; |
|
9 |
import java.sql.SQLException; |
|
10 |
import java.sql.Statement; |
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.List; |
|
13 |
|
|
14 |
import org.apache.commons.logging.Log; |
|
15 |
import org.apache.commons.logging.LogFactory; |
|
16 |
import org.postgis.PGbox2d; |
|
17 |
|
|
18 |
import es.logex.callejero.modelo.BoundingBox; |
|
19 |
|
|
20 |
/* logEx. Lógica Extrema s.l.* |
|
21 |
* Copyright (C) 2007 Lógica Extrema and Generalitat Valenciana. |
|
22 |
* |
|
23 |
* This program is free software; you can redistribute it and/or |
|
24 |
* modify it under the terms of the GNU General Public License |
|
25 |
* as published by the Free Software Foundation; either version 2 |
|
26 |
* of the License, or (at your option) any later version. |
|
27 |
* |
|
28 |
* This program is distributed in the hope that it will be useful, |
|
29 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
30 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
31 |
* GNU General Public License for more details. |
|
32 |
* |
|
33 |
* You should have received a copy of the GNU General Public License |
|
34 |
* along with this program; if not, write to the Free Software |
|
35 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
36 |
* |
|
37 |
* For more information, contact: |
|
38 |
* |
|
39 |
* Generalitat Valenciana |
|
40 |
* Conselleria d'Infraestructures i Transport |
|
41 |
* Av. Blasco Ibañez, 50 |
|
42 |
* 46010 VALENCIA |
|
43 |
* SPAIN |
|
44 |
* |
|
45 |
* +34 963862235 |
|
46 |
* gvsig@gva.es |
|
47 |
* www.gvsig.gva.es |
|
48 |
* |
|
49 |
* or |
|
50 |
* |
|
51 |
* Lógica Extrema s.l. |
|
52 |
* Avda. Cortes Valencianas |
|
53 |
* 46015 Valencia |
|
54 |
* Spain |
|
55 |
* |
|
56 |
* logic@logex.es |
|
57 |
*/ |
|
58 |
|
|
59 |
/** |
|
60 |
* @author kike |
|
61 |
* |
|
62 |
*/ |
|
63 |
public class Callejero implements ICallejero { |
|
64 |
|
|
65 |
Log log = LogFactory.getLog(this.getClass()); |
|
66 |
|
|
67 |
private static List<String> municipios = new ArrayList<String>(); |
|
68 |
public Connection conn = null; |
|
69 |
|
|
70 |
public Callejero(Connection conn) { |
|
71 |
this.conn = conn; |
|
72 |
} |
|
73 |
|
|
74 |
private ResultSet EjecutaSql(String query) { |
|
75 |
ResultSet r= null; |
|
76 |
|
|
77 |
try { |
|
78 |
if(log.isDebugEnabled()) |
|
79 |
{ |
|
80 |
log.debug("Executing SQL:" + query); |
|
81 |
} |
|
82 |
Statement s = conn.createStatement(); |
|
83 |
r = s.executeQuery(query); |
|
84 |
|
|
85 |
}catch (Exception e){ |
|
86 |
log.error(e.getMessage()); |
|
87 |
} |
|
88 |
|
|
89 |
return r; |
|
90 |
} |
|
91 |
|
|
92 |
/*** |
|
93 |
* Devuelve una lista de candidatos a partir de un municipio, calle, número |
|
94 |
* |
|
95 |
*/ |
|
96 |
public List<String> getCandidatos(String municipio, String calle, String numero) { |
|
97 |
String candMunicipio = null; |
|
98 |
if (municipio == null) |
|
99 |
candMunicipio = ""; |
|
100 |
else |
|
101 |
candMunicipio = municipio; |
|
102 |
|
|
103 |
String candCalle = null; |
|
104 |
if (calle == null) |
|
105 |
candCalle = ""; |
|
106 |
else |
|
107 |
candCalle = calle; |
|
108 |
|
|
109 |
String candNumero = null; |
|
110 |
if (numero == null) |
|
111 |
candNumero = ""; |
|
112 |
else |
|
113 |
candNumero = numero; |
|
114 |
|
|
115 |
String query = null; |
|
116 |
ResultSet r = null; |
|
117 |
List<String> lista = new ArrayList<String>(); |
|
118 |
|
|
119 |
log.debug("Decidir query en función de parámetros "); |
|
120 |
|
|
121 |
if ( !candMunicipio.equals("")) { //hay municipio |
|
122 |
if (candCalle.equals("")) { //municipio sin calle |
|
123 |
/*query = "select municipio as texto_candidato,LogexLevenshtein('" + candMunicipio.toUpperCase() + |
|
124 |
"',municipio) , extent from candidatos_extent where calle isnull order by LogexLevenshtein('" + |
|
125 |
candMunicipio.toUpperCase() + "',municipio) ASC LIMIT 10";*/ |
|
126 |
query = "select municipio as texto_candidato,Levenshtein('" + candMunicipio.toUpperCase() + |
|
127 |
"',municipio) , extent from candidatos_extent where calle isnull order by Levenshtein('" + |
|
128 |
candMunicipio.toUpperCase() + "',municipio) ASC LIMIT 10"; |
|
129 |
} else { //municipio con calle |
|
130 |
query = "select municipio || ' - ' ||calle as texto_candidato,LogexLevenshtein('" + candCalle.toUpperCase() + |
|
131 |
"',calle), Levenshtein('" + candMunicipio.toUpperCase() +"',municipio), extent " + |
|
132 |
" from candidatos_extent order by LogexLevenshtein('" + candCalle.toUpperCase() + "',calle) + " + |
|
133 |
" Levenshtein('" + candMunicipio.toUpperCase() + "',municipio) ASC LIMIT 10"; |
|
134 |
} |
|
135 |
} else { //solo calle |
|
136 |
if (!candCalle.equals("")) { |
|
137 |
query = "select municipio || ' - ' ||calle as texto_candidato,LogexLevenshtein('" + candCalle.toUpperCase() + |
|
138 |
"',calle) , extent from candidatos_extent order by LogexLevenshtein('" + |
|
139 |
candCalle.toUpperCase() + "',calle) ASC LIMIT 10"; |
|
140 |
} |
|
141 |
|
|
142 |
} |
|
143 |
|
|
144 |
if (query == null) |
|
145 |
return lista; |
|
146 |
|
|
147 |
log.debug("Ejecutar query " + query); |
|
148 |
r = this.EjecutaSql(query); |
|
149 |
String text; |
|
150 |
BoundingBox extent = new BoundingBox(); |
|
151 |
|
|
152 |
try { |
|
153 |
while (r.next()) { |
|
154 |
PGbox2d pgBox = new PGbox2d(r.getString("extent")); |
|
155 |
|
|
156 |
double[] lowers = {pgBox.getLLB().x, pgBox.getLLB().y}; |
|
157 |
double[] uppers = {pgBox.getURT().x, pgBox.getURT().y}; |
|
158 |
extent.setLowersBoundingBox(lowers); |
|
159 |
extent.setUppersBoundingBox(uppers); |
|
160 |
|
|
161 |
lista.add(r.getString("texto_candidato") + "#$" + extent.toString()); |
|
162 |
} |
|
163 |
} catch (SQLException e) { |
|
164 |
log.error(e.getMessage(),e); |
|
165 |
|
|
166 |
} finally{ |
|
167 |
if(r!=null) |
|
168 |
{ |
|
169 |
try { |
|
170 |
r.close(); |
|
171 |
} catch (SQLException e) { |
|
172 |
log.error(e.getMessage(),e); |
|
173 |
} |
|
174 |
} |
|
175 |
} |
|
176 |
return lista; |
|
177 |
|
|
178 |
} |
|
179 |
|
|
180 |
|
|
181 |
/** |
|
182 |
* Devuelve una lista con los nombres de todos los municipios de la base de datos |
|
183 |
* |
|
184 |
* @return una lista de municipios |
|
185 |
*/ |
|
186 |
public List<String> getMunicipios() { |
|
187 |
ResultSet r = null; |
|
188 |
try{ |
|
189 |
if (this.municipios.isEmpty() ) { |
|
190 |
log.debug("Municipios vacío. Se llena por primera vez"); |
|
191 |
|
|
192 |
r = this.EjecutaSql("select * from municipios"); |
|
193 |
while (r.next()) { |
|
194 |
municipios.add(r.getString("ine_denomina")); |
|
195 |
} |
|
196 |
|
|
197 |
log.debug("Añadidos " + r.getRow() + "municipios a Callejero.municipios"); |
|
198 |
} |
|
199 |
|
|
200 |
|
|
201 |
}catch (Exception e) { |
|
202 |
log.error(e.getMessage(),e); |
|
203 |
} |
|
204 |
finally{ |
|
205 |
if(r!=null) |
|
206 |
{ |
|
207 |
try { |
|
208 |
r.close(); |
|
209 |
} catch (SQLException e) { |
|
210 |
// TODO Auto-generated catch block |
|
211 |
e.printStackTrace(); |
|
212 |
} |
|
213 |
} |
|
214 |
} |
|
215 |
return municipios; |
|
216 |
} |
|
217 |
|
|
218 |
/** |
|
219 |
* Dado el nombre de un municipio devuelve los 10 mejores |
|
220 |
* candidatos. Si se encuentra un municipio con el mismo nombre |
|
221 |
* sólo se devuelve el municipio encontrado. |
|
222 |
*/ |
|
223 |
public List<String> getMunicipiosLV(String municipio){ |
|
224 |
ResultSet r = null; |
|
225 |
List<String> retMunis = new ArrayList<String>(); |
|
226 |
try{ |
|
227 |
|
|
228 |
|
|
229 |
r = this.EjecutaSql("select distinct ine_denomina, levenshtein(upper('"+municipio+ |
|
230 |
"'),upper(BUSQUEDA)) from municipios order by levenshtein(upper('"+municipio+ |
|
231 |
"'),upper(BUSQUEDA)) asc LIMIT 10"); |
|
232 |
while (r.next()) { |
|
233 |
retMunis.add(r.getString("ine_denomina")); |
|
234 |
} |
|
235 |
|
|
236 |
}catch (Exception e) { |
|
237 |
log.error(e.getMessage(),e); |
|
238 |
} |
|
239 |
finally{ |
|
240 |
if(r!=null) |
|
241 |
{ |
|
242 |
try { |
|
243 |
r.close(); |
|
244 |
} catch (SQLException e) { |
|
245 |
// TODO Auto-generated catch block |
|
246 |
e.printStackTrace(); |
|
247 |
} |
|
248 |
} |
|
249 |
} |
|
250 |
return retMunis; |
|
251 |
// LevenshteinDistance lv = new LevenshteinDistance();; |
|
252 |
// List<String> lista = new ArrayList<String>(); |
|
253 |
// |
|
254 |
// return lv.getTopX(municipio, getMunicipios(),10); |
|
255 |
|
|
256 |
} |
|
257 |
|
|
258 |
/** |
|
259 |
* Devuelve el mapa con sus layers, cada layer tendrá su gmldocument |
|
260 |
*/ |
|
261 |
public IMap getMapFromExtent(BoundingBox box) { |
|
262 |
IMap map = null; |
|
263 |
|
|
264 |
return map; |
|
265 |
} |
|
266 |
|
|
267 |
/** |
|
268 |
* Devuelve el extent máximo de la capa especificada. Quizás debería estar en un package de utils... |
|
269 |
* y devolver los máximos... |
|
270 |
* @return |
|
271 |
* @throws Exception |
|
272 |
*/ |
|
273 |
public Rectangle2D getMaxExtent(String layerName) throws Exception{ |
|
274 |
ResultSet r = null; |
|
275 |
Statement s = null; |
|
276 |
PGbox2d pgBox = null; |
|
277 |
|
|
278 |
try { |
|
279 |
s = conn.createStatement(); |
|
280 |
r = s.executeQuery("SELECT EXTENT(the_GEOM) as bbox FROM " + layerName); |
|
281 |
|
|
282 |
if (r.next() ) { |
|
283 |
pgBox = (PGbox2d) r.getObject("bbox"); |
|
284 |
} |
|
285 |
|
|
286 |
Rectangle2D rec = new Rectangle2D.Double(pgBox.getLLB().x,pgBox.getLLB().y, |
|
287 |
pgBox.getURT().x-pgBox.getLLB().x, pgBox.getURT().y-pgBox.getLLB().y) ; |
|
288 |
return rec; |
|
289 |
|
|
290 |
} catch (SQLException e) { |
|
291 |
// TODO Auto-generated catch block |
|
292 |
e.printStackTrace(); |
|
293 |
throw e; |
|
294 |
} |
|
295 |
} |
|
296 |
|
|
297 |
public ArrayList<String> getLayerList() { |
|
298 |
ArrayList<String> list = new ArrayList<String>(); |
|
299 |
|
|
300 |
return list; |
|
301 |
} |
|
302 |
} |
|
303 |
|
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/callejero/core/GMLProducer.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package es.logex.callejero.core; |
|
5 |
|
|
6 |
import java.io.File; |
|
7 |
import java.io.OutputStream; |
|
8 |
import java.util.List; |
|
9 |
|
|
10 |
import org.apache.commons.logging.Log; |
|
11 |
import org.apache.commons.logging.LogFactory; |
|
12 |
import org.gvsig.gpe.GPEErrorHandler; |
|
13 |
import org.gvsig.gpe.GPERegister; |
|
14 |
import org.gvsig.gpe.writers.GPEWriterHandler; |
|
15 |
import org.postgis.Geometry; |
|
16 |
import org.postgis.LineString; |
|
17 |
import org.postgis.MultiLineString; |
|
18 |
import org.postgis.MultiPolygon; |
|
19 |
import org.postgis.PGgeometry; |
|
20 |
import org.postgis.Point; |
|
21 |
import org.postgis.Polygon; |
|
22 |
|
|
23 |
import es.logex.callejero.exceptions.CallejeroGPEErrorHandler; |
|
24 |
import es.logex.callejero.modelo.BoundingBox; |
|
25 |
import es.logex.callejero.modelo.DataElement; |
|
26 |
import es.logex.callejero.modelo.GeometryElement; |
|
27 |
import es.logex.utils.ConvertUtils; |
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
/** |
|
32 |
* @author kike |
|
33 |
* |
|
34 |
*/ |
|
35 |
public class GMLProducer { |
|
36 |
|
|
37 |
/*private String filename = "FILETEMP"; |
|
38 |
private GPEWriterHandler writerHandler = null; |
|
39 |
private GPEContentHandler contenHandler = null; |
|
40 |
private GPEErrorHandler errorHandler = null; |
|
41 |
private GPEParser parser = null; |
|
42 |
private File outputFile = null;*/ |
|
43 |
|
|
44 |
private String outputFileName = ""; |
|
45 |
private GPEWriterHandler writer = null; |
|
46 |
private String writerName = "GML writer"; |
|
47 |
private GPEErrorHandler errorHandler; |
|
48 |
|
|
49 |
private String outPath = null; |
|
50 |
ILayer layer = null; |
|
51 |
Long i = 0L; |
|
52 |
|
|
53 |
Log log = LogFactory.getLog(this.getClass()); |
|
54 |
|
|
55 |
public GMLProducer(ILayer _layer,String outPath){ |
|
56 |
|
|
57 |
log.debug("Constructor donde se rellenan los valores del writer"); |
|
58 |
this.outPath = outPath; |
|
59 |
this.layer = _layer; |
|
60 |
|
|
61 |
//GPEDefaults.setProperty(GPEDefaults.DEFAULT_FILE_NAME, outputFileName); |
|
62 |
//GPEDefaults.setProperty(GPEDefaults.XSD_SCHEMA_FILE, schema); |
|
63 |
//GPEDefaults.setProperty(GPEDefaults.COORDINATES_SEPARATOR, GPEDefaults.DEFAULT_BLANC_SPACE); |
|
64 |
//GPEDefaults.setProperty(GPEDefaults.DECIMAL, ) |
|
65 |
|
|
66 |
try{ |
|
67 |
//Register the writer |
|
68 |
GPERegister.addGpeWriterHandler(writerName,"Writer de GML hasta la versión 2.1", |
|
69 |
org.gvsig.gpe.gml.writer.GPEGmlv2WriterHandlerImplementor.class); |
|
70 |
|
|
71 |
//Gets the writer |
|
72 |
writer = GPERegister.createWriter(writerName); |
|
73 |
errorHandler = new CallejeroGPEErrorHandler(); |
|
74 |
writer.setErrorHandler(errorHandler); |
|
75 |
|
|
76 |
this.outputFileName = this.outPath + File.separatorChar + System.currentTimeMillis() + "_"+ layer.getName() + ".gml"; |
|
77 |
writer.setFileName(outputFileName); |
|
78 |
|
|
79 |
log.debug("Ok. El writer está creado"); |
|
80 |
|
|
81 |
} catch (Exception e){ |
|
82 |
log.error("Error inicializando el writer"); |
|
83 |
log.error(e.getMessage()); |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
public void writeHeadGmlFile() throws Throwable { |
|
90 |
|
|
91 |
try { |
|
92 |
//this.crs = layer.getExtent().getCrsBoundingBox(); |
|
93 |
|
|
94 |
// si no tenemos esquema, que ponga el nombre de la capa.xsd |
|
95 |
/*if (schema=="") { |
|
96 |
GPEDefaults.setProperty(GPEDefaults.XSD_SCHEMA_FILE, layer.getName() + ".xsd"); |
|
97 |
}*/ |
|
98 |
/*if (outputFileName == "") { |
|
99 |
GPEDefaults.setProperty(GPEDefaults.DEFAULT_FILE_NAME, layer.getName()); |
|
100 |
}*/ |
|
101 |
|
|
102 |
writer.initialize(); |
|
103 |
|
|
104 |
writer.startLayer("1", layer.getName(), layer.getDescription(),null ,null); |
|
105 |
|
|
106 |
|
|
107 |
BoundingBox box = layer.getExtent(); |
|
108 |
double xb[] = {box.getLowersBoundingBox()[0],box.getUppersBoundingBox()[0]} ; |
|
109 |
double yb[] = {box.getLowersBoundingBox()[1],box.getUppersBoundingBox()[1]} ; |
|
110 |
double[] emptyZ = new double[2]; |
|
111 |
|
|
112 |
writer.startBbox("box" ,xb, yb, emptyZ, box.getCrsBoundingBox()); |
|
113 |
writer.endBbox(); |
|
114 |
|
|
115 |
} finally { |
|
116 |
if (errorHandler.getErrorsSize() > 0) { |
|
117 |
throw new Throwable(errorHandler.getErrorAt(0)); |
|
118 |
} |
|
119 |
} |
|
120 |
} |
|
121 |
|
|
122 |
public void writeStartFeature() throws Throwable{ |
|
123 |
try { |
|
124 |
i+=1; |
|
125 |
writer.startFeature("f" + i,layer.getName(),null); |
|
126 |
} finally { |
|
127 |
if (errorHandler.getErrorsSize() > 0) { |
|
128 |
throw new Throwable(errorHandler.getErrorAt(0)); |
|
129 |
} |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
public void writeGeomElement(GeometryElement geomElement) throws Throwable{ |
|
134 |
try { |
|
135 |
|
|
136 |
PGgeometry geom = geomElement.getGeometry(); |
|
137 |
if (geomElement != null) { |
|
138 |
|
|
139 |
writer.startElement(geomElement.getName(), null , null); |
|
140 |
|
|
141 |
switch (geom.getGeoType()) { |
|
142 |
case Geometry.MULTIPOLYGON: |
|
143 |
MultiPolygon multip = (MultiPolygon) geom.getGeometry(); |
|
144 |
writer.startMultiPolygon(Long.toString(i),null); |
|
145 |
|
|
146 |
for (Polygon p : multip.getPolygons() ) { |
|
147 |
///TODO: No seguir si tiene más de un anillo. |
|
148 |
//extraer en arrays las coordenadas |
|
149 |
double[] x = new double[p.numPoints()]; |
|
150 |
double[] y = new double[p.numPoints()]; |
|
151 |
double[] z = new double[p.numPoints()]; |
|
152 |
|
|
153 |
ConvertUtils.ConvertCoordinatesToXYZ(p, x, y, z); |
|
154 |
|
|
155 |
writer.startPolygon("p" + i, x, y, z,null); |
|
156 |
writer.endPolygon(); |
|
157 |
|
|
158 |
} |
|
159 |
writer.endMultiPolygon(); |
|
160 |
writer.endElement(); |
|
161 |
|
|
162 |
break; |
|
163 |
|
|
164 |
case Geometry.MULTILINESTRING: |
|
165 |
MultiLineString multil = (MultiLineString) geom.getGeometry(); |
|
166 |
writer.startMultiLineString(Long.toString(i),null); |
|
167 |
|
|
168 |
for (LineString ls : multil.getLines()) { |
|
169 |
double[] x = new double[ls.numPoints()]; |
|
170 |
double[] y = new double[ls.numPoints()]; |
|
171 |
double[] z = new double[ls.numPoints()]; |
|
172 |
|
|
173 |
ConvertUtils.ConvertCoordinatesToXYZ(ls, x, y, z); |
|
174 |
|
|
175 |
writer.startLineString("l" + i, x, y, z, null); |
|
176 |
writer.endLineString(); |
|
177 |
} |
|
178 |
writer.endMultiLineString(); |
|
179 |
writer.endElement(); |
|
180 |
|
|
181 |
break; |
|
182 |
|
|
183 |
case Geometry.POINT: |
|
184 |
Point p = (Point) geom.getGeometry(); |
|
185 |
|
|
186 |
writer.startPoint("l" + i, p.x, p.y, p.z, null); |
|
187 |
writer.endPoint(); |
|
188 |
|
|
189 |
writer.endElement(); |
|
190 |
//writer.endFeature(); |
|
191 |
break; |
|
192 |
|
|
193 |
default: |
|
194 |
break; |
|
195 |
} |
|
196 |
} |
|
197 |
} finally { |
|
198 |
if (errorHandler.getErrorsSize() > 0) { |
|
199 |
throw new Throwable(errorHandler.getErrorAt(0)); |
|
200 |
} |
|
201 |
} |
|
202 |
} |
|
203 |
|
|
204 |
public void writeEndFeature() throws Throwable{ |
|
205 |
try { |
|
206 |
writer.endFeature(); |
|
207 |
} finally { |
|
208 |
if (errorHandler.getErrorsSize() > 0) { |
|
209 |
throw new Throwable(errorHandler.getErrorAt(0)); |
|
210 |
} |
|
211 |
} |
|
212 |
} |
|
213 |
|
|
214 |
public void writeDataElement(List<DataElement> listData) throws Throwable{ |
|
215 |
try { |
|
216 |
for (DataElement de : listData) { |
|
217 |
writer.startElement(de.getName(), (Object)de.getValue(), null); |
|
218 |
writer.endElement(); |
|
219 |
} |
|
220 |
} finally { |
|
221 |
if (errorHandler.getErrorsSize() > 0) { |
|
222 |
throw new Throwable(errorHandler.getErrorAt(0)); |
|
223 |
} |
|
224 |
} |
|
225 |
} |
|
226 |
|
|
227 |
public void writeEndGmlFile() throws Throwable{ |
|
228 |
try { |
|
229 |
writer.endLayer(); |
|
230 |
writer.close(); |
|
231 |
} finally { |
|
232 |
if (errorHandler.getErrorsSize() > 0) { |
|
233 |
throw new Throwable(errorHandler.getErrorAt(0)); |
|
234 |
} |
|
235 |
} |
|
236 |
} |
|
237 |
|
|
238 |
public File getFile() { |
|
239 |
return writer.getOutputFile(); |
|
240 |
} |
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
} |
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/callejero/core/ILayer.java | ||
---|---|---|
1 |
package es.logex.callejero.core; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import es.logex.callejero.modelo.*; |
|
6 |
|
|
7 |
public interface ILayer { |
|
8 |
|
|
9 |
public BoundingBox getExtent(); |
|
10 |
|
|
11 |
public void setExtent(BoundingBox box); |
|
12 |
|
|
13 |
public String getCrs(); |
|
14 |
|
|
15 |
public void setCrs(String crs); |
|
16 |
|
|
17 |
public String getName(); |
|
18 |
/** |
|
19 |
* @return la lista de las features. |
|
20 |
*/ |
|
21 |
public List<Feature> getListFeature(); |
|
22 |
|
|
23 |
public String getDescription(); |
|
24 |
|
|
25 |
public void fillFromDb() throws Throwable; |
|
26 |
///public void setName(String name); |
|
27 |
//public Document getDocument(); |
|
28 |
// public void setExtent(BoundingBox box); |
|
29 |
//public void setListFeature(List<Feature> listFeature); |
|
30 |
public String getFileName(); |
|
31 |
|
|
32 |
public void setFileName(String fileName) throws Throwable; |
|
33 |
} |
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/callejero/core/IMap.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package es.logex.callejero.core; |
|
5 |
|
|
6 |
import es.logex.callejero.modelo.*; |
|
7 |
import java.util.*; |
|
8 |
|
|
9 |
/** |
|
10 |
* @author kike |
|
11 |
* |
|
12 |
*/ |
|
13 |
|
|
14 |
public interface IMap { |
|
15 |
|
|
16 |
/** |
|
17 |
* Rellena todas las capas del mapa generando para cada una su documento gml. |
|
18 |
* @throws Throwable |
|
19 |
*/ |
|
20 |
public void fillLayers() throws Throwable; |
|
21 |
/** |
|
22 |
* Especifica el extent del mapa así como su crs. |
|
23 |
* @param box |
|
24 |
*/ |
|
25 |
public void setExtent(BoundingBox box); |
|
26 |
/** |
|
27 |
* Recupera el box del mapa. |
|
28 |
* @return |
|
29 |
*/ |
|
30 |
public BoundingBox getExtent(); |
|
31 |
/** |
|
32 |
* Devuelve una lista de Layers |
|
33 |
*/ |
|
34 |
public List<ILayer> getLayers(); |
|
35 |
|
|
36 |
} |
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/callejero/core/ICallejero.java | ||
---|---|---|
1 |
package es.logex.callejero.core; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import es.logex.callejero.modelo.*; |
|
6 |
|
|
7 |
public interface ICallejero { |
|
8 |
|
|
9 |
public List<String> getMunicipios(); |
|
10 |
public List<String> getMunicipiosLV(String municipio); |
|
11 |
public IMap getMapFromExtent(BoundingBox box); |
|
12 |
|
|
13 |
} |
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/callejero/core/LayerFile.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package es.logex.callejero.core; |
|
5 |
|
|
6 |
import java.awt.geom.Rectangle2D; |
|
7 |
import java.io.File; |
|
8 |
import java.sql.Connection; |
|
9 |
import java.sql.ResultSet; |
|
10 |
import java.sql.ResultSetMetaData; |
|
11 |
import java.sql.SQLException; |
|
12 |
import java.sql.Statement; |
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
import org.apache.commons.logging.Log; |
|
17 |
import org.apache.commons.logging.LogFactory; |
|
18 |
import org.postgis.PGbox2d; |
|
19 |
|
|
20 |
import es.logex.callejero.modelo.BoundingBox; |
|
21 |
import es.logex.callejero.modelo.DataElement; |
|
22 |
import es.logex.callejero.modelo.Feature; |
|
23 |
import es.logex.callejero.modelo.GeometryElement; |
|
24 |
|
|
25 |
/** |
|
26 |
* @author kike |
|
27 |
* |
|
28 |
*/ |
|
29 |
public class LayerFile implements ILayer { |
|
30 |
|
|
31 |
private String name; |
|
32 |
|
|
33 |
private String description; |
|
34 |
|
|
35 |
private String fileName = ""; |
|
36 |
|
|
37 |
protected Connection conn = null; |
|
38 |
private BoundingBox box; |
|
39 |
|
|
40 |
Log log = LogFactory.getLog(this.getClass()); |
|
41 |
|
|
42 |
GMLProducer gmlProducer = null; |
|
43 |
|
|
44 |
private String crs; |
|
45 |
|
|
46 |
private String detailLevel = null; |
|
47 |
|
|
48 |
/* |
|
49 |
* constructor a partir del nombre y el extent |
|
50 |
*/ |
|
51 |
public LayerFile(String name, Connection conn, String inputDetailLevel, String outputPath) { |
|
52 |
log.info("Constructor LayerFile = " + name ); |
|
53 |
|
|
54 |
// TODO: No hacer nada en el constructor. Implentar el patrón lazy, o |
|
55 |
// cargar la capa explícitamente |
|
56 |
this.conn = conn; |
|
57 |
this.name = name; |
|
58 |
this.detailLevel = inputDetailLevel; |
|
59 |
|
|
60 |
gmlProducer = new GMLProducer(this,outputPath); |
|
61 |
} |
|
62 |
|
|
63 |
public BoundingBox getExtent() { |
|
64 |
return this.box; |
|
65 |
} |
|
66 |
|
|
67 |
public void setExtent(BoundingBox box) { |
|
68 |
this.box = box; |
|
69 |
} |
|
70 |
/* |
|
71 |
* (non-Javadoc) |
|
72 |
* |
|
73 |
* @see es.logex.callejero.core.ILayer#getName() |
|
74 |
*/ |
|
75 |
public String getName() { |
|
76 |
return name; |
|
77 |
} |
|
78 |
|
|
79 |
public List<Feature> getListFeature() { |
|
80 |
return null; |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* Construye una lista con el nombre de los campos de una tabla |
|
85 |
* |
|
86 |
* @param tabla |
|
87 |
* @return su lista de campos |
|
88 |
*/ |
|
89 |
@SuppressWarnings("unused") |
|
90 |
private List<String> getFieldsName(String tabla) throws Throwable { |
|
91 |
|
|
92 |
Statement st = null; |
|
93 |
ResultSet rs = null; |
|
94 |
// array with fields |
|
95 |
List<String> arrayFields = new ArrayList<String>(); |
|
96 |
|
|
97 |
try { |
|
98 |
// To obtain the fields |
|
99 |
String query = "select * from " + tabla + " LIMIT 1;"; |
|
100 |
|
|
101 |
st = conn.createStatement(); |
|
102 |
|
|
103 |
log.debug("Se va a ejecutar la siguiente sentencia : \n" + query); |
|
104 |
rs = st.executeQuery(query); |
|
105 |
|
|
106 |
ResultSetMetaData rsmd = rs.getMetaData(); |
|
107 |
|
|
108 |
for (int i = 0; i < arrayFields.size() + 1; i++) { |
|
109 |
if (!rsmd.getColumnName(i + 1).equalsIgnoreCase("the_geom")) { |
|
110 |
arrayFields.add(rsmd.getColumnName(i + 1)); |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
} catch (SQLException e) { |
|
115 |
log.error("Error obteniendo nombres de campos para la tabla " |
|
116 |
+ tabla); |
|
117 |
log.error(e.getMessage()); |
|
118 |
throw e; |
|
119 |
} |
|
120 |
|
|
121 |
log.debug("Campos de la tabla/capa " + tabla); |
|
122 |
for (String s : arrayFields) { |
|
123 |
log.debug("\n " + s); |
|
124 |
} |
|
125 |
return arrayFields; |
|
126 |
} |
|
127 |
|
|
128 |
private String getSrsTable(String tableName) throws Exception { |
|
129 |
// se podría averiguar el srs de la tabla de dos formas. |
|
130 |
// 1. Consultando en la tabla geometry_elements |
|
131 |
// 2. consultando el srs de una geometría de la tabla, ya que todas van |
|
132 |
// a ser iguales. |
|
133 |
// Quizás esta segunda evita la posible "descoordinación" entre las dos |
|
134 |
// tablas. |
|
135 |
ResultSet r = null; |
|
136 |
Statement s = null; |
|
137 |
try { |
|
138 |
s = conn.createStatement(); |
|
139 |
|
|
140 |
String query = "SELECT SRID(the_geom) as srsTable FROM " + tableName + " LIMIT 1 "; |
|
141 |
|
|
142 |
r = s.executeQuery(query); |
|
143 |
|
|
144 |
if ( r.next()) { |
|
145 |
return r.getString("srsTable"); |
|
146 |
} else { |
|
147 |
throw new Exception("Las geometrías de la tabla " + tableName + " no tienen sistema de referencia"); |
|
148 |
} |
|
149 |
} finally { |
|
150 |
try { |
|
151 |
if (r != null) |
|
152 |
r.close(); |
|
153 |
if (s !=null) |
|
154 |
s.close(); |
|
155 |
|
|
156 |
} catch (SQLException e2) { |
|
157 |
log.error("Error cerrando recordsets " + this.getName()); |
|
158 |
log.error(e2.getMessage()); |
|
159 |
throw e2; |
|
160 |
} |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
/* |
|
165 |
* (non-Javadoc) |
|
166 |
* |
|
167 |
* @see es.logex.callejero.core.IDBFeatureExtractor#exec(es.logex.callejero.modelo.BoundingBox, |
|
168 |
* es.logex.callejero.core.ILayer) |
|
169 |
*/ |
|
170 |
public File FromDbToFile(BoundingBox newExtent) throws Throwable { |
|
171 |
|
|
172 |
ResultSet r = null; |
|
173 |
ResultSetMetaData rmd = null; |
|
174 |
Statement s = null; |
|
175 |
|
|
176 |
String query = null; |
|
177 |
|
|
178 |
try { |
|
179 |
|
|
180 |
this.box = transformBBox(newExtent, this.name); |
|
181 |
|
|
182 |
s = conn.createStatement(); |
|
183 |
String srsTable = getSrsTable(this.getName()); |
|
184 |
|
|
185 |
//TODO: Afinar el comportamiento del detailLevel |
|
186 |
if (detailLevel.equalsIgnoreCase("SAMPLE")) { |
|
187 |
//En el caso de detailLeve="SAMPLE" no restringimos por bbox la selección de elementos |
|
188 |
//y leemos el primer elemento que exista en la tabla. OJO!!!! y si no hay elementos en la tabla? |
|
189 |
//TODO: Crear un comportamiento razonable para cuando no haya elementos en la tabla. |
|
190 |
query = "SELECT * FROM " + this.getName() + " LIMIT 1"; |
|
191 |
} else { |
|
192 |
query = "SELECT * FROM " + this.getName() + " WHERE the_geom " |
|
193 |
+ " && TRANSFORM(SETSRID('BOX3D" |
|
194 |
+ newExtent.toString() + "'::box3d," |
|
195 |
+newExtent.getSRID() + ")," + srsTable + ") "; |
|
196 |
} |
|
197 |
|
|
198 |
log.info("Preparado para ejecutar el query : " + query); |
|
199 |
r = s.executeQuery(query); |
|
200 |
|
|
201 |
rmd = r.getMetaData(); |
|
202 |
|
|
203 |
log.debug("Se van a recuperar las features"); |
|
204 |
|
|
205 |
gmlProducer.writeHeadGmlFile(); |
|
206 |
|
|
207 |
while (r.next()) { |
|
208 |
|
|
209 |
List<DataElement> ldata = new ArrayList<DataElement>(); |
|
210 |
GeometryElement geomElement = new GeometryElement(); |
|
211 |
|
|
212 |
for (int t = 1; t <= rmd.getColumnCount(); t++) { |
|
213 |
String columnName = rmd.getColumnName(t); |
|
214 |
if (columnName.equals("the_geom")) {// TODO: Ojo,habría que |
|
215 |
// leer el nombre del |
|
216 |
// campo de la tabla de |
|
217 |
// geometry_columns. |
|
218 |
geomElement.setName(columnName); |
|
219 |
geomElement.setGeometry(r.getObject("the_geom")); |
|
220 |
} // TODO: En realidad una feature podría tener más de una |
|
221 |
// geometría asociada, habría que currárselo con una |
|
222 |
// lista(ya, un poco exagerado pero....). |
|
223 |
else { |
|
224 |
ldata.add(new DataElement(columnName, r |
|
225 |
.getString(columnName))); |
|
226 |
} |
|
227 |
} |
|
228 |
|
|
229 |
gmlProducer.writeStartFeature(); |
|
230 |
|
|
231 |
if (ldata.size() > 0) { |
|
232 |
gmlProducer.writeDataElement(ldata); |
|
233 |
} |
|
234 |
if (geomElement != null) { |
|
235 |
gmlProducer.writeGeomElement(geomElement); |
|
236 |
} |
|
237 |
|
|
238 |
gmlProducer.writeEndFeature(); |
|
239 |
} |
|
240 |
|
|
241 |
gmlProducer.writeEndGmlFile(); |
|
242 |
|
|
243 |
return gmlProducer.getFile(); |
|
244 |
|
|
245 |
} catch (SQLException sqle) { |
|
246 |
log.error("Error ejecutando sql\n " + query + "\n " |
|
247 |
+ " para la capa " + this.getName()); |
|
248 |
log.error(sqle.getMessage()); |
|
249 |
throw sqle; |
|
250 |
} finally { |
|
251 |
try { |
|
252 |
if (r != null) |
|
253 |
r.close(); |
|
254 |
if (s != null) |
|
255 |
s.close(); |
|
256 |
|
|
257 |
} catch (SQLException e2) { |
|
258 |
log.error("Error cerrando recordsets " + this.getName()); |
|
259 |
log.error(e2.getMessage()); |
|
260 |
throw e2; |
|
261 |
} |
|
262 |
} |
|
263 |
|
|
264 |
} |
|
265 |
|
|
266 |
private BoundingBox transformBBox(BoundingBox newExtent, String layerName) throws Exception { |
|
267 |
ResultSet r = null; |
|
268 |
Statement s = null; |
|
269 |
PGbox2d pgBox = null; |
|
270 |
String srsTable; |
|
271 |
try { |
|
272 |
|
|
273 |
srsTable = getSrsTable(layerName); |
|
274 |
|
|
275 |
s = conn.createStatement(); |
|
276 |
String query = "SELECT EXTENT(the_GEOM) as bbox FROM " + layerName + " where the_geom && TRANSFORM(SETSRID('BOX3D" + newExtent.toString() + "'::box3d,"+ newExtent.getSRID() + ")," + srsTable + ")"; |
|
277 |
//String query = "SELECT EXTENT(the_geom) as bbox FROM municipios_geom where the_geom && SETSRID('BOX(626673.9375 4191040,815708.0625 4519371)'::box2d,23030)"; |
|
278 |
log.debug("query transFormBBox : " + query); |
|
279 |
|
|
280 |
r = s.executeQuery(query); |
|
281 |
|
|
282 |
if (r.next() ) |
|
283 |
pgBox = (PGbox2d) r.getObject("bbox"); |
|
284 |
else |
|
285 |
return null; |
|
286 |
|
|
287 |
Rectangle2D rec = null; |
|
288 |
|
|
289 |
if (pgBox == null) { |
|
290 |
rec = new Rectangle2D.Double(0.0,0.0,0.0,0.0); |
|
291 |
} else { |
|
292 |
rec = new Rectangle2D.Double(pgBox.getLLB().x,pgBox.getLLB().y, |
|
293 |
pgBox.getURT().x-pgBox.getLLB().x, pgBox.getURT().y-pgBox.getLLB().y) ; |
|
294 |
} |
|
295 |
Double[] lowers = {rec.getMinX(), rec.getMinY()}; |
|
296 |
Double[] uppers = {rec.getMaxX(), rec.getMaxY()}; |
|
297 |
BoundingBox box = new BoundingBox(lowers, uppers, "EPSG:" + srsTable ); |
|
298 |
|
|
299 |
return box; |
|
300 |
|
|
301 |
} catch (SQLException e) { |
|
302 |
// TODO Auto-generated catch block |
|
303 |
e.printStackTrace(); |
|
304 |
throw e; |
|
305 |
} finally { |
|
306 |
try { |
|
307 |
if (r != null) |
|
308 |
r.close(); |
|
309 |
if (s != null) |
|
310 |
s.close(); |
|
311 |
|
|
312 |
} catch (SQLException e2) { |
|
313 |
log.error("Error cerrando recordsets " + this.getName()); |
|
314 |
log.error(e2.getMessage()); |
|
315 |
throw e2; |
|
316 |
} |
|
317 |
} |
|
318 |
} |
|
319 |
|
|
320 |
public String getDescription() { |
|
321 |
return description; |
|
322 |
} |
|
323 |
|
|
324 |
public void setDescription(String description) { |
|
325 |
this.description = description; |
|
326 |
} |
|
327 |
|
|
328 |
public String getFileName() { |
|
329 |
return fileName; |
|
330 |
} |
|
331 |
|
|
332 |
public void setFileName(String fileName) { |
|
333 |
this.fileName = fileName; |
|
334 |
} |
|
335 |
|
|
336 |
public void fillFromDb() throws Throwable { |
|
337 |
// TODO Auto-generated method stub |
|
338 |
throw new Throwable("Método no implementado"); |
|
339 |
} |
|
340 |
|
|
341 |
|
|
342 |
public String getCrs() { |
|
343 |
return this.crs; |
|
344 |
} |
|
345 |
|
|
346 |
|
|
347 |
public void setCrs(String crs) { |
|
348 |
this.crs = crs; |
|
349 |
} |
|
350 |
} |
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/utils/LevenshteinElement.java | ||
---|---|---|
1 |
package es.logex.utils; |
|
2 |
|
|
3 |
public class LevenshteinElement implements Comparable<LevenshteinElement> { |
|
4 |
protected final int distance; |
|
5 |
protected final String name; |
|
6 |
|
|
7 |
public LevenshteinElement(int distance, String name) { |
|
8 |
this.distance = distance; |
|
9 |
this.name = name; |
|
10 |
} |
|
11 |
|
|
12 |
public int compareTo(LevenshteinElement that) { |
|
13 |
return (distance < that.distance) ? -1 |
|
14 |
: (distance > that.distance) ? 1 |
|
15 |
: 0; |
|
16 |
} |
|
17 |
|
|
18 |
public boolean equals(Object obj) { |
|
19 |
return (obj instanceof LevenshteinElement) ? (compareTo((LevenshteinElement)obj) == 0) : false; |
|
20 |
} |
|
21 |
|
|
22 |
public int hashCode() { |
|
23 |
return distance; |
|
24 |
} |
|
25 |
} |
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/utils/LevenshteinDistance.java | ||
---|---|---|
1 |
package es.logex.utils; |
|
2 |
|
|
3 |
import java.util.*; |
|
4 |
|
|
5 |
|
|
6 |
/** |
|
7 |
* Se llama Distancia de Levenshtein o distancia de edición el número mínimo de |
|
8 |
* operaciones requeridas para transformar una cadena de caracteres en otra. |
|
9 |
* Se entiende por operación, bien una inserción, eliminación o la substitución |
|
10 |
* de un carácter |
|
11 |
* @author kike |
|
12 |
*/ |
|
13 |
public class LevenshteinDistance { |
|
14 |
|
|
15 |
static int maxDistance = 32000; |
|
16 |
|
|
17 |
private static int minimum(int a, int b, int c) { |
|
18 |
if(a<=b && a<=c) |
|
19 |
return a; |
|
20 |
if(b<=a && b<=c) |
|
21 |
return b; |
|
22 |
return c; |
|
23 |
} |
|
24 |
|
|
25 |
public static int computeLevenshteinDistance(String str1, String str2) { |
|
26 |
return computeLevenshteinDistance(str1.toCharArray(), |
|
27 |
str2.toCharArray()); |
|
28 |
} |
|
29 |
|
|
30 |
private static int computeLevenshteinDistance(char [] str1, char [] str2) { |
|
31 |
int [][]distance = new int[str1.length+1][]; |
|
32 |
|
|
33 |
for(int i=0;i<=str1.length;i++) |
|
34 |
{ |
|
35 |
distance[i]=new int[str2.length+1]; |
|
36 |
distance[i][0]=i; |
|
37 |
} |
|
38 |
for(int j=0;j<str2.length+1;j++) |
|
39 |
distance[0][j]=j; |
|
40 |
|
|
41 |
for(int i=1;i<=str1.length;i++) |
|
42 |
for(int j=1;j<=str2.length;j++) |
|
43 |
distance[i][j]= minimum(distance[i-1][j]+1, |
|
44 |
distance[i][j-1]+1, |
|
45 |
distance[i-1][j-1]+ |
|
46 |
((str1[i-1]==str2[j-1])?0:1)); |
|
47 |
|
|
48 |
return distance[str1.length][str2.length]; |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* Devuelve una lista con los 10 elementos de la lista más cercanos a la cadena |
|
53 |
* de entrada. |
|
54 |
* @param cadena |
|
55 |
* @param lista |
|
56 |
* @return |
|
57 |
*/ |
|
58 |
public List<String> getTopX(String cadena, List<String> lista,int x) { |
|
59 |
List<String> outputList = new ArrayList<String>(); |
|
60 |
|
|
61 |
if (cadena == null || lista == null ) { |
|
62 |
return outputList; |
|
63 |
} |
|
64 |
|
|
65 |
if (lista.isEmpty() || cadena.trim() == ""){ |
|
66 |
return outputList; |
|
67 |
} |
|
68 |
|
|
69 |
if (x <= 0) { |
|
70 |
return outputList; |
|
71 |
} |
|
72 |
|
|
73 |
LevenshteinElement lve = new LevenshteinElement(maxDistance, ""); |
|
74 |
LevenshteinElement[] outputArray = new LevenshteinElement[x]; |
|
75 |
|
|
76 |
for (int i = 0; i < x; i++) { |
|
77 |
outputArray[i] = lve; |
|
78 |
} |
|
79 |
|
|
80 |
for (String s : lista){ |
|
81 |
|
|
82 |
if (s.equalsIgnoreCase(cadena)) { |
|
83 |
outputList.clear(); |
|
84 |
outputList.add(cadena); |
|
85 |
break; |
|
86 |
} |
|
87 |
|
|
88 |
LevenshteinElement lv = new LevenshteinElement(computeLevenshteinDistance(cadena.toUpperCase(), s.toUpperCase()),s.toUpperCase()); |
|
89 |
|
|
90 |
for (int i = 0; i < x ; i++) { |
|
91 |
if (lv.distance < outputArray[i].distance){ |
|
92 |
outputArray[i] = lv; |
|
93 |
break; |
|
94 |
} |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
//Si no está vacía quiere decir que ha encontrado |
|
99 |
//la cadena exacta en la lista |
|
100 |
if (outputList.isEmpty()) { |
|
101 |
for (int i = 0; i < x; i++) { |
|
102 |
if (outputArray[i].name != null) { |
|
103 |
outputList.add(outputArray[i].name); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
} |
|
108 |
|
|
109 |
return outputList; |
|
110 |
} |
|
111 |
} |
tmp/trunk/servidor/WPS_Callejero_Server/Callejero/src/es/logex/utils/logexXml.java | ||
---|---|---|
1 |
package es.logex.utils; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import javax.xml.parsers.DocumentBuilder; |
|
6 |
import javax.xml.parsers.DocumentBuilderFactory; |
|
7 |
import javax.xml.parsers.ParserConfigurationException; |
|
8 |
|
|
9 |
import org.w3c.dom.Document; |
Also available in: Unified diff