Revision 36348
branches/v2_0_0_prep/libraries/libFMap_dalfile/src-test/org/gvsig/fmap/dal/store/shp/Bug15643Test.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.fmap.dal.store.shp; |
|
23 |
|
|
24 |
import junit.framework.TestCase; |
|
25 |
|
|
26 |
import com.vividsolutions.jts.geom.Coordinate; |
|
27 |
import com.vividsolutions.jts.geom.GeometryFactory; |
|
28 |
|
|
29 |
import org.gvsig.fmap.dal.DALLocator; |
|
30 |
import org.gvsig.fmap.dal.DataManager; |
|
31 |
import org.gvsig.fmap.dal.DataTypes; |
|
32 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
33 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
34 |
import org.gvsig.fmap.dal.feature.Feature; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
36 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
37 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
|
38 |
import org.gvsig.fmap.geom.Geometry; |
|
39 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
40 |
import org.gvsig.fmap.geom.GeometryManager; |
|
41 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
|
42 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
|
43 |
import org.gvsig.fmap.geom.operation.fromjts.FromJTS; |
|
44 |
import org.gvsig.tools.exception.BaseException; |
|
45 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
46 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
47 |
import org.gvsig.tools.visitor.Visitor; |
|
48 |
|
|
49 |
/** |
|
50 |
* @author gvSIG Team |
|
51 |
* @version $Id$ |
|
52 |
*/ |
|
53 |
public class Bug15643Test extends TestCase { |
|
54 |
|
|
55 |
public void testBug15643() throws Exception { |
|
56 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
57 |
DataManager manager = DALLocator.getDataManager(); |
|
58 |
|
|
59 |
EditableFeatureType type = new DefaultEditableFeatureType(); |
|
60 |
type.add("geom", org.gvsig.fmap.geom.DataTypes.GEOMETRY) |
|
61 |
.setGeometryType(Geometry.TYPES.POINT) |
|
62 |
.setGeometrySubType(Geometry.SUBTYPES.GEOM2D); |
|
63 |
type.setDefaultGeometryAttributeName("geom"); |
|
64 |
type.add("float", DataTypes.FLOAT).setSize(5); |
|
65 |
type.add("double", DataTypes.DOUBLE).setSize(5); |
|
66 |
type.add("int", DataTypes.INT).setSize(5); |
|
67 |
type.add("long", DataTypes.LONG).setSize(5); |
|
68 |
|
|
69 |
NewFeatureStoreParameters destParams = |
|
70 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
|
71 |
"FilesystemExplorer", "Shape"); |
|
72 |
destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
|
73 |
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
|
74 |
destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
|
75 |
destParams.setDynValue("crs", "EPSG:23030"); |
|
76 |
destParams.setDefaultFeatureType(type); |
|
77 |
|
|
78 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
|
79 |
FeatureStore store = |
|
80 |
(FeatureStore) manager.openStore("Shape", destParams); |
|
81 |
|
|
82 |
store.edit(); |
|
83 |
EditableFeature feature = store.createNewFeature().getEditable(); |
|
84 |
com.vividsolutions.jts.geom.Geometry g = |
|
85 |
new GeometryFactory().createPoint(new Coordinate(0, 0)); |
|
86 |
|
|
87 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
88 |
int opCode = geometryManager.getGeometryOperationCode(FromJTS.NAME); |
|
89 |
GeometryOperation converter = |
|
90 |
geometryManager.getGeometryOperation(opCode, Geometry.TYPES.POINT, |
|
91 |
Geometry.SUBTYPES.GEOM2D); |
|
92 |
GeometryOperationContext ctx = new GeometryOperationContext(); |
|
93 |
ctx.setAttribute(FromJTS.PARAM, g); |
|
94 |
Geometry fmapGeom = (Geometry) converter.invoke(null, ctx); |
|
95 |
feature.setGeometry(feature.getType() |
|
96 |
.getDefaultGeometryAttributeIndex(), fmapGeom); |
|
97 |
feature.set("float", 34.0f); |
|
98 |
feature.set("double", 34.0d); |
|
99 |
feature.set("int", 34); |
|
100 |
feature.set("long", 34l); |
|
101 |
store.insert(feature); |
|
102 |
store.finishEditing(); |
|
103 |
store.dispose(); |
|
104 |
|
|
105 |
store = (FeatureStore) manager.openStore("Shape", destParams); |
|
106 |
|
|
107 |
store.accept(new Visitor() { |
|
108 |
|
|
109 |
public void visit(Object obj) throws VisitCanceledException, BaseException { |
|
110 |
Feature feature = (Feature) obj; |
|
111 |
assertEquals(34.0f, feature.getFloat("float")); |
|
112 |
assertEquals(34.0d, feature.getDouble("double")); |
|
113 |
assertEquals(34, feature.getInt("int")); |
|
114 |
assertEquals(34l, feature.getLong("long")); |
|
115 |
} |
|
116 |
}); |
|
117 |
|
|
118 |
} |
|
119 |
|
|
120 |
} |
Also available in: Unified diff