Revision 27064 branches/v2_0_0_prep/libraries/libGeocoding/src/org/gvsig/geocoding/geommatches/MatcherUtils.java

View differences:

MatcherUtils.java
1
/* 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

  
1 28
package org.gvsig.geocoding.geommatches;
2 29

  
3 30
import java.awt.geom.PathIterator;
......
21 48
import com.vividsolutions.jts.linearref.LengthIndexedLine;
22 49
import com.vividsolutions.jts.operation.overlay.OverlayOp;
23 50

  
51
/**
52
 * This class has the utilities to work with geometries and search th geocoding
53
 * point
54
 * 
55
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
56
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
57
 */
58

  
24 59
public class MatcherUtils {
25 60

  
26
	private static final Logger log = LoggerFactory.getLogger(MatcherUtils.class);
61
	private static final Logger log = LoggerFactory
62
			.getLogger(MatcherUtils.class);
27 63

  
28 64
	/**
29 65
	 * Get internal point from one geometry (polygon)
30 66
	 * 
31 67
	 * @param geomGV
32
	 *            (gvSIG geometry)
33 68
	 * @return
34 69
	 */
35 70
	public static Point2D internalPointGeometry(Geometry geomGV) {
......
39 74
			com.vividsolutions.jts.geom.Point pto = geomJTS.getInteriorPoint();
40 75
			return new Point2D(pto.getX(), pto.getY());
41 76
		}
42
		log.error("Centroid point null ......");
77
		log.debug("Internal Point NULL ......");
43 78
		return null;
44 79
	}
45 80

  
46 81
	/**
82
	 * parse geometries of gvSIG model to JTS model
47 83
	 * 
48 84
	 * @param geoms
49
	 * @return
85
	 *            list of gvSIG geometries
86
	 * @return list of JTS geometries
50 87
	 */
51 88
	public static List<com.vividsolutions.jts.geom.Geometry> parseGeomsGVToJTS(
52 89
			List<Geometry> geoms) {
......
60 97
			}
61 98
			return list;
62 99
		} else {
100
			log.debug("List of geometries is NULL  ......");
63 101
			return null;
64 102
		}
65 103
	}
66 104

  
67 105
	/**
106
	 * Parse one gvSIG geomerty to JTS geometry
68 107
	 * 
69
	 * @param geoms
70
	 * @return
108
	 * @param geom
109
	 *            gvSIG geometry
110
	 * @return JTS geometry
71 111
	 */
72 112
	public static com.vividsolutions.jts.geom.Geometry parseGeomGVToJTS(
73 113
			Geometry geom) {
......
77 117
					.geometryToJts(geom);
78 118
			return ge;
79 119
		} else {
120
			log.debug("Geometry is NULL  ......");
80 121
			return null;
81 122
		}
82 123
	}
83 124

  
84 125
	/**
126
	 * parse a list of gvSIG geometries to JTS geometries
85 127
	 * 
86 128
	 * @param geoms
129
	 *            list gvSIG geometries to JTS geometries
87 130
	 * @return
88 131
	 */
89 132
	public static List<Geometry> parseGeomsJTSToGV(
......
97 140
			}
98 141
			return list;
99 142
		} else {
143
			log.debug("List of geometries is NULL  ......");
100 144
			return null;
101 145
		}
102 146
	}
103 147

  
104 148
	/**
149
	 * Parse a gvSIG geometry to JTS geometry
105 150
	 * 
106
	 * @param geoms
107
	 * @return
151
	 * @param geom
152
	 *            gvSIg geometry
153
	 * @return JTS geometry
108 154
	 */
109 155
	public static Geometry parseGeomJTSToGV(
110 156
			com.vividsolutions.jts.geom.Geometry geom) {
......
112 158
			Geometry ge = Converter.jtsToGeometry(geom);
113 159
			return ge;
114 160
		} else {
161
			log.debug("Geometry is NULL  ......");
115 162
			return null;
116 163
		}
117 164
	}
......
120 167
	 * This method intersect two lines and return the intersection point. If
121 168
	 * result is null, two lines doesn't intersect
122 169
	 * 
123
	 * @param geometriesJts
170
	 * @param geom1Jts
171
	 * @param geom2Jts
124 172
	 * @return
125 173
	 */
126 174
	public static Point2D intersectTwoLinesJTS(
......
130 178
		com.vividsolutions.jts.geom.Geometry interBBoxJTS = null;
131 179
		com.vividsolutions.jts.geom.Geometry geomPointJTS = null;
132 180

  
133
		if (geom1Jts != null || geom2Jts != null) {
134
			log.debug("Intersect: Two geometries not nulls");
181
		if (geom1Jts != null && geom2Jts != null) {
135 182

  
136 183
			interBBoxJTS = OverlayOp.overlayOp(geom1Jts.getEnvelope(), geom2Jts
137 184
					.getEnvelope(), OverlayOp.INTERSECTION);
......
145 192
					log.debug("Intersect: Intersect in the point X= "
146 193
							+ geomPointJTS.getCoordinate().x + " Y= "
147 194
							+ geomPointJTS.getCoordinate().y);
148
					Point2D pto = new Point2D(geomPointJTS.getCoordinate().x,geomPointJTS.getCoordinate().y);
195
					Point2D pto = new Point2D(geomPointJTS.getCoordinate().x,
196
							geomPointJTS.getCoordinate().y);
149 197
					return pto;
150 198
				} else {
151 199
					log.debug("Intersect: Two lines don't intersect");
......
156 204
				return null;
157 205
			}
158 206
		}
207
		log.debug("Some Geometries are NULL  ......");
159 208
		return null;
160 209
	}
161 210

  
162 211
	/**
163
	 * This method makes the union the geometries with one attribute common.
212
	 * This method does the union the lines geometries (Features) with a
213
	 * attribute common
164 214
	 * 
165
	 * @param geomsJts
215
	 * @param scoreFeats
166 216
	 * @return
167 217
	 */
168 218
	public static List<DissolveResult> dissolveLinesJTS(
......
176 226
			used[i] = false;
177 227
		}
178 228

  
179
		// None elemnts
229
		// None elements
180 230
		if (scoreFeats.size() == 0) {
181 231
			return null;
182 232
		}
......
221 271
					res.setJTSGeom(ge1);
222 272
					res.setScoredFeatures(feats);
223 273
				}
224

  
225 274
			}
226 275
		}
227

  
228 276
		return result;
229 277
	}
230 278

  
231 279
	/**
232
	 * This method makes the union the geometries with one attribute common.
280
	 * This method does the union the polygon geometries with a attribute
281
	 * common.
233 282
	 * 
234 283
	 * @param geomsJts
235 284
	 * @return
......
300 349
				}
301 350
			}
302 351
		}
303

  
304 352
		return result;
305 353
	}
306 354

  
307 355
	/**
308 356
	 * This method group geometries to one attribute
309 357
	 * 
310
	 * @param fieldPosition
311
	 *            position of the field with the attribute
358
	 * @param desc
312 359
	 * @param features
313
	 *            features collection
314 360
	 * @return
315 361
	 */
316 362
	public static HashMap<String, List<ScoredFeature>> groupScoredFeaturesByAttribute(
......
384 430
	}
385 431

  
386 432
	/**
387
	 * 
388 433
	 * This method calculates a point perpendicular to the line at a distance
389 434
	 * 
390 435
	 * @param inicio
391
	 *            initial point of the line
392 436
	 * @param fin
393
	 *            end point of the line
394 437
	 * @param linePoint
395
	 *            middle point over line
396 438
	 * @param dist
397
	 *            perpendicular distance to the line
398 439
	 * @return
399 440
	 */
400 441
	public static Point2D getPerpendicularPointFromLine(Point2D inicio,
......
421 462

  
422 463
	/**
423 464
	 * Calculate the position in the line with offset
424
	 * 
465
	 * @param geoms
425 466
	 * @param linePoint
426
	 *            middle point over the liner
427 467
	 * @param dist
428
	 *            perpendicular distance since the line
429 468
	 * @return
430 469
	 */
431 470
	public static Point2D getOffsetPosition(Geometry[] geoms,
......
451 490
				return MatcherUtils.getPerpendicularPointFromLine(inicio, fin,
452 491
						linePoint, dist);
453 492
			}
454

  
455 493
		}
456 494
		log.debug("Return original point without offset");
457 495
		return linePoint;

Also available in: Unified diff