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 / Bug15643Test.java @ 40559
History | View | Annotate | Download (5.1 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.fmap.dal.store.shp; |
||
25 | |||
26 | import junit.framework.TestCase; |
||
27 | |||
28 | import com.vividsolutions.jts.geom.Coordinate; |
||
29 | import com.vividsolutions.jts.geom.GeometryFactory; |
||
30 | |||
31 | import org.gvsig.fmap.dal.DALLocator; |
||
32 | import org.gvsig.fmap.dal.DataManager; |
||
33 | import org.gvsig.fmap.dal.DataTypes; |
||
34 | import org.gvsig.fmap.dal.feature.EditableFeature; |
||
35 | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
||
36 | import org.gvsig.fmap.dal.feature.Feature; |
||
37 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
38 | import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
||
39 | import org.gvsig.fmap.geom.Geometry; |
||
40 | import org.gvsig.fmap.geom.GeometryLocator; |
||
41 | import org.gvsig.fmap.geom.GeometryManager; |
||
42 | import org.gvsig.fmap.geom.operation.GeometryOperation; |
||
43 | import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
||
44 | import org.gvsig.fmap.geom.operation.fromjts.FromJTS; |
||
45 | import org.gvsig.fmap.geom.type.GeometryType; |
||
46 | import org.gvsig.tools.exception.BaseException; |
||
47 | import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
||
48 | import org.gvsig.tools.visitor.VisitCanceledException; |
||
49 | import org.gvsig.tools.visitor.Visitor; |
||
50 | |||
51 | /**
|
||
52 | * Code to test bug gvsig-desktop#15643. This is based on the code provided by
|
||
53 | * the bug reporter (see ticket), thanks to him!!
|
||
54 | *
|
||
55 | * @author gvSIG Team
|
||
56 | * @version $Id$
|
||
57 | */
|
||
58 | public class Bug15643Test extends TestCase { |
||
59 | |||
60 | public void testBug15643() throws Exception { |
||
61 | new DefaultLibrariesInitializer().fullInitialize();
|
||
62 | DataManager manager = DALLocator.getDataManager(); |
||
63 | GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
||
64 | |||
65 | NewFeatureStoreParameters destParams = |
||
66 | (NewFeatureStoreParameters) manager.createNewStoreParameters( |
||
67 | "FilesystemExplorer", "Shape"); |
||
68 | EditableFeatureType type = destParams.getDefaultFeatureType(); |
||
69 | GeometryType geometryType = |
||
70 | geometryManager.getGeometryType(Geometry.TYPES.POINT, |
||
71 | Geometry.SUBTYPES.GEOM2D); |
||
72 | type.add("geom", org.gvsig.fmap.geom.DataTypes.GEOMETRY)
|
||
73 | .setGeometryType(geometryType); |
||
74 | type.setDefaultGeometryAttributeName("geom");
|
||
75 | type.add("float", DataTypes.FLOAT).setSize(5); |
||
76 | type.add("double", DataTypes.DOUBLE).setSize(5); |
||
77 | type.add("int", DataTypes.INT).setSize(5); |
||
78 | type.add("long", DataTypes.LONG).setSize(5); |
||
79 | |||
80 | destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
||
81 | destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
||
82 | destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
||
83 | destParams.setDynValue("crs", "EPSG:23030"); |
||
84 | destParams.setDefaultFeatureType(type); |
||
85 | |||
86 | manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
||
87 | FeatureStore store = |
||
88 | (FeatureStore) manager.openStore("Shape", destParams);
|
||
89 | |||
90 | store.edit(); |
||
91 | EditableFeature feature = store.createNewFeature().getEditable(); |
||
92 | com.vividsolutions.jts.geom.Geometry g = |
||
93 | new GeometryFactory().createPoint(new Coordinate(0, 0)); |
||
94 | |||
95 | int opCode = geometryManager.getGeometryOperationCode(FromJTS.NAME);
|
||
96 | GeometryOperation converter = |
||
97 | geometryManager.getGeometryOperation(opCode, Geometry.TYPES.POINT, |
||
98 | Geometry.SUBTYPES.GEOM2D); |
||
99 | GeometryOperationContext ctx = new GeometryOperationContext();
|
||
100 | ctx.setAttribute(FromJTS.PARAM, g); |
||
101 | Geometry fmapGeom = (Geometry) converter.invoke(null, ctx);
|
||
102 | feature.setGeometry(feature.getType() |
||
103 | .getDefaultGeometryAttributeIndex(), fmapGeom); |
||
104 | feature.setFloat("float", 34.0f); |
||
105 | feature.setDouble("double", 34.0d); |
||
106 | feature.setInt("int", 34); |
||
107 | feature.setLong("long", 34l); |
||
108 | store.insert(feature); |
||
109 | store.finishEditing(); |
||
110 | |||
111 | store.accept(new Visitor() {
|
||
112 | |||
113 | public void visit(Object obj) throws VisitCanceledException, |
||
114 | BaseException { |
||
115 | Feature feature = (Feature) obj; |
||
116 | assertEquals(34.0f, feature.getFloat("float")); |
||
117 | assertEquals(34.0d, feature.getDouble("double")); |
||
118 | assertEquals(34, feature.getInt("int")); |
||
119 | assertEquals(34l, feature.getLong("long")); |
||
120 | } |
||
121 | }); |
||
122 | |||
123 | store.dispose(); |
||
124 | } |
||
125 | |||
126 | } |