Statistics
| Revision:

root / trunk / libraries / libTopology / src / org / gvsig / fmap / core / FLyrUtil.java @ 23048

History | View | Annotate | Download (4.3 KB)

1
/*
2
 * Created on 10-abr-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: 
47
* $Log: 
48
*/
49
package org.gvsig.fmap.core;
50

    
51
import java.util.ArrayList;
52
import java.util.List;
53

    
54
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
55
import com.iver.cit.gvsig.fmap.MapContext;
56
import com.iver.cit.gvsig.fmap.core.IFeature;
57
import com.iver.cit.gvsig.fmap.core.IGeometry;
58
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
59
import com.iver.cit.gvsig.fmap.layers.FLayer;
60
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
61
import com.iver.cit.gvsig.fmap.layers.LayersIterator;
62
import com.iver.cit.gvsig.fmap.spatialindex.INearestNeighbourFinder;
63
import com.iver.cit.gvsig.fmap.spatialindex.ISpatialIndex;
64
import com.iver.cit.gvsig.fmap.spatialindex.RTreeJsi;
65

    
66
/**
67
 * Utility methods to work with FMap layers
68
 * @author Alvaro Zabala
69
 *
70
 */
71
public class FLyrUtil {
72
        /**
73
         * From a given FLyrVect it returns an INearestNeighbourFinder
74
         * spatial index.
75
         * 
76
         * @param lyr
77
         * @return
78
         */
79
        public static INearestNeighbourFinder getNearestNeighbourFinder(FLyrVect lyr) throws ReadDriverException{
80
                ISpatialIndex spatialIndex = lyr.getISpatialIndex();
81
                if( spatialIndex instanceof INearestNeighbourFinder){
82
                        return (INearestNeighbourFinder) spatialIndex;
83
                }
84
                
85
                RTreeJsi newSptIdx = new RTreeJsi();
86
                newSptIdx.create();
87
                IFeatureIterator iterator = lyr.getSource().getFeatureIterator();
88
                while(iterator.hasNext()){
89
                        IFeature feature = iterator.next();
90
                        IGeometry geometry = feature.getGeometry();
91
                        if(geometry != null)
92
                                newSptIdx.insert(geometry.getBounds2D(), Integer.parseInt(feature.getID()));
93
                }
94
                return newSptIdx;        
95
        }
96
        
97
        public static  List<FLyrVect> getActiveVectorialLyrs(MapContext mapContext){
98
                List<FLyrVect> activeVectorialLyrs = new ArrayList<FLyrVect>();
99
                LayersIterator it = new LayersIterator(mapContext.getLayers());
100
                while (it.hasNext())
101
                {
102
                        FLayer aux = (FLayer) it.next();
103
                        if (!aux.isActive())
104
                                continue;
105

    
106
                        if(aux instanceof FLyrVect)
107
                        {
108
                                activeVectorialLyrs.add((FLyrVect)aux);
109
                        }//if
110
                }//while
111
                return activeVectorialLyrs;
112
        }
113
        
114
        public static List<FLyrVect> getVectorialLayers(MapContext mapContext){
115
                List<FLyrVect> activeVectorialLyrs = new ArrayList<FLyrVect>();
116
                LayersIterator it = new LayersIterator(mapContext.getLayers());
117
                while (it.hasNext())
118
                {
119
                        FLayer aux = (FLayer) it.next();
120
                        if(aux instanceof FLyrVect)
121
                        {
122
                                activeVectorialLyrs.add((FLyrVect)aux);
123
                        }//if
124
                }//while
125
                return activeVectorialLyrs;
126
        }
127
        
128
        public static List<FLyrVect> getLayersOfType(MapContext mapContext, int shapeType){
129
                List<FLyrVect> activeVectorialLyrs = new ArrayList<FLyrVect>();
130
                LayersIterator it = new LayersIterator(mapContext.getLayers());
131
                while (it.hasNext())
132
                {
133
                        FLayer aux = (FLayer) it.next();
134
                        if(aux instanceof FLyrVect)
135
                        {
136
                                FLyrVect aux2 = (FLyrVect)aux;
137
                                try {
138
                                        if(aux2.getShapeType() == shapeType)
139
                                                activeVectorialLyrs.add((FLyrVect)aux);
140
                                } catch (ReadDriverException e) {
141
                                        continue;
142
                                }
143
                        }//if
144
                }//while
145
                return activeVectorialLyrs;
146
        }
147

    
148
}