root / branches / v2_0_0_prep / libraries / libFMap_dalfile / src-test / org / gvsig / fmap / dal / store / shp / Bug15643Test.java @ 38083
History | View | Annotate | Download (5.11 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.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.fmap.geom.type.GeometryType; |
45 |
import org.gvsig.tools.exception.BaseException; |
46 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
47 |
import org.gvsig.tools.visitor.VisitCanceledException; |
48 |
import org.gvsig.tools.visitor.Visitor; |
49 |
|
50 |
/**
|
51 |
* Code to test bug gvsig-desktop#15643. This is based on the code provided by
|
52 |
* the bug reporter (see ticket), thanks to him!!
|
53 |
*
|
54 |
* @author gvSIG Team
|
55 |
* @version $Id$
|
56 |
*/
|
57 |
public class Bug15643Test extends TestCase { |
58 |
|
59 |
public void testBug15643() throws Exception { |
60 |
new DefaultLibrariesInitializer().fullInitialize();
|
61 |
DataManager manager = DALLocator.getDataManager(); |
62 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
63 |
|
64 |
EditableFeatureType type = new DefaultEditableFeatureType();
|
65 |
GeometryType geometryType = |
66 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
67 |
Geometry.SUBTYPES.GEOM2D); |
68 |
type.add("geom", org.gvsig.fmap.geom.DataTypes.GEOMETRY)
|
69 |
.setGeometryType(geometryType); |
70 |
type.setDefaultGeometryAttributeName("geom");
|
71 |
type.add("float", DataTypes.FLOAT).setSize(5); |
72 |
type.add("double", DataTypes.DOUBLE).setSize(5); |
73 |
type.add("int", DataTypes.INT).setSize(5); |
74 |
type.add("long", DataTypes.LONG).setSize(5); |
75 |
|
76 |
NewFeatureStoreParameters destParams = |
77 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
78 |
"FilesystemExplorer", "Shape"); |
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 |
feature.setGeometry(feature.getType() |
102 |
.getDefaultGeometryAttributeIndex(), fmapGeom); |
103 |
feature.setFloat("float", 34.0f); |
104 |
feature.setDouble("double", 34.0d); |
105 |
feature.setInt("int", 34); |
106 |
feature.setLong("long", 34l); |
107 |
store.insert(feature); |
108 |
store.finishEditing(); |
109 |
|
110 |
store.accept(new Visitor() {
|
111 |
|
112 |
public void visit(Object obj) throws VisitCanceledException, |
113 |
BaseException { |
114 |
Feature feature = (Feature) obj; |
115 |
assertEquals(34.0f, feature.getFloat("float")); |
116 |
assertEquals(34.0d, feature.getDouble("double")); |
117 |
assertEquals(34, feature.getInt("int")); |
118 |
assertEquals(34l, feature.getLong("long")); |
119 |
} |
120 |
}); |
121 |
|
122 |
store.dispose(); |
123 |
} |
124 |
|
125 |
} |