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 / Bug15642Test.java @ 40435
History | View | Annotate | Download (4.63 KB)
1 | 40435 | jjdelcerro | /* 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.FeatureAttributeDescriptor; |
||
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.library.impl.DefaultLibrariesInitializer; |
||
45 | |||
46 | /**
|
||
47 | * Code to test bug gvsig-desktop#15642. This is based on the code provided by
|
||
48 | * the bug reporter (see ticket), thanks to him!!
|
||
49 | *
|
||
50 | * @author gvSIG Team
|
||
51 | * @version $Id$
|
||
52 | */
|
||
53 | public class Bug15642Test extends TestCase { |
||
54 | |||
55 | public void testBug15642() throws Exception { |
||
56 | new DefaultLibrariesInitializer().fullInitialize();
|
||
57 | DataManager manager = DALLocator.getDataManager(); |
||
58 | GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
||
59 | |||
60 | NewFeatureStoreParameters destParams = |
||
61 | (NewFeatureStoreParameters) manager.createNewStoreParameters( |
||
62 | "FilesystemExplorer", "Shape"); |
||
63 | |||
64 | EditableFeatureType type = destParams.getDefaultFeatureType(); |
||
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("long", DataTypes.LONG).setSize(5); |
||
73 | |||
74 | destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
||
75 | destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
||
76 | destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
||
77 | destParams.setDynValue("crs", "EPSG:23030"); |
||
78 | destParams.setDefaultFeatureType(type); |
||
79 | |||
80 | manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
||
81 | FeatureStore store = |
||
82 | (FeatureStore) manager.openStore("Shape", destParams);
|
||
83 | |||
84 | store.edit(); |
||
85 | EditableFeature feature = store.createNewFeature().getEditable(); |
||
86 | com.vividsolutions.jts.geom.Geometry g = |
||
87 | new GeometryFactory().createPoint(new Coordinate(0, 0)); |
||
88 | |||
89 | int opCode = geometryManager.getGeometryOperationCode(FromJTS.NAME);
|
||
90 | GeometryOperation converter = |
||
91 | geometryManager.getGeometryOperation(opCode, Geometry.TYPES.POINT, |
||
92 | Geometry.SUBTYPES.GEOM2D); |
||
93 | GeometryOperationContext ctx = new GeometryOperationContext();
|
||
94 | ctx.setAttribute(FromJTS.PARAM, g); |
||
95 | Geometry fmapGeom = (Geometry) converter.invoke(null, ctx);
|
||
96 | feature.setGeometry(feature.getType() |
||
97 | .getDefaultGeometryAttributeIndex(), fmapGeom); |
||
98 | feature.setFloat("float", 34.0f); |
||
99 | feature.setLong("long", 34l); |
||
100 | store.insert(feature); |
||
101 | store.finishEditing(); |
||
102 | |||
103 | FeatureAttributeDescriptor defaultGeometryAttribute = |
||
104 | store.getDefaultFeatureType().getDefaultGeometryAttribute(); |
||
105 | |||
106 | geometryType = defaultGeometryAttribute.getGeomType(); |
||
107 | assertEquals(Geometry.TYPES.POINT, geometryType.getType()); |
||
108 | assertEquals(Geometry.SUBTYPES.GEOM2D, geometryType.getSubType()); |
||
109 | |||
110 | store.dispose(); |
||
111 | } |
||
112 | |||
113 | } |