Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / indexes / memoryspatial / MemorySpatialIndexProvider.java @ 44158

History | View | Annotate | Download (3.57 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.feature.impl.indexes.memoryspatial;
25

    
26
import java.util.List;
27

    
28
import org.gvsig.fmap.dal.exception.DataException;
29
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException;
30
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
31
import org.gvsig.fmap.dal.feature.spi.index.AbstractFeatureIndexProvider;
32
import org.gvsig.fmap.geom.Geometry;
33
import org.gvsig.fmap.geom.GeometryLocator;
34
import org.gvsig.fmap.geom.SpatialIndex;
35
import org.gvsig.fmap.geom.primitive.Envelope;
36

    
37
public class MemorySpatialIndexProvider extends AbstractFeatureIndexProvider {
38

    
39
        private SpatialIndex index = null;
40
        
41
        public MemorySpatialIndexProvider() {
42
                
43
        }
44
        
45
    public void initialize() {
46
            try {
47
                        this.index = GeometryLocator.getGeometryManager().createDefaultMemorySpatialIndex();
48
                } catch (Exception e) {
49
                        throw new RuntimeException();
50
                }
51
    }
52

    
53
    public void delete(Object o, FeatureReferenceProviderServices fref) {
54
        Geometry geom = (Geometry) o;
55
        this.index.remove(geom, fref.getOID());
56
    }
57

    
58
    public void insert(Object o, FeatureReferenceProviderServices fref) {
59
        if (o == null ) {
60
            return;
61
        }
62
        Geometry geom = (Geometry) o;
63
        this.index.insert(geom, fref.getOID());
64

    
65
    }
66

    
67
    public List match(Object value) throws FeatureIndexException {
68
        Envelope env = null;
69
        if (value instanceof Envelope) {
70
            env = (Envelope) value;
71
        } else {
72
            if (value instanceof Geometry) {
73
                env = ((Geometry) value).getEnvelope();
74
            }
75
        }
76
        return new LongList(this.index.queryAsList(env));
77
        
78
    }
79

    
80
    public List match(Object min, Object max) {
81
        throw new UnsupportedOperationException(
82
            "Can't perform this kind of search.");
83
    }
84

    
85
    public List nearest(int count, Object value) throws FeatureIndexException {
86
        throw new UnsupportedOperationException(
87
            "Can't perform this kind of search.");
88
    }
89

    
90
    public boolean isMatchSupported() {
91
        return true;
92
    }
93

    
94
    public boolean isNearestSupported() {
95
        return false;
96
    }
97

    
98
    public boolean isNearestToleranceSupported() {
99
        return false;
100
    }
101

    
102
    public boolean isRangeSupported() {
103
        return false;
104
    }
105

    
106
    public List nearest(int count, Object value, Object tolerance)
107
        throws FeatureIndexException {
108
        throw new UnsupportedOperationException();
109
    }
110

    
111
    public List range(Object value1, Object value2)
112
        throws FeatureIndexException {
113
        throw new UnsupportedOperationException();
114
    }
115

    
116
    public void clear() throws DataException {
117
        this.index.removeAll();
118
    }
119
 }