Revision 10627 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/spatialindex/RTreeSptLib.java
RTreeSptLib.java | ||
---|---|---|
35 | 35 |
*/ |
36 | 36 |
private static final int defaultPageSize = 32 * 1024; |
37 | 37 |
private static final double defaultFillFactor = 0.85d; |
38 |
|
|
38 |
|
|
39 | 39 |
/** |
40 | 40 |
* Size of memory buffer of the index |
41 | 41 |
*/ |
... | ... | |
52 | 52 |
* @param fileName name of the rtree spatial index file |
53 | 53 |
* @throws SpatialIndexException |
54 | 54 |
*/ |
55 |
|
|
55 |
|
|
56 | 56 |
public RTreeSptLib(boolean overwriteFile, String fileName) |
57 | 57 |
throws SpatialIndexException { |
58 | 58 |
try { |
... | ... | |
71 | 71 |
diskfile = new DiskStorageManager(ps); |
72 | 72 |
load(); |
73 | 73 |
} catch (SecurityException e) { |
74 |
throw new SpatialIndexException("No tenemos permisos de escritura?", e); |
|
74 |
//throw new SpatialIndexException("No tenemos permisos de escritura?", e); |
|
75 |
throw new SpatialIndexException(); |
|
75 | 76 |
} catch (FileNotFoundException e) { |
76 |
throw new SpatialIndexException("El fichero no existe", e); |
|
77 |
//throw new SpatialIndexException("El fichero no existe", e); |
|
78 |
throw new SpatialIndexException(); |
|
77 | 79 |
} catch (IOException e) { |
78 |
throw new SpatialIndexException("Error de I/O", e); |
|
80 |
//throw new SpatialIndexException("Error de I/O", e); |
|
81 |
throw new SpatialIndexException(); |
|
79 | 82 |
} |
80 | 83 |
} |
81 |
|
|
84 |
|
|
82 | 85 |
/** |
83 | 86 |
* If the spatial index file exists and has content |
84 | 87 |
*/ |
85 | 88 |
public boolean exists(){ |
86 | 89 |
return (new File(rtreeFile+".dat").length() != 0); |
87 | 90 |
} |
88 |
|
|
89 |
|
|
91 |
|
|
92 |
|
|
90 | 93 |
class RTreeVisitor implements IVisitor{ |
91 | 94 |
ArrayList solution = new ArrayList(); |
92 | 95 |
public void visitNode(INode n) { |
... | ... | |
99 | 102 |
} |
100 | 103 |
} |
101 | 104 |
|
102 |
|
|
105 |
|
|
103 | 106 |
public List query(Rectangle2D rect) { |
104 | 107 |
List solution = null; |
105 | 108 |
Region region = createRegion(rect); |
... | ... | |
122 | 125 |
* Warn! This RTree implemention doesnt care if 'index' |
123 | 126 |
* entry has been indexed yet |
124 | 127 |
*/ |
125 |
public void insert(Rectangle2D rect, int index) {
|
|
128 |
public void insert(Rectangle2D rect, int index) { |
|
126 | 129 |
rtree.insertData(null, createRegion(rect), index); |
127 | 130 |
} |
128 |
|
|
131 |
|
|
129 | 132 |
private Region createRegion(Rectangle2D rect){ |
130 | 133 |
Region region = null; |
131 | 134 |
double xmin = rect.getMinX(); |
... | ... | |
173 | 176 |
return solution; |
174 | 177 |
} |
175 | 178 |
|
176 |
|
|
177 |
|
|
179 |
|
|
180 |
|
|
178 | 181 |
public void flush(){ |
179 | 182 |
rtree.flush(); |
180 | 183 |
} |
181 |
|
|
184 |
|
|
182 | 185 |
public static void main(String[] args){ |
183 | 186 |
try { |
184 | 187 |
File file = new File("c:/kk/pruebartree.idx"); |
... | ... | |
199 | 202 |
rtree.insert(new Rectangle2D.Double(0,0, 40, 48540), 6); |
200 | 203 |
rtree.insert(new Rectangle2D.Double(0,0, 6330, 56400), 7); |
201 | 204 |
rtree.flush(); |
202 |
|
|
205 |
|
|
203 | 206 |
} catch (SpatialIndexException e) { |
204 | 207 |
e.printStackTrace(); |
205 | 208 |
System.exit(-1); |
206 | 209 |
} |
207 |
|
|
210 |
|
|
208 | 211 |
} |
209 | 212 |
|
210 | 213 |
public void load() { |
Also available in: Unified diff