root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / clip / fmap / ClipVisitor.java @ 5628
History | View | Annotate | Download (5.55 KB)
1 |
/*
|
---|---|
2 |
* Created on 16-feb-2006
|
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: ClipVisitor.java 5628 2006-06-02 18:21:28Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.3 2006-06-02 18:21:28 azabala
|
49 |
* *** empty log message ***
|
50 |
*
|
51 |
* Revision 1.2 2006/05/31 09:10:12 fjp
|
52 |
* Ubicaci?n de IWriter
|
53 |
*
|
54 |
* Revision 1.1 2006/05/24 21:14:07 azabala
|
55 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
56 |
*
|
57 |
* Revision 1.6 2006/03/28 16:27:36 azabala
|
58 |
* *** empty log message ***
|
59 |
*
|
60 |
* Revision 1.5 2006/03/17 19:52:43 azabala
|
61 |
* *** empty log message ***
|
62 |
*
|
63 |
* Revision 1.4 2006/03/15 18:30:39 azabala
|
64 |
* *** empty log message ***
|
65 |
*
|
66 |
* Revision 1.3 2006/03/14 18:32:46 fjp
|
67 |
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
|
68 |
*
|
69 |
* Revision 1.2 2006/03/07 21:01:33 azabala
|
70 |
* *** empty log message ***
|
71 |
*
|
72 |
* Revision 1.1 2006/03/06 19:48:39 azabala
|
73 |
* *** empty log message ***
|
74 |
*
|
75 |
* Revision 1.2 2006/02/19 20:56:21 azabala
|
76 |
* *** empty log message ***
|
77 |
*
|
78 |
* Revision 1.1 2006/02/17 16:33:05 azabala
|
79 |
* *** empty log message ***
|
80 |
*
|
81 |
*
|
82 |
*/
|
83 |
package com.iver.cit.gvsig.geoprocess.clip.fmap; |
84 |
|
85 |
import com.iver.cit.gvsig.fmap.DriverException; |
86 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
87 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
88 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
89 |
import com.iver.cit.gvsig.fmap.edition.ISchemaManager; |
90 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
91 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
92 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
93 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
94 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
95 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
96 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
97 |
import com.iver.cit.gvsig.geoprocess.core.fmap.FeaturePersisterProcessor; |
98 |
import com.vividsolutions.jts.geom.Geometry; |
99 |
/**
|
100 |
* This class analyzes all features of a layer, clipping its geometries
|
101 |
* with the convex hull of another layer.
|
102 |
* If the geometry of the feature analyzed doesnt intersect with the convex
|
103 |
* hull geometry, the clipvisitor will ignore it.
|
104 |
*
|
105 |
* It intersects, computes intersection and creates a new feature with
|
106 |
* the same attributes and the new intersection geometry.
|
107 |
* @author azabala
|
108 |
*
|
109 |
*/
|
110 |
public class ClipVisitor implements FeatureVisitor { |
111 |
|
112 |
/**
|
113 |
* Clipping geometry: the convex hull of the
|
114 |
* clipping layer
|
115 |
*/
|
116 |
private Geometry clippingConvexHull;
|
117 |
/**
|
118 |
* It allows visitor to get attribute values link to geometries
|
119 |
*/
|
120 |
private SelectableDataSource recordset;
|
121 |
/**
|
122 |
* Processes individual clip results
|
123 |
*/
|
124 |
private FeaturePersisterProcessor resultProcessor;
|
125 |
/**
|
126 |
* Constructor. It requires clipping geometry.
|
127 |
* @param clippingGeometry
|
128 |
*/
|
129 |
public ClipVisitor(Geometry clippingGeometry,
|
130 |
ITableDefinition layerDefinition, |
131 |
ISchemaManager schemaManager, |
132 |
IWriter writer){ |
133 |
|
134 |
this.clippingConvexHull = clippingGeometry;
|
135 |
try {
|
136 |
this.resultProcessor = new FeaturePersisterProcessor(layerDefinition, |
137 |
schemaManager,writer); |
138 |
} catch (EditionException e) {
|
139 |
// TODO Auto-generated catch block
|
140 |
e.printStackTrace(); |
141 |
} |
142 |
|
143 |
} |
144 |
|
145 |
/**
|
146 |
* clips feature's geometry with the clipping geometry, preserving
|
147 |
* feature's original attributes.
|
148 |
* If feature's geometry doesnt touch clipping geometry, it will be
|
149 |
* ignored.
|
150 |
*/
|
151 |
public void visit(IGeometry g, int index) throws VisitException { |
152 |
if(g == null) |
153 |
return;
|
154 |
Geometry jtsGeom = g.toJTSGeometry(); |
155 |
if(!jtsGeom.getEnvelope().intersects(clippingConvexHull.getEnvelope()))
|
156 |
return;
|
157 |
if(jtsGeom.intersects(clippingConvexHull)){
|
158 |
Geometry newGeom = jtsGeom.intersection(clippingConvexHull); |
159 |
resultProcessor.processJtsGeometry(newGeom, index); |
160 |
} |
161 |
} |
162 |
|
163 |
public void stop(FLayer layer) { |
164 |
resultProcessor.finish(); |
165 |
} |
166 |
|
167 |
public boolean start(FLayer layer) { |
168 |
if(layer instanceof AlphanumericData && layer instanceof VectorialData){ |
169 |
try {
|
170 |
this.recordset = ((AlphanumericData)layer).getRecordset();
|
171 |
this.resultProcessor.setSelectableDataSource(recordset);
|
172 |
} catch (DriverException e) {
|
173 |
return false;//must we throw an Exception?? |
174 |
} |
175 |
return true; |
176 |
} |
177 |
return false; |
178 |
} |
179 |
|
180 |
public SelectableDataSource getRecordset() {
|
181 |
return recordset;
|
182 |
} |
183 |
|
184 |
public void setRecordset(SelectableDataSource recordset) { |
185 |
this.recordset = recordset;
|
186 |
} |
187 |
|
188 |
public String getProcessDescription() { |
189 |
return "Clipping features agaisnt a clip geometry"; |
190 |
} |
191 |
} |
192 |
|