root / trunk / libraries / libFMap / src / com / vividsolutions / jts / algorithms / SnapSimplePointInAreaLocator.java @ 10627
History | View | Annotate | Download (3.44 KB)
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 |
} |
114 |
|
115 |
} |
116 |
|