Revision 19509

View differences:

tags/J2ME_compat_v1_2_Build_1209/libraries/libFMap/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>libFMap</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>de.loskutov.FileSync.FSBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>com.gentleware.uml2.reveng.IncrementalReverseEngineeringBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
		<buildCommand>
24
			<name>com.gentleware.uml2.resource.xmi.xmiIndexBuilder</name>
25
			<arguments>
26
			</arguments>
27
		</buildCommand>
28
	</buildSpec>
29
	<natures>
30
		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
31
		<nature>org.eclipse.jdt.core.javanature</nature>
32
		<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
33
		<nature>com.gentleware.uml2.reveng.RoundtripProject</nature>
34
		<nature>com.gentleware.uml2.resource.xmi.indexedXmiNature</nature>
35
	</natures>
36
</projectDescription>
tags/J2ME_compat_v1_2_Build_1209/libraries/libFMap/src/com/vividsolutions/jts/algorithms/SnapPointLocator.java
1
/*
2
 * Created on 06-oct-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
 *
46
 * $Id: SnapPointLocator.java 13685 2007-09-13 18:02:35Z azabala $
47
 * $Log$
48
 * Revision 1.3  2007-09-13 17:59:04  azabala
49
 * changes to adapt to JTS 1.8
50
 *
51
 * Revision 1.2  2007/03/06 17:08:55  caballero
52
 * Exceptions
53
 *
54
 * Revision 1.1  2006/12/04 19:29:31  azabala
55
 * *** empty log message ***
56
 *
57
 * Revision 1.1  2006/10/17 18:25:53  azabala
58
 * *** empty log message ***
59
 *
60
 * Revision 1.1  2006/10/09 19:10:56  azabala
61
 * First version in CVS
62
 *
63
 *
64
 */
65
package com.vividsolutions.jts.algorithms;
66

  
67
import java.util.Iterator;
68

  
69
import com.vividsolutions.jts.algorithm.BoundaryNodeRule;
70
import com.vividsolutions.jts.geom.Coordinate;
71
import com.vividsolutions.jts.geom.Geometry;
72
import com.vividsolutions.jts.geom.GeometryCollection;
73
import com.vividsolutions.jts.geom.GeometryCollectionIterator;
74
import com.vividsolutions.jts.geom.LineString;
75
import com.vividsolutions.jts.geom.LinearRing;
76
import com.vividsolutions.jts.geom.Location;
77
import com.vividsolutions.jts.geom.MultiLineString;
78
import com.vividsolutions.jts.geom.MultiPolygon;
79
import com.vividsolutions.jts.geom.Polygon;
80

  
81
public class SnapPointLocator extends
82
		com.vividsolutions.jts.algorithm.PointLocator {
83

  
84
	private BoundaryNodeRule boundaryRule = BoundaryNodeRule.ENDPOINT_BOUNDARY_RULE; // OGC_SFS_BOUNDARY_RULE;
85

  
86
	private boolean isIn; // true if the point lies in or on any Geometry
87

  
88
	// element
89

  
90
	private int numBoundaries; // the number of sub-elements whose boundaries
91

  
92
	// the point lies in
93

  
94
	public SnapPointLocator() {
95
	}
96

  
97
	public SnapPointLocator(BoundaryNodeRule boundaryRule) {
98
		if (boundaryRule == null)
99
			throw new IllegalArgumentException("Rule must be non-null");
100
		this.boundaryRule = boundaryRule;
101
	}
102

  
103
	/**
104
	 * Convenience method to test a point for intersection with a Geometry
105
	 * 
106
	 * @param p
107
	 *            the coordinate to test
108
	 * @param geom
109
	 *            the Geometry to test
110
	 * @return <code>true</code> if the point is in the interior or boundary
111
	 *         of the Geometry
112
	 */
113
	public boolean intersects(Coordinate p, Geometry geom, double snapTolerance) {
114
		return locate(p, geom, snapTolerance) != Location.EXTERIOR;
115
	}
116

  
117
	/**
118
	 * Computes the topological relationship ({@link Location}) of a single
119
	 * point to a Geometry. It handles both single-element and multi-element
120
	 * Geometries. The algorithm for multi-part Geometries takes into account
121
	 * the SFS Boundary Determination Rule.
122
	 * 
123
	 * @return the {@link Location} of the point relative to the input Geometry
124
	 */
125
	public int locate(Coordinate p, Geometry geom, double snapTolerance) {
126
		if (geom.isEmpty())
127
			return Location.EXTERIOR;
128

  
129
		if (geom instanceof LinearRing) {
130
			return locate(p, (LinearRing) geom, snapTolerance);
131
		}
132
		if (geom instanceof LineString) {
133
			return locate(p, (LineString) geom, snapTolerance);
134
		} else if (geom instanceof Polygon) {
135
			return locate(p, (Polygon) geom, snapTolerance);
136
		}
137
		isIn = false;
138
		numBoundaries = 0;
139
		computeLocation(p, geom, snapTolerance);
140

  
141
//		if (SnappingGeometryGraph.isInBoundary(numBoundaries))
142
//			return Location.BOUNDARY;
143
		
144
		if (boundaryRule.isInBoundary(numBoundaries))
145
			return Location.BOUNDARY;
146

  
147
		if (numBoundaries > 0 || isIn)
148
			return Location.INTERIOR;
149
		return Location.EXTERIOR;
150
	}
151

  
152
	
153
	private void computeLocation(Coordinate p, Geometry geom,
154
			double snapTolerance) {
155
		if (geom instanceof LinearRing) {
156
			updateLocationInfo(locate(p, (LinearRing) geom, snapTolerance));
157
		}
158
		if (geom instanceof LineString) {
159
			updateLocationInfo(locate(p, (LineString) geom, snapTolerance));
160
		} else if (geom instanceof Polygon) {
161
			updateLocationInfo(locate(p, (Polygon) geom, snapTolerance));
162
		} else if (geom instanceof MultiLineString) {
163
			MultiLineString ml = (MultiLineString) geom;
164
			for (int i = 0; i < ml.getNumGeometries(); i++) {
165
				LineString l = (LineString) ml.getGeometryN(i);
166
				updateLocationInfo(locate(p, l, snapTolerance));
167
			}
168
		} else if (geom instanceof MultiPolygon) {
169
			MultiPolygon mpoly = (MultiPolygon) geom;
170
			for (int i = 0; i < mpoly.getNumGeometries(); i++) {
171
				Polygon poly = (Polygon) mpoly.getGeometryN(i);
172
				updateLocationInfo(locate(p, poly, snapTolerance));
173
			}
174
		} else if (geom instanceof GeometryCollection) {
175
			Iterator geomi = new GeometryCollectionIterator(
176
					(GeometryCollection) geom);
177
			while (geomi.hasNext()) {
178
				Geometry g2 = (Geometry) geomi.next();
179
				if (g2 != geom)
180
					computeLocation(p, g2, snapTolerance);
181
			}
182
		}
183
	}
184

  
185
	private void updateLocationInfo(int loc) {
186
		if (loc == Location.INTERIOR)
187
			isIn = true;
188
		if (loc == Location.BOUNDARY)
189
			numBoundaries++;
190
	}
191

  
192
	private int locate(Coordinate p, LineString l, double snapTolerance) {
193
		Coordinate[] pt = l.getCoordinates();
194
		if (!l.isClosed()) {
195
			if (p.distance(pt[0]) <= snapTolerance
196
					|| p.distance(pt[pt.length - 1]) <= snapTolerance) {
197
				return Location.BOUNDARY;
198
			}
199
		}
200
		if (SnapCGAlgorithms.isOnLine(p, pt, snapTolerance))
201
			return Location.INTERIOR;
202
		return Location.EXTERIOR;
203
	}
204

  
205
	private int locate(Coordinate p, LinearRing ring, double snapTolerance) {
206
		// can this test be folded into isPointInRing ?
207
		if (SnapCGAlgorithms.isOnLine(p, ring.getCoordinates())) {
208
			return Location.BOUNDARY;
209
		}
210
		if (SnapCGAlgorithms.isPointInRing(p, ring.getCoordinates(),
211
				snapTolerance))
212
			return Location.INTERIOR;
213
		return Location.EXTERIOR;
214
	}
215

  
216
	private int locate(Coordinate p, Polygon poly, double snapTolerance) {
217
		if (poly.isEmpty())
218
			return Location.EXTERIOR;
219
		LinearRing shell = (LinearRing) poly.getExteriorRing();
220

  
221
		int shellLoc = locate(p, shell, snapTolerance);
222
		if (shellLoc == Location.EXTERIOR)
223
			return Location.EXTERIOR;
224
		if (shellLoc == Location.BOUNDARY)
225
			return Location.BOUNDARY;
226
		// now test if the point lies in or on the holes
227
		for (int i = 0; i < poly.getNumInteriorRing(); i++) {
228
			LinearRing hole = (LinearRing) poly.getInteriorRingN(i);
229
			int holeLoc = locate(p, hole, snapTolerance);
230
			if (holeLoc == Location.INTERIOR)
231
				return Location.EXTERIOR;
232
			if (holeLoc == Location.BOUNDARY)
233
				return Location.BOUNDARY;
234
		}
235
		return Location.INTERIOR;
236
	}
237
}
tags/J2ME_compat_v1_2_Build_1209/libraries/libFMap/src/com/vividsolutions/jts/algorithms/SnapCGAlgorithms.java
1
/*
2
 * Created on 06-oct-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: SnapCGAlgorithms.java 13683 2007-09-13 17:58:32Z azabala $
47
* $Log$
48
* Revision 1.2  2007-09-13 17:58:32  azabala
49
* added snapEquals2D method
50
*
51
* Revision 1.1  2006/12/04 19:29:31  azabala
52
* *** empty log message ***
53
*
54
* Revision 1.2  2006/10/19 16:06:48  azabala
55
* *** empty log message ***
56
*
57
* Revision 1.1  2006/10/17 18:25:53  azabala
58
* *** empty log message ***
59
*
60
* Revision 1.1  2006/10/09 19:10:56  azabala
61
* First version in CVS
62
*
63
*
64
*/
65
package com.vividsolutions.jts.algorithms;
66

  
67
import com.vividsolutions.jts.algorithm.CGAlgorithms;
68
import com.vividsolutions.jts.algorithm.RobustDeterminant;
69
import com.vividsolutions.jts.geom.Coordinate;
70
import com.vividsolutions.jts.operation.overlay.SnapLineIntersector;
71

  
72
public class SnapCGAlgorithms extends CGAlgorithms {
73
	/**
74
	   * Test whether a point lies on the line segments defined by a
75
	   * list of coordinates.
76
	   *
77
	   * @return true true if
78
	   * the point is a vertex of the line or lies in the interior of a line
79
	   * segment in the linestring
80
	   */
81
	  public static boolean isOnLine(Coordinate p, Coordinate[] pt, double snapTol) {
82
	    SnapLineIntersector lineIntersector = new SnapLineIntersector(snapTol);
83
	    for (int i = 1; i < pt.length; i++) {
84
	      Coordinate p0 = pt[i - 1];
85
	      Coordinate p1 = pt[i];
86
	      lineIntersector.computeIntersection(p, p0, p1);
87
	      if (lineIntersector.hasIntersection()) {
88
	        return true;
89
	      }
90
	    }
91
	    return false;
92
	  }
93
	  public static boolean isPointInRing(Coordinate p, Coordinate[] ring, double snapTolerance) {
94
		    /*
95
		     *  For each segment l = (i-1, i), see if it crosses ray from test point in positive x direction.
96
		     */
97
		    int crossings = 0;  // number of segment/ray crossings
98
		    
99
		    SnapLineIntersector lineIntersector = new SnapLineIntersector(snapTolerance);
100
		    
101
		    for (int i = 1; i < ring.length; i++) {
102
		      int i1 = i - 1;
103
		      Coordinate p1 = ring[i];
104
		      Coordinate p2 = ring[i1];
105
		      
106
		      lineIntersector.computeIntersection(p, p1, p2);
107
		      if (lineIntersector.hasIntersection()) {
108
		        crossings ++;
109
		      }
110

  
111
//		      if (((p1.y > (p.y - snapTolerance)) && (p2.y <= (p.y + snapTolerance))) ||
112
//		          ((p2.y > (p.y - snapTolerance)) && (p1.y <= (p.y) + snapTolerance))) {//si no se cumple, no pueden intersectar
113
//		        
114
//		    	double x1 = p1.x - p.x;
115
//		        double y1 = p1.y - p.y;
116
//		        double x2 = p2.x - p.x;
117
//		        double y2 = p2.y - p.y;
118
//		        /*
119
//		        *  segment straddles x axis, so compute intersection with x-axis.
120
//		         */
121
//		        double xInt = RobustDeterminant.signOfDet2x2(x1, y1, x2, y2) / (y2 - y1);
122
//		        //xsave = xInt;
123
//		        /*
124
//		        *  crosses ray if strictly positive intersection.
125
//		         */
126
//		        if (xInt > 0.0) {
127
//		          crossings++;
128
//		        }
129
//		      }
130
		    }
131
		    /*
132
		     *  p is inside if number of crossings is odd.
133
		     */
134
		    if ((crossings % 2) == 1) {
135
		      return true;
136
		    }
137
		    else {
138
		      return false;
139
		    }
140
		  }
141
	  
142
	  /**
143
	   * Computes the orientation of a point q to the directed line segment p1-p2.
144
	   * The orientation of a point relative to a directed line segment indicates
145
	   * which way you turn to get to q after travelling from p1 to p2.
146
	   *
147
	   * @return 1 if q is counter-clockwise from p1-p2
148
	   * @return -1 if q is clockwise from p1-p2
149
	   * @return 0 if q is collinear with p1-p2
150
	   */
151
	  public static int computeOrientation(Coordinate p1, Coordinate p2, Coordinate q) {
152
	    return orientationIndex(p1, p2, q);
153
	  }
154
	  /**
155
	   * Returns the index of the direction of the point <code>q</code>
156
	   * relative to a
157
	   * vector specified by <code>p1-p2</code>.
158
	   *
159
	   * @param p1 the origin point of the vector
160
	   * @param p2 the final point of the vector
161
	   * @param q the point to compute the direction to
162
	   *
163
	   * @return 1 if q is counter-clockwise (left) from p1-p2
164
	   * @return -1 if q is clockwise (right) from p1-p2
165
	   * @return 0 if q is collinear with p1-p2
166
	   */
167
	  public static int orientationIndex(Coordinate p1, Coordinate p2, Coordinate q) {
168
	    // travelling along p1->p2, turn counter clockwise to get to q return 1,
169
	    // travelling along p1->p2, turn clockwise to get to q return -1,
170
	    // p1, p2 and q are colinear return 0.
171
	    double dx1 = p2.x - p1.x;
172
	    double dy1 = p2.y - p1.y;
173
	    double dx2 = q.x - p2.x;
174
	    double dy2 = q.y - p2.y;
175
	    return RobustDeterminant.signOfDet2x2(dx1, dy1, dx2, dy2);
176
	  }
177
	  
178
	  
179
	  public static boolean snapEquals2D(Coordinate a, Coordinate b, double snapTolerance){
180
		  return a.distance(b) <= snapTolerance;
181
	  }
182
	  
183
	  
184
}
185

  
tags/J2ME_compat_v1_2_Build_1209/libraries/libFMap/src/com/vividsolutions/jts/algorithms/SnapSimplePointInAreaLocator.java
1
/*
2
 * Created on 06-oct-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: SnapSimplePointInAreaLocator.java 10627 2007-03-06 17:10:21Z caballero $
47
* $Log$
48
* Revision 1.2  2007-03-06 17:08:55  caballero
49
* Exceptions
50
*
51
* Revision 1.1  2006/12/04 19:29:31  azabala
52
* *** empty log message ***
53
*
54
* Revision 1.1  2006/10/17 18:25:53  azabala
55
* *** empty log message ***
56
*
57
* Revision 1.1  2006/10/09 19:10:56  azabala
58
* First version in CVS
59
*
60
*
61
*/
62
package com.vividsolutions.jts.algorithms;
63

  
64
import java.util.Iterator;
65

  
66
import com.vividsolutions.jts.geom.Coordinate;
67
import com.vividsolutions.jts.geom.Geometry;
68
import com.vividsolutions.jts.geom.GeometryCollection;
69
import com.vividsolutions.jts.geom.GeometryCollectionIterator;
70
import com.vividsolutions.jts.geom.LinearRing;
71
import com.vividsolutions.jts.geom.Location;
72
import com.vividsolutions.jts.geom.Polygon;
73

  
74
public class SnapSimplePointInAreaLocator extends
75
		com.vividsolutions.jts.algorithm.SimplePointInAreaLocator {
76
	 public static int locate(Coordinate p, Geometry geom, double snapTolerance)
77
	  {
78
	    if (geom.isEmpty()) return Location.EXTERIOR;
79

  
80
	    if (containsPoint(p, geom, snapTolerance))
81
	      return Location.INTERIOR;
82
	    return Location.EXTERIOR;
83
	  }
84

  
85
	  private static boolean containsPoint(Coordinate p, Geometry geom, double snapTolerance)
86
	  {
87
	    if (geom instanceof Polygon) {
88
	      return containsPointInPolygon(p, (Polygon) geom);
89
	    }
90
	    else if (geom instanceof GeometryCollection) {
91
	      Iterator geomi = new GeometryCollectionIterator((GeometryCollection) geom);
92
	      while (geomi.hasNext()) {
93
	        Geometry g2 = (Geometry) geomi.next();
94
	        if (g2 != geom)
95
	          if (containsPoint(p, g2, snapTolerance))
96
	            return true;
97
	      }
98
	    }
99
	    return false;
100
	  }
101

  
102
	  public static boolean containsPointInPolygon(Coordinate p, Polygon poly, double snapTolerance)
103
	  {
104
	    if (poly.isEmpty()) return false;
105
	    LinearRing shell = (LinearRing) poly.getExteriorRing();
106
	    if (! SnapCGAlgorithms.isPointInRing(p, shell.getCoordinates(), snapTolerance)) return false;
107
	    // now test if the point lies in or on the holes
108
	    for (int i = 0; i < poly.getNumInteriorRing(); i++) {
109
	      LinearRing hole = (LinearRing) poly.getInteriorRingN(i);
110
	      if (SnapCGAlgorithms.isPointInRing(p, hole.getCoordinates(), snapTolerance)) return false;
111
	    }
112
	    return true;
113
	  }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff