gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.reproject / src / main / java / org / gvsig / geoprocess / algorithm / reproject / ReprojectOperation.java @ 175
History | View | Annotate | Download (3 KB)
1 |
/*
|
---|---|
2 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2010 Generalitat Valenciana.
|
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 |
|
21 |
package org.gvsig.geoprocess.algorithm.reproject; |
22 |
|
23 |
import java.util.Iterator; |
24 |
import java.util.List; |
25 |
|
26 |
import es.unex.sextante.core.Sextante; |
27 |
|
28 |
import org.cresques.cts.ICoordTrans; |
29 |
import org.cresques.cts.IProjection; |
30 |
|
31 |
import org.gvsig.fmap.dal.exception.DataException; |
32 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
33 |
import org.gvsig.fmap.dal.feature.Feature; |
34 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
35 |
import org.gvsig.geoprocess.algorithm.base.core.GeometryOperation; |
36 |
|
37 |
/**
|
38 |
* Operation to reproject a Feature
|
39 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
40 |
*/
|
41 |
public class ReprojectOperation extends GeometryOperation { |
42 |
private ICoordTrans transf = null; |
43 |
|
44 |
public ReprojectOperation(IProjection srcProj, IProjection dstProj) {
|
45 |
this.transf = srcProj.getCT(dstProj);
|
46 |
} |
47 |
|
48 |
/*
|
49 |
* (non-Javadoc)
|
50 |
* @see org.gvsig.geoprocess.algorithm.base.core.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.Feature)
|
51 |
*/
|
52 |
@SuppressWarnings("unchecked") |
53 |
public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature feature) {
|
54 |
List geomList = feature.getGeometries();
|
55 |
try {
|
56 |
if(geomList == null) { |
57 |
org.gvsig.fmap.geom.Geometry geom = feature.getDefaultGeometry(); |
58 |
geom.reProject(transf); |
59 |
EditableFeature editFeat = feature.getEditable(); |
60 |
editFeat.setDefaultGeometry(geom); |
61 |
persister.addFeature(feature, geom); |
62 |
} else {
|
63 |
Iterator<org.gvsig.fmap.geom.Geometry> itGeom = geomList.iterator();
|
64 |
EditableFeature editFeat = null;
|
65 |
boolean first = true; |
66 |
int nGeom = 0; |
67 |
while(itGeom.hasNext()) {
|
68 |
org.gvsig.fmap.geom.Geometry geom = itGeom.next(); |
69 |
geom.reProject(transf); |
70 |
editFeat = feature.getEditable(); |
71 |
editFeat.setGeometry(nGeom, geom); |
72 |
nGeom ++; |
73 |
if(first)
|
74 |
persister.addFeature(editFeat, geom); |
75 |
else
|
76 |
persister.addGeometryToExistingFeature(editFeat, geom); |
77 |
} |
78 |
} |
79 |
} catch (DataException e) {
|
80 |
Sextante.addErrorToLog(e); |
81 |
} catch (CreateGeometryException e) {
|
82 |
Sextante.addErrorToLog(e); |
83 |
} |
84 |
|
85 |
return lastEditFeature;
|
86 |
} |
87 |
|
88 |
@Override
|
89 |
public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature featureInput) { |
90 |
} |
91 |
} |
92 |
|