root / trunk / libraries / libTopology / src / org / gvsig / jump / adapter / IFeatureAdapter.java @ 23045
History | View | Annotate | Download (3.68 KB)
1 |
/*
|
---|---|
2 |
* Created on 10-abr-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 |
*/
|
49 |
package org.gvsig.jump.adapter; |
50 |
|
51 |
import java.rmi.server.UID; |
52 |
import java.util.Date; |
53 |
|
54 |
import org.gvsig.fmap.core.NewFConverter; |
55 |
|
56 |
import com.hardcode.gdbms.engine.values.Value; |
57 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
58 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
59 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
60 |
import com.iver.cit.gvsig.fmap.core.IRow; |
61 |
import com.vividsolutions.jts.geom.Geometry; |
62 |
import com.vividsolutions.jump.feature.AttributeType; |
63 |
import com.vividsolutions.jump.feature.Feature; |
64 |
|
65 |
/**
|
66 |
* Adapts a JUMP's feature to IFeature interface.
|
67 |
* @author Alvaro Zabala
|
68 |
*
|
69 |
*/
|
70 |
public class IFeatureAdapter implements IFeature { |
71 |
|
72 |
|
73 |
Feature feature; |
74 |
String uid;
|
75 |
|
76 |
|
77 |
public IFeatureAdapter(Feature feature){
|
78 |
this.feature = feature;
|
79 |
this.uid = new UID().toString(); |
80 |
} |
81 |
|
82 |
public IGeometry getGeometry() {
|
83 |
|
84 |
Geometry geometry = feature.getGeometry(); |
85 |
if(geometry != null) |
86 |
return NewFConverter.toFMap(geometry);
|
87 |
else
|
88 |
return null; |
89 |
|
90 |
} |
91 |
|
92 |
public void setGeometry(IGeometry geom) { |
93 |
Geometry geometry = NewFConverter.toJtsGeometry(geom); |
94 |
feature.setGeometry(geometry); |
95 |
} |
96 |
|
97 |
public IRow cloneRow() {
|
98 |
return new IFeatureAdapter(this.feature.clone(true)); |
99 |
} |
100 |
|
101 |
public Value getAttribute(int fieldId) { |
102 |
|
103 |
Object attr = feature.getAttribute(fieldId);
|
104 |
AttributeType type = feature.getSchema().getAttributeType(fieldId); |
105 |
Value solution = ValueFactory.createNullValue(); |
106 |
if(type == AttributeType.STRING){
|
107 |
solution = ValueFactory.createValue((String) attr);
|
108 |
}else if(type == AttributeType.DOUBLE){ |
109 |
solution = ValueFactory.createValue(((Double)attr).doubleValue());
|
110 |
}else if(type == AttributeType.INTEGER){ |
111 |
solution = ValueFactory.createValue(((Integer)attr).intValue());
|
112 |
}else if(type == AttributeType.DATE){ |
113 |
solution = ValueFactory.createValue(((Date)attr));
|
114 |
} |
115 |
return solution;
|
116 |
} |
117 |
|
118 |
public Value[] getAttributes() { |
119 |
int numFields = feature.getSchema().getAttributeCount();
|
120 |
Value[] solution = new Value[numFields]; |
121 |
for(int i = 0; i < numFields; i++){ |
122 |
solution[i] = getAttribute(i); |
123 |
} |
124 |
return solution;
|
125 |
} |
126 |
|
127 |
public String getID() { |
128 |
return this.uid; |
129 |
} |
130 |
|
131 |
public void setAttributes(Value[] att) { |
132 |
int numValues = att.length;
|
133 |
for(int i = 0; i < numValues; i++){ |
134 |
feature.setAttribute(i, att[i]); |
135 |
} |
136 |
} |
137 |
|
138 |
public void setID(String ID) { |
139 |
this.uid = ID;
|
140 |
} |
141 |
|
142 |
} |