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 @ 45139
History | View | Annotate | Download (7.14 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.DataTypes; |
37 |
import org.gvsig.fmap.dal.exception.InitializeException; |
38 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
39 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
40 |
import org.gvsig.fmap.dal.feature.FeatureType; |
41 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProviderFactory; |
42 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
43 |
import org.gvsig.fmap.dal.store.dbf.utils.DbaseFile; |
44 |
import org.gvsig.fmap.geom.Geometry; |
45 |
import org.gvsig.fmap.geom.GeometryLocator; |
46 |
import org.gvsig.fmap.geom.type.GeometryType; |
47 |
import org.gvsig.tools.ToolsLocator; |
48 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
49 |
import org.gvsig.tools.dynobject.DynObject; |
50 |
|
51 |
@SuppressWarnings("UseSpecificCatch") |
52 |
public class SHPStoreProviderFactory extends AbstractFeatureStoreProviderFactory { |
53 |
|
54 |
private static final Logger LOGGER = LoggerFactory.getLogger(SHPStoreProviderFactory.class); |
55 |
|
56 |
public static final String DEFAULT_GEOMETRY_FIELD_NAME = "GEOMETRY"; |
57 |
public static final int DEFAULT_GEOMETRY_TYPE = Geometry.TYPES.MULTIPOLYGON; |
58 |
public static final int DEFAULT_GEOMETRY_SUBTYPE = Geometry.SUBTYPES.GEOM2D; |
59 |
|
60 |
protected SHPStoreProviderFactory(String name, String description) { |
61 |
super(name, description);
|
62 |
} |
63 |
|
64 |
@Override
|
65 |
public DataStoreProvider createProvider(DataParameters parameters,
|
66 |
DataStoreProviderServices providerServices) |
67 |
throws InitializeException {
|
68 |
return new SHPStoreProvider((SHPStoreParameters) parameters, providerServices); |
69 |
} |
70 |
|
71 |
@Override
|
72 |
public DynObject createParameters() {
|
73 |
return new SHPStoreParameters(); |
74 |
} |
75 |
|
76 |
@Override
|
77 |
public int allowCreate() { |
78 |
return YES;
|
79 |
} |
80 |
|
81 |
@Override
|
82 |
public int allowWrite() { |
83 |
return YES;
|
84 |
} |
85 |
|
86 |
@Override
|
87 |
public int allowRead() { |
88 |
return YES;
|
89 |
} |
90 |
|
91 |
@Override
|
92 |
public int hasRasterSupport() { |
93 |
return NO;
|
94 |
} |
95 |
|
96 |
@Override
|
97 |
public int hasTabularSupport() { |
98 |
return YES;
|
99 |
} |
100 |
|
101 |
@Override
|
102 |
public int hasVectorialSupport() { |
103 |
return YES;
|
104 |
} |
105 |
|
106 |
public int allowMultipleGeometryTypes() { |
107 |
return NO;
|
108 |
} |
109 |
|
110 |
@Override
|
111 |
public int allowEditableFeatureType() { |
112 |
return YES;
|
113 |
} |
114 |
|
115 |
@Override
|
116 |
public int useLocalIndexesCanImprovePerformance() { |
117 |
return YES;
|
118 |
} |
119 |
|
120 |
@Override
|
121 |
public int isOptimalRecoverFeaturesByReference() { |
122 |
return YES;
|
123 |
} |
124 |
|
125 |
@Override
|
126 |
public List getSupportedDataTypes() { |
127 |
|
128 |
DataTypesManager manager = ToolsLocator.getDataTypesManager(); |
129 |
|
130 |
List resp = new ArrayList<Integer>(); |
131 |
resp.add(manager.get(DataTypes.STRING)); |
132 |
resp.add(manager.get(DataTypes.INT)); |
133 |
resp.add(manager.get(DataTypes.FLOAT)); |
134 |
resp.add(manager.get(DataTypes.DATE)); |
135 |
resp.add(manager.get(DataTypes.GEOMETRY)); |
136 |
return resp;
|
137 |
} |
138 |
|
139 |
@Override
|
140 |
public List getSupportedGeometryTypesSubtypes() { |
141 |
// null means all supported
|
142 |
|
143 |
List<int[]> supported = new ArrayList<>(); |
144 |
|
145 |
supported.add(new int[]{Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D}); |
146 |
supported.add(new int[]{Geometry.TYPES.LINE, Geometry.SUBTYPES.GEOM2D}); |
147 |
supported.add(new int[]{Geometry.TYPES.POLYGON, Geometry.SUBTYPES.GEOM2D}); |
148 |
|
149 |
supported.add(new int[]{Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2DM}); |
150 |
supported.add(new int[]{Geometry.TYPES.LINE, Geometry.SUBTYPES.GEOM2DM}); |
151 |
supported.add(new int[]{Geometry.TYPES.POLYGON, Geometry.SUBTYPES.GEOM2DM}); |
152 |
|
153 |
supported.add(new int[]{Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM3DM}); |
154 |
supported.add(new int[]{Geometry.TYPES.LINE, Geometry.SUBTYPES.GEOM3DM}); |
155 |
supported.add(new int[]{Geometry.TYPES.POLYGON, Geometry.SUBTYPES.GEOM3DM}); |
156 |
|
157 |
supported.add(new int[]{Geometry.TYPES.MULTIPOINT, Geometry.SUBTYPES.GEOM2D}); |
158 |
supported.add(new int[]{Geometry.TYPES.MULTILINE, Geometry.SUBTYPES.GEOM2D}); |
159 |
supported.add(new int[]{Geometry.TYPES.MULTIPOLYGON, Geometry.SUBTYPES.GEOM2D}); |
160 |
|
161 |
supported.add(new int[]{Geometry.TYPES.MULTIPOINT, Geometry.SUBTYPES.GEOM2DM}); |
162 |
supported.add(new int[]{Geometry.TYPES.MULTILINE, Geometry.SUBTYPES.GEOM2DM}); |
163 |
supported.add(new int[]{Geometry.TYPES.MULTIPOLYGON, Geometry.SUBTYPES.GEOM2DM}); |
164 |
|
165 |
supported.add(new int[]{Geometry.TYPES.MULTIPOINT, Geometry.SUBTYPES.GEOM3DM}); |
166 |
supported.add(new int[]{Geometry.TYPES.MULTILINE, Geometry.SUBTYPES.GEOM3DM}); |
167 |
supported.add(new int[]{Geometry.TYPES.MULTIPOLYGON, Geometry.SUBTYPES.GEOM3DM}); |
168 |
|
169 |
return supported;
|
170 |
} |
171 |
|
172 |
@Override
|
173 |
public boolean allowsMandatoryAttributes() { |
174 |
return false; |
175 |
} |
176 |
|
177 |
@Override
|
178 |
public boolean allowsPrimaryKeyAttributes() { |
179 |
return false; |
180 |
} |
181 |
|
182 |
/**
|
183 |
* @return dummy feature type. Must be overridden by subclasses
|
184 |
*
|
185 |
*/
|
186 |
@Override
|
187 |
public FeatureType createDefaultFeatureType() {
|
188 |
DataManager dm = DALLocator.getDataManager(); |
189 |
EditableFeatureType eft = dm.createFeatureType(); |
190 |
|
191 |
EditableFeatureAttributeDescriptor efatd |
192 |
= eft.add(DEFAULT_GEOMETRY_FIELD_NAME, DataTypes.GEOMETRY); |
193 |
|
194 |
GeometryType gt = null;
|
195 |
try {
|
196 |
gt = GeometryLocator.getGeometryManager().getGeometryType( |
197 |
DEFAULT_GEOMETRY_TYPE, |
198 |
DEFAULT_GEOMETRY_SUBTYPE); |
199 |
efatd.setGeometryType(gt); |
200 |
} catch (Exception ex) { |
201 |
LOGGER.info("Error while setting geom type: " + ex.getMessage());
|
202 |
LOGGER.info("Trying deprecated way...");
|
203 |
efatd.setGeometryType(DEFAULT_GEOMETRY_TYPE, DEFAULT_GEOMETRY_SUBTYPE); |
204 |
} |
205 |
eft.setDefaultGeometryAttributeName(DEFAULT_GEOMETRY_FIELD_NAME); |
206 |
return eft.getNotEditableCopy();
|
207 |
} |
208 |
|
209 |
@Override
|
210 |
public int getMaxAttributeNameSize() { |
211 |
return DbaseFile.MAX_FIELD_NAME_LENGTH;
|
212 |
} |
213 |
|
214 |
@Override
|
215 |
public boolean supportNumericOID() { |
216 |
return true; |
217 |
} |
218 |
} |