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