svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libGeocoding / src / org / gvsig / geocoding / result / impl / GeomMatchResult.java @ 28375
History | View | Annotate | Download (4.97 KB)
1 | 27904 | vsanjaime | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2008 Prodevelop S.L. main development
|
||
26 | */
|
||
27 | |||
28 | package org.gvsig.geocoding.result.impl; |
||
29 | |||
30 | import java.awt.Color; |
||
31 | import java.util.ArrayList; |
||
32 | import java.util.List; |
||
33 | |||
34 | import org.gvsig.fmap.geom.Geometry; |
||
35 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
36 | import org.gvsig.fmap.mapcontext.rendering.symbols.SimpleMarkerSymbol; |
||
37 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory; |
||
38 | import org.gvsig.geocoding.address.Address; |
||
39 | import org.gvsig.geocoding.result.GeocodingResult; |
||
40 | import org.gvsig.geocoding.result.ScoredFeature; |
||
41 | |||
42 | |||
43 | //
|
||
44 | /**
|
||
45 | 28375 | vsanjaime | * Implementation with the results of geocoding process. It has the geometry of the
|
46 | 27904 | vsanjaime | * geocoding position and the features related. This objects are stored in a
|
47 | * TreeSet the best to worst quality.
|
||
48 | *
|
||
49 | * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
||
50 | * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
|
||
51 | */
|
||
52 | |||
53 | public class GeomMatchResult implements GeocodingResult, |
||
54 | Comparable<GeomMatchResult> {
|
||
55 | |||
56 | private List<List<ScoredFeature>> sources = new ArrayList<List<ScoredFeature>>(); private Geometry geom = null; |
||
57 | private Address address;
|
||
58 | |||
59 | /**
|
||
60 | * Get address
|
||
61 | *
|
||
62 | * @return address
|
||
63 | */
|
||
64 | public Address getAddress() {
|
||
65 | return this.address; |
||
66 | } |
||
67 | |||
68 | /**
|
||
69 | * Get geometry
|
||
70 | *
|
||
71 | * @return geom
|
||
72 | */
|
||
73 | public Geometry getGeometry() {
|
||
74 | return geom;
|
||
75 | } |
||
76 | |||
77 | /**
|
||
78 | * Get the score. return the first score of the main list of scored feature
|
||
79 | *
|
||
80 | * @return score
|
||
81 | */
|
||
82 | public double getScore() { |
||
83 | return sources.get(0).get(0).getScore(); |
||
84 | } |
||
85 | |||
86 | /**
|
||
87 | * Get list of the scored features related with this result
|
||
88 | *
|
||
89 | * @return
|
||
90 | */
|
||
91 | public List<List<ScoredFeature>> getSources() { |
||
92 | return sources;
|
||
93 | } |
||
94 | |||
95 | /**
|
||
96 | * Get main source list
|
||
97 | *
|
||
98 | * @return source
|
||
99 | */
|
||
100 | public List<ScoredFeature> getMainSources() { |
||
101 | return sources.get(0); |
||
102 | } |
||
103 | |||
104 | /**
|
||
105 | * get second source list
|
||
106 | *
|
||
107 | * @return source
|
||
108 | */
|
||
109 | public List<ScoredFeature> getSecondSources() { |
||
110 | if (sources.size() == 2) { |
||
111 | return sources.get(1); |
||
112 | } |
||
113 | return null; |
||
114 | } |
||
115 | |||
116 | /**
|
||
117 | * get third source list
|
||
118 | *
|
||
119 | * @return source
|
||
120 | */
|
||
121 | public List<ScoredFeature> getThirdSources() { |
||
122 | if (sources.size() == 3) { |
||
123 | return sources.get(2); |
||
124 | } |
||
125 | return null; |
||
126 | } |
||
127 | |||
128 | /**
|
||
129 | * Set the list of list with scored features
|
||
130 | *
|
||
131 | * @param sources
|
||
132 | */
|
||
133 | public void setSources(List<List<ScoredFeature>> sources) { |
||
134 | this.sources = sources;
|
||
135 | } |
||
136 | |||
137 | /**
|
||
138 | * Set main source list
|
||
139 | *
|
||
140 | * @param source
|
||
141 | */
|
||
142 | public void setMainSources(List<ScoredFeature> source) { |
||
143 | this.sources.add(0, source); |
||
144 | } |
||
145 | |||
146 | /**
|
||
147 | * Set second source list
|
||
148 | *
|
||
149 | * @param source
|
||
150 | */
|
||
151 | public void setSecondSources(List<ScoredFeature> source) { |
||
152 | this.sources.add(1, source); |
||
153 | } |
||
154 | |||
155 | /**
|
||
156 | * Set third source list
|
||
157 | *
|
||
158 | * @param source
|
||
159 | */
|
||
160 | public void setThirdSources(List<ScoredFeature> source) { |
||
161 | this.sources.add(2, source); |
||
162 | } |
||
163 | |||
164 | /**
|
||
165 | * Get geometry
|
||
166 | *
|
||
167 | * @return
|
||
168 | */
|
||
169 | public Geometry getGeom() {
|
||
170 | return geom;
|
||
171 | } |
||
172 | |||
173 | /**
|
||
174 | * Set geometry (point) of the result
|
||
175 | *
|
||
176 | * @param geom
|
||
177 | */
|
||
178 | public void setGeom(Geometry geom) { |
||
179 | this.geom = geom;
|
||
180 | } |
||
181 | |||
182 | /**
|
||
183 | * Compare to other result
|
||
184 | */
|
||
185 | public int compareTo(GeomMatchResult gmres) { |
||
186 | |||
187 | double score = gmres.getScore();
|
||
188 | if (this.getScore() > score) { |
||
189 | return -1; |
||
190 | } else if (this.getScore() < score) { |
||
191 | return 1; |
||
192 | } else {
|
||
193 | Address adr = this.getAddress();
|
||
194 | if (adr != null) { |
||
195 | return adr.compareTo(gmres.getAddress());
|
||
196 | } else {
|
||
197 | return 1; |
||
198 | } |
||
199 | } |
||
200 | } |
||
201 | |||
202 | /**
|
||
203 | * Set address
|
||
204 | *
|
||
205 | * @param address
|
||
206 | */
|
||
207 | public void setAddress(Address address) { |
||
208 | this.address = address;
|
||
209 | } |
||
210 | |||
211 | /**
|
||
212 | * Get shape to draw result position on gvSIG view
|
||
213 | *
|
||
214 | * @return
|
||
215 | */
|
||
216 | public ISymbol getSymbolPosition() {
|
||
217 | |||
218 | SimpleMarkerSymbol symbol = (SimpleMarkerSymbol) SymbologyFactory |
||
219 | .createDefaultMarkerSymbol(); |
||
220 | symbol.setStyle(SimpleMarkerSymbol.CIRCLE_STYLE); |
||
221 | symbol.setSize(4);
|
||
222 | symbol.setColor(Color.RED);
|
||
223 | return symbol;
|
||
224 | } |
||
225 | |||
226 | } |