svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrGT2.java @ 11807
History | View | Annotate | Download (8.59 KB)
1 | 513 | fjp | /*
|
---|---|---|---|
2 | 2943 | fjp | * Created on 20-sep-2005
|
3 | 513 | fjp | *
|
4 | 2943 | fjp | * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 | 9010 | caballero | *
|
6 | 1100 | fjp | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 | 9010 | caballero | *
|
8 | 1100 | fjp | * 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 | 9010 | caballero | *
|
13 | 1100 | fjp | * 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 | 9010 | caballero | *
|
18 | 1100 | fjp | * 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 | 2943 | fjp | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
21 | 9010 | caballero | *
|
22 | 1100 | fjp | * 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 | 9010 | caballero | *
|
34 | 1100 | fjp | * or
|
35 | 9010 | caballero | *
|
36 | 1100 | fjp | * IVER T.I. S.A
|
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | 9010 | caballero | *
|
41 | 1100 | fjp | * +34 963163400
|
42 | * dac@iver.es
|
||
43 | */
|
||
44 | 513 | fjp | package com.iver.cit.gvsig.fmap.layers; |
45 | |||
46 | import java.awt.Graphics2D; |
||
47 | import java.awt.geom.Rectangle2D; |
||
48 | import java.awt.image.BufferedImage; |
||
49 | import java.io.IOException; |
||
50 | 2943 | fjp | import java.util.NoSuchElementException; |
51 | 513 | fjp | |
52 | 9010 | caballero | import javax.print.attribute.PrintRequestAttributeSet; |
53 | |||
54 | 2943 | fjp | import org.geotools.data.DataStore; |
55 | import org.geotools.data.DefaultQuery; |
||
56 | import org.geotools.data.DefaultTransaction; |
||
57 | import org.geotools.data.FeatureReader; |
||
58 | 513 | fjp | import org.geotools.data.FeatureSource; |
59 | 2943 | fjp | import org.geotools.data.Query; |
60 | import org.geotools.data.Transaction; |
||
61 | import org.geotools.feature.Feature; |
||
62 | import org.geotools.feature.IllegalAttributeException; |
||
63 | import org.geotools.filter.AbstractFilter; |
||
64 | import org.geotools.filter.BBoxExpression; |
||
65 | import org.geotools.filter.FilterFactory; |
||
66 | 10627 | caballero | import org.geotools.filter.FilterType; |
67 | 2943 | fjp | import org.geotools.filter.GeometryFilter; |
68 | import org.geotools.filter.IllegalFilterException; |
||
69 | 513 | fjp | |
70 | 10627 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
71 | import com.iver.cit.gvsig.exceptions.visitors.VisitorException; |
||
72 | 513 | fjp | import com.iver.cit.gvsig.fmap.ViewPort; |
73 | 2943 | fjp | import com.iver.cit.gvsig.fmap.core.IGeometry; |
74 | import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
||
75 | 10815 | jaume | import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
76 | 2943 | fjp | import com.iver.cit.gvsig.fmap.core.gt2.FLiteShape; |
77 | 10815 | jaume | import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
78 | 2943 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
79 | 5713 | fjp | import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
80 | 5317 | fjp | import com.iver.utiles.swing.threads.Cancellable; |
81 | 513 | fjp | import com.vividsolutions.jts.geom.Envelope; |
82 | 2943 | fjp | import com.vividsolutions.jts.geom.Geometry; |
83 | 513 | fjp | |
84 | 2943 | fjp | public class FLyrGT2 extends FLyrSecuential { |
85 | 9010 | caballero | |
86 | 2943 | fjp | DataStore dataStore; |
87 | String typeName;
|
||
88 | String tableName;
|
||
89 | static FilterFactory ff = FilterFactory.createFilterFactory();
|
||
90 | 513 | fjp | |
91 | 10627 | caballero | public Rectangle2D getFullExtent() throws ReadDriverException { |
92 | 2943 | fjp | Rectangle2D r;
|
93 | Envelope jtsR = null;
|
||
94 | try {
|
||
95 | jtsR = dataStore.getFeatureSource(tableName).getBounds(); |
||
96 | 9010 | caballero | } catch (IOException e) { |
97 | 10627 | caballero | throw new ReadDriverException(getName(),e); |
98 | 2943 | fjp | } |
99 | r = FConverter.convertEnvelopeToRectangle2D(jtsR); |
||
100 | return r;
|
||
101 | } |
||
102 | 513 | fjp | |
103 | 2969 | fjp | private void prepareDrawing() |
104 | { |
||
105 | 9010 | caballero | |
106 | 2969 | fjp | } |
107 | private void drawSelectedFeatures() |
||
108 | { |
||
109 | 9010 | caballero | |
110 | 2969 | fjp | } |
111 | 2943 | fjp | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
112 | 10627 | caballero | Cancellable cancel, double scale) throws ReadDriverException { |
113 | 2943 | fjp | if (!isWithinScale(scale)) return; |
114 | 513 | fjp | try {
|
115 | 2969 | fjp | prepareDrawing(); |
116 | 2943 | fjp | FeatureSource featSource = dataStore.getFeatureSource(tableName); |
117 | 9010 | caballero | |
118 | 2943 | fjp | Envelope env = new Envelope(viewPort.getExtent().getMinX(),
|
119 | 9010 | caballero | viewPort.getExtent().getMinY(), viewPort.getExtent().getMaxX(), |
120 | 2943 | fjp | viewPort.getExtent().getMaxY()); |
121 | 513 | fjp | |
122 | 2943 | fjp | // create filter to select only features that satify 300000 >= "field" >= 100000
|
123 | 9010 | caballero | |
124 | 2943 | fjp | BBoxExpression bb = ff.createBBoxExpression(env); |
125 | GeometryFilter bboxFilter = |
||
126 | ff.createGeometryFilter(AbstractFilter.GEOMETRY_BBOX); |
||
127 | bboxFilter.addRightGeometry(bb); |
||
128 | String strGeom = dataStore.getSchema(tableName).getDefaultGeometry().getName();
|
||
129 | bboxFilter.addLeftGeometry( |
||
130 | ff.createAttributeExpression(dataStore.getSchema(tableName),strGeom)); |
||
131 | 9010 | caballero | |
132 | 2943 | fjp | Query theQuery = new DefaultQuery(tableName, bboxFilter); |
133 | // Query theQuery = new DefaultQuery(tableName, Filter.NONE);
|
||
134 | 9010 | caballero | Transaction t = new DefaultTransaction();
|
135 | 2943 | fjp | FeatureReader reader = dataStore.getFeatureReader(theQuery, t); |
136 | Feature f = null;
|
||
137 | 10815 | jaume | IMarkerSymbol sym = SymbologyFactory.createDefaultMarkerSymbol(); |
138 | 2943 | fjp | while ( reader.hasNext() ) {
|
139 | if (cancel.isCanceled()) {
|
||
140 | reader.close(); |
||
141 | break;
|
||
142 | } |
||
143 | 9010 | caballero | |
144 | 2943 | fjp | f = reader.next(); |
145 | Geometry geom = f.getDefaultGeometry(); |
||
146 | FLiteShape shpLite = new FLiteShape(geom);
|
||
147 | IGeometry gAux = ShapeFactory.createGeometry(shpLite); |
||
148 | gAux.draw(g,viewPort,sym); |
||
149 | } |
||
150 | 9010 | caballero | |
151 | reader.close(); |
||
152 | |||
153 | 2943 | fjp | } catch (IOException e) { |
154 | 10627 | caballero | throw new ReadDriverException(getName(),e); |
155 | 2943 | fjp | } catch (IllegalFilterException e) {
|
156 | 10627 | caballero | throw new ReadDriverException(getName(),e); |
157 | 2943 | fjp | } catch (NoSuchElementException e) { |
158 | 10627 | caballero | throw new ReadDriverException(getName(),e); |
159 | 2943 | fjp | } catch (IllegalAttributeException e) {
|
160 | 10627 | caballero | throw new ReadDriverException(getName(),e); |
161 | 513 | fjp | } |
162 | |||
163 | 2943 | fjp | } |
164 | 513 | fjp | |
165 | 2943 | fjp | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
166 | 10627 | caballero | double scale, PrintRequestAttributeSet properties) throws ReadDriverException { |
167 | 2943 | fjp | // TODO Auto-generated method stub
|
168 | 562 | fernando | |
169 | 2943 | fjp | } |
170 | |||
171 | /**
|
||
172 | * @return Returns the dataStore.
|
||
173 | */
|
||
174 | public DataStore getDataStore() {
|
||
175 | return dataStore;
|
||
176 | } |
||
177 | |||
178 | /**
|
||
179 | * @param dataStore The dataStore to set.
|
||
180 | 9010 | caballero | * @throws IOException
|
181 | 2943 | fjp | */
|
182 | public void setDataStore(DataStore dataStore) throws IOException { |
||
183 | this.dataStore = dataStore;
|
||
184 | // feature type name is defaulted to the name of shapefile (without extension)
|
||
185 | typeName = dataStore.getTypeNames()[0];
|
||
186 | } |
||
187 | |||
188 | /**
|
||
189 | * @param tableName The tableName to set.
|
||
190 | */
|
||
191 | public void setTableName(String tableName) { |
||
192 | this.tableName = tableName;
|
||
193 | } |
||
194 | |||
195 | 10627 | caballero | public void process(FeatureVisitor visitor, FBitSet subset) throws ReadDriverException, VisitorException { |
196 | 5713 | fjp | // TODO Auto-generated method stub
|
197 | 9010 | caballero | |
198 | 5713 | fjp | } |
199 | |||
200 | 10627 | caballero | public void process(FeatureVisitor visitor, Rectangle2D rect) throws ReadDriverException, VisitorException { |
201 | 5713 | fjp | try
|
202 | { |
||
203 | 9010 | caballero | |
204 | 5713 | fjp | Envelope env = FConverter.convertRectangle2DtoEnvelope(rect); |
205 | 9010 | caballero | |
206 | |||
207 | 5713 | fjp | BBoxExpression bb = ff.createBBoxExpression(env); |
208 | GeometryFilter bboxFilter = |
||
209 | 10627 | caballero | ff.createGeometryFilter(FilterType.GEOMETRY_BBOX); |
210 | 5713 | fjp | bboxFilter.addRightGeometry(bb); |
211 | String strGeom = dataStore.getSchema(tableName).getDefaultGeometry().getName();
|
||
212 | bboxFilter.addLeftGeometry( |
||
213 | ff.createAttributeExpression(dataStore.getSchema(tableName),strGeom)); |
||
214 | 9010 | caballero | |
215 | 5713 | fjp | Query theQuery = new DefaultQuery(tableName, bboxFilter); |
216 | // Query theQuery = new DefaultQuery(tableName, Filter.NONE);
|
||
217 | 9010 | caballero | Transaction t = new DefaultTransaction();
|
218 | 5713 | fjp | FeatureReader reader = dataStore.getFeatureReader(theQuery, t); |
219 | Feature f = null;
|
||
220 | 9010 | caballero | while ( reader.hasNext() ) {
|
221 | 5713 | fjp | f = reader.next(); |
222 | Geometry geom = f.getDefaultGeometry(); |
||
223 | FLiteShape shpLite = new FLiteShape(geom);
|
||
224 | IGeometry gAux = ShapeFactory.createGeometry(shpLite); |
||
225 | visitor.visit(gAux, -1);
|
||
226 | } |
||
227 | 9010 | caballero | |
228 | reader.close(); |
||
229 | |||
230 | 5713 | fjp | } catch (IOException e) { |
231 | 10627 | caballero | throw new ReadDriverException(getName(),e); |
232 | 5713 | fjp | } catch (IllegalFilterException e) {
|
233 | 10627 | caballero | throw new ReadDriverException(getName(),e); |
234 | 5713 | fjp | } catch (NoSuchElementException e) { |
235 | 10627 | caballero | throw new ReadDriverException(getName(),e); |
236 | 5713 | fjp | } catch (IllegalAttributeException e) {
|
237 | 10627 | caballero | throw new ReadDriverException(getName(),e); |
238 | 5713 | fjp | } |
239 | |||
240 | 9010 | caballero | |
241 | 5713 | fjp | } |
242 | |||
243 | 10627 | caballero | public void process(FeatureVisitor visitor) throws ReadDriverException, VisitorException { |
244 | 5713 | fjp | // TODO Auto-generated method stub
|
245 | 9010 | caballero | |
246 | 5713 | fjp | } |
247 | |||
248 | 10627 | caballero | public SelectableDataSource getRecordset() {
|
249 | 5713 | fjp | // TODO Auto-generated method stub
|
250 | // fjp: simplificar SelectableDataSource y quitar los m?todos que no
|
||
251 | // necesitamos. (getPrimeryKeys, getDataWare, getDataFactory... etc)
|
||
252 | return null; |
||
253 | } |
||
254 | |||
255 | 513 | fjp | } |