svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_spatialindex / src / org / gvsig / fmap / data / index / spatial / gt2 / QuadTreeGt2Factory.java @ 23803
History | View | Annotate | Download (2.58 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 {{Company}} {{Task}}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.fmap.data.index.spatial.gt2; |
29 |
|
30 |
import java.io.File; |
31 |
import java.io.IOException; |
32 |
|
33 |
import org.gvsig.fmap.data.index.Index; |
34 |
import org.gvsig.fmap.data.index.IndexException; |
35 |
import org.gvsig.fmap.data.index.IndexFactory; |
36 |
import org.gvsig.fmap.data.index.IndexParameters; |
37 |
import org.gvsig.fmap.geom.primitive.Envelope; |
38 |
import org.gvsig.tools.exception.BaseException; |
39 |
|
40 |
public class QuadTreeGt2Factory extends IndexFactory { |
41 |
|
42 |
static {
|
43 |
registerFactory(Factories.TYPE_GEOMETRY.GT2_QUADTREE, "QuadTreeGt2Factory", QuadTreeGt2Factory.class);
|
44 |
} |
45 |
|
46 |
public Index createIndex(IndexParameters params) throws IndexException { |
47 |
if (params == null) throw new IllegalArgumentException("IndexParameters cannot be null."); |
48 |
if (params.getFeatureStore() == null) throw new IllegalArgumentException("FeatureStore cannot be null."); |
49 |
if (params.getFeatureType() == null) throw new IllegalArgumentException("FeatureType cannot be null."); |
50 |
|
51 |
Index index = null;
|
52 |
|
53 |
try {
|
54 |
File file = null; |
55 |
if (params.getName() == null) { |
56 |
file = File.createTempFile(params.getFeatureStore().getName(), ".qix"); |
57 |
} else {
|
58 |
file = new File(params.getFeatureStore().getName() + "-" + params.getName() + ".qix"); |
59 |
} |
60 |
|
61 |
Envelope envelope = (Envelope) params.getFeatureStore().getMetadata().get("extent");
|
62 |
int featureCount = params.getFeatureStore().getDataCollection().size();
|
63 |
|
64 |
index = new QuadtreeGt2(file.getAbsolutePath(), "NM", envelope, featureCount, params.isOverwrite()); |
65 |
index.rebuild(); |
66 |
} catch (IOException e) { |
67 |
throw new IndexException(e); |
68 |
} catch (BaseException e) {
|
69 |
throw new IndexException(e); |
70 |
} |
71 |
|
72 |
return index;
|
73 |
} |
74 |
} |