Revision 1234
tags/org.gvsig.gdal-1.0.229/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/resources/org/gvsig/gdal/prov/ogr/OGRMetadata.xml | ||
---|---|---|
1 |
<?xml version="1.0"?> |
|
2 |
<!-- |
|
3 |
Definitions of metadata fields of a shp file. |
|
4 |
--> |
|
5 |
<definitions> |
|
6 |
<version>1.0.0</version> |
|
7 |
<classes> |
|
8 |
|
|
9 |
<class name="OGRDataStoreProvider" namespace="Metadata"> |
|
10 |
<extends> |
|
11 |
<class namespace="Metadata" name="SpatialProvider"/> |
|
12 |
</extends> |
|
13 |
<description>Metadata of a OGR provider</description> |
|
14 |
<fields> |
|
15 |
</fields> |
|
16 |
</class> |
|
17 |
|
|
18 |
</classes> |
|
19 |
</definitions> |
tags/org.gvsig.gdal-1.0.229/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/resources/org/gvsig/gdal/prov/ogr/OGRExplorerParameters.xml | ||
---|---|---|
1 |
<?xml version="1.0"?> |
|
2 |
<definitions> |
|
3 |
<version>1.0.0</version> |
|
4 |
<classes> |
|
5 |
<class name="OGRDataExplorerParameters"> |
|
6 |
<description>Store the parameters needed to create OGR data explorers |
|
7 |
</description> |
|
8 |
<fields> |
|
9 |
<field name="file" type="file" mandatory="false" group="Basic"> |
|
10 |
<description>Resource file</description> |
|
11 |
</field> |
|
12 |
<field name="connectionString" type="string" mandatory="false" |
|
13 |
group="Basic"> |
|
14 |
<description>Connection string to open data source</description> |
|
15 |
</field> |
|
16 |
</fields> |
|
17 |
</class> |
|
18 |
</classes> |
|
19 |
</definitions> |
tags/org.gvsig.gdal-1.0.229/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/resources/org/gvsig/gdal/prov/ogr/OGRNewDataStoreParameters.xml | ||
---|---|---|
1 |
<definitions> |
|
2 |
<version>1.0.0</version> |
|
3 |
<classes> |
|
4 |
<class name="OGRNewDataStoreParameters"> |
|
5 |
<description>Store the parameters needed to create OGR data stores |
|
6 |
</description> |
|
7 |
<extends> |
|
8 |
<class namespace="dal" name="NewProviderParameters" /> |
|
9 |
<class>OGRDataStoreParameters</class> |
|
10 |
</extends> |
|
11 |
<fields> |
|
12 |
<field name="driverName" type="string" mandatory="false" group="Basic"> |
|
13 |
<description>Name of driver</description> |
|
14 |
</field> |
|
15 |
<field name="datasetCreationOptions" type="List" mandatory="false" group="Basic"> |
|
16 |
<description>Name of driver</description> |
|
17 |
</field> |
|
18 |
</fields> |
|
19 |
</class> |
|
20 |
</classes> |
|
21 |
</definitions> |
tags/org.gvsig.gdal-1.0.229/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/resources/org/gvsig/gdal/prov/ogr/OGRDataStoreParameters.xml | ||
---|---|---|
1 |
<?xml version="1.0"?> |
|
2 |
<definitions> |
|
3 |
<version>1.0.0</version> |
|
4 |
<classes> |
|
5 |
<class name="OGRDataStoreParameters"> |
|
6 |
<extends> |
|
7 |
<class namespace="dal" name="ProviderParameters" /> |
|
8 |
</extends> |
|
9 |
<description>Store the parameters needed to open OGR stores |
|
10 |
</description> |
|
11 |
<fields> |
|
12 |
<field name="CRS" type="crs" mandatory="false" group="Basic"> |
|
13 |
<description>Coordinate reference system used</description> |
|
14 |
</field> |
|
15 |
<field name="file" type="file" mandatory="false" group="Basic"> |
|
16 |
<description>Resource file</description> |
|
17 |
</field> |
|
18 |
<field name="connectionString" type="string" mandatory="false" |
|
19 |
group="Basic"> |
|
20 |
<description>Connection string to open data source</description> |
|
21 |
</field> |
|
22 |
<field name="layerName" type="string" mandatory="false" group="Basic"> |
|
23 |
<description>Layer name of data source</description> |
|
24 |
</field> |
|
25 |
<field name="defaultGeometryField" type="string" mandatory="false" |
|
26 |
group="Basic"> |
|
27 |
<description>Name of default geometry field</description> |
|
28 |
</field> |
|
29 |
<field name="ignoreSpatialFilter" type="boolean" mandatory="false" |
|
30 |
group="Advanced" defaultValue="true"> |
|
31 |
<description>Ignore spatial filter</description> |
|
32 |
</field> |
|
33 |
</fields> |
|
34 |
</class> |
|
35 |
</classes> |
|
36 |
</definitions> |
tags/org.gvsig.gdal-1.0.229/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.gdal.prov.ogr.OGRLibrary |
tags/org.gvsig.gdal-1.0.229/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/java/org/gvsig/gdal/prov/ogr/OGRDataExplorer.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2016 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 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 |
* 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.gdal.prov.ogr; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
import java.util.ArrayList; |
|
28 |
import java.util.List; |
|
29 |
|
|
30 |
import org.apache.commons.lang3.StringUtils; |
|
31 |
import org.cresques.cts.ICRSFactory; |
|
32 |
import org.cresques.cts.IProjection; |
|
33 |
import org.gdal.ogr.DataSource; |
|
34 |
import org.gdal.ogr.FieldDefn; |
|
35 |
import org.gdal.ogr.GeomFieldDefn; |
|
36 |
import org.gdal.ogr.Layer; |
|
37 |
import org.gdal.ogr.ogr; |
|
38 |
import org.gdal.ogr.ogrConstants; |
|
39 |
import org.gdal.osr.SpatialReference; |
|
40 |
import org.gvsig.fmap.dal.DALLocator; |
|
41 |
import org.gvsig.fmap.dal.DataManager; |
|
42 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
43 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
44 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
45 |
import org.gvsig.fmap.dal.exception.DataException; |
|
46 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
47 |
import org.gvsig.fmap.dal.exception.ReadRuntimeException; |
|
48 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
49 |
import org.gvsig.fmap.dal.resource.ResourceAction; |
|
50 |
import org.gvsig.fmap.dal.resource.file.FileResource; |
|
51 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
|
52 |
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices; |
|
53 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
|
54 |
import org.gvsig.fmap.dal.spi.AbstractDataServerExplorer; |
|
55 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider; |
|
56 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
|
57 |
import org.gvsig.tools.dynobject.DynField; |
|
58 |
import org.slf4j.Logger; |
|
59 |
import org.slf4j.LoggerFactory; |
|
60 |
|
|
61 |
/** |
|
62 |
* |
|
63 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
|
64 |
* |
|
65 |
*/ |
|
66 |
public class OGRDataExplorer extends AbstractDataServerExplorer implements DataServerExplorerProvider, ResourceConsumer { |
|
67 |
|
|
68 |
private static final Logger LOG = LoggerFactory.getLogger(OGRDataExplorer.class); |
|
69 |
|
|
70 |
/** |
|
71 |
* |
|
72 |
*/ |
|
73 |
public static final String NAME = "OGRDataExplorer"; |
|
74 |
|
|
75 |
private DataServerExplorerProviderServices providerServives; |
|
76 |
protected OGRDataExplorerParameters parameters; |
|
77 |
|
|
78 |
private ResourceProvider resourceProvider; |
|
79 |
|
|
80 |
protected DataSource dataSource; |
|
81 |
|
|
82 |
protected Boolean updateSupport; |
|
83 |
|
|
84 |
private List<Layer> layerList; |
|
85 |
|
|
86 |
/** |
|
87 |
* @param parameters |
|
88 |
* Parameters to open data explorer. |
|
89 |
* @param providerServices |
|
90 |
* Available services |
|
91 |
* @throws InitializeException |
|
92 |
* If there is some error initializing this store provider |
|
93 |
*/ |
|
94 |
public OGRDataExplorer(OGRDataExplorerParameters parameters, |
|
95 |
DataServerExplorerProviderServices providerServices) throws InitializeException { |
|
96 |
super(parameters, providerServices); |
|
97 |
this.providerServives = providerServices; |
|
98 |
this.parameters = parameters; |
|
99 |
|
|
100 |
getResourceProvider().addConsumer(this); |
|
101 |
} |
|
102 |
|
|
103 |
private ResourceProvider getResourceProvider() { |
|
104 |
if (this.resourceProvider == null) { |
|
105 |
ResourceManagerProviderServices manager = |
|
106 |
(ResourceManagerProviderServices) DALLocator.getResourceManager(); |
|
107 |
|
|
108 |
if (StringUtils.isBlank(parameters.getConnectionString())) { |
|
109 |
try { |
|
110 |
this.resourceProvider = |
|
111 |
(FileResource) manager.createAddResource(FileResource.NAME, |
|
112 |
new Object[] { this.parameters.getFile().getAbsolutePath() }); |
|
113 |
} catch (InitializeException e) { |
|
114 |
throw new ReadRuntimeException(getProviderName(), e); |
|
115 |
} |
|
116 |
} else { |
|
117 |
try { |
|
118 |
this.resourceProvider = |
|
119 |
(OGRResource) manager.createAddResource(OGRResource.NAME, |
|
120 |
new Object[] { this.parameters.getConnectionString() }); |
|
121 |
} catch (InitializeException e) { |
|
122 |
throw new ReadRuntimeException(getProviderName(), e); |
|
123 |
} |
|
124 |
} |
|
125 |
} |
|
126 |
return this.resourceProvider; |
|
127 |
} |
|
128 |
|
|
129 |
protected synchronized DataSource getDataSource() throws OGRUnsupportedFormatException { |
|
130 |
if (this.dataSource == null) { |
|
131 |
// Prioritize connection string over file |
|
132 |
if (StringUtils.isNotBlank(this.parameters.getConnectionString())) { |
|
133 |
// Trying to open in update mode |
|
134 |
this.dataSource = ogr.Open(this.parameters.getConnectionString(), 1); |
|
135 |
|
|
136 |
if (this.dataSource == null) { |
|
137 |
this.dataSource = ogr.Open(this.parameters.getConnectionString()); |
|
138 |
updateSupport = false; |
|
139 |
} else { |
|
140 |
updateSupport = true; |
|
141 |
} |
|
142 |
|
|
143 |
} else if (this.parameters.getFile() != null && this.parameters.getFile().exists()) { |
|
144 |
|
|
145 |
// Trying to open in update mode |
|
146 |
this.dataSource = ogr.Open(this.parameters.getFile().getAbsolutePath(), 1); |
|
147 |
|
|
148 |
if (this.dataSource == null) { |
|
149 |
this.dataSource = ogr.Open(this.parameters.getFile().getAbsolutePath()); |
|
150 |
updateSupport = false; |
|
151 |
} else { |
|
152 |
updateSupport = true; |
|
153 |
} |
|
154 |
|
|
155 |
} else { |
|
156 |
throw new IllegalStateException( |
|
157 |
"Invalid parameters. Connection string must not be blank or file must exists"); |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 |
if (this.dataSource == null) { |
|
162 |
|
|
163 |
if (StringUtils.isNotBlank(this.parameters.getConnectionString())) { |
|
164 |
throw new OGRUnsupportedFormatException(this.parameters.getConnectionString()); |
|
165 |
} |
|
166 |
} |
|
167 |
|
|
168 |
return this.dataSource; |
|
169 |
} |
|
170 |
|
|
171 |
@SuppressWarnings("unchecked") |
|
172 |
protected List<Layer> getLayerList() { |
|
173 |
if (this.layerList == null) { |
|
174 |
this.layerList = (List<Layer>) getResourceProvider().execute(new ResourceAction() { |
|
175 |
|
|
176 |
@Override |
|
177 |
public Object run() throws Exception { |
|
178 |
List<Layer> layers = new ArrayList<Layer>(); |
|
179 |
|
|
180 |
for (int i = 0; i < getDataSource().GetLayerCount(); i++) { |
|
181 |
layers.add(getDataSource().GetLayer(i)); |
|
182 |
} |
|
183 |
|
|
184 |
return layers; |
|
185 |
} |
|
186 |
}); |
|
187 |
} |
|
188 |
return this.layerList; |
|
189 |
} |
|
190 |
|
|
191 |
private Boolean hasUpdateSupport() throws OGRUnsupportedFormatException { |
|
192 |
if (this.updateSupport == null) { |
|
193 |
// Open data source to check update support of driver |
|
194 |
getDataSource(); |
|
195 |
} |
|
196 |
return this.updateSupport; |
|
197 |
} |
|
198 |
|
|
199 |
@Override |
|
200 |
public String getProviderName() { |
|
201 |
return NAME; |
|
202 |
} |
|
203 |
|
|
204 |
@Override |
|
205 |
public boolean canAdd() { |
|
206 |
|
|
207 |
return (boolean) getResourceProvider().execute(new ResourceAction() { |
|
208 |
|
|
209 |
@Override |
|
210 |
public Object run() throws Exception { |
|
211 |
return getDataSource().TestCapability(ogrConstants.ODsCCreateLayer) |
|
212 |
&& getDataSource().TestCapability(ogrConstants.ODsCDeleteLayer) |
|
213 |
&& hasUpdateSupport(); |
|
214 |
} |
|
215 |
}); |
|
216 |
} |
|
217 |
|
|
218 |
@Override |
|
219 |
public boolean canAdd(String storeName) throws DataException { |
|
220 |
return getDataStoreProviderNames().contains(storeName) && canAdd(); |
|
221 |
} |
|
222 |
|
|
223 |
@SuppressWarnings("rawtypes") |
|
224 |
@Override |
|
225 |
public List list() throws DataException { |
|
226 |
return list(MODE_ALL); |
|
227 |
} |
|
228 |
|
|
229 |
@SuppressWarnings("rawtypes") |
|
230 |
@Override |
|
231 |
public List list(int mode) throws DataException { |
|
232 |
List<Layer> layerList = getLayerList(); |
|
233 |
DataManager dataManager = DALLocator.getDataManager(); |
|
234 |
|
|
235 |
List<OGRDataStoreParameters> parametersList = new ArrayList<OGRDataStoreParameters>(); |
|
236 |
for (Layer layer : layerList) { |
|
237 |
|
|
238 |
OGRDataStoreParameters storeParameters = |
|
239 |
(OGRDataStoreParameters) dataManager.createStoreParameters(OGRDataStoreProvider.NAME); |
|
240 |
String connectionString = this.parameters.getConnectionString(); |
|
241 |
File file = this.parameters.getFile(); |
|
242 |
storeParameters.setConnectionString(connectionString); |
|
243 |
storeParameters.setFile(file); |
|
244 |
storeParameters.setLayerName(layer.GetName()); |
|
245 |
parametersList.add(storeParameters); |
|
246 |
} |
|
247 |
return parametersList; |
|
248 |
} |
|
249 |
|
|
250 |
@Override |
|
251 |
public boolean add(String provider, final NewDataStoreParameters parameters, |
|
252 |
final boolean overwrite) throws DataException { |
|
253 |
|
|
254 |
if (canAdd()) { |
|
255 |
|
|
256 |
return (boolean) getResourceProvider().execute(new ResourceAction() { |
|
257 |
|
|
258 |
@Override |
|
259 |
public Object run() throws Exception { |
|
260 |
|
|
261 |
if (parameters instanceof OGRNewDataStoreParameters) { |
|
262 |
OGRNewDataStoreParameters ogrParameters = |
|
263 |
(OGRNewDataStoreParameters) parameters; |
|
264 |
|
|
265 |
String layerName = ogrParameters.getLayerName(); |
|
266 |
if (overwrite) { |
|
267 |
for (int i = 0; i < getLayerList().size(); i++) { |
|
268 |
if (getLayerList().get(i).GetName().equals(layerName)) { |
|
269 |
getDataSource().DeleteLayer(i); |
|
270 |
} |
|
271 |
} |
|
272 |
} else { |
|
273 |
for (Layer layer : getLayerList()) { |
|
274 |
if (layer.GetName().equals(layerName)) { |
|
275 |
return false; |
|
276 |
} |
|
277 |
} |
|
278 |
} |
|
279 |
|
|
280 |
EditableFeatureType editableFeatureType = |
|
281 |
ogrParameters.getDefaultFeatureType(); |
|
282 |
|
|
283 |
OGRConverter converter = new OGRConverter(); |
|
284 |
|
|
285 |
// If SRS is defined convert it to spatial reference |
|
286 |
IProjection projection = editableFeatureType.getDefaultSRS(); |
|
287 |
SpatialReference srs = null; |
|
288 |
if (projection != null) { |
|
289 |
srs = new SpatialReference(projection.export(ICRSFactory.FORMAT_PROJ4)); |
|
290 |
} |
|
291 |
|
|
292 |
// Convert to geometry type to OGR Geometry type |
|
293 |
Integer ogrGeometryType = null; |
|
294 |
if (editableFeatureType.getDefaultGeometryAttribute() != null) { |
|
295 |
int geomType = |
|
296 |
editableFeatureType.getDefaultGeometryAttribute().getGeomType() |
|
297 |
.getType(); |
|
298 |
ogrGeometryType = converter.convertToOGRGeomType(geomType); |
|
299 |
} |
|
300 |
|
|
301 |
// Create layer |
|
302 |
Layer newlayer = null; |
|
303 |
if (srs == null) { |
|
304 |
newlayer = getDataSource().CreateLayer(layerName); |
|
305 |
} else if (ogrGeometryType == null && srs != null) { |
|
306 |
newlayer = getDataSource().CreateLayer(layerName, srs); |
|
307 |
} else if (ogrGeometryType != null && srs != null) { |
|
308 |
newlayer = getDataSource().CreateLayer(layerName, srs, ogrGeometryType); |
|
309 |
} |
|
310 |
|
|
311 |
List<FieldDefn> fields = |
|
312 |
converter.convertFields(editableFeatureType.getNotEditableCopy()); |
|
313 |
for (FieldDefn fieldDefn : fields) { |
|
314 |
newlayer.CreateField(fieldDefn); |
|
315 |
} |
|
316 |
|
|
317 |
List<GeomFieldDefn> geometryFields = |
|
318 |
converter.convertGeometryFields( |
|
319 |
editableFeatureType.getNotEditableCopy(), false); |
|
320 |
for (GeomFieldDefn geomFieldDefn : geometryFields) { |
|
321 |
newlayer.CreateGeomField(geomFieldDefn); |
|
322 |
} |
|
323 |
return true; |
|
324 |
} |
|
325 |
return false; |
|
326 |
} |
|
327 |
}); |
|
328 |
} |
|
329 |
return false; |
|
330 |
} |
|
331 |
|
|
332 |
@Override |
|
333 |
public void remove(final DataStoreParameters parameters) throws DataException { |
|
334 |
|
|
335 |
if (canAdd()) { |
|
336 |
|
|
337 |
getResourceProvider().execute(new ResourceAction() { |
|
338 |
|
|
339 |
@Override |
|
340 |
public Object run() throws Exception { |
|
341 |
if (parameters instanceof OGRNewDataStoreParameters) { |
|
342 |
OGRNewDataStoreParameters ogrParameters = |
|
343 |
(OGRNewDataStoreParameters) parameters; |
|
344 |
|
|
345 |
String layerName = ogrParameters.getLayerName(); |
|
346 |
for (int i = 0; i < getLayerList().size(); i++) { |
|
347 |
if (getLayerList().get(i).GetName().equals(layerName)) { |
|
348 |
getDataSource().DeleteLayer(i); |
|
349 |
return true; |
|
350 |
} |
|
351 |
} |
|
352 |
} |
|
353 |
return false; |
|
354 |
} |
|
355 |
}); |
|
356 |
} |
|
357 |
} |
|
358 |
|
|
359 |
@Override |
|
360 |
public NewDataStoreParameters getAddParameters(String storeName) throws DataException { |
|
361 |
|
|
362 |
if (getDataStoreProviderNames().contains(storeName)) { |
|
363 |
OGRNewDataStoreParameters newParameters = new OGRNewDataStoreParameters(); |
|
364 |
newParameters.setFile(this.parameters.getFile()); |
|
365 |
newParameters.setConnectionString(this.parameters.getConnectionString()); |
|
366 |
return newParameters; |
|
367 |
} |
|
368 |
|
|
369 |
return null; |
|
370 |
} |
|
371 |
|
|
372 |
@Override |
|
373 |
public DataServerExplorerParameters getParameters() { |
|
374 |
return parameters; |
|
375 |
} |
|
376 |
|
|
377 |
@SuppressWarnings("rawtypes") |
|
378 |
@Override |
|
379 |
public List getDataStoreProviderNames() { |
|
380 |
List<String> providerNames = new ArrayList<String>(); |
|
381 |
providerNames.add(OGRDataStoreProvider.NAME); |
|
382 |
return providerNames; |
|
383 |
} |
|
384 |
|
|
385 |
@Override |
|
386 |
public void doDispose() { |
|
387 |
|
|
388 |
try { |
|
389 |
getDataSource().SyncToDisk(); |
|
390 |
getDataSource().delete(); |
|
391 |
} catch (OGRUnsupportedFormatException e) { |
|
392 |
LOG.warn("Can not dispose OGRDataExplorer", e); |
|
393 |
} |
|
394 |
|
|
395 |
this.dataSource = null; |
|
396 |
this.layerList = null; |
|
397 |
|
|
398 |
getResourceProvider().removeConsumer(this); |
|
399 |
this.resourceProvider = null; |
|
400 |
} |
|
401 |
|
|
402 |
@Override |
|
403 |
public DataServerExplorerProviderServices getServerExplorerProviderServices() { |
|
404 |
return providerServives; |
|
405 |
} |
|
406 |
|
|
407 |
@Override |
|
408 |
public boolean closeResourceRequested(ResourceProvider resource) { |
|
409 |
|
|
410 |
try { |
|
411 |
getDataSource().SyncToDisk(); |
|
412 |
getDataSource().delete(); |
|
413 |
} catch (OGRUnsupportedFormatException e) { |
|
414 |
LOG.warn(String.format("Can not close requested resource %1s", resource), e); |
|
415 |
} |
|
416 |
|
|
417 |
this.dataSource = null; |
|
418 |
this.layerList = null; |
|
419 |
return true; |
|
420 |
} |
|
421 |
|
|
422 |
@Override |
|
423 |
public void resourceChanged(ResourceProvider resource) { |
|
424 |
|
|
425 |
try { |
|
426 |
getDataSource().SyncToDisk(); |
|
427 |
getDataSource().delete(); |
|
428 |
} catch (OGRUnsupportedFormatException e) { |
|
429 |
LOG.warn("Can not sync to disk or release native resources to reopen data source", e); |
|
430 |
} |
|
431 |
|
|
432 |
this.dataSource = null; |
|
433 |
this.layerList = null; |
|
434 |
} |
|
435 |
|
|
436 |
@Override |
|
437 |
public DataStoreParameters get(String name) throws DataException { |
|
438 |
// "name" es un nombre de fichero sin path. |
|
439 |
|
|
440 |
// No tengo nada clara esta implementacion |
|
441 |
OGRDataStoreParameters params = new OGRDataStoreParameters(); |
|
442 |
// |
|
443 |
// Copiamos los paramametros que se llamen igual entre el explorer y |
|
444 |
// el DataStoreParametes |
|
445 |
for( DynField field : params.getDynClass().getDynFields() ) { |
|
446 |
String fieldName = field.getName(); |
|
447 |
if( parameters.hasDynValue(fieldName) ) { |
|
448 |
params.setDynValue(fieldName, parameters.getDynValue(fieldName)); |
|
449 |
} |
|
450 |
} |
|
451 |
// Si el file es una carpeta asignamos como file el fichero name que haya |
|
452 |
// en ella |
|
453 |
// Si el file es un fichero cogemos el fichero name que se encuentre en |
|
454 |
// su misma carpeta. |
|
455 |
if( parameters.getFile().isDirectory() ) { |
|
456 |
params.setFile(new File(parameters.getFile(),name)); |
|
457 |
} else { |
|
458 |
params.setFile(new File(parameters.getFile().getParentFile(),name)); |
|
459 |
} |
|
460 |
// Usamos como layer el nombre del fichero pasado como parametro. |
|
461 |
params.setLayerName(name); |
|
462 |
return params; |
|
463 |
} |
|
464 |
} |
tags/org.gvsig.gdal-1.0.229/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/java/org/gvsig/gdal/prov/ogr/OGRDataStoreParameters.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2016 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 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 |
* 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.gdal.prov.ogr; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
|
|
28 |
import org.apache.commons.lang3.StringUtils; |
|
29 |
import org.cresques.cts.IProjection; |
|
30 |
import org.gvsig.fmap.dal.feature.OpenFeatureStoreParameters; |
|
31 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
|
32 |
import org.gvsig.fmap.dal.spi.AbstractDataStoreParameters; |
|
33 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
34 |
import org.gvsig.tools.ToolsLocator; |
|
35 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
|
36 |
|
|
37 |
/** |
|
38 |
* |
|
39 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
|
40 |
* |
|
41 |
*/ |
|
42 |
public class OGRDataStoreParameters extends AbstractDataStoreParameters implements OpenFeatureStoreParameters, |
|
43 |
FilesystemStoreParameters { |
|
44 |
|
|
45 |
/** |
|
46 |
* |
|
47 |
*/ |
|
48 |
public static final String PARAMETERS_DEFINITION_NAME = "OGRDataStoreParameters"; |
|
49 |
|
|
50 |
/** |
|
51 |
* |
|
52 |
*/ |
|
53 |
public static final String FILE_PARAMTER_NAME = "file"; |
|
54 |
|
|
55 |
/** |
|
56 |
* |
|
57 |
*/ |
|
58 |
public static final String LAYER_NAME_PARAMTER_NAME = "layerName"; |
|
59 |
|
|
60 |
/** |
|
61 |
* |
|
62 |
*/ |
|
63 |
public static final String CONNECTION_STRING_PARAMETER_NAME = "connectionString"; |
|
64 |
|
|
65 |
/** |
|
66 |
* |
|
67 |
*/ |
|
68 |
public static final String DEFAULT_GEOMETRY_PARAMETER_NAME = "defaultGeometryField"; |
|
69 |
|
|
70 |
/** |
|
71 |
* |
|
72 |
*/ |
|
73 |
public static final String CRS_PARAMETER_NAME = "crs"; |
|
74 |
|
|
75 |
/** |
|
76 |
* |
|
77 |
*/ |
|
78 |
public static final String IGNORE_SPATIAL_FILTER = "ignoreSpatialFilter"; |
|
79 |
|
|
80 |
|
|
81 |
protected DelegatedDynObject parameters; |
|
82 |
|
|
83 |
/** |
|
84 |
* |
|
85 |
*/ |
|
86 |
public OGRDataStoreParameters() { |
|
87 |
this.parameters = |
|
88 |
(DelegatedDynObject) ToolsLocator.getDynObjectManager().createDynObject( |
|
89 |
ToolsLocator.getPersistenceManager().getDefinition(PARAMETERS_DEFINITION_NAME)); |
|
90 |
this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, |
|
91 |
OGRDataStoreProvider.NAME); |
|
92 |
} |
|
93 |
|
|
94 |
@Override |
|
95 |
public String getDataStoreName() { |
|
96 |
return OGRDataStoreProvider.NAME; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public String getDescription() { |
|
101 |
return OGRDataStoreProvider.DESCRIPTION; |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* @return File |
|
106 |
*/ |
|
107 |
public File getFile() { |
|
108 |
return (File) this.getDynValue(FILE_PARAMTER_NAME); |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* @return String |
|
113 |
*/ |
|
114 |
public String getLayerName() { |
|
115 |
return (String) this.getDynValue(LAYER_NAME_PARAMTER_NAME); |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* @return String |
|
120 |
*/ |
|
121 |
public String getConnectionString() { |
|
122 |
return (String) this.getDynValue(CONNECTION_STRING_PARAMETER_NAME); |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* @return String |
|
127 |
*/ |
|
128 |
public String getDefaultGeometryField() { |
|
129 |
return (String) this.getDynValue(DEFAULT_GEOMETRY_PARAMETER_NAME); |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* |
|
134 |
* @return String |
|
135 |
*/ |
|
136 |
public IProjection getCRS() { |
|
137 |
return (IProjection) this.getDynValue(CRS_PARAMETER_NAME); |
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 |
* @param file |
|
142 |
* File |
|
143 |
*/ |
|
144 |
public void setFile(File file) { |
|
145 |
this.setDynValue(FILE_PARAMTER_NAME, file); |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* @param layerName |
|
150 |
* Name of layer |
|
151 |
*/ |
|
152 |
public void setLayerName(String layerName) { |
|
153 |
this.setDynValue(LAYER_NAME_PARAMTER_NAME, layerName); |
|
154 |
} |
|
155 |
|
|
156 |
/** |
|
157 |
* @param connectionString |
|
158 |
* Connection string |
|
159 |
*/ |
|
160 |
public void setConnectionString(String connectionString) { |
|
161 |
this.setDynValue(CONNECTION_STRING_PARAMETER_NAME, connectionString); |
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
165 |
* @param defaultGeoemtryField |
|
166 |
* Name of defualt geometry field. |
|
167 |
*/ |
|
168 |
public void setDefaultGeometryField(String defaultGeoemtryField) { |
|
169 |
this.setDynValue(DEFAULT_GEOMETRY_PARAMETER_NAME, defaultGeoemtryField); |
|
170 |
} |
|
171 |
|
|
172 |
/** |
|
173 |
* |
|
174 |
* @param crs |
|
175 |
*/ |
|
176 |
public void setCRS(IProjection crs) { |
|
177 |
this.setDynValue(CRS_PARAMETER_NAME, crs); |
|
178 |
} |
|
179 |
|
|
180 |
@Override |
|
181 |
public boolean isValid() { |
|
182 |
if ((this.getFile() != null && this.getFile().exists()) |
|
183 |
|| StringUtils.isNotBlank(this.getConnectionString())) { |
|
184 |
return true; |
|
185 |
} |
|
186 |
return false; |
|
187 |
} |
|
188 |
|
|
189 |
@Override |
|
190 |
protected DelegatedDynObject getDelegatedDynObject() { |
|
191 |
return parameters; |
|
192 |
} |
|
193 |
|
|
194 |
} |
tags/org.gvsig.gdal-1.0.229/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/java/org/gvsig/gdal/prov/ogr/BasicOGRDataStoreProviderFactory.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2016 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 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 |
* 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.gdal.prov.ogr; |
|
25 |
|
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.List; |
|
28 |
|
|
29 |
import org.gvsig.fmap.dal.DataParameters; |
|
30 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
31 |
import org.gvsig.fmap.dal.DataStoreProvider; |
|
32 |
import org.gvsig.fmap.dal.DataTypes; |
|
33 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
34 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProviderFactory; |
|
35 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
36 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
37 |
import org.gvsig.tools.dynobject.DynObject; |
|
38 |
|
|
39 |
/** |
|
40 |
* |
|
41 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
|
42 |
* |
|
43 |
*/ |
|
44 |
public class BasicOGRDataStoreProviderFactory extends AbstractFeatureStoreProviderFactory implements |
|
45 |
OGRDataStoreProviderFactory { |
|
46 |
|
|
47 |
/** |
|
48 |
* @param name |
|
49 |
* Name of factory |
|
50 |
* @param description |
|
51 |
* Description of factory |
|
52 |
*/ |
|
53 |
public BasicOGRDataStoreProviderFactory(String name, String description) { |
|
54 |
super(name, description); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public DataStoreProvider createProvider(DataParameters dataParameters, |
|
59 |
DataStoreProviderServices providerServices) throws InitializeException { |
|
60 |
return new OGRDataStoreProvider((DataStoreParameters) dataParameters, providerServices); |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public DynObject createParameters() { |
|
65 |
return new OGRDataStoreParameters(); |
|
66 |
} |
|
67 |
|
|
68 |
public int allowMultipleGeometryTypes() { |
|
69 |
return UNKNOWN; |
|
70 |
} |
|
71 |
|
|
72 |
public int allowEditableFeatureType() { |
|
73 |
return UNKNOWN; |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* See {@link OGRConverter#convertToDataType(int)} method. The list of data |
|
78 |
* type of OGR. If the list of OGR types changes update this method. |
|
79 |
*/ |
|
80 |
@SuppressWarnings("rawtypes") |
|
81 |
public List getSupportedDataTypes() { |
|
82 |
|
|
83 |
List<Integer> supportedDataTypes = new ArrayList<Integer>(); |
|
84 |
|
|
85 |
supportedDataTypes.add(DataTypes.BOOLEAN); |
|
86 |
supportedDataTypes.add(DataTypes.DATE); |
|
87 |
supportedDataTypes.add(DataTypes.FLOAT); |
|
88 |
supportedDataTypes.add(DataTypes.DOUBLE); |
|
89 |
supportedDataTypes.add(DataTypes.STRING); |
|
90 |
supportedDataTypes.add(DataTypes.INT); |
|
91 |
supportedDataTypes.add(DataTypes.LONG); |
|
92 |
supportedDataTypes.add(DataTypes.TIME); |
|
93 |
|
|
94 |
return supportedDataTypes; |
|
95 |
} |
|
96 |
|
|
97 |
@SuppressWarnings("rawtypes") |
|
98 |
public List getSupportedGeometryTypesSubtypes() { |
|
99 |
List<Integer> supportedSubtypes = new ArrayList<Integer>(); |
|
100 |
supportedSubtypes.add(SUBTYPES.GEOM2D); |
|
101 |
return supportedSubtypes; |
|
102 |
} |
|
103 |
|
|
104 |
public boolean allowsMandatoryAttributes() { |
|
105 |
return false; |
|
106 |
} |
|
107 |
|
|
108 |
public boolean allowsPrimaryKeyAttributes() { |
|
109 |
return false; |
|
110 |
} |
|
111 |
|
|
112 |
public int useLocalIndexesCanImprovePerformance() { |
|
113 |
return UNKNOWN; |
|
114 |
} |
|
115 |
|
|
116 |
@Override |
|
117 |
public DynObject createDataExplorerParameters(Object connectionString) { |
|
118 |
return new OGRDataExplorerParameters(); |
|
119 |
} |
|
120 |
|
|
121 |
@Override |
|
122 |
public DynObject createParameters(Object connectionObject) { |
|
123 |
return createParameters(); |
|
124 |
} |
|
125 |
|
|
126 |
@Override |
|
127 |
public String getDriver() { |
|
128 |
return null; |
|
129 |
} |
|
130 |
|
|
131 |
} |
tags/org.gvsig.gdal-1.0.229/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/java/org/gvsig/gdal/prov/ogr/OGRResourceParameters.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2016 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.gdal.prov.ogr; |
|
25 |
|
|
26 |
import org.gvsig.fmap.dal.resource.spi.AbstractResourceParameters; |
|
27 |
import org.gvsig.tools.ToolsLocator; |
|
28 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
29 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
|
30 |
import org.gvsig.tools.dynobject.DynClass; |
|
31 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
32 |
|
|
33 |
/** |
|
34 |
* |
|
35 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
|
36 |
* |
|
37 |
*/ |
|
38 |
public class OGRResourceParameters extends AbstractResourceParameters { |
|
39 |
|
|
40 |
/** |
|
41 |
* |
|
42 |
*/ |
|
43 |
public static final String DYNCLASS_NAME = "OGRResourceParameters"; |
|
44 |
|
|
45 |
/** |
|
46 |
* |
|
47 |
*/ |
|
48 |
private static final String DYNFIELDNAME_NAME = "name"; |
|
49 |
|
|
50 |
/** |
|
51 |
* |
|
52 |
*/ |
|
53 |
private static final String DYNFIELDNAME_CONNECTION_STRING = "connectionString"; |
|
54 |
|
|
55 |
private DelegatedDynObject delegatedDynObject; |
|
56 |
|
|
57 |
/** |
|
58 |
* |
|
59 |
*/ |
|
60 |
public OGRResourceParameters() { |
|
61 |
super(); |
|
62 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
63 |
DynClass definition = (DynClass) manager.getDefinition(DYNCLASS_NAME); |
|
64 |
this.delegatedDynObject = |
|
65 |
(DelegatedDynObject) ToolsLocator.getDynObjectManager().createDynObject(definition); |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* |
|
70 |
* @param connectionString |
|
71 |
* Connection string |
|
72 |
*/ |
|
73 |
public OGRResourceParameters(String connectionString) { |
|
74 |
this(); |
|
75 |
setDynValue(DYNFIELDNAME_NAME, |
|
76 |
String.valueOf(connectionString.hashCode()).concat("@OGResource")); |
|
77 |
setDynValue(DYNFIELDNAME_CONNECTION_STRING, connectionString); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* |
|
82 |
* @param params |
|
83 |
* Array with parameter values |
|
84 |
*/ |
|
85 |
public OGRResourceParameters(Object[] params) { |
|
86 |
this((String) params[0]); |
|
87 |
} |
|
88 |
|
|
89 |
@Override |
|
90 |
public String getTypeName() { |
|
91 |
return OGRResource.NAME; |
|
92 |
} |
|
93 |
|
|
94 |
@Override |
|
95 |
protected DelegatedDynObject getDelegatedDynObject() { |
|
96 |
return delegatedDynObject; |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* @return String |
|
101 |
*/ |
|
102 |
public String getName() { |
|
103 |
return (String) this.getDynValue(DYNFIELDNAME_NAME); |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* @return String |
|
108 |
*/ |
|
109 |
public String getConnectionString() { |
|
110 |
return (String) this.getDynValue(DYNFIELDNAME_CONNECTION_STRING); |
|
111 |
} |
|
112 |
|
|
113 |
protected static void registerPersistenceDefinition() { |
|
114 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
115 |
DynClass definition = (DynClass) manager.getDefinition(DYNCLASS_NAME); |
|
116 |
if (definition == null) { |
|
117 |
definition = (DynClass) manager.addDefinition(OGRResourceParameters.class, |
|
118 |
DYNCLASS_NAME, DYNCLASS_NAME + " persistence definition", null, null); |
|
119 |
|
|
120 |
definition.addDynField(DYNFIELDNAME_NAME).setType(DataTypes.STRING) |
|
121 |
.setDescription("Name of resource"); |
|
122 |
definition.addDynField(DYNFIELDNAME_CONNECTION_STRING).setType(DataTypes.STRING) |
|
123 |
.setDescription("Connection string"); |
|
124 |
} |
|
125 |
} |
|
126 |
} |
tags/org.gvsig.gdal-1.0.229/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/java/org/gvsig/gdal/prov/ogr/OGRDataExplorerParameters.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2016 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 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 |
* 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.gdal.prov.ogr; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
import org.apache.commons.lang3.StringUtils; |
|
28 |
|
|
29 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
30 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
|
31 |
import org.gvsig.fmap.dal.spi.AbstractDataParameters; |
|
32 |
import org.gvsig.tools.ToolsLocator; |
|
33 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
|
34 |
|
|
35 |
/** |
|
36 |
* |
|
37 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
|
38 |
* |
|
39 |
*/ |
|
40 |
public class OGRDataExplorerParameters extends AbstractDataParameters |
|
41 |
implements DataServerExplorerParameters { |
|
42 |
|
|
43 |
/** |
|
44 |
* |
|
45 |
*/ |
|
46 |
public static final String PARAMETERS_DEFINITION_NAME = "OGRDataExplorerParameters"; |
|
47 |
|
|
48 |
/** |
|
49 |
* |
|
50 |
*/ |
|
51 |
public static final String FILE_PARAMETER_NAME = "file"; |
|
52 |
|
|
53 |
/** |
|
54 |
* |
|
55 |
*/ |
|
56 |
public static final String CONNECTION_STRING_PARAMETER_NAME = "connectionString"; |
|
57 |
|
|
58 |
private DelegatedDynObject parameters; |
|
59 |
|
|
60 |
/** |
|
61 |
* |
|
62 |
*/ |
|
63 |
public OGRDataExplorerParameters() { |
|
64 |
this.parameters = (DelegatedDynObject) ToolsLocator.getDynObjectManager().createDynObject( |
|
65 |
ToolsLocator.getPersistenceManager().getDefinition(PARAMETERS_DEFINITION_NAME)); |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public String getExplorerName() { |
|
70 |
return OGRDataExplorer.NAME; |
|
71 |
} |
|
72 |
|
|
73 |
@Override |
|
74 |
protected DelegatedDynObject getDelegatedDynObject() { |
|
75 |
return this.parameters; |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* |
|
80 |
* @return File |
|
81 |
*/ |
|
82 |
public File getFile() { |
|
83 |
return (File) this.getDynValue(FILE_PARAMETER_NAME); |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* |
|
88 |
* @return String |
|
89 |
*/ |
|
90 |
public String getConnectionString() { |
|
91 |
return (String) this.getDynValue(CONNECTION_STRING_PARAMETER_NAME); |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* |
|
96 |
* @param file |
|
97 |
* File |
|
98 |
*/ |
|
99 |
public void setFile(File file) { |
|
100 |
this.setDynValue(FILE_PARAMETER_NAME, file); |
|
101 |
} |
|
102 |
|
|
103 |
/** |
|
104 |
* |
|
105 |
* @param connection |
|
106 |
* Connection string |
|
107 |
*/ |
|
108 |
public void setConnectionString(String connection) { |
|
109 |
this.setDynValue(CONNECTION_STRING_PARAMETER_NAME, connection); |
|
110 |
} |
|
111 |
|
|
112 |
@Override |
|
113 |
public boolean isTheSameServerExplorer(DataServerExplorerParameters params) { |
|
114 |
if(!(params instanceof OGRDataExplorerParameters)){ |
|
115 |
return false; |
|
116 |
} |
|
117 |
File f1 = this.getFile(); |
|
118 |
File f2 = ((OGRDataExplorerParameters)params).getFile(); |
|
119 |
if( f1 == null || f2==null ) { |
|
120 |
return false; |
|
121 |
} |
|
122 |
return StringUtils.equals(f1.getAbsolutePath(),f2.getAbsolutePath()); |
|
123 |
} |
|
124 |
} |
tags/org.gvsig.gdal-1.0.229/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/java/org/gvsig/gdal/prov/ogr/OGRUnsupportedFormatException.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2016 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 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 |
* 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.gdal.prov.ogr; |
|
25 |
|
|
26 |
import java.util.Map; |
|
27 |
|
|
28 |
import org.gvsig.fmap.dal.exception.DataException; |
|
29 |
|
|
30 |
/** |
|
31 |
* |
|
32 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
|
33 |
* |
|
34 |
*/ |
|
35 |
@SuppressWarnings("unchecked") |
|
36 |
public class OGRUnsupportedFormatException extends DataException { |
|
37 |
|
|
38 |
private static final long serialVersionUID = -2670314598211236837L; |
|
39 |
|
|
40 |
private final static String MESSAGE = |
|
41 |
"Unsupported vectorial format. There are not any OGR driver registered to open %(connectionString)"; |
|
42 |
|
|
43 |
private final static String KEY = "_UnsupportedVectorialFormatException"; |
|
44 |
|
|
45 |
/** |
|
46 |
* @param messageFormat |
|
47 |
* Message format |
|
48 |
* @param cause |
|
49 |
* Cause |
|
50 |
* @param messageKey |
|
51 |
* Message key |
|
52 |
* @param code |
|
53 |
* code |
|
54 |
* @param values |
|
55 |
* Values |
|
56 |
*/ |
|
57 |
public OGRUnsupportedFormatException(String messageFormat, Throwable cause, String messageKey, |
|
58 |
long code, Map<Object, Object> values) { |
|
59 |
super(messageFormat, cause, messageKey, code); |
|
60 |
this.values.putAll(values); |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* @param messageFormat |
|
65 |
* Message format |
|
66 |
* @param cause |
|
67 |
* Cause |
|
68 |
* @param values |
|
69 |
* Values |
|
70 |
*/ |
|
71 |
public OGRUnsupportedFormatException(String messageFormat, Throwable cause, |
|
72 |
Map<Object, Object> values) { |
|
73 |
super(messageFormat, cause, KEY, serialVersionUID); |
|
74 |
this.values.putAll(values); |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* @param connectionString |
|
79 |
* Conenction string |
|
80 |
*/ |
|
81 |
public OGRUnsupportedFormatException(String connectionString) { |
|
82 |
super(MESSAGE, KEY, serialVersionUID); |
|
83 |
this.values.put("connectionString", connectionString); |
|
84 |
} |
|
85 |
|
|
86 |
} |
tags/org.gvsig.gdal-1.0.229/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/java/org/gvsig/gdal/prov/ogr/OGRDataStoreProvider.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2016 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 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 |
* 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.gdal.prov.ogr; |
|
25 |
|
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.Iterator; |
|
28 |
import java.util.List; |
|
29 |
|
|
30 |
import org.apache.commons.lang3.StringUtils; |
|
31 |
import org.gdal.ogr.DataSource; |
|
32 |
import org.gdal.ogr.Feature; |
|
33 |
import org.gdal.ogr.FeatureDefn; |
|
34 |
import org.gdal.ogr.FieldDefn; |
|
35 |
import org.gdal.ogr.GeomFieldDefn; |
|
36 |
import org.gdal.ogr.Geometry; |
|
37 |
import org.gdal.ogr.Layer; |
|
38 |
import org.gdal.ogr.ogr; |
|
39 |
import org.gdal.ogr.ogrConstants; |
|
40 |
|
|
41 |
import org.gvsig.fmap.dal.DataStore; |
|
42 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
43 |
import org.gvsig.fmap.dal.DataTypes; |
|
44 |
import org.gvsig.fmap.dal.FileHelper; |
|
45 |
import org.gvsig.fmap.dal.exception.DataException; |
|
46 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
47 |
import org.gvsig.fmap.dal.exception.OpenException; |
|
48 |
import org.gvsig.fmap.dal.exception.ReadRuntimeException; |
|
49 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
50 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
51 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
52 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder; |
|
53 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder.FeatureQueryOrderMember; |
|
54 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
55 |
import org.gvsig.fmap.dal.feature.FeatureType.FeatureTypeChanged; |
|
56 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider; |
|
57 |
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider; |
|
58 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
59 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
|
60 |
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
|
61 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
|
62 |
import org.gvsig.fmap.dal.resource.ResourceAction; |
|
63 |
import org.gvsig.fmap.dal.resource.file.FileResource; |
|
64 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
|
65 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
|
66 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
67 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
68 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
69 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
70 |
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
|
71 |
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
|
72 |
import org.gvsig.tools.dynobject.DynObject; |
|
73 |
import org.gvsig.tools.evaluator.Evaluator; |
|
74 |
import org.gvsig.tools.exception.BaseException; |
|
75 |
|
|
76 |
import org.slf4j.Logger; |
|
77 |
import org.slf4j.LoggerFactory; |
|
78 |
|
|
79 |
/** |
|
80 |
* |
|
81 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
|
82 |
* |
|
83 |
*/ |
|
84 |
public class OGRDataStoreProvider extends AbstractFeatureStoreProvider implements |
|
85 |
FeatureStoreProvider, ResourceConsumer { |
|
86 |
|
|
87 |
private static final Logger LOG = LoggerFactory.getLogger(OGRDataStoreProvider.class); |
|
88 |
|
|
89 |
/** |
|
90 |
* |
|
91 |
*/ |
|
92 |
public static final String METADATA_DEFINITION_NAME = "OGRDataStoreProvider"; |
|
93 |
|
|
94 |
/** |
|
95 |
* |
|
96 |
*/ |
|
97 |
public static final String NAME = "OGRDataStoreProvider"; |
|
98 |
|
|
99 |
/** |
|
100 |
* |
|
101 |
*/ |
|
102 |
public static final String DESCRIPTION = "OGR provider to open vectorial resources"; |
|
103 |
|
|
104 |
protected DataSource dataSource; |
|
105 |
|
|
106 |
private Envelope envelope; |
|
107 |
|
|
108 |
private Layer newLayer; |
|
109 |
|
|
110 |
protected ResourceProvider resourceProvider; |
|
111 |
|
|
112 |
private Boolean updateSupport; |
|
113 |
|
|
114 |
private boolean opened = false; |
|
115 |
|
|
116 |
protected OGRDataStoreProvider(DataStoreParameters dataParameters, |
|
117 |
DataStoreProviderServices storeServices, DynObject metadata) throws InitializeException { |
|
118 |
super(dataParameters, storeServices, metadata); |
|
119 |
|
|
120 |
// Set CRS parameter to metadata |
|
121 |
this.setDynValue(DataStore.METADATA_CRS, dataParameters.getDynValue(DataStore.METADATA_CRS)); |
|
122 |
|
|
123 |
getResource().addConsumer(this); |
|
124 |
|
|
125 |
try { |
|
126 |
this.open(); |
|
127 |
} catch (OpenException e) { |
|
128 |
throw new InitializeException(NAME, e); |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
protected OGRDataStoreProvider(DataStoreParameters dataParameters, |
|
133 |
DataStoreProviderServices storeServices) throws InitializeException { |
|
134 |
this(dataParameters, storeServices, FileHelper |
|
135 |
.newMetadataContainer(METADATA_DEFINITION_NAME)); |
|
136 |
} |
|
137 |
|
|
138 |
/* |
|
139 |
* Lazy initialization of data source |
|
140 |
*/ |
|
141 |
protected synchronized DataSource getDataSource() throws OGRUnsupportedFormatException { |
|
142 |
if (this.dataSource == null) { |
|
143 |
|
|
144 |
// Prioritize connection string over file |
|
145 |
if (StringUtils.isNotBlank(getOGRParameters().getConnectionString())) { |
|
146 |
|
|
147 |
// Trying to open in update mode |
|
148 |
this.dataSource = ogr.Open(getOGRParameters().getConnectionString(), 1); |
|
149 |
|
|
150 |
if (this.dataSource == null) { |
|
151 |
this.dataSource = ogr.Open(getOGRParameters().getConnectionString()); |
|
152 |
updateSupport = false; |
|
153 |
} else { |
|
154 |
updateSupport = true; |
|
155 |
} |
|
156 |
|
|
157 |
} else if (getOGRParameters().getFile() != null |
|
158 |
&& getOGRParameters().getFile().exists()) { |
|
159 |
|
|
160 |
// Trying to open in update mode |
|
161 |
this.dataSource = ogr.Open(getOGRParameters().getFile().getAbsolutePath(), 1); |
|
162 |
|
|
163 |
if (this.dataSource == null) { |
|
164 |
this.dataSource = ogr.Open(getOGRParameters().getFile().getAbsolutePath()); |
|
165 |
updateSupport = false; |
|
166 |
} else { |
|
167 |
updateSupport = true; |
|
168 |
} |
|
169 |
|
|
170 |
} else { |
|
171 |
throw new IllegalStateException( |
|
172 |
"Invalid parameters. Connection string must not be blank or file must exists"); |
|
173 |
} |
|
174 |
} |
|
175 |
|
|
176 |
if (this.dataSource == null) { |
|
177 |
|
|
178 |
if (StringUtils.isNotBlank(getOGRParameters().getConnectionString())) { |
|
179 |
throw new OGRUnsupportedFormatException(getOGRParameters().getConnectionString()); |
|
180 |
} |
|
181 |
} |
|
182 |
|
|
183 |
return this.dataSource; |
|
184 |
} |
|
185 |
|
|
186 |
/* |
|
187 |
* Lazy initialization of update support flag |
|
188 |
*/ |
|
189 |
private Boolean hasUpdateSupport() throws OGRUnsupportedFormatException { |
|
190 |
if (this.updateSupport == null) { |
|
191 |
getDataSource(); |
|
192 |
} |
|
193 |
return this.updateSupport; |
|
194 |
} |
|
195 |
|
|
196 |
/* |
|
197 |
* Lazy initialization of layer |
|
198 |
*/ |
|
199 |
protected Layer getLayer() throws OGRUnsupportedFormatException { |
|
200 |
if (this.newLayer == null) { |
|
201 |
this.newLayer = getDataSource().GetLayer(getOGRParameters().getLayerName()); |
|
202 |
// this.layer = getDataSource().GetLayer(0); |
|
203 |
if (this.newLayer == null) { |
|
204 |
LOG.warn("Can not get layer with {} name. Get first layer of data source", |
|
205 |
getOGRParameters().getLayerName()); |
|
206 |
this.newLayer = getDataSource().GetLayer(0); |
|
207 |
getOGRParameters().setLayerName(this.newLayer.GetName()); |
|
208 |
} |
|
209 |
} |
|
210 |
return this.newLayer; |
|
211 |
} |
|
212 |
|
|
213 |
/* |
|
214 |
* Lazy envelope initialization |
|
215 |
*/ |
|
216 |
@Override |
|
217 |
public Envelope getEnvelope() throws DataException { |
Also available in: Unified diff