Revision 27064

View differences:

branches/v2_0_0_prep/libraries/libGeocoding/src/org/gvsig/geocoding/geommatches/DoubleCrossLineMatcher.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

  
28
package org.gvsig.geocoding.geommatches;
29

  
30
import java.util.ArrayList;
31
import java.util.HashMap;
32
import java.util.Iterator;
33
import java.util.List;
34
import java.util.Map;
35

  
36
import org.gvsig.fmap.dal.feature.Feature;
37
import org.gvsig.fmap.geom.Geometry;
38
import org.gvsig.fmap.geom.primitive.Curve2D;
39
import org.gvsig.fmap.geom.util.Converter;
40

  
41
/**
42
 * 
43
 * This class gets the line between two lines
44
 * 
45
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
46
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
47
 * 
48
 */
49

  
50
public class DoubleCrossLineMatcher extends GeomMatcher {
51

  
52
	/**
53
	 * Search lines between two lines
54
	 */
55
	@SuppressWarnings("unchecked")
56
	public Curve2D[] match() {
57

  
58
		// Group first features collection
59
		HashMap geomstreets1 = groupFeaturesByAttribute(this
60
				.getGroupFieldPosition(), (List) this.getFeatures().get(0));
61
		List streets1 = new ArrayList();
62
		Iterator it1 = geomstreets1.entrySet().iterator();
63
		while (it1.hasNext()) {
64
			Map.Entry e = (Map.Entry) it1.next();
65
			ArrayList geomss = (ArrayList) e.getValue();
66
			// Insert geometries of one street into array
67
			Geometry[] arrGeoms = new Geometry[geomss.size()];
68
			for (int i = 0; i < geomss.size(); i++) {
69
				arrGeoms[i] = (Geometry) geomss.get(i);
70
			}
71
			// Parse geometries to JTS
72
			com.vividsolutions.jts.geom.Geometry[] geomsjts = parseGeomsToJTS(
73
					geomss.get(0).getClass(), arrGeoms);
74
			// Make the UNION of the all geometries with the same attribute
75
			com.vividsolutions.jts.geom.Geometry geomstreetjts1 = unionLinesJTS(geomsjts);
76
			streets1.add(geomstreetjts1);
77
		}
78
		// Group second features collection by one field
79
		HashMap geomstreets2 = groupFeaturesByAttribute(this
80
				.getGroupFieldPosition(), (List) this.getFeatures().get(1));
81
		List streets2 = new ArrayList();
82
		Iterator it2 = geomstreets2.entrySet().iterator();
83
		while (it2.hasNext()) {
84
			Map.Entry e = (Map.Entry) it2.next();
85
			ArrayList geomss = (ArrayList) e.getValue();
86
			// Insert geometries of one street into array
87
			Geometry[] arrGeoms = new Geometry[geomss.size()];
88
			for (int i = 0; i < geomss.size(); i++) {
89
				arrGeoms[i] = (Geometry) geomss.get(i);
90
			}
91
			// Parse geometries to JTS
92
			com.vividsolutions.jts.geom.Geometry[] geomsjts = parseGeomsToJTS(
93
					geomss.get(0).getClass(), arrGeoms);
94
			// Make the UNION of the all geometries with the same attribute
95
			com.vividsolutions.jts.geom.Geometry geomstreetjts2 = unionLinesJTS(geomsjts);
96
			streets2.add(geomstreetjts2);
97
		}
98
		// Group third features collection
99
		HashMap ppalstreets = groupFeaturesByAttribute(this
100
				.getGroupFieldPosition(), (List) this.getFeatures().get(2));
101
		List streets3 = new ArrayList();
102
		Iterator it3 = ppalstreets.entrySet().iterator();
103
		while (it3.hasNext()) {
104
			Map.Entry e = (Map.Entry) it3.next();
105
			ArrayList geomss = (ArrayList) e.getValue();
106
			// Insert geometries of one street into array
107
			Geometry[] arrGeoms = new Geometry[geomss.size()];
108
			for (int i = 0; i < geomss.size(); i++) {
109
				arrGeoms[i] = (Geometry) geomss.get(i);
110
			}
111
			// Parse geometries to JTS
112
			com.vividsolutions.jts.geom.Geometry[] geomsjts = parseGeomsToJTS(
113
					geomss.get(0).getClass(), arrGeoms);
114
			// Make the UNION of the all geometries with the same attribute
115
			com.vividsolutions.jts.geom.Geometry geomstreetjts3 = unionLinesJTS(geomsjts);
116
			streets3.add(geomstreetjts3);
117
		}
118

  
119
		// Intersect each main street with all streets of the second group, if
120
		// it intersects with some street proof with the intersection with
121
		// second streets group
122
		List geomStreets = new ArrayList();
123

  
124
		com.vividsolutions.jts.geom.Point[] segment = new com.vividsolutions.jts.geom.Point[2];
125

  
126
		for (int i = 0; i < streets3.size(); i++) {
127
			log.debug("STREET PPAL: " + i);
128
			com.vividsolutions.jts.geom.Geometry street3jts = (com.vividsolutions.jts.geom.Geometry) streets3
129
					.get(i);
130
			for (int j = 0; j < streets1.size(); j++) {
131
				log.debug("STREET: " + i + " SECUNDARY: " + j);
132
				com.vividsolutions.jts.geom.Geometry street1jts = (com.vividsolutions.jts.geom.Geometry) streets1
133
						.get(j);
134
				com.vividsolutions.jts.geom.Point pto = intersectTwoLinesJTS(
135
						street3jts, street1jts);
136
				if (pto != null) {
137
					for (int k = 0; k < streets2.size(); k++) {
138
						log.debug("STREET: " + i + " SECUNDARY: " + j
139
								+ " TERTIARY: " + k);
140
						com.vividsolutions.jts.geom.Geometry street2jts = (com.vividsolutions.jts.geom.Geometry) streets2
141
								.get(k);
142

  
143
						com.vividsolutions.jts.geom.Point pto2 = intersectTwoLinesJTS(
144
								street3jts, street2jts);
145
						if (pto2 != null) {
146
							segment[0] = pto;
147
							segment[1] = pto2;
148
							geomStreets.add(segment);
149
							log.debug("Segment added. Number: "
150
									+ geomStreets.size());
151
							log.debug("Segment x1= " + pto.getCoordinate().x
152
									+ " y1= " + pto.getCoordinate().y);
153
							log.debug("Segment x2= " + pto2.getCoordinate().x
154
									+ " y1= " + pto2.getCoordinate().y);
155
						}
156
					}
157
				}
158
			}
159
		}
160

  
161
		List ppalFeats = (List) getFeatures().get(2);
162
		List results = new ArrayList();
163

  
164
		Iterator it7 = ppalFeats.iterator();
165
		while (it7.hasNext()) {
166
			Feature fea = (Feature) it7.next();
167
			Geometry geomet = (Geometry) fea.getGeometry("GEOMETRY");
168
			Geometry[] ges = new Geometry[1];
169
			ges[0] = geomet;
170
			com.vividsolutions.jts.geom.Geometry[] jtsGeoms = parseGeomsToJTS(
171
					ges[0].getClass(), ges);
172
			for (int i = 0; i < jtsGeoms.length; i++) {
173
				for (int j = 0; j < geomStreets.size(); j++) {
174
					com.vividsolutions.jts.geom.Point[] ptos = (com.vividsolutions.jts.geom.Point[]) geomStreets
175
							.get(j);
176
					boolean cont1 = (jtsGeoms[i].intersects(ptos[0]));
177
					if (cont1) {
178
						boolean cont2 = jtsGeoms[i].intersects(ptos[1]);
179
						if (cont2) {
180
							results.add(fea);
181
						}
182
					}
183
				}
184
			}
185
		}
186

  
187
		Curve2D[] sublines = new Curve2D[results.size()];
188
		Geometry[] geome1 = new Geometry[1];
189
		Geometry geome = null;
190

  
191
		for (int i = 0; i < results.size(); i++) {
192

  
193
			geome = (Geometry) ((Feature) results.get(i))
194
					.getGeometry("GEOMETRY");
195

  
196
			geome1[0] = geome;
197
			com.vividsolutions.jts.geom.Geometry[] tempsJts = parseGeomsToJTS(
198
					geome1[0].getClass(), geome1);
199
			com.vividsolutions.jts.geom.Geometry tempgeom = unionLinesJTS(tempsJts);
200
			Geometry geometr = Converter.jtsToGeometry(tempgeom);
201
			sublines[i] = (Curve2D) geometr;
202

  
203
		}
204

  
205
		return sublines;
206
	}
207

  
208
}
branches/v2_0_0_prep/libraries/libGeocoding/src/org/gvsig/geocoding/geommatches/CrossLineMatcher.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

  
28
package org.gvsig.geocoding.geommatches;
29

  
30
import java.util.ArrayList;
31
import java.util.HashMap;
32
import java.util.HashSet;
33
import java.util.Iterator;
34
import java.util.List;
35
import java.util.Map;
36
import java.util.Set;
37

  
38

  
39
import org.gvsig.fmap.geom.Geometry;
40
import org.gvsig.fmap.geom.primitive.Point2D;
41
import org.slf4j.Logger;
42
import org.slf4j.LoggerFactory;
43

  
44
/**
45
 * This class searchs positions in cross lines (cross ways)
46
 * 
47
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
48
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
49
 * 
50
 */
51

  
52
public class CrossLineMatcher extends GeomMatcher {
53

  
54
	private Logger log = LoggerFactory.getLogger(CrossLineMatcher.class);
55

  
56
	/**
57
	 * Search the position in the cross lines
58
	 * 
59
	 * @return cross points
60
	 */
61

  
62
	@SuppressWarnings("unchecked")
63
	public Point2D[] match() {
64

  
65
		// Group first features collection by one field
66
		HashMap geomstreets1 = groupFeaturesByAttribute(this
67
				.getGroupFieldPosition(), (List) this.getFeatures().get(0));
68
		List streets1 = new ArrayList();
69
		Iterator itt1 = geomstreets1.entrySet().iterator();
70
		while (itt1.hasNext()) {
71
			Map.Entry e = (Map.Entry) itt1.next();
72
			ArrayList geomss1 = (ArrayList) e.getValue();
73
			// Insert geometries of one street into array
74
			Geometry[] arrGeoms1 = new Geometry[geomss1.size()];
75
			for (int i = 0; i < geomss1.size(); i++) {
76
				arrGeoms1[i] = (Geometry) geomss1.get(i);
77
			}
78
			// Parse geometries to JTS
79
			com.vividsolutions.jts.geom.Geometry[] geomsjts1 = parseGeomsToJTS(
80
					geomss1.get(0).getClass(), arrGeoms1);
81
			// Make the UNION of the all geometries with the same attribute
82
			com.vividsolutions.jts.geom.Geometry geomstreetjts1 = unionLinesJTS(geomsjts1);
83
			streets1.add(geomstreetjts1);
84
		}
85

  
86
		// Group second features collection by one field
87
		HashMap geomstreets2 = groupFeaturesByAttribute(this
88
				.getGroupFieldPosition(), (List) this.getFeatures().get(1));
89
		List streets2 = new ArrayList();
90
		Iterator itt2 = geomstreets2.entrySet().iterator();
91
		while (itt2.hasNext()) {
92
			Map.Entry e = (Map.Entry) itt2.next();
93
			ArrayList geomss = (ArrayList) e.getValue();
94
			// Insert geometries of one street into array
95
			Geometry[] arrGeoms = new Geometry[geomss.size()];
96
			for (int i = 0; i < geomss.size(); i++) {
97
				arrGeoms[i] = (Geometry) geomss.get(i);
98
			}
99
			// Parse geometries to JTS
100
			com.vividsolutions.jts.geom.Geometry[] geomsjts = parseGeomsToJTS(
101
					geomss.get(0).getClass(), arrGeoms);
102
			// Make the UNION of the all geometries with the same attribute
103
			com.vividsolutions.jts.geom.Geometry geomstreetjts = unionLinesJTS(geomsjts);
104
			streets2.add(geomstreetjts);
105
		}
106

  
107
		// Proof the intersection of geometries
108
		com.vividsolutions.jts.geom.Point pto = null;
109
		Set interPoints = new HashSet();
110
		for (int i = 0; i < streets1.size(); i++) {
111
			com.vividsolutions.jts.geom.Geometry geomJts1 = (com.vividsolutions.jts.geom.Geometry) streets1
112
					.get(i);
113
			for (int j = 0; j < streets2.size(); j++) {
114
				com.vividsolutions.jts.geom.Geometry geomJts2 = (com.vividsolutions.jts.geom.Geometry) streets2
115
						.get(j);
116

  
117
				pto = intersectTwoLinesJTS(geomJts1, geomJts2);
118
				if (pto != null) {
119
					log.debug("Intersecction point. X= " + pto.getX() + " Y= "
120
							+ pto.getY());
121
					interPoints.add(pto);
122
					log.debug("Point added ");
123
				} else {
124
					log.info("No intersection between two lines");
125
				}
126
				log.debug("-------------------");
127
			}
128
		}
129

  
130
		// Parse HashSet to Point2D Array
131
		Point2D[] points = new Point2D[interPoints.size()];
132
		Iterator itt5 = interPoints.iterator();
133
		int cont = 0;
134
		while (itt5.hasNext()) {
135
			com.vividsolutions.jts.geom.Point po = (com.vividsolutions.jts.geom.Point) itt5
136
					.next();
137
			points[cont] = new Point2D(po.getCoordinate().x,
138
					po.getCoordinate().y);
139
			cont++;
140
		}
141
		return points;
142
	}
143
}
branches/v2_0_0_prep/libraries/libGeocoding/src/org/gvsig/geocoding/geommatches/SimpleLineMatcher.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

  
28
package org.gvsig.geocoding.geommatches;
29

  
30
import java.awt.geom.PathIterator;
31
import java.util.ArrayList;
32
import java.util.HashMap;
33
import java.util.Iterator;
34
import java.util.List;
35
import java.util.Map;
36

  
37
import org.gvsig.fmap.dal.feature.Feature;
38
import org.gvsig.fmap.geom.Geometry;
39
import org.gvsig.fmap.geom.primitive.Curve2D;
40
import org.gvsig.fmap.geom.primitive.Point2D;
41
import org.gvsig.fmap.geom.util.UtilFunctions;
42

  
43
import com.vividsolutions.jts.geom.Coordinate;
44
import com.vividsolutions.jts.linearref.LengthIndexedLine;
45

  
46
/**
47
 * 
48
 * This class searchs positions over lines (ways)
49
 * 
50
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
51
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
52
 * 
53
 */
54
public class SimpleLineMatcher extends GeomMatcher {
55

  
56
	/**
57
	 * This method gets the position over lines (Streets) or next to the lines
58
	 * 
59
	 * @return
60
	 */
61
	@SuppressWarnings("unchecked")
62
	public Geometry[] match() {
63

  
64
		// Group the geometries by one field
65
		HashMap geomstreets1 = groupFeaturesByAttribute(this
66
				.getGroupFieldPosition(), (List) this.getFeatures().get(0));
67
		Iterator it = geomstreets1.entrySet().iterator();
68
		Point2D[] points = new Point2D[geomstreets1.size()];
69
		int position = 0;
70
		while (it.hasNext()) {
71
			Map.Entry e = (Map.Entry) it.next();
72
			ArrayList geomss = (ArrayList) e.getValue();
73
			// Insert geometries of one street into array
74
			Geometry[] arrGeoms = new Geometry[geomss.size()];
75
			for (int i = 0; i < geomss.size(); i++) {
76
				arrGeoms[i] = (Geometry) geomss.get(i);
77
			}
78
			// Parse geometries to JTS
79
			com.vividsolutions.jts.geom.Geometry[] geomsjts = parseGeomsToJTS(
80
					geomss.get(0).getClass(), arrGeoms);
81
			// Make the UNION of the all geometries with the same attribute
82
			com.vividsolutions.jts.geom.Geometry geomstreetjts = unionLinesJTS(geomsjts);
83

  
84
			// Get the point of the geometry (LINE)
85
			Point2D point = getLinesPosition(geomstreetjts, getParams());
86
			points[position] = point;
87
			position++;
88
		}
89

  
90
		return points;
91

  
92
	}
93

  
94
	/**
95
	 * Calculate the position inside sigle line
96
	 * 
97
	 * @param geometryJts
98
	 *            line of street
99
	 * @param params
100
	 *            Parameters to position the point over the lines
101
	 * @return
102
	 */
103
	private Point2D getLinesPosition(
104
			com.vividsolutions.jts.geom.Geometry geometryJts,
105
			MatchesParams params) {
106

  
107
		double totaldistance = geometryJts.getLength();
108
		LengthIndexedLine lenline = new LengthIndexedLine(geometryJts);
109

  
110
		Long distance = params.getDistance();
111
		Integer relativedist = params.getRelativeDistance();
112
		Double offset = params.getOffset();
113

  
114
		Coordinate coors = null;
115

  
116
		// first calculate with the distance
117
		if (distance != null) {
118

  
119
			if (lenline.isValidIndex(distance)) {
120
				coors = lenline.extractPoint(distance);
121
				// with offset
122
				if (offset != null && offset.doubleValue() > 0) {
123
					return getOffsetPosition(new Point2D(coors.x, coors.y),
124
							offset);
125
				}
126
				// Without offset
127
				else {
128
					return new Point2D(coors.x, coors.y);
129
				}
130
			}
131
		}
132
		// Calculate percentage of distance
133
		else if (relativedist != null) {
134
			if (totaldistance > 0) {
135
				double dist = (relativedist * totaldistance) / 100.0;
136
				coors = lenline.extractPoint(dist);
137
				// with offset
138
				if (offset != null && offset.doubleValue() > 0) {
139
					return getOffsetPosition(new Point2D(coors.x, coors.y),
140
							offset);
141
				}
142
				// Without offset
143
				else {
144
					return new Point2D(coors.x, coors.y);
145
				}
146
			}
147
		}
148
		// Any other case
149
		else {
150
			if (totaldistance > 0) {
151
				double dist = totaldistance / 2.0;
152
				coors = lenline.extractPoint(dist);
153
				// with offset
154
				if (offset != null && offset.doubleValue() > 0) {
155
					return getOffsetPosition(new Point2D(coors.x, coors.y),
156
							offset);
157
				}
158
				// Without offset
159
				else {
160
					return new Point2D(coors.x, coors.y);
161
				}
162
			}
163
		}
164
		return null;
165
	}
166

  
167
	/**
168
	 * Calculate the position in the line with offset
169
	 * 
170
	 * @param linePoint
171
	 *            middle point over the liner
172
	 * @param dist
173
	 *            perpendicular distance since the line
174
	 * @return
175
	 */
176
	@SuppressWarnings("unchecked")
177
	private Point2D getOffsetPosition(Point2D linePoint, double dist) {
178

  
179
		List feats = (List) getFeatures().get(0);
180
		Geometry[] geoms = new Geometry[feats.size()];
181
		Iterator it = feats.iterator();
182
		int cont = 0;
183
		while (it.hasNext()) {
184
			geoms[cont] = (Geometry) ((Feature) it.next())
185
					.getGeometry("GEOMETRY");
186
			cont++;
187
		}
188
		for (int j = 0; j < geoms.length; j++) {
189
			double[] coords = new double[6];
190
			Point2D inicio = null;
191
			Point2D fin = null;
192

  
193
			boolean inter = geoms[j].intersects(linePoint.getBounds2D());
194
			if (inter) {
195
				PathIterator iter = ((Curve2D) geoms[j]).getGeneralPathX()
196
						.getPathIterator(null);
197
				iter.currentSegment(coords);
198
				inicio = new Point2D(coords[0], coords[1]);
199

  
200
				iter.next();
201
				iter.currentSegment(coords);
202
				fin = new Point2D(coords[0], coords[1]);
203

  
204
				log.debug("Return point with offset");
205
				return getPerpendicularPoint(inicio, fin, linePoint, dist);
206
			}
207

  
208
		}
209
		log.debug("Return original point without offset");
210
		return linePoint;
211

  
212
	}
213

  
214
	/**
215
	 * 
216
	 * This method calculates a point perpendicular to the line at a distance
217
	 * 
218
	 * @param inicio
219
	 *            initial point of the line
220
	 * @param fin
221
	 *            end point of the line
222
	 * @param linePoint
223
	 *            middle point over line
224
	 * @param dist
225
	 *            perpendicular distance to the line
226
	 * @return
227
	 */
228
	private Point2D getPerpendicularPoint(Point2D inicio, Point2D fin,
229
			Point2D linePoint, double dist) {
230

  
231
		java.awt.geom.Point2D p1 = new java.awt.geom.Point2D.Double(inicio
232
				.getX(), inicio.getY());
233
		java.awt.geom.Point2D p2 = new java.awt.geom.Point2D.Double(fin.getX(),
234
				fin.getY());
235
		java.awt.geom.Point2D perpPoint = new java.awt.geom.Point2D.Double(
236
				linePoint.getX(), linePoint.getY());
237

  
238
		java.awt.geom.Point2D[] p = UtilFunctions.getPerpendicular(p1, p2,
239
				perpPoint);
240
		java.awt.geom.Point2D unit = UtilFunctions.getUnitVector(p[0], p[1]);
241

  
242
		java.awt.geom.Point2D res = new java.awt.geom.Point2D.Double(perpPoint
243
				.getX()
244
				+ (unit.getX() * dist), perpPoint.getY() + (unit.getY() * dist));
245

  
246
		return new Point2D(res.getX(), res.getY());
247
	}
248

  
249
}
branches/v2_0_0_prep/libraries/libGeocoding/src/org/gvsig/geocoding/geommatches/MatchesParams.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

  
28
package org.gvsig.geocoding.geommatches;
29

  
30
import java.util.HashMap;
31
import java.util.Map;
32

  
33
/**
34
 * 
35
 * class
36
 * 
37
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
38
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
39
 * 
40
 */
41

  
42
public class MatchesParams {
43

  
44
	private Map<String, Object> atts = new HashMap<String, Object>();
45

  
46
	private static final String RELATIVEDIST = "RELATIVEDIST";
47
	private static final String DISTANCE = "DISTANCE";
48
	private static final String OFFSET = "OFFSET";
49

  
50
	/**
51
	 * Constructor class
52
	 */
53
	public MatchesParams() {
54
		setDistance(null);
55
		setRelativeDistance(null);
56
		setOffset(null);
57
	}
58

  
59
	/**
60
	 * Set the distance from initial node
61
	 * 
62
	 * @param distance
63
	 */
64
	public void setDistance(Long distance) {
65
		setAttribute(DISTANCE, distance);
66
	}
67

  
68
	/**
69
	 * Set the relative distance from the total distance
70
	 * 
71
	 * @param relative
72
	 */
73
	public void setRelativeDistance(Integer relative) {
74
		setAttribute(RELATIVEDIST, relative);
75
	}
76

  
77
	/**
78
	 * Set the offset distance from the way If the value is positive the offset
79
	 * is in the right side If the value is negative the offset is in the left
80
	 * side
81
	 * 
82
	 * @param offset
83
	 */
84
	public void setOffset(Double offset) {
85
		setAttribute(OFFSET, offset);
86
	}
87

  
88
	/**
89
	 * Get the distance
90
	 * 
91
	 * @return
92
	 */
93
	public Long getDistance() {
94
		return (Long) getAttribute(DISTANCE);
95
	}
96

  
97
	/**
98
	 * Get the relative distance in percentage value
99
	 * 
100
	 * @return
101
	 */
102
	public Integer getRelativeDistance() {
103
		return (Integer) getAttribute(RELATIVEDIST);
104
	}
105

  
106
	/**
107
	 * Get the distance from the way If the value is positive the offset is in
108
	 * the right side If the value is negative the offset is in the left side
109
	 * 
110
	 * @return
111
	 */
112
	public Double getOffset() {
113
		return (Double) getAttribute(OFFSET);
114
	}
115

  
116
	private Object getAttribute(Object key) {
117
		return this.atts.get(key);
118
	}
119

  
120
	private void setAttribute(String name, Object value) {
121
		this.atts.put(name, value);
122

  
123
	}
124

  
125
}
branches/v2_0_0_prep/libraries/libGeocoding/src/org/gvsig/geocoding/geommatches/GeomMatcher.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

  
28
package org.gvsig.geocoding.geommatches;
29

  
30
import java.util.ArrayList;
31
import java.util.HashMap;
32
import java.util.Iterator;
33
import java.util.List;
34

  
35
import org.gvsig.fmap.dal.feature.Feature;
36
import org.gvsig.fmap.geom.DefaultGeometryManager;
37
import org.gvsig.fmap.geom.Geometry;
38
import org.gvsig.fmap.geom.GeometryManager;
39
import org.gvsig.fmap.geom.operation.GeometryOperation;
40
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
41
import org.gvsig.fmap.geom.operation.tojts.ToJTS;
42
import org.slf4j.Logger;
43
import org.slf4j.LoggerFactory;
44

  
45
import com.vividsolutions.jts.operation.overlay.OverlayOp;
46

  
47
/**
48
 * 
49
 * class
50
 * 
51
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
52
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
53
 * 
54
 */
55

  
56
public abstract class GeomMatcher {
57

  
58
	public Logger log = LoggerFactory.getLogger(GeomMatcher.class);
59

  
60
	@SuppressWarnings( { "unused", "unchecked" })
61
	private List listFeats;
62
	private MatchesParams params;
63
	private int fieldPosition;
64

  
65
	/**
66
	 * Set features
67
	 * 
68
	 * @param _collectionsList
69
	 */
70
	@SuppressWarnings("unchecked")
71
	public void setFeatures(List listFeatures) {
72
		this.listFeats = listFeatures;
73
	}
74

  
75
	/**
76
	 * Get the features
77
	 * 
78
	 * @return
79
	 */
80
	@SuppressWarnings("unchecked")
81
	public List getFeatures() {
82
		return this.listFeats;
83
	}
84

  
85
	/**
86
	 * Set field name to group features
87
	 * 
88
	 * @param _collectionsList
89
	 */
90
	public void setGroupField(int _fieldPosition) {
91
		this.fieldPosition = _fieldPosition;
92
	}
93

  
94
	/**
95
	 * Get the group field name
96
	 * 
97
	 * @return
98
	 */
99
	public int getGroupFieldPosition() {
100
		return this.fieldPosition;
101
	}
102

  
103
	/**
104
	 * Get the parameters to make a match
105
	 * 
106
	 * @param context
107
	 */
108
	public void setParams(MatchesParams context) {
109
		this.params = context;
110
	};
111

  
112
	/**
113
	 * Set the parameters to make a match
114
	 * 
115
	 * @return
116
	 */
117
	public MatchesParams getParams() {
118
		return params;
119
	}
120

  
121
	/**
122
	 * This method parses geometries (FMap) to geometries (JTS)
123
	 * 
124
	 * @param geomClass
125
	 *            type of geometry (Point2d.class, Curve2D.class, ...)
126
	 * @param geoms
127
	 * @return
128
	 */
129
	@SuppressWarnings("unchecked")
130
	protected com.vividsolutions.jts.geom.Geometry[] parseGeomsToJTS(
131
			Class geomClass, Geometry[] geoms) {
132

  
133
		com.vividsolutions.jts.geom.Geometry[] geomsjts = new com.vividsolutions.jts.geom.Geometry[geoms.length];
134

  
135
		GeometryManager gm = new DefaultGeometryManager();
136
		GeometryOperation geomOp = null;
137

  
138
		try {
139
			geomOp = gm.getGeometryOperation(geomClass, ToJTS.CODE);
140

  
141
			// Fill the operation context with required params
142
			GeometryOperationContext ctx = new GeometryOperationContext();
143

  
144
			// Here is the main loop where you call the operation
145
			for (int i = 0; i < geoms.length; i++) {
146
				geomsjts[i] = (com.vividsolutions.jts.geom.Geometry) geomOp
147
						.invoke(geoms[i], ctx);
148
			}
149

  
150
		} catch (Exception e) {
151
			log.debug("Error parsing geometries to JTS", e);
152
		}
153
		log.debug("Geometry parsed");
154
		return geomsjts;
155
	}
156

  
157
	/**
158
	 * This method makes the union the geometries with one attribute common.
159
	 * 
160
	 * @param geomsJts
161
	 * @return
162
	 */
163
	protected com.vividsolutions.jts.geom.Geometry unionLinesJTS(
164
			com.vividsolutions.jts.geom.Geometry[] geomsJts) {
165

  
166
		com.vividsolutions.jts.geom.Geometry geometJTS = null;
167

  
168
		// if there are more that one geometries
169
		if (geomsJts.length > 1) {
170

  
171
			geometJTS = OverlayOp.overlayOp(geomsJts[0], geomsJts[1],
172
					OverlayOp.UNION);
173

  
174
			for (int i = 2; i < geomsJts.length; i++) {
175
				geometJTS = OverlayOp.overlayOp(geometJTS, geomsJts[i],
176
						OverlayOp.UNION);
177
			}
178
			log.debug("Union of geometries");
179
			return geometJTS;
180

  
181
		}
182
		// Only there is one geometry
183
		else {
184
			log.debug("Union of geometries");
185
			return geomsJts[0];
186
		}
187
	}
188

  
189
	// /**
190
	// *
191
	// * @param geometriesJts
192
	// * @return
193
	// */
194
	// protected List intersectLinesJTS(
195
	// com.vividsolutions.jts.geom.Geometry[] geometriesJts) {
196
	//
197
	// List points = new ArrayList();
198
	// com.vividsolutions.jts.geom.Geometry geomPointsJTS = null;
199
	// com.vividsolutions.jts.geom.Geometry interBBoxJTS = null;
200
	// com.vividsolutions.jts.geom.Geometry colPointsJts[] = null;
201
	//
202
	// if (geometriesJts.length > 0 || geometriesJts != null) {
203
	//
204
	// for (int i = 0; i < geometriesJts.length; i++) {
205
	//
206
	// for (int j = i + 1; j < geometriesJts.length; j++) {
207
	//
208
	// interBBoxJTS = OverlayOp.overlayOp(geometriesJts[i]
209
	// .getEnvelope(), geometriesJts[j].getEnvelope(),
210
	// OverlayOp.INTERSECTION);
211
	// if (interBBoxJTS.getGeometryType().compareTo("LineString") == 0) {
212
	// geomPointsJTS = OverlayOp.overlayOp(geometriesJts[i],
213
	// geometriesJts[j], OverlayOp.INTERSECTION);
214
	// if (geomPointsJTS.getGeometryType().compareTo("Point") == 0) {
215
	//
216
	// boolean toca = false;
217
	// for (int k = 0; k < points.size(); k++) {
218
	// com.vividsolutions.jts.geom.Point po =
219
	// (com.vividsolutions.jts.geom.Point) points
220
	// .get(k);
221
	// if (po.getCoordinate().x == geomPointsJTS
222
	// .getCoordinate().x
223
	// && po.getCoordinate().y == geomPointsJTS
224
	// .getCoordinate().y) {
225
	// toca = true;
226
	// break;
227
	// }
228
	// }
229
	// if (!toca) {
230
	// points.add(geomPointsJTS);
231
	// }
232
	// }
233
	// }
234
	// }
235
	// }
236
	// return points;
237
	//
238
	// } else {
239
	// return points;
240
	// }
241
	// }
242

  
243
	/**
244
	 * This method intersect two lines and return the intersection point. If
245
	 * result is null, two lines doesn't intersect
246
	 * 
247
	 * @param geometriesJts
248
	 * @return
249
	 */
250
	protected com.vividsolutions.jts.geom.Point intersectTwoLinesJTS(
251
			com.vividsolutions.jts.geom.Geometry geom1Jts,
252
			com.vividsolutions.jts.geom.Geometry geom2Jts) {
253

  
254
		com.vividsolutions.jts.geom.Geometry interBBoxJTS = null;
255
		com.vividsolutions.jts.geom.Geometry geomPointJTS = null;
256

  
257
		if (geom1Jts != null || geom2Jts != null) {
258
			log.debug("Intersect: Two geometries not nulls");
259

  
260
			interBBoxJTS = OverlayOp.overlayOp(geom1Jts.getEnvelope(), geom2Jts
261
					.getEnvelope(), OverlayOp.INTERSECTION);
262
			if (interBBoxJTS.getGeometryType().compareTo("LineString") == 0
263
					|| interBBoxJTS.getGeometryType().compareTo("Polygon") == 0) {
264
				log.debug("Intersect: Intersect two BBOX");
265
				geomPointJTS = OverlayOp.overlayOp(geom1Jts, geom2Jts,
266
						OverlayOp.INTERSECTION);
267

  
268
				if (geomPointJTS.getGeometryType().compareTo("Point") == 0) {
269
					log.debug("Intersect: Intersect in the point X= "
270
							+ geomPointJTS.getCoordinate().x + " Y= "
271
							+ geomPointJTS.getCoordinate().y);
272
					return (com.vividsolutions.jts.geom.Point) geomPointJTS;
273
				} else {
274
					log.debug("Intersect: Two lines don't intersect");
275
					return null;
276
				}
277
			} else {
278
				log.debug("Intersect: Two BBOX don't intersect");
279
				return null;
280
			}
281
		}
282
		return null;
283

  
284
	}
285

  
286
	/**
287
	 * This method group geometries to one attribute
288
	 * 
289
	 * @param fieldPosition
290
	 *            position of the field with the attribute
291
	 * @param feats
292
	 *            features collection
293
	 * @return
294
	 */
295
	@SuppressWarnings("unchecked")
296
	protected HashMap groupFeaturesByAttribute(int fieldPosition, List feats) {
297

  
298
		HashMap coleccion = new HashMap();
299
		Iterator it = feats.iterator();
300
		// Go for all geometries of the collection
301
		while (it.hasNext()) {
302
			// Get feature
303
			Feature featur = (Feature) it.next();
304
			String key = featur.get(fieldPosition).toString();
305
			// Get geometry
306
			Geometry geomet = (Geometry) featur.getGeometry("GEOMETRY");
307
			// Store the geometries for attribute in the List
308
			boolean contiene = coleccion.containsKey(key);
309
			if (!contiene) {
310
				List geomss = new ArrayList();
311
				geomss.add(geomet);
312
				coleccion.put(key, geomss);
313
			} else {
314
				((ArrayList) coleccion.get(key)).add(geomet);
315
			}
316
		}
317
		return coleccion;
318
	}
319

  
320
	/**
321
	 * This abstract method gets the position over the geometries
322
	 * 
323
	 * @return
324
	 */
325
	public abstract Geometry[] match();
326

  
327
}
branches/v2_0_0_prep/libraries/libGeocoding/src/org/gvsig/geocoding/geommatches/PolygonMatcher.java
1
package org.gvsig.geocoding.geommatches;
2

  
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.Iterator;
6
import java.util.List;
7
import java.util.Map;
8

  
9
import org.gvsig.fmap.geom.Geometry;
10
import org.gvsig.fmap.geom.primitive.Point2D;
11

  
12
import com.vividsolutions.jts.algorithm.InteriorPointArea;
13

  
14
public class PolygonMatcher extends GeomMatcher {
15

  
16
	/**
17
	 * This method match the centroids (Point2D) of polygons. If there are some
18
	 * multipolygon in the result features the centroid will be a MultiPoint
19
	 */
20
	@Override
21
	public Geometry[] match() {
22

  
23
		HashMap polys = groupFeaturesByAttribute(this.getGroupFieldPosition(),
24
				(List) this.getFeatures().get(0));
25
		Iterator it = polys.entrySet().iterator();
26
		Geometry[] mPoints = new Geometry[polys.size()];
27
		int position = 0;
28
		while (it.hasNext()) {
29
			Map.Entry e = (Map.Entry) it.next();
30
			ArrayList geomss = (ArrayList) e.getValue();
31

  
32
			// Insert geometries of one street into array
33
			Geometry[] arrGeoms = new Geometry[geomss.size()];
34
			for (int i = 0; i < geomss.size(); i++) {
35
				Geometry ggeom = (Geometry) geomss.get(i);
36
				arrGeoms[i] = ggeom;
37
			}
38
			// Parse geometries to JTS
39
			com.vividsolutions.jts.geom.Geometry[] geomsjts = parseGeomsToJTS(
40
					geomss.get(0).getClass(), arrGeoms);
41
			// Get centroid of polygon or polygons
42
			for (int j = 0; j < geomsjts.length; j++) {
43
				Point2D pts = getCenterOfPolygon(geomsjts[j]);
44
				mPoints[position] = pts;
45
				position++;
46
			}
47
		}
48
		return mPoints;
49
	}
50

  
51
	/**
52
	 * This method calculate the centroid of one polygon. Always the centroid
53
	 * will be within the polygon.
54
	 * 
55
	 * @param geomjts
56
	 * @return
57
	 */
58
	private Point2D getCenterOfPolygon(
59
			com.vividsolutions.jts.geom.Geometry geomjts) {
60

  
61
		InteriorPointArea centro = new InteriorPointArea(geomjts);
62
		com.vividsolutions.jts.geom.Point pto = geomjts.getInteriorPoint();
63

  
64
		return new Point2D(pto.getX(), pto.getY());
65
	}
66

  
67
}
branches/v2_0_0_prep/libraries/libGeocoding/src/org/gvsig/geocoding/geommatches/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;
branches/v2_0_0_prep/libraries/libGeocoding/src/org/gvsig/geocoding/pattern/GeocodingSource.java
27 27

  
28 28
package org.gvsig.geocoding.pattern;
29 29

  
30

  
31 30
import org.gvsig.fmap.dal.feature.FeatureStore;
32 31
import org.gvsig.geocoding.styles.AbstractGeocodingStyle;
33 32
import org.gvsig.tools.persistence.AbstractPersistenceManager;
......
38 37
import org.slf4j.LoggerFactory;
39 38

  
40 39
/**
41
 * Class Source.
40
 * Class Source. this class has the geocoding style and the FeatureStore of the
41
 * data source
42 42
 * 
43
 * This class has the address components and the layer source
43
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
44
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
44 45
 */
45 46
public class GeocodingSource implements Persistent {
46 47

  
47
	private static final Logger log = LoggerFactory.getLogger(GeocodingSource.class);
48
	private static final Logger log = LoggerFactory
49
			.getLogger(GeocodingSource.class);
50

  
48 51
	private static final String STYLE = "style";
49 52
	private static final String LAYERSOURCE = "layersource";
50 53

  
branches/v2_0_0_prep/libraries/libGeocoding/src/org/gvsig/geocoding/pattern/Settings.java
31 31
import org.gvsig.tools.persistence.PersistenceException;
32 32
import org.gvsig.tools.persistence.Persistent;
33 33
import org.gvsig.tools.persistence.PersistentState;
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
34 36

  
35 37
/**
36
 * Class Settings.
38
 * Class Settings. this class has the parameters that define the quality of
39
 * search.
37 40
 * 
38
 * This class is one of the elements that define address pattern
41
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
42
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
39 43
 */
40 44
public class Settings implements Persistent {
45
	
46
	private static final Logger log = LoggerFactory
47
	.getLogger(Settings.class);
41 48

  
42 49
	private static final String ACCURACY = "accuracy";
43 50
	private static final String RESULTSNUMBER = "resultsnumber";
......
48 55
	private int quality;
49 56

  
50 57
	/**
51
	 * Default Constructor
58
	 * Default Constructor with parameters initializated.
52 59
	 */
53 60
	public Settings() {
54 61
		this.accuracy = 80;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff