root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / fmap / GeometryPersisterProcessor.java @ 5754
History | View | Annotate | Download (4.28 KB)
1 | 5412 | azabala | /*
|
---|---|---|---|
2 | * Created on 09-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$
|
||
47 | * $Log$
|
||
48 | 5547 | fjp | * Revision 1.2 2006-05-31 09:10:12 fjp
|
49 | * Ubicaci?n de IWriter
|
||
50 | *
|
||
51 | * Revision 1.1 2006/05/24 21:12:16 azabala
|
||
52 | 5412 | azabala | * primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
53 | *
|
||
54 | * Revision 1.4 2006/05/01 19:10:09 azabala
|
||
55 | * comentario
|
||
56 | *
|
||
57 | * Revision 1.3 2006/03/14 18:32:46 fjp
|
||
58 | * Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
|
||
59 | *
|
||
60 | * Revision 1.2 2006/02/26 20:54:52 azabala
|
||
61 | * *** empty log message ***
|
||
62 | *
|
||
63 | * Revision 1.1 2006/02/17 16:33:25 azabala
|
||
64 | * *** empty log message ***
|
||
65 | *
|
||
66 | * Revision 1.3 2006/02/13 17:52:45 azabala
|
||
67 | * *** empty log message ***
|
||
68 | *
|
||
69 | * Revision 1.2 2006/02/12 21:02:58 azabala
|
||
70 | * *** empty log message ***
|
||
71 | *
|
||
72 | * Revision 1.1 2006/02/09 16:00:36 azabala
|
||
73 | * First version in CVS
|
||
74 | *
|
||
75 | *
|
||
76 | */
|
||
77 | package com.iver.cit.gvsig.geoprocess.core.fmap; |
||
78 | |||
79 | import com.iver.cit.gvsig.fmap.core.IFeature; |
||
80 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
81 | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
||
82 | import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
||
83 | import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
||
84 | import com.iver.cit.gvsig.fmap.edition.EditionException; |
||
85 | import com.iver.cit.gvsig.fmap.edition.ISchemaManager; |
||
86 | import com.iver.cit.gvsig.fmap.edition.IWriter; |
||
87 | import com.vividsolutions.jts.geom.Geometry; |
||
88 | /**
|
||
89 | * Persists individual buffer results in a persistent data
|
||
90 | * store
|
||
91 | * @author azabala
|
||
92 | *
|
||
93 | */
|
||
94 | public class GeometryPersisterProcessor implements GeoprocessingResultsProcessor { |
||
95 | protected ITableDefinition layerDefinition;
|
||
96 | protected ISchemaManager schemaManager;
|
||
97 | protected IWriter writer;
|
||
98 | |||
99 | private long numProcessed = 0; |
||
100 | |||
101 | public GeometryPersisterProcessor(ITableDefinition layerDefinition,
|
||
102 | ISchemaManager schemaManager, |
||
103 | IWriter writer) throws EditionException{
|
||
104 | this.layerDefinition = layerDefinition;
|
||
105 | this.schemaManager = schemaManager;
|
||
106 | this.writer = writer;
|
||
107 | this.schemaManager.createOrAlterSchema(layerDefinition);
|
||
108 | this.writer.preProcess();
|
||
109 | } |
||
110 | //FIXME usar el atributo INDEX para leer del recordset atributos
|
||
111 | public void processJtsGeometry(Geometry g, int index) { |
||
112 | IGeometry fmapBuffer = FConverter.jts_to_igeometry(g); |
||
113 | Object[] attrs = new Object[1]; |
||
114 | attrs[0] = new Long(numProcessed++); |
||
115 | IFeature feature = FeatureFactory.createFeature(attrs, |
||
116 | fmapBuffer, |
||
117 | layerDefinition); |
||
118 | DefaultRowEdited editedFeature = new
|
||
119 | DefaultRowEdited(feature, |
||
120 | DefaultRowEdited.STATUS_ADDED, (int)numProcessed);
|
||
121 | try {
|
||
122 | writer.process(editedFeature); |
||
123 | } catch (EditionException e) {
|
||
124 | // TODO Auto-generated catch block
|
||
125 | e.printStackTrace(); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | public void finish() { |
||
130 | try {
|
||
131 | writer.postProcess(); |
||
132 | } catch (EditionException e) {
|
||
133 | // TODO Auto-generated catch block
|
||
134 | e.printStackTrace(); |
||
135 | } |
||
136 | } |
||
137 | |||
138 | public void processFeature(IFeature feature) { |
||
139 | DefaultRowEdited editedFeature = new
|
||
140 | DefaultRowEdited(feature, |
||
141 | DefaultRowEdited.STATUS_ADDED, (int)numProcessed);
|
||
142 | try {
|
||
143 | writer.process(editedFeature); |
||
144 | } catch (EditionException e) {
|
||
145 | // TODO Auto-generated catch block
|
||
146 | e.printStackTrace(); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | } |