Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / vividsolutions / jts / geomgraph / SnapEdgeList.java @ 10627

History | View | Annotate | Download (4.64 KB)

1
/*
2
 * Created on 04-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: SnapEdgeList.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:30:23  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/05 19:20:57  azabala
58
* first version in cvs
59
*
60
*
61
*/
62
package com.vividsolutions.jts.geomgraph;
63

    
64
import java.awt.geom.Rectangle2D;
65
import java.util.ArrayList;
66
import java.util.Collection;
67
import java.util.Iterator;
68
import java.util.List;
69

    
70
import com.iver.cit.gvsig.fmap.spatialindex.RTreeJsi;
71
import com.vividsolutions.jts.geom.Envelope;
72
/**
73
 * Overwrites jts' EdgeList to allow spatial queries
74
 * consideering snap.
75
 * 
76
 * (for example, (0 0, 5 0) and (0.01 0.01, 5.01 0.02)
77
 * arent equivalent in findEqualEdge, even thought with a
78
 * snap distance of 0.1
79
 * 
80
 * 
81
 * 
82
 * */
83
public class SnapEdgeList extends EdgeList {
84
        private List edges = new ArrayList();
85
         
86
//          private SpatialIndex index = new Quadtree();
87
        
88
        //El quadtree no funciona bien para indexar dimensiones
89
        //lineales o lineas.
90
        
91
          private RTreeJsi spatialIndex = new RTreeJsi();
92
          private double snapTolerance;
93
          
94
          
95
          
96
          public SnapEdgeList(double snapTolerance) {
97
                  this.snapTolerance = snapTolerance;
98
          }
99

    
100
          /**
101
           * Insert an edge unless it is already in the list
102
           */
103
          public void add(Edge e)
104
          {
105
//        int position = edges.size();                  
106
            edges.add(e);
107
            //TODO me peta el indice espacial
108
//            Envelope oldEnvelope = e.getEnvelope();
109
//                Rectangle2D newEnvelope = getEnvelopeForSnap(oldEnvelope);
110
//                spatialIndex.insert(newEnvelope, position);
111
          }
112

    
113
          private Rectangle2D getEnvelopeForSnap(Envelope oldEnvelope){
114
                        double xmin = oldEnvelope.getMinX() - snapTolerance;
115
                          double ymin = oldEnvelope.getMinY() - snapTolerance;
116
                          double width = oldEnvelope.getWidth() + snapTolerance;
117
                          double height = oldEnvelope.getHeight() + snapTolerance;
118
                          
119
                          return new Rectangle2D.Double(xmin, ymin, width, height);
120
          }
121

    
122

    
123
//         <FIX> fast lookup for edges
124
          /**
125
           * If there is an edge equal to e already in the list, return it.
126
           * Otherwise return null.
127
           * @return  equal edge, if there is one already in the list
128
           *          null otherwise
129
           */
130
          public Edge findEqualEdge(Edge e)
131
          {
132
                  //TODO NO ENCUENTRO UN INDICE ESPACIAL EN CONDICIONES
133
//            Collection testEdges = spatialIndex.
134
//             query(getEnvelopeForSnap(e.getEnvelope()));
135
                  //PETA CON QUADTREE Y CON RTREE DE JSI
136

    
137
                Collection testEdges = edges;  
138
                  
139
            for (Iterator i = testEdges.iterator(); i.hasNext(); ) {
140
                    //TODO me peta el indice espacial
141
//              int index = ((Integer)i.next()).intValue();
142
              Edge testEdge = (Edge) i.next();        
143
                    
144
//              Edge testEdge = (Edge) edges.get(index);
145
              if (testEdge.equals(e) ) return testEdge;
146
            }
147
            return null;
148
          }
149
          
150
          public void addAll(Collection edgeColl)
151
          {
152
            for (Iterator i = edgeColl.iterator(); i.hasNext(); ) {
153
              add((Edge) i.next());
154
            }
155
          }
156
          
157
          public Iterator iterator() { return edges.iterator(); }
158

    
159
          public Edge get(int i) { return (Edge) edges.get(i); }
160

    
161
          /**
162
           * If the edge e is already in the list, return its index.
163
           * @return  index, if e is already in the list
164
           *          -1 otherwise
165
           */
166
          public int findEdgeIndex(Edge e)
167
          {
168
            for (int i = 0; i < edges.size(); i++) {
169
              if ( ((Edge) edges.get(i)).equals(e) ) return i;
170
            }
171
            return -1;
172
          }
173

    
174
          
175
          public List getEdges() { return edges; }
176

    
177
}
178