Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / vividsolutions / jts / geomgraph / SnapEdgeList.java @ 9178

History | View | Annotate | Download (4.77 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 9178 2006-12-04 19:30:23Z azabala $
47
* $Log$
48
* Revision 1.1  2006-12-04 19:30:23  azabala
49
* *** empty log message ***
50
*
51
* Revision 1.1  2006/10/17 18:25:53  azabala
52
* *** empty log message ***
53
*
54
* Revision 1.1  2006/10/05 19:20:57  azabala
55
* first version in cvs
56
*
57
*
58
*/
59
package com.vividsolutions.jts.geomgraph;
60

    
61
import java.awt.geom.Rectangle2D;
62
import java.util.ArrayList;
63
import java.util.Collection;
64
import java.util.Iterator;
65
import java.util.List;
66

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

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

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

    
123

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

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

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

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

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

    
178
}
179