svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / gvsig / geoprocessing / impl / jtsprocessors / FeaturePersisterProcessor.java @ 4820
History | View | Annotate | Download (4.13 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: FeaturePersisterProcessor.java 4447 2006-03-15 18:35:56Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.4 2006-03-15 18:34:03 azabala
|
49 |
* *** empty log message ***
|
50 |
*
|
51 |
* Revision 1.3 2006/03/14 18:32:46 fjp
|
52 |
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
|
53 |
*
|
54 |
* Revision 1.2 2006/02/26 20:54:52 azabala
|
55 |
* *** empty log message ***
|
56 |
*
|
57 |
* Revision 1.1 2006/02/17 16:33:25 azabala
|
58 |
* *** empty log message ***
|
59 |
*
|
60 |
*
|
61 |
*/
|
62 |
package com.iver.gvsig.geoprocessing.impl.jtsprocessors; |
63 |
|
64 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
65 |
import com.hardcode.gdbms.engine.values.Value; |
66 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
67 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
68 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
69 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
70 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
71 |
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
72 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
73 |
import com.iver.cit.gvsig.fmap.edition.ISchemaManager; |
74 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
75 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
76 |
import com.iver.gvsig.geoprocessing.schemabuilder.FeatureFactory; |
77 |
import com.vividsolutions.jts.geom.Geometry; |
78 |
/**
|
79 |
* It saves in a persistent data store the result of an individual geoprocess.
|
80 |
* @author azabala
|
81 |
*
|
82 |
|
83 |
*
|
84 |
*/
|
85 |
public class FeaturePersisterProcessor extends GeometryPersisterProcessor { |
86 |
|
87 |
private SelectableDataSource recordset;
|
88 |
|
89 |
public FeaturePersisterProcessor(ITableDefinition layerDefinition, ISchemaManager schemaManager, IWriter writer) throws EditionException { |
90 |
super(layerDefinition, schemaManager, writer);
|
91 |
} |
92 |
|
93 |
public FeaturePersisterProcessor(ITableDefinition layerDefinition,ISchemaManager schemaManager, IWriter writer, SelectableDataSource recordset) throws EditionException{ |
94 |
this(layerDefinition, schemaManager, writer);
|
95 |
this.recordset = recordset;
|
96 |
} |
97 |
|
98 |
public void setSelectableDataSource(SelectableDataSource recordset){ |
99 |
this.recordset = recordset;
|
100 |
} |
101 |
|
102 |
public void processJtsGeometry(Geometry g, int index) { |
103 |
IGeometry clipGeometry = FConverter.jts_to_igeometry(g); |
104 |
FieldDescription[] fields = this.layerDefinition.getFieldsDesc(); |
105 |
Value[] attrs = new Value[fields.length]; |
106 |
for(int i = 0; i < fields.length; i++){ |
107 |
FieldDescription field = fields[i]; |
108 |
String attrName = field.getFieldName();
|
109 |
Value value = null;
|
110 |
try {
|
111 |
int fieldIndex = recordset.getFieldIndexByName(attrName);
|
112 |
value = recordset.getFieldValue(index, fieldIndex); |
113 |
} catch (DriverException e) {
|
114 |
// TODO Auto-generated catch block
|
115 |
e.printStackTrace(); |
116 |
} |
117 |
attrs[i] = value; |
118 |
}//for
|
119 |
|
120 |
IFeature feature = FeatureFactory.createFeature(attrs, |
121 |
clipGeometry); |
122 |
DefaultRowEdited editedFeature = new
|
123 |
DefaultRowEdited(feature, |
124 |
DefaultRowEdited.STATUS_ADDED, index); |
125 |
try {
|
126 |
writer.process(editedFeature); |
127 |
} catch (EditionException e) {
|
128 |
// TODO Auto-generated catch block
|
129 |
e.printStackTrace(); |
130 |
} |
131 |
} |
132 |
|
133 |
} |
134 |
|