svn-gvsig-desktop / tags / J2ME_compat_v1_2_Build_1209 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / featureiterators / ReprojectWrapperFeatureIterator.java @ 19509
History | View | Annotate | Download (3.51 KB)
1 |
/*
|
---|---|
2 |
* Created on 07-jun-2007
|
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: ReprojectWrapperFeatureIterator.java 13882 2007-09-19 16:25:05Z jaume $
|
47 |
* $Log$
|
48 |
* Revision 1.2 2007-09-19 16:25:04 jaume
|
49 |
* ReadExpansionFileException removed from this context
|
50 |
*
|
51 |
* Revision 1.1 2007/06/07 11:49:28 azabala
|
52 |
* first version in cvs
|
53 |
*
|
54 |
*
|
55 |
*/
|
56 |
package com.iver.cit.gvsig.fmap.drivers.featureiterators; |
57 |
|
58 |
import org.cresques.cts.ICoordTrans; |
59 |
import org.cresques.cts.IProjection; |
60 |
|
61 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
62 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
63 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
64 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
65 |
|
66 |
/**
|
67 |
* FeatureIterator for drivers that can not reproject
|
68 |
* features
|
69 |
* @author azabala
|
70 |
*
|
71 |
*/
|
72 |
public class ReprojectWrapperFeatureIterator implements IFeatureIterator{ |
73 |
|
74 |
|
75 |
IFeatureIterator featureIterator; |
76 |
protected IProjection sourceProjection;
|
77 |
protected IProjection targetProjection;
|
78 |
|
79 |
public ReprojectWrapperFeatureIterator(IFeatureIterator featureIterator,
|
80 |
IProjection sourceProj, |
81 |
IProjection targetProj){ |
82 |
this.featureIterator = featureIterator;
|
83 |
this.sourceProjection = sourceProj;
|
84 |
this.targetProjection = targetProj;
|
85 |
} |
86 |
|
87 |
public boolean hasNext() throws ReadDriverException { |
88 |
return featureIterator.hasNext();
|
89 |
} |
90 |
|
91 |
public IFeature next() throws ReadDriverException { |
92 |
IFeature solution = featureIterator.next(); |
93 |
reprojectIfNecessary(solution.getGeometry()); |
94 |
return solution;
|
95 |
} |
96 |
|
97 |
public void closeIterator() throws ReadDriverException { |
98 |
featureIterator.closeIterator(); |
99 |
} |
100 |
|
101 |
/**
|
102 |
*
|
103 |
* Checks if must reproject the given geom
|
104 |
* and reprojects it if true
|
105 |
* @param geom
|
106 |
*
|
107 |
* TODO Esto es igual que DefaultFeatureIterator. Esta clase
|
108 |
* no extiende de la anterior porque esta clase no quiere saber nada
|
109 |
* del origen de datos (ReadableVectorial). Refactorizar y crear una
|
110 |
* clase abstracta intermedia entre ambas
|
111 |
*/
|
112 |
protected void reprojectIfNecessary(IGeometry geom){ |
113 |
if(this.targetProjection != null && |
114 |
this.sourceProjection != null && |
115 |
this.targetProjection.getAbrev() != this.sourceProjection.getAbrev()){ |
116 |
ICoordTrans trans = sourceProjection.getCT(targetProjection); |
117 |
geom.reProject(trans); |
118 |
} |
119 |
} |
120 |
|
121 |
} |
122 |
|