svn-gvsig-desktop / tags / v1_1_Build_1009 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrGT2.java @ 12649
History | View | Annotate | Download (8.99 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 | *
|
||
6 | 1100 | fjp | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 | 2943 | fjp | *
|
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 | 2943 | fjp | *
|
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 | 2943 | fjp | *
|
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 | *
|
||
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 | 2943 | fjp | *
|
34 | 1100 | fjp | * or
|
35 | 2943 | fjp | *
|
36 | 1100 | fjp | * IVER T.I. S.A
|
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | 2943 | fjp | *
|
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 | 9013 | 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.Filter; |
||
66 | import org.geotools.filter.FilterFactory; |
||
67 | import org.geotools.filter.GeometryFilter; |
||
68 | import org.geotools.filter.IllegalFilterException; |
||
69 | 513 | fjp | |
70 | 651 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
71 | 513 | fjp | import com.iver.cit.gvsig.fmap.ViewPort; |
72 | 2943 | fjp | import com.iver.cit.gvsig.fmap.core.IGeometry; |
73 | import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
||
74 | import com.iver.cit.gvsig.fmap.core.gt2.FLiteShape; |
||
75 | import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
||
76 | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
||
77 | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
||
78 | 5713 | fjp | import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
79 | import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
||
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 | |||
86 | DataStore dataStore; |
||
87 | String typeName;
|
||
88 | String tableName;
|
||
89 | static FilterFactory ff = FilterFactory.createFilterFactory();
|
||
90 | 513 | fjp | |
91 | 2943 | fjp | public Rectangle2D getFullExtent() throws DriverException { |
92 | // TODO Auto-generated method stub
|
||
93 | Rectangle2D r;
|
||
94 | Envelope jtsR = null;
|
||
95 | try {
|
||
96 | jtsR = dataStore.getFeatureSource(tableName).getBounds(); |
||
97 | } catch (IOException e) { |
||
98 | e.printStackTrace(); |
||
99 | throw new DriverException(e); |
||
100 | } |
||
101 | r = FConverter.convertEnvelopeToRectangle2D(jtsR); |
||
102 | return r;
|
||
103 | } |
||
104 | 513 | fjp | |
105 | 2969 | fjp | private void prepareDrawing() |
106 | { |
||
107 | |||
108 | } |
||
109 | private void drawSelectedFeatures() |
||
110 | { |
||
111 | |||
112 | } |
||
113 | 2943 | fjp | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
114 | Cancellable cancel, double scale) throws DriverException { |
||
115 | if (!isWithinScale(scale)) return; |
||
116 | 513 | fjp | try {
|
117 | 2969 | fjp | prepareDrawing(); |
118 | 2943 | fjp | FeatureSource featSource = dataStore.getFeatureSource(tableName); |
119 | |||
120 | Envelope env = new Envelope(viewPort.getExtent().getMinX(),
|
||
121 | viewPort.getExtent().getMinY(), viewPort.getExtent().getMaxX(), |
||
122 | viewPort.getExtent().getMaxY()); |
||
123 | 513 | fjp | |
124 | 2943 | fjp | // create filter to select only features that satify 300000 >= "field" >= 100000
|
125 | |||
126 | BBoxExpression bb = ff.createBBoxExpression(env); |
||
127 | GeometryFilter bboxFilter = |
||
128 | ff.createGeometryFilter(AbstractFilter.GEOMETRY_BBOX); |
||
129 | bboxFilter.addRightGeometry(bb); |
||
130 | String strGeom = dataStore.getSchema(tableName).getDefaultGeometry().getName();
|
||
131 | bboxFilter.addLeftGeometry( |
||
132 | ff.createAttributeExpression(dataStore.getSchema(tableName),strGeom)); |
||
133 | |||
134 | Query theQuery = new DefaultQuery(tableName, bboxFilter); |
||
135 | // Query theQuery = new DefaultQuery(tableName, Filter.NONE);
|
||
136 | Transaction t = new DefaultTransaction();
|
||
137 | FeatureReader reader = dataStore.getFeatureReader(theQuery, t); |
||
138 | Feature f = null;
|
||
139 | FSymbol sym = new FSymbol(FConstant.SYMBOL_TYPE_FILL);
|
||
140 | while ( reader.hasNext() ) {
|
||
141 | if (cancel.isCanceled()) {
|
||
142 | reader.close(); |
||
143 | break;
|
||
144 | } |
||
145 | |||
146 | f = reader.next(); |
||
147 | Geometry geom = f.getDefaultGeometry(); |
||
148 | FLiteShape shpLite = new FLiteShape(geom);
|
||
149 | IGeometry gAux = ShapeFactory.createGeometry(shpLite); |
||
150 | gAux.draw(g,viewPort,sym); |
||
151 | } |
||
152 | |||
153 | reader.close(); |
||
154 | |||
155 | } catch (IOException e) { |
||
156 | e.printStackTrace(); |
||
157 | throw new DriverException(e); |
||
158 | } catch (IllegalFilterException e) {
|
||
159 | // TODO Auto-generated catch block
|
||
160 | e.printStackTrace(); |
||
161 | } catch (NoSuchElementException e) { |
||
162 | // TODO Auto-generated catch block
|
||
163 | e.printStackTrace(); |
||
164 | } catch (IllegalAttributeException e) {
|
||
165 | // TODO Auto-generated catch block
|
||
166 | e.printStackTrace(); |
||
167 | 513 | fjp | } |
168 | |||
169 | 2943 | fjp | } |
170 | 513 | fjp | |
171 | 2943 | fjp | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
172 | 9013 | caballero | double scale, PrintRequestAttributeSet properties) throws DriverException { |
173 | 2943 | fjp | // TODO Auto-generated method stub
|
174 | 562 | fernando | |
175 | 2943 | fjp | } |
176 | |||
177 | /**
|
||
178 | * @return Returns the dataStore.
|
||
179 | */
|
||
180 | public DataStore getDataStore() {
|
||
181 | return dataStore;
|
||
182 | } |
||
183 | |||
184 | /**
|
||
185 | * @param dataStore The dataStore to set.
|
||
186 | * @throws IOException
|
||
187 | */
|
||
188 | public void setDataStore(DataStore dataStore) throws IOException { |
||
189 | this.dataStore = dataStore;
|
||
190 | // feature type name is defaulted to the name of shapefile (without extension)
|
||
191 | typeName = dataStore.getTypeNames()[0];
|
||
192 | } |
||
193 | |||
194 | /**
|
||
195 | * @param tableName The tableName to set.
|
||
196 | */
|
||
197 | public void setTableName(String tableName) { |
||
198 | this.tableName = tableName;
|
||
199 | } |
||
200 | |||
201 | 5713 | fjp | public void process(FeatureVisitor visitor, FBitSet subset) throws DriverException, VisitException { |
202 | // TODO Auto-generated method stub
|
||
203 | |||
204 | } |
||
205 | |||
206 | public void process(FeatureVisitor visitor, Rectangle2D rect) throws DriverException, VisitException { |
||
207 | try
|
||
208 | { |
||
209 | |||
210 | Envelope env = FConverter.convertRectangle2DtoEnvelope(rect); |
||
211 | |||
212 | |||
213 | BBoxExpression bb = ff.createBBoxExpression(env); |
||
214 | GeometryFilter bboxFilter = |
||
215 | ff.createGeometryFilter(AbstractFilter.GEOMETRY_BBOX); |
||
216 | bboxFilter.addRightGeometry(bb); |
||
217 | String strGeom = dataStore.getSchema(tableName).getDefaultGeometry().getName();
|
||
218 | bboxFilter.addLeftGeometry( |
||
219 | ff.createAttributeExpression(dataStore.getSchema(tableName),strGeom)); |
||
220 | |||
221 | Query theQuery = new DefaultQuery(tableName, bboxFilter); |
||
222 | // Query theQuery = new DefaultQuery(tableName, Filter.NONE);
|
||
223 | Transaction t = new DefaultTransaction();
|
||
224 | FeatureReader reader = dataStore.getFeatureReader(theQuery, t); |
||
225 | Feature f = null;
|
||
226 | while ( reader.hasNext() ) {
|
||
227 | f = reader.next(); |
||
228 | Geometry geom = f.getDefaultGeometry(); |
||
229 | FLiteShape shpLite = new FLiteShape(geom);
|
||
230 | IGeometry gAux = ShapeFactory.createGeometry(shpLite); |
||
231 | visitor.visit(gAux, -1);
|
||
232 | } |
||
233 | |||
234 | reader.close(); |
||
235 | |||
236 | } catch (IOException e) { |
||
237 | e.printStackTrace(); |
||
238 | throw new DriverException(e); |
||
239 | } catch (IllegalFilterException e) {
|
||
240 | // TODO Auto-generated catch block
|
||
241 | e.printStackTrace(); |
||
242 | } catch (NoSuchElementException e) { |
||
243 | // TODO Auto-generated catch block
|
||
244 | e.printStackTrace(); |
||
245 | } catch (IllegalAttributeException e) {
|
||
246 | // TODO Auto-generated catch block
|
||
247 | e.printStackTrace(); |
||
248 | } |
||
249 | |||
250 | |||
251 | } |
||
252 | |||
253 | public void process(FeatureVisitor visitor) throws DriverException, VisitException { |
||
254 | // TODO Auto-generated method stub
|
||
255 | |||
256 | } |
||
257 | |||
258 | public SelectableDataSource getRecordset() throws DriverException { |
||
259 | // TODO Auto-generated method stub
|
||
260 | // fjp: simplificar SelectableDataSource y quitar los m?todos que no
|
||
261 | // necesitamos. (getPrimeryKeys, getDataWare, getDataFactory... etc)
|
||
262 | return null; |
||
263 | } |
||
264 | |||
265 | 513 | fjp | } |