Revision 4179 org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/grid/roi/VectorialROIsReader.java
VectorialROIsReader.java | ||
---|---|---|
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
4 | 4 |
* of the Valencian Government (CIT) |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
9 | 9 |
* of the License, or (at your option) any later version. |
10 |
*
|
|
10 |
* |
|
11 | 11 |
* This program is distributed in the hope that it will be useful, |
12 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 |
* GNU General Public License for more details. |
15 |
*
|
|
15 |
* |
|
16 | 16 |
* You should have received a copy of the GNU General Public License |
17 | 17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 |
* MA 02110-1301, USA. |
20 |
*
|
|
20 |
* |
|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.raster.impl.grid.roi; |
23 | 23 |
|
... | ... | |
29 | 29 |
import java.util.List; |
30 | 30 |
|
31 | 31 |
import org.cresques.cts.IProjection; |
32 |
import org.slf4j.LoggerFactory; |
|
33 |
|
|
32 | 34 |
import org.gvsig.fmap.dal.DALLocator; |
33 | 35 |
import org.gvsig.fmap.dal.DataManager; |
34 | 36 |
import org.gvsig.fmap.dal.coverage.exception.FileNotExistsException; |
... | ... | |
52 | 54 |
import org.gvsig.raster.roi.ROI; |
53 | 55 |
import org.gvsig.raster.roi.ROIReader; |
54 | 56 |
import org.gvsig.tools.dispose.DisposableIterator; |
55 |
import org.slf4j.LoggerFactory; |
|
56 | 57 |
|
57 | 58 |
|
58 | 59 |
public class VectorialROIsReader implements ROIReader { |
59 | 60 |
private HashMap<String, ROI> rois = null; |
60 | 61 |
private RasterDataStore store = null; |
61 | 62 |
private Envelope bbox = null; |
62 |
private FeatureStore[] featureStore = null;
|
|
63 |
private FeatureStore[] featureStore = null; |
|
63 | 64 |
|
64 | 65 |
public VectorialROIsReader( |
65 |
FeatureStore featureStore,
|
|
66 |
RasterDataStore store,
|
|
66 |
FeatureStore featureStore, |
|
67 |
RasterDataStore store, |
|
67 | 68 |
IProjection projection) { |
68 | 69 |
Rectangle2D e = store.getExtent().toRectangle2D(); |
69 | 70 |
try { |
... | ... | |
72 | 73 |
} catch (CreateEnvelopeException e1) { |
73 | 74 |
LoggerFactory.getLogger(VectorialROIsReader.class).error("Error creating the envelope", e); |
74 | 75 |
} |
75 |
|
|
76 |
|
|
76 | 77 |
this.store = store; |
77 | 78 |
this.featureStore = new FeatureStore[1]; |
78 | 79 |
this.featureStore[0] = featureStore; |
79 | 80 |
} |
80 |
|
|
81 |
|
|
81 | 82 |
/** |
82 | 83 |
* Constructor using the envelope of the raster layer |
83 | 84 |
* @param filename |
... | ... | |
87 | 88 |
* @throws FileNotExistsException |
88 | 89 |
*/ |
89 | 90 |
public VectorialROIsReader( |
90 |
String filename,
|
|
91 |
RasterDataStore store,
|
|
91 |
String filename, |
|
92 |
RasterDataStore store, |
|
92 | 93 |
IProjection projection) throws ROIException, FileNotExistsException { |
93 | 94 |
Rectangle2D e = store.getExtent().toRectangle2D(); |
94 | 95 |
try { |
... | ... | |
101 | 102 |
} |
102 | 103 |
|
103 | 104 |
public VectorialROIsReader( |
104 |
String filename,
|
|
105 |
RasterDataStore store,
|
|
105 |
String filename, |
|
106 |
RasterDataStore store, |
|
106 | 107 |
IProjection projection, |
107 | 108 |
Envelope bbox) throws ROIException, FileNotExistsException { |
108 | 109 |
init(filename, store, projection, bbox); |
109 | 110 |
} |
110 |
|
|
111 |
|
|
111 | 112 |
public void init( |
112 |
String filename,
|
|
113 |
RasterDataStore store,
|
|
113 |
String filename, |
|
114 |
RasterDataStore store, |
|
114 | 115 |
IProjection projection, |
115 | 116 |
Envelope bbox) throws ROIException, FileNotExistsException { |
116 | 117 |
this.store = store; |
... | ... | |
119 | 120 |
if(file.exists()) { |
120 | 121 |
this.featureStore = new FeatureStore[1]; |
121 | 122 |
this.featureStore[0] = openOneROIFile(file, projection); |
122 |
} else {
|
|
123 |
file = new File(filename + ".shp");
|
|
123 |
} else { |
|
124 |
file = new File(filename + ".shp"); |
|
124 | 125 |
if(file.exists()) { |
125 | 126 |
this.featureStore = new FeatureStore[1]; |
126 | 127 |
this.featureStore[0] = openOneROIFile(file, projection); |
... | ... | |
128 | 129 |
this.featureStore = openThreeROIFiles(filename, projection); |
129 | 130 |
} |
130 | 131 |
} |
131 |
|
|
132 |
|
|
132 | 133 |
} |
133 |
|
|
134 |
|
|
134 | 135 |
private FeatureStore[] openThreeROIFiles(String filename, IProjection projection) throws ROIException, FileNotExistsException { |
135 | 136 |
FeatureStore[] featureStore = new FeatureStore[3]; |
136 | 137 |
if(filename.endsWith(".shp")) { |
... | ... | |
142 | 143 |
featureStore[0] = openOneROIFile(file, projection); |
143 | 144 |
existsAtLeastOne = true; |
144 | 145 |
} |
145 |
|
|
146 |
|
|
146 | 147 |
file = new File(filename + "_points.shp"); |
147 | 148 |
if(file.exists()) { |
148 | 149 |
featureStore[1] = openOneROIFile(file, projection); |
149 | 150 |
existsAtLeastOne = true; |
150 | 151 |
} |
151 |
|
|
152 |
|
|
152 | 153 |
file = new File(filename + "_polylines.shp"); |
153 | 154 |
if(file.exists()) { |
154 | 155 |
featureStore[2] = openOneROIFile(file, projection); |
155 | 156 |
existsAtLeastOne = true; |
156 | 157 |
} |
157 |
|
|
158 |
|
|
158 | 159 |
if(!existsAtLeastOne) |
159 | 160 |
throw new FileNotExistsException("file not found"); |
160 | 161 |
return featureStore; |
161 | 162 |
} |
162 |
|
|
163 |
|
|
163 | 164 |
private FeatureStore openOneROIFile(File file, IProjection projection) throws ROIException { |
164 | 165 |
DataManager datamanager = DALLocator.getDataManager(); |
165 | 166 |
SHPStoreParameters params = null; |
... | ... | |
183 | 184 |
throw new ROIException(e.getMessage(), e); |
184 | 185 |
} |
185 | 186 |
} |
186 |
|
|
187 |
|
|
187 | 188 |
public List<ROI> read(List<ROI> existingROIs) throws ROIException { |
188 | 189 |
for (int i = 0; i < this.featureStore.length; i++) { |
189 | 190 |
try { |
... | ... | |
220 | 221 |
DisposableIterator features = null; |
221 | 222 |
try { |
222 | 223 |
set = featureStore.getFeatureSet(); |
223 |
features = set.iterator();
|
|
224 |
features = set.fastIterator();
|
|
224 | 225 |
String defaultROIName = "ROI"; |
225 | 226 |
while (features.hasNext()) { |
226 | 227 |
Feature feature = (Feature) features.next(); |
227 |
|
|
228 |
if(feature.getDefaultGeometry() == null ||
|
|
228 |
|
|
229 |
if(feature.getDefaultGeometry() == null || |
|
229 | 230 |
feature.getDefaultGeometry() instanceof NullGeometry) |
230 | 231 |
continue; |
231 |
if(feature.getDefaultGeometry() != null &&
|
|
232 |
if(feature.getDefaultGeometry() != null && |
|
232 | 233 |
!feature.getDefaultGeometry().getEnvelope().intersects(bbox)) |
233 | 234 |
continue; |
234 | 235 |
|
Also available in: Unified diff