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 / main / java / org / gvsig / fmap / dal / store / shp / SHPStoreProviderFactory.java @ 43020
History | View | Annotate | Download (7.09 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.dal.store.shp; |
25 |
|
26 |
import java.util.ArrayList; |
27 |
import java.util.List; |
28 |
|
29 |
import org.slf4j.Logger; |
30 |
import org.slf4j.LoggerFactory; |
31 |
|
32 |
import org.gvsig.fmap.dal.DALLocator; |
33 |
import org.gvsig.fmap.dal.DataManager; |
34 |
import org.gvsig.fmap.dal.DataParameters; |
35 |
import org.gvsig.fmap.dal.DataStoreProvider; |
36 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
37 |
import org.gvsig.fmap.dal.DataTypes; |
38 |
import org.gvsig.fmap.dal.exception.InitializeException; |
39 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
40 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
41 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
42 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
43 |
import org.gvsig.fmap.dal.feature.FeatureType; |
44 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProviderFactory; |
45 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
46 |
import org.gvsig.fmap.dal.store.dbf.utils.DbaseFile; |
47 |
import org.gvsig.fmap.geom.Geometry; |
48 |
import org.gvsig.fmap.geom.GeometryLocator; |
49 |
import org.gvsig.fmap.geom.type.GeometryType; |
50 |
import org.gvsig.tools.ToolsLocator; |
51 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
52 |
import org.gvsig.tools.dynobject.DynObject; |
53 |
|
54 |
public class SHPStoreProviderFactory extends AbstractFeatureStoreProviderFactory { |
55 |
|
56 |
private static final Logger logger = LoggerFactory.getLogger(SHPStoreProviderFactory.class); |
57 |
|
58 |
public static final String DEFAULT_GEOMETRY_FIELD_NAME = "GEOMETRY"; |
59 |
public static final int DEFAULT_GEOMETRY_TYPE = Geometry.TYPES.SURFACE; |
60 |
public static final int DEFAULT_GEOMETRY_SUBTYPE = Geometry.SUBTYPES.GEOM2D; |
61 |
|
62 |
protected SHPStoreProviderFactory(String name, String description) { |
63 |
super(name, description);
|
64 |
} |
65 |
|
66 |
public DataStoreProvider createProvider(DataParameters parameters,
|
67 |
DataStoreProviderServices providerServices) |
68 |
throws InitializeException {
|
69 |
return new SHPStoreProvider((SHPStoreParameters) parameters, providerServices); |
70 |
} |
71 |
|
72 |
public DynObject createParameters() {
|
73 |
return new SHPStoreParameters(); |
74 |
} |
75 |
|
76 |
public int allowCreate() { |
77 |
return YES;
|
78 |
} |
79 |
|
80 |
public int allowWrite() { |
81 |
return YES;
|
82 |
} |
83 |
|
84 |
public int allowRead() { |
85 |
return YES;
|
86 |
} |
87 |
|
88 |
public int hasRasterSupport() { |
89 |
return NO;
|
90 |
} |
91 |
|
92 |
public int hasTabularSupport() { |
93 |
return YES;
|
94 |
} |
95 |
|
96 |
public int hasVectorialSupport() { |
97 |
return YES;
|
98 |
} |
99 |
|
100 |
public int allowMultipleGeometryTypes() { |
101 |
return NO;
|
102 |
} |
103 |
|
104 |
|
105 |
public int allowEditableFeatureType() { |
106 |
return YES;
|
107 |
} |
108 |
|
109 |
public int useLocalIndexesCanImprovePerformance() { |
110 |
return YES;
|
111 |
} |
112 |
|
113 |
public List getSupportedDataTypes() { |
114 |
|
115 |
DataTypesManager manager = ToolsLocator.getDataTypesManager(); |
116 |
|
117 |
List resp = new ArrayList<Integer>(); |
118 |
resp.add(manager.get(DataTypes.STRING)); |
119 |
resp.add(manager.get(DataTypes.INT)); |
120 |
resp.add(manager.get(DataTypes.FLOAT)); |
121 |
resp.add(manager.get(DataTypes.DATE)); |
122 |
resp.add(manager.get(DataTypes.GEOMETRY)); |
123 |
return resp;
|
124 |
} |
125 |
|
126 |
public List getSupportedGeometryTypesSubtypes() { |
127 |
// null means all supported
|
128 |
int[] item = null; |
129 |
List resp = new ArrayList<int[]>(); |
130 |
// ====================================== 2d
|
131 |
item = new int[2]; |
132 |
item[0] = Geometry.TYPES.POINT;
|
133 |
item[1] = Geometry.SUBTYPES.GEOM2D;
|
134 |
resp.add(item); |
135 |
|
136 |
item = new int[2]; |
137 |
item[0] = Geometry.TYPES.CURVE;
|
138 |
item[1] = Geometry.SUBTYPES.GEOM2D;
|
139 |
resp.add(item); |
140 |
|
141 |
item = new int[2]; |
142 |
item[0] = Geometry.TYPES.SURFACE;
|
143 |
item[1] = Geometry.SUBTYPES.GEOM2D;
|
144 |
resp.add(item); |
145 |
|
146 |
item = new int[2]; |
147 |
item[0] = Geometry.TYPES.MULTIPOINT;
|
148 |
item[1] = Geometry.SUBTYPES.GEOM2D;
|
149 |
resp.add(item); |
150 |
// ====================================== 3d
|
151 |
item = new int[2]; |
152 |
item[0] = Geometry.TYPES.POINT;
|
153 |
item[1] = Geometry.SUBTYPES.GEOM3D;
|
154 |
resp.add(item); |
155 |
|
156 |
item = new int[2]; |
157 |
item[0] = Geometry.TYPES.CURVE;
|
158 |
item[1] = Geometry.SUBTYPES.GEOM3D;
|
159 |
resp.add(item); |
160 |
|
161 |
item = new int[2]; |
162 |
item[0] = Geometry.TYPES.SURFACE;
|
163 |
item[1] = Geometry.SUBTYPES.GEOM3D;
|
164 |
resp.add(item); |
165 |
|
166 |
item = new int[2]; |
167 |
item[0] = Geometry.TYPES.MULTIPOINT;
|
168 |
item[1] = Geometry.SUBTYPES.GEOM3D;
|
169 |
resp.add(item); |
170 |
// ====================================== 2dm
|
171 |
item = new int[2]; |
172 |
item[0] = Geometry.TYPES.POINT;
|
173 |
item[1] = Geometry.SUBTYPES.GEOM2DM;
|
174 |
resp.add(item); |
175 |
|
176 |
item = new int[2]; |
177 |
item[0] = Geometry.TYPES.CURVE;
|
178 |
item[1] = Geometry.SUBTYPES.GEOM2DM;
|
179 |
resp.add(item); |
180 |
|
181 |
item = new int[2]; |
182 |
item[0] = Geometry.TYPES.SURFACE;
|
183 |
item[1] = Geometry.SUBTYPES.GEOM2DM;
|
184 |
resp.add(item); |
185 |
|
186 |
item = new int[2]; |
187 |
item[0] = Geometry.TYPES.MULTIPOINT;
|
188 |
item[1] = Geometry.SUBTYPES.GEOM2DM;
|
189 |
resp.add(item); |
190 |
// ======================================
|
191 |
|
192 |
return resp;
|
193 |
} |
194 |
|
195 |
public boolean allowsMandatoryAttributes() { |
196 |
return false; |
197 |
} |
198 |
|
199 |
public boolean allowsPrimaryKeyAttributes() { |
200 |
return false; |
201 |
} |
202 |
|
203 |
/**
|
204 |
* @return dummy feature type. Must be overridden by subclasses
|
205 |
*
|
206 |
*/
|
207 |
public FeatureType createDefaultFeatureType() {
|
208 |
DataManager dm = DALLocator.getDataManager(); |
209 |
EditableFeatureType eft = dm.createFeatureType(); |
210 |
|
211 |
EditableFeatureAttributeDescriptor efatd = |
212 |
eft.add(DEFAULT_GEOMETRY_FIELD_NAME, DataTypes.GEOMETRY); |
213 |
|
214 |
GeometryType gt = null;
|
215 |
try {
|
216 |
gt = GeometryLocator.getGeometryManager().getGeometryType( |
217 |
DEFAULT_GEOMETRY_TYPE, |
218 |
DEFAULT_GEOMETRY_SUBTYPE); |
219 |
efatd.setGeometryType(gt); |
220 |
} catch (Exception ex) { |
221 |
logger.info("Error while setting geom type: " + ex.getMessage());
|
222 |
logger.info("Trying deprecated way...");
|
223 |
efatd.setGeometryType(DEFAULT_GEOMETRY_TYPE); |
224 |
efatd.setGeometrySubType(DEFAULT_GEOMETRY_SUBTYPE); |
225 |
} |
226 |
eft.setDefaultGeometryAttributeName(DEFAULT_GEOMETRY_FIELD_NAME); |
227 |
return eft.getNotEditableCopy();
|
228 |
} |
229 |
|
230 |
@Override
|
231 |
public int getMaxAttributeNameSize() { |
232 |
return DbaseFile.MAX_FIELD_NAME_LENGTH;
|
233 |
} |
234 |
} |