root / trunk / libraries / libCq_CMS_praster / src / org / cresques / px / gml / FeatureCollection.java @ 8026
History | View | Annotate | Download (5.47 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.cresques.px.gml; |
25 |
|
26 |
import org.cresques.cts.ICoordTrans; |
27 |
import org.cresques.cts.IProjection; |
28 |
|
29 |
import org.cresques.geo.ViewPortData; |
30 |
|
31 |
import org.cresques.px.Extent; |
32 |
import org.cresques.px.IObjList; |
33 |
import org.cresques.px.PxObj; |
34 |
import org.cresques.px.dxf.DxfEntityList; |
35 |
|
36 |
import java.awt.Graphics2D; |
37 |
import java.awt.geom.Point2D; |
38 |
|
39 |
import java.util.Hashtable; |
40 |
import java.util.Iterator; |
41 |
import java.util.Vector; |
42 |
|
43 |
|
44 |
/**
|
45 |
* FeatureCollection de .gml y .shp
|
46 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
47 |
* jmorell: A?adidas a FeatureCollection las capacidades de almacenamiento propias de
|
48 |
* Feature mediante herencia.
|
49 |
*/
|
50 |
public class FeatureCollection extends Feature implements IObjList.vector { |
51 |
IProjection proj = null;
|
52 |
public Vector data = null; |
53 |
|
54 |
/**
|
55 |
* Constructor de FeatureCollection.
|
56 |
* @param proj, Proyecci?n cartogr?fica en la que se encuentra la FeatureCollection.
|
57 |
*/
|
58 |
public FeatureCollection(IProjection proj) {
|
59 |
extent = new Extent();
|
60 |
data = new Vector(); |
61 |
property = new Hashtable(); |
62 |
} |
63 |
|
64 |
/**
|
65 |
* Permite a?adir un objeto gr?fico a la lista.
|
66 |
* @param obj, Objeto gr?fico que implemente el interface Extent.Has
|
67 |
*/
|
68 |
public void add(Extent.Has feature) { |
69 |
Extent ext = feature.getExtent(); |
70 |
|
71 |
if (extent != null) { |
72 |
extent.add(ext); |
73 |
data.add(feature); |
74 |
} |
75 |
} |
76 |
|
77 |
/**
|
78 |
* Devuelve los obhjetos gr?ficos de la lista cuyos extents contengan al
|
79 |
* punto que se le pasa como argumento.
|
80 |
* @param pt, punto para localizar los objetos gr?ficos.
|
81 |
* @return IObjList, Conjunto de objetos gr?ficos que contienen a pt.
|
82 |
*/
|
83 |
public IObjList getAt(Point2D pt) { |
84 |
IObjList oList = new DxfEntityList(proj);
|
85 |
Iterator iter = iterator();
|
86 |
|
87 |
while (iter.hasNext()) {
|
88 |
Extent.Has o = (Extent.Has) iter.next(); |
89 |
|
90 |
if (o.getExtent().isAt(pt)) {
|
91 |
oList.add(o); |
92 |
} |
93 |
} |
94 |
|
95 |
return oList;
|
96 |
} |
97 |
|
98 |
/**
|
99 |
* Devuelve un iterador para recorrer los elementos de la lista de objetos gr?ficos.
|
100 |
* @return Iterator, iterador.
|
101 |
*/
|
102 |
public Iterator iterator() { |
103 |
return data.iterator();
|
104 |
} |
105 |
|
106 |
/**
|
107 |
* Devuelve la cantidad de elementos que contiene la lista de objetos gr?ficos.
|
108 |
* @return int
|
109 |
*/
|
110 |
public int size() { |
111 |
return data.size();
|
112 |
} |
113 |
|
114 |
/**
|
115 |
* Permite eliminar un elemento de la lista de objetos gr?ficos.
|
116 |
* @param obj, Objeto que queremos eliminar.
|
117 |
*/
|
118 |
public void remove(Object obj) { |
119 |
data.remove(obj); |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Permite vac?ar la lista de objetos gr?ficos.
|
124 |
*/
|
125 |
public void clear() { |
126 |
extent = new Extent();
|
127 |
data.clear(); |
128 |
} |
129 |
|
130 |
/**
|
131 |
* Devuelve uno de los elementos de la lista de objetos gr?ficos.
|
132 |
* @param i, ?ndice del elemento de la lista que queremos obtener.
|
133 |
* @return Extent.Has, elemento gr?fico que queremos obtener.
|
134 |
*/
|
135 |
public Extent.Has get(int i) { |
136 |
return (Extent.Has) data.get(i);
|
137 |
} |
138 |
|
139 |
/**
|
140 |
* Devuelve la proyecci?n cartogr?fica en la que se encuentra la FeatureCollection.
|
141 |
* @return IProjection, proyecci?n cartogr?fica.
|
142 |
*/
|
143 |
public IProjection getProjection() {
|
144 |
return proj;
|
145 |
} |
146 |
|
147 |
/**
|
148 |
* Establece la proyecci?n cartogr?fica en la que se encuentra la FeatureCollection.
|
149 |
* @param p, Proyecci?n cartogr?fica.
|
150 |
*/
|
151 |
public void setProjection(IProjection p) { |
152 |
proj = p; |
153 |
} |
154 |
|
155 |
/**
|
156 |
* Permite cambiar la proyecci?n en la que se encuentra la FeatureCollection a
|
157 |
* trav?s de un conjunto de coordenadas de transformaci?n.
|
158 |
* @param rp, Coordenadas de transformaci?n.
|
159 |
*/
|
160 |
public void reProject(ICoordTrans rp) { |
161 |
extent = new Extent();
|
162 |
|
163 |
Feature f; |
164 |
Geometry g; |
165 |
Iterator iter = iterator();
|
166 |
|
167 |
while (iter.hasNext()) {
|
168 |
f = (Feature) iter.next(); |
169 |
g = f.getGeometry(); |
170 |
g.reProject(rp); |
171 |
extent.add(g.getExtent()); |
172 |
} |
173 |
|
174 |
setProjection(rp.getPDest()); |
175 |
} |
176 |
|
177 |
/**
|
178 |
* Permite dibujar las Features que conforman la FeatureCollection.
|
179 |
*/
|
180 |
public void draw(Graphics2D g, ViewPortData vp) { |
181 |
Iterator iter = iterator();
|
182 |
|
183 |
while (iter.hasNext()) {
|
184 |
Feature f = (Feature) iter.next(); |
185 |
f.draw(g, vp); |
186 |
} |
187 |
} |
188 |
|
189 |
/**
|
190 |
* Permite obtener el extent de la FeatureCollection.
|
191 |
* @return Extent, rect?ngulo en donde se ubican las Features que conforman la
|
192 |
* FeatureCollection.
|
193 |
*/
|
194 |
public Extent getExtent() {
|
195 |
return extent;
|
196 |
} |
197 |
} |