svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.shp / src / test / java / org / gvsig / fmap / dal / store / shp / Bug15617Test.java @ 40435
History | View | Annotate | Download (5.2 KB)
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.geom.Geometry; |
38 |
import org.gvsig.fmap.geom.GeometryLocator; |
39 |
import org.gvsig.fmap.geom.GeometryManager; |
40 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
41 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
42 |
import org.gvsig.fmap.geom.operation.fromjts.FromJTS; |
43 |
import org.gvsig.fmap.geom.type.GeometryType; |
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 |
* Code to test bug gvsig-desktop#15617.
|
51 |
*
|
52 |
* @author gvSIG Team
|
53 |
* @version $Id$
|
54 |
*/
|
55 |
public class Bug15617Test extends TestCase { |
56 |
|
57 |
public void testBug15617() throws Exception { |
58 |
new DefaultLibrariesInitializer().fullInitialize();
|
59 |
DataManager manager = DALLocator.getDataManager(); |
60 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
61 |
|
62 |
NewFeatureStoreParameters destParams = |
63 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
64 |
"FilesystemExplorer", "Shape"); |
65 |
|
66 |
EditableFeatureType type = destParams.getDefaultFeatureType(); |
67 |
GeometryType geometryType = |
68 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
69 |
Geometry.SUBTYPES.GEOM2D); |
70 |
type.add("geom", org.gvsig.fmap.geom.DataTypes.GEOMETRY)
|
71 |
.setGeometryType(geometryType); |
72 |
type.setDefaultGeometryAttributeName("geom");
|
73 |
// type.add("float", DataTypes.FLOAT).setSize(5);
|
74 |
// type.add("double", DataTypes.DOUBLE).setSize(5);
|
75 |
type.add("int", DataTypes.INT).setSize(5); |
76 |
// type.add("long", DataTypes.LONG).setSize(5);
|
77 |
type.add("bool", DataTypes.BOOLEAN);
|
78 |
|
79 |
destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
80 |
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
81 |
destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
82 |
destParams.setDynValue("crs", "EPSG:23030"); |
83 |
destParams.setDefaultFeatureType(type); |
84 |
|
85 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
86 |
FeatureStore store = |
87 |
(FeatureStore) manager.openStore("Shape", destParams);
|
88 |
|
89 |
store.edit(); |
90 |
EditableFeature feature = store.createNewFeature().getEditable(); |
91 |
com.vividsolutions.jts.geom.Geometry g = |
92 |
new GeometryFactory().createPoint(new Coordinate(0, 0)); |
93 |
|
94 |
int opCode = geometryManager.getGeometryOperationCode(FromJTS.NAME);
|
95 |
GeometryOperation converter = |
96 |
geometryManager.getGeometryOperation(opCode, Geometry.TYPES.POINT, |
97 |
Geometry.SUBTYPES.GEOM2D); |
98 |
GeometryOperationContext ctx = new GeometryOperationContext();
|
99 |
ctx.setAttribute(FromJTS.PARAM, g); |
100 |
Geometry fmapGeom = (Geometry) converter.invoke(null, ctx);
|
101 |
|
102 |
feature.setGeometry(feature.getType() |
103 |
.getDefaultGeometryAttributeIndex(), fmapGeom); |
104 |
// feature.setFloat("float", 34.0f);
|
105 |
// feature.setDouble("double", 34.0d);
|
106 |
feature.setInt("int", 25); |
107 |
// feature.setLong("long", 34l);
|
108 |
feature.setBoolean("bool", true); |
109 |
assertEquals(true, feature.getBoolean("bool")); |
110 |
store.insert(feature); |
111 |
store.finishEditing(); |
112 |
|
113 |
store.accept(new Visitor() {
|
114 |
|
115 |
public void visit(Object obj) throws VisitCanceledException, |
116 |
BaseException { |
117 |
Feature feature = (Feature) obj; |
118 |
// assertEquals(34.0f, feature.getFloat("float"));
|
119 |
// assertEquals(34.0d, feature.getDouble("double"));
|
120 |
assertEquals(25, feature.getInt("int")); |
121 |
// assertEquals(34l, feature.getLong("long"));
|
122 |
assertEquals(true, feature.getBoolean("bool")); |
123 |
} |
124 |
}); |
125 |
|
126 |
store.dispose(); |
127 |
} |
128 |
|
129 |
} |