Revision 884
tags/org.gvsig.gdal-1.0.159/org.gvsig.gdal.gpx/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
3 |
|
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<artifactId>org.gvsig.gdal.gpx</artifactId> |
|
6 |
<packaging>jar</packaging> |
|
7 |
<name>org.gvsig.gdal.gpx</name> |
|
8 |
<parent> |
|
9 |
<groupId>org.gvsig</groupId> |
|
10 |
<artifactId>org.gvsig.gdal</artifactId> |
|
11 |
<version>1.0.16-SNAPSHOT</version> |
|
12 |
</parent> |
|
13 |
<dependencies> |
|
14 |
<dependency> |
|
15 |
<groupId>org.gdal</groupId> |
|
16 |
<artifactId>gdal</artifactId> |
|
17 |
</dependency> |
|
18 |
<dependency> |
|
19 |
<groupId>commons-io</groupId> |
|
20 |
<artifactId>commons-io</artifactId> |
|
21 |
<scope>compile</scope> |
|
22 |
</dependency> |
|
23 |
<dependency> |
|
24 |
<groupId>org.gvsig</groupId> |
|
25 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
26 |
<scope>compile</scope> |
|
27 |
</dependency> |
|
28 |
<dependency> |
|
29 |
<groupId>org.gvsig</groupId> |
|
30 |
<artifactId>org.gvsig.projection.api</artifactId> |
|
31 |
<scope>compile</scope> |
|
32 |
</dependency> |
|
33 |
<dependency> |
|
34 |
<groupId>org.gvsig</groupId> |
|
35 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
36 |
<scope>compile</scope> |
|
37 |
</dependency> |
|
38 |
<dependency> |
|
39 |
<groupId>org.gvsig</groupId> |
|
40 |
<artifactId>org.gvsig.fmap.dal.spi</artifactId> |
|
41 |
<scope>compile</scope> |
|
42 |
</dependency> |
|
43 |
<dependency> |
|
44 |
<groupId>org.gvsig</groupId> |
|
45 |
<artifactId>org.gvsig.metadata.lib.basic.api</artifactId> |
|
46 |
<scope>compile</scope> |
|
47 |
</dependency> |
|
48 |
<dependency> |
|
49 |
<groupId>org.gvsig</groupId> |
|
50 |
<artifactId>org.gvsig.fmap.geometry.api</artifactId> |
|
51 |
<scope>compile</scope> |
|
52 |
</dependency> |
|
53 |
|
|
54 |
<dependency> |
|
55 |
<groupId>org.gvsig</groupId> |
|
56 |
<artifactId>org.gvsig.utils</artifactId> |
|
57 |
<scope>compile</scope> |
|
58 |
</dependency> |
|
59 |
<dependency> |
|
60 |
<groupId>org.gvsig</groupId> |
|
61 |
<artifactId>org.gvsig.fmap.dal.file.lib</artifactId> |
|
62 |
<scope>compile</scope> |
|
63 |
</dependency> |
|
64 |
</dependencies> |
|
65 |
<modules> |
|
66 |
|
|
67 |
</modules> |
|
68 |
</project> |
|
0 | 69 |
tags/org.gvsig.gdal-1.0.159/org.gvsig.gdal.gpx/src/main/resources/org/gvsig/fmap/dal/store/gpx/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="OGR_DRIVER" namespace="Metadata"> |
|
10 |
<extends> |
|
11 |
<class namespace="Metadata" name="SpatialProvider"/> |
|
12 |
</extends> |
|
13 |
<description>Metadata of a OGR store</description> |
|
14 |
<fields> |
|
15 |
</fields> |
|
16 |
</class> |
|
17 |
|
|
18 |
</classes> |
|
19 |
</definitions> |
|
0 | 20 |
tags/org.gvsig.gdal-1.0.159/org.gvsig.gdal.gpx/src/main/resources/org/gvsig/fmap/dal/store/gpx/OGRParameters.xml | ||
---|---|---|
1 |
<?xml version= "1.0 "?> |
|
2 |
<definitions> |
|
3 |
<version>1.0.0</version> |
|
4 |
<classes> |
|
5 |
<class name="OGRStoreParameters"> |
|
6 |
<extends> |
|
7 |
<class namespace="dal" name="ProviderParameters"/> |
|
8 |
</extends> |
|
9 |
<description>Store the parameters need to open a OGR file</description> |
|
10 |
<fields> |
|
11 |
<field name="File" type="file" mandatory="true" group="Basic"> |
|
12 |
<description>Driver file</description> |
|
13 |
</field> |
|
14 |
<field name="Driver" type="string" mandatory="false" defaultValue="" group="Basic"> |
|
15 |
<description>Sets the driver needed to open.</description> |
|
16 |
</field> |
|
17 |
</fields> |
|
18 |
</class> |
|
19 |
</classes> |
|
20 |
</definitions> |
|
0 | 21 |
tags/org.gvsig.gdal-1.0.159/org.gvsig.gdal.gpx/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.fmap.dal.store.gpx.OGRLibrary |
tags/org.gvsig.gdal-1.0.159/org.gvsig.gdal.gpx/src/main/java/org/gvsig/fmap/dal/store/gpx/UnsupportedOGRVersionException.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.gpx; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.exception.DataException; |
|
4 |
|
|
5 |
public class UnsupportedOGRVersionException extends DataException { |
|
6 |
|
|
7 |
/** |
|
8 |
* |
|
9 |
*/ |
|
10 |
private static final long serialVersionUID = -7335241420683266251L; |
|
11 |
private final static String MESSAGE_FORMAT = "Unssuported version of Driver of file '%(file)'. Try to convert using Autodesk convertor from '%(autodeskurl)'"; |
|
12 |
private final static String MESSAGE_KEY = "_UnsupportedDriverVersionException"; |
|
13 |
|
|
14 |
public final static String AUTODESK_URL = "http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=7024151"; |
|
15 |
|
|
16 |
public UnsupportedOGRVersionException(String file, |
|
17 |
Throwable cause) { |
|
18 |
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID); |
|
19 |
setValue("file", file); |
|
20 |
setValue("autodeskurl", AUTODESK_URL); |
|
21 |
} |
|
22 |
} |
|
0 | 23 |
tags/org.gvsig.gdal-1.0.159/org.gvsig.gdal.gpx/src/main/java/org/gvsig/fmap/dal/store/gpx/OGRStoreProviderFactory.java | ||
---|---|---|
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.gpx; |
|
25 |
|
|
26 |
import org.gvsig.fmap.dal.DataParameters; |
|
27 |
import org.gvsig.fmap.dal.DataStoreProvider; |
|
28 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
29 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
|
30 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProviderFactory; |
|
31 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
32 |
import org.gvsig.tools.dynobject.DynObject; |
|
33 |
|
|
34 |
public class OGRStoreProviderFactory extends AbstractFeatureStoreProviderFactory implements FeatureStoreProviderFactory{ |
|
35 |
|
|
36 |
public OGRStoreProviderFactory(String name, String description) { |
|
37 |
super(name, description); |
|
38 |
} |
|
39 |
|
|
40 |
public DataStoreProvider createProvider(DataParameters parameters, |
|
41 |
DataStoreProviderServices providerServices) |
|
42 |
throws InitializeException { |
|
43 |
return new OGRStoreProvider((OGRStoreParameters) parameters, providerServices); |
|
44 |
} |
|
45 |
|
|
46 |
public DynObject createParameters() { |
|
47 |
return new OGRStoreParameters(); |
|
48 |
} |
|
49 |
|
|
50 |
public int allowCreate() { |
|
51 |
return NO; |
|
52 |
} |
|
53 |
|
|
54 |
public int allowWrite() { |
|
55 |
return NO; |
|
56 |
} |
|
57 |
|
|
58 |
public int allowRead() { |
|
59 |
return YES; |
|
60 |
} |
|
61 |
|
|
62 |
public int hasRasterSupport() { |
|
63 |
return NO; |
|
64 |
} |
|
65 |
|
|
66 |
public int hasTabularSupport() { |
|
67 |
return YES; |
|
68 |
} |
|
69 |
|
|
70 |
public int hasVectorialSupport() { |
|
71 |
return YES; |
|
72 |
} |
|
73 |
|
|
74 |
public int allowMultipleGeometryTypes() { |
|
75 |
return YES; |
|
76 |
} |
|
77 |
|
|
78 |
public int allowEditableFeatureType() { |
|
79 |
return NO; |
|
80 |
} |
|
81 |
|
|
82 |
} |
|
0 | 83 |
tags/org.gvsig.gdal-1.0.159/org.gvsig.gdal.gpx/src/main/java/org/gvsig/fmap/dal/store/gpx/OGRStoreParameters.java | ||
---|---|---|
1 |
/* 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 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 IVER T.I. S.A. {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.store.gpx; |
|
29 |
|
|
30 |
import java.io.File; |
|
31 |
|
|
32 |
import org.cresques.cts.IProjection; |
|
33 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
34 |
import org.gvsig.fmap.dal.FileHelper; |
|
35 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
37 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
38 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
|
39 |
import org.gvsig.fmap.dal.spi.AbstractDataParameters; |
|
40 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
41 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
|
42 |
|
|
43 |
public class OGRStoreParameters extends AbstractDataParameters implements |
|
44 |
DataStoreParameters, FilesystemStoreParameters, |
|
45 |
NewFeatureStoreParameters { |
|
46 |
|
|
47 |
public static final String PARAMETERS_DEFINITION_NAME = "OGRStoreParameters"; |
|
48 |
|
|
49 |
private static final String FIELD_FILE = "file"; |
|
50 |
private static final String FIELD_CRS = "CRS"; |
|
51 |
private static final String FIELD_DRIVER = "Driver"; |
|
52 |
|
|
53 |
private DelegatedDynObject parameters; |
|
54 |
|
|
55 |
public OGRStoreParameters() { |
|
56 |
this(PARAMETERS_DEFINITION_NAME); |
|
57 |
} |
|
58 |
|
|
59 |
protected OGRStoreParameters(String parametersDefinitionName) { |
|
60 |
this(parametersDefinitionName, OGRStoreProvider.NAME); |
|
61 |
} |
|
62 |
|
|
63 |
public OGRStoreParameters(String parametersDefinitionName, String name) { |
|
64 |
super(); |
|
65 |
this.parameters = (DelegatedDynObject) FileHelper.newParameters(parametersDefinitionName); |
|
66 |
this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, |
|
67 |
name); |
|
68 |
} |
|
69 |
|
|
70 |
protected DelegatedDynObject getDelegatedDynObject() { |
|
71 |
return parameters; |
|
72 |
} |
|
73 |
|
|
74 |
public String getDataStoreName() { |
|
75 |
return (String) this |
|
76 |
.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME); |
|
77 |
} |
|
78 |
|
|
79 |
public String getDescription() { |
|
80 |
return this.getDynClass().getDescription(); |
|
81 |
} |
|
82 |
|
|
83 |
public void setCRS(IProjection crs) { |
|
84 |
setDynValue(FIELD_CRS, crs); |
|
85 |
} |
|
86 |
|
|
87 |
public void setCRS(String crs) { |
|
88 |
setDynValue(FIELD_CRS, crs); |
|
89 |
} |
|
90 |
|
|
91 |
public IProjection getCRS() { |
|
92 |
return (IProjection) getDynValue(FIELD_CRS); |
|
93 |
} |
|
94 |
|
|
95 |
public void setDriver(String driver) { |
|
96 |
setDynValue(FIELD_DRIVER, driver); |
|
97 |
} |
|
98 |
|
|
99 |
public String getDriver() { |
|
100 |
return (String) getDynValue(FIELD_DRIVER); |
|
101 |
} |
|
102 |
|
|
103 |
public String getFileName() { |
|
104 |
return this.getFile().getPath(); |
|
105 |
} |
|
106 |
|
|
107 |
public void setFileName(String file) { |
|
108 |
setDynValue(FIELD_FILE, file); |
|
109 |
} |
|
110 |
|
|
111 |
public boolean isValid() { |
|
112 |
if (getCRS() == null) { |
|
113 |
return false; |
|
114 |
} |
|
115 |
if (getFile() == null) { |
|
116 |
return false; |
|
117 |
} |
|
118 |
return true; |
|
119 |
} |
|
120 |
|
|
121 |
public File getFile() { |
|
122 |
return (File) this.getDynValue(FIELD_FILE); |
|
123 |
} |
|
124 |
|
|
125 |
public void setFile(File file) { |
|
126 |
this.setDynValue(FIELD_FILE, file); |
|
127 |
} |
|
128 |
|
|
129 |
public EditableFeatureType getDefaultFeatureType() { |
|
130 |
return null; //TODO ???? |
|
131 |
} |
|
132 |
|
|
133 |
public void setDefaultFeatureType(FeatureType defaultFeatureType) { |
|
134 |
throw new UnsupportedOperationException(); |
|
135 |
} |
|
136 |
|
|
137 |
} |
|
0 | 138 |
tags/org.gvsig.gdal-1.0.159/org.gvsig.gdal.gpx/src/main/java/org/gvsig/fmap/dal/store/gpx/OGRLibrary.java | ||
---|---|---|
1 |
/* 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 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.fmap.dal.store.gpx; |
|
29 |
|
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.List; |
|
32 |
|
|
33 |
import org.gvsig.fmap.dal.DALFileLibrary; |
|
34 |
import org.gvsig.fmap.dal.DALFileLocator; |
|
35 |
import org.gvsig.fmap.dal.DALLibrary; |
|
36 |
import org.gvsig.fmap.dal.DALLocator; |
|
37 |
import org.gvsig.fmap.dal.FileHelper; |
|
38 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
39 |
import org.gvsig.metadata.MetadataLibrary; |
|
40 |
import org.gvsig.metadata.exceptions.MetadataException; |
|
41 |
import org.gvsig.tools.ToolsLocator; |
|
42 |
import org.gvsig.tools.dynobject.DynClass; |
|
43 |
import org.gvsig.tools.dynobject.DynField; |
|
44 |
import org.gvsig.tools.dynobject.DynObjectManager; |
|
45 |
import org.gvsig.tools.library.AbstractLibrary; |
|
46 |
import org.gvsig.tools.library.LibraryException; |
|
47 |
import org.slf4j.Logger; |
|
48 |
import org.slf4j.LoggerFactory; |
|
49 |
|
|
50 |
public class OGRLibrary extends AbstractLibrary { |
|
51 |
|
|
52 |
private static final Logger logger = LoggerFactory.getLogger(OGRLibrary.class); |
|
53 |
|
|
54 |
@Override |
|
55 |
public void doRegistration() { |
|
56 |
registerAsImplementationOf(OGRLibrary.class); |
|
57 |
require(DALLibrary.class); |
|
58 |
require(DALFileLibrary.class); |
|
59 |
require(MetadataLibrary.class); |
|
60 |
} |
|
61 |
|
|
62 |
@Override |
|
63 |
protected void doInitialize() throws LibraryException { |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
protected void doPostInitialize() throws LibraryException { |
|
68 |
List<Throwable> exs = new ArrayList<Throwable>(); |
|
69 |
|
|
70 |
FileHelper.registerParametersDefinition( |
|
71 |
OGRStoreParameters.PARAMETERS_DEFINITION_NAME, |
|
72 |
OGRStoreParameters.class, |
|
73 |
"OGRParameters.xml" |
|
74 |
); |
|
75 |
try { |
|
76 |
FileHelper.registerMetadataDefinition( |
|
77 |
OGRStoreProvider.METADATA_DEFINITION_NAME, |
|
78 |
OGRStoreProvider.class, |
|
79 |
"OGRMetadata.xml" |
|
80 |
); |
|
81 |
} catch (MetadataException e) { |
|
82 |
throw new LibraryException(getClass(), e); |
|
83 |
} |
|
84 |
|
|
85 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator |
|
86 |
.getDataManager(); |
|
87 |
try { |
|
88 |
if (!dataman.getStoreProviders().contains(OGRStoreProvider.NAME)) { |
|
89 |
dataman.registerStoreProviderFactory(new OGRStoreProviderFactory(OGRStoreProvider.NAME, OGRStoreProvider.DESCRIPTION)); |
|
90 |
} |
|
91 |
} catch (RuntimeException e) { |
|
92 |
exs.add(e); |
|
93 |
} |
|
94 |
|
|
95 |
|
|
96 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
|
97 |
OGRStoreProvider.NAME, OGRStoreProvider.DESCRIPTION, |
|
98 |
OGRFilesystemServerProvider.class); |
|
99 |
|
|
100 |
DynObjectManager dynMan = ToolsLocator.getDynObjectManager(); |
|
101 |
DynClass dynClass = dynMan.get( |
|
102 |
OGRStoreProvider.METADATA_DEFINITION_NAME); |
|
103 |
DynField field; |
|
104 |
if (dynClass == null) { |
|
105 |
dynClass = dynMan.add( |
|
106 |
OGRStoreProvider.METADATA_DEFINITION_NAME); |
|
107 |
|
|
108 |
} |
|
109 |
|
|
110 |
if (exs.size() > 0) { |
|
111 |
throw new LibraryException(this.getClass(), exs); |
|
112 |
} |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
|
|
117 |
|
|
0 | 118 |
tags/org.gvsig.gdal-1.0.159/org.gvsig.gdal.gpx/src/main/java/org/gvsig/fmap/dal/store/gpx/OGRFilesystemServerProvider.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.gpx; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
import org.gvsig.fmap.dal.DALLocator; |
|
6 |
import org.gvsig.fmap.dal.DataManager; |
|
7 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
8 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
9 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
10 |
import org.gvsig.fmap.dal.exception.CreateException; |
|
11 |
import org.gvsig.fmap.dal.exception.DataException; |
|
12 |
import org.gvsig.fmap.dal.exception.FileNotFoundException; |
|
13 |
import org.gvsig.fmap.dal.exception.RemoveException; |
|
14 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
15 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
|
16 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
|
17 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider; |
|
18 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider; |
|
19 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices; |
|
20 |
|
|
21 |
public class OGRFilesystemServerProvider extends AbstractFilesystemServerExplorerProvider |
|
22 |
implements FilesystemServerExplorerProvider, ResourceConsumer { |
|
23 |
|
|
24 |
//private FilesystemServerExplorerProviderServices serverExplorer; |
|
25 |
|
|
26 |
public String getDataStoreProviderName() { |
|
27 |
return OGRStoreProvider.NAME; |
|
28 |
} |
|
29 |
|
|
30 |
public int getMode() { |
|
31 |
return DataServerExplorer.MODE_FEATURE | DataServerExplorer.MODE_GEOMETRY; |
|
32 |
} |
|
33 |
|
|
34 |
public boolean accept(File pathname) { |
|
35 |
return (pathname.getName().toLowerCase().endsWith(".gpx")); |
|
36 |
//return true; |
|
37 |
} |
|
38 |
|
|
39 |
public String getDescription() { |
|
40 |
return OGRStoreProvider.DESCRIPTION; |
|
41 |
} |
|
42 |
|
|
43 |
public DataStoreParameters getParameters(File file) throws DataException { |
|
44 |
DataManager manager = DALLocator.getDataManager(); |
|
45 |
OGRStoreParameters params = (OGRStoreParameters) manager |
|
46 |
.createStoreParameters(this |
|
47 |
.getDataStoreProviderName()); |
|
48 |
params.setFileName(file.getPath()); |
|
49 |
return params; |
|
50 |
} |
|
51 |
|
|
52 |
public boolean canCreate() { |
|
53 |
return true; |
|
54 |
} |
|
55 |
|
|
56 |
public boolean canCreate(NewDataStoreParameters parameters) { |
|
57 |
if (!(parameters instanceof OGRStoreParameters)) { |
|
58 |
throw new IllegalArgumentException(); // FIXME ??? |
|
59 |
} |
|
60 |
OGRStoreParameters driverParams = (OGRStoreParameters) parameters; |
|
61 |
// TODO comporbar si el ftype es correcto (para este formato es fijo) |
|
62 |
File file = new File(driverParams.getFileName()); |
|
63 |
|
|
64 |
if (driverParams.getCRS() == null) { |
|
65 |
return false; |
|
66 |
} |
|
67 |
// TODO comprobamos extension del fichero ?? |
|
68 |
if (file.exists()) { |
|
69 |
return file.canWrite(); |
|
70 |
} else { |
|
71 |
return file.getParentFile().canWrite(); |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
public void create(NewDataStoreParameters parameters, boolean overwrite) |
|
76 |
throws CreateException { |
|
77 |
// FIXME Exception |
|
78 |
throw new UnsupportedOperationException(); |
|
79 |
} |
|
80 |
|
|
81 |
public NewDataStoreParameters getCreateParameters() throws DataException { |
|
82 |
return (NewFeatureStoreParameters) DALLocator.getDataManager() |
|
83 |
.createStoreParameters(this.getDataStoreProviderName()); |
|
84 |
} |
|
85 |
|
|
86 |
public void initialize( |
|
87 |
FilesystemServerExplorerProviderServices serverExplorer) { |
|
88 |
//this.serverExplorer = serverExplorer; |
|
89 |
} |
|
90 |
|
|
91 |
public void remove(DataStoreParameters parameters) throws RemoveException { |
|
92 |
File file = new File(((OGRStoreParameters) parameters).getFileName()); |
|
93 |
if (!file.exists()) { |
|
94 |
throw new RemoveException(this.getDataStoreProviderName(), |
|
95 |
new FileNotFoundException(file)); |
|
96 |
} |
|
97 |
if (!file.delete()) { |
|
98 |
// FIXME throws ??? |
|
99 |
} |
|
100 |
|
|
101 |
} |
|
102 |
|
|
103 |
public boolean closeResourceRequested(ResourceProvider resource) { |
|
104 |
// while it is using a resource anyone can't close it |
|
105 |
return false; |
|
106 |
} |
|
107 |
|
|
108 |
/* |
|
109 |
* (non-Javadoc) |
|
110 |
* |
|
111 |
* @see |
|
112 |
* org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org. |
|
113 |
* gvsig.fmap.dal.resource.spi.ResourceProvider) |
|
114 |
*/ |
|
115 |
public void resourceChanged(ResourceProvider resource) { |
|
116 |
//Do nothing |
|
117 |
|
|
118 |
} |
|
119 |
|
|
120 |
|
|
121 |
} |
|
0 | 122 |
tags/org.gvsig.gdal-1.0.159/org.gvsig.gdal.gpx/src/main/java/org/gvsig/fmap/dal/store/gpx/OGRStoreProvider.java | ||
---|---|---|
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.gpx; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
import java.io.IOException; |
|
28 |
import java.util.ArrayList; |
|
29 |
import java.util.HashMap; |
|
30 |
import java.util.List; |
|
31 |
|
|
32 |
import org.apache.commons.io.FilenameUtils; |
|
33 |
import org.apache.commons.lang3.StringUtils; |
|
34 |
import org.gdal.gdal.gdal; |
|
35 |
import org.gdal.ogr.DataSource; |
|
36 |
import org.gdal.ogr.Driver; |
|
37 |
import org.gdal.ogr.FeatureDefn; |
|
38 |
import org.gdal.ogr.Layer; |
|
39 |
import org.gdal.ogr.ogr; |
|
40 |
import org.gvsig.fmap.dal.DALLocator; |
|
41 |
import org.gvsig.fmap.dal.DataManager; |
|
42 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
43 |
import org.gvsig.fmap.dal.DataStoreNotification; |
|
44 |
import org.gvsig.fmap.dal.DataTypes; |
|
45 |
import org.gvsig.fmap.dal.FileHelper; |
|
46 |
import org.gvsig.fmap.dal.exception.DataException; |
|
47 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
48 |
import org.gvsig.fmap.dal.exception.OpenException; |
|
49 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
50 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
51 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
52 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
53 |
import org.gvsig.fmap.dal.feature.Feature; |
|
54 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
55 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
56 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
57 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
58 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
|
59 |
import org.gvsig.fmap.dal.feature.spi.memory.AbstractMemoryStoreProvider; |
|
60 |
import org.gvsig.fmap.dal.resource.file.FileResource; |
|
61 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
|
62 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
|
63 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
|
64 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
|
65 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
66 |
import org.gvsig.fmap.geom.Geometry; |
|
67 |
import org.gvsig.fmap.geom.GeometryException; |
|
68 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
69 |
import org.gvsig.fmap.geom.GeometryManager; |
|
70 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
71 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
72 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
73 |
import org.gvsig.tools.ToolsLocator; |
|
74 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
75 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
76 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
|
77 |
import org.gvsig.tools.exception.BaseException; |
|
78 |
import org.gvsig.tools.exception.NotYetImplemented; |
|
79 |
import org.gvsig.tools.locator.LocatorException; |
|
80 |
import org.gvsig.tools.persistence.PersistentState; |
|
81 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
82 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
83 |
import org.gvsig.tools.task.TaskStatusManager; |
|
84 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
85 |
import org.gvsig.tools.visitor.Visitor; |
|
86 |
import org.slf4j.Logger; |
|
87 |
import org.slf4j.LoggerFactory; |
|
88 |
|
|
89 |
|
|
90 |
public class OGRStoreProvider extends AbstractMemoryStoreProvider implements |
|
91 |
ResourceConsumer { |
|
92 |
private static final Logger logger = LoggerFactory.getLogger(OGRStoreProvider.class); |
|
93 |
|
|
94 |
public static final String NAME = "OGR_DRIVER"; |
|
95 |
public static final String DESCRIPTION = "GPX file"; |
|
96 |
|
|
97 |
public static final String METADATA_DEFINITION_NAME = NAME; |
|
98 |
|
|
99 |
private ResourceProvider resource; |
|
100 |
|
|
101 |
private long counterNewsOIDs = 0; |
|
102 |
private Envelope envelope; |
|
103 |
private boolean need_calculate_envelope = false; |
|
104 |
private SimpleTaskStatus taskStatus; |
|
105 |
|
|
106 |
|
|
107 |
public OGRStoreProvider(OGRStoreParameters parameters, |
|
108 |
DataStoreProviderServices storeServices) throws InitializeException { |
|
109 |
super( |
|
110 |
parameters, |
|
111 |
storeServices, |
|
112 |
FileHelper.newMetadataContainer(METADATA_DEFINITION_NAME) |
|
113 |
); |
|
114 |
|
|
115 |
gdal.AllRegister(); |
|
116 |
ogr.RegisterAll(); |
|
117 |
|
|
118 |
TaskStatusManager manager = ToolsLocator.getTaskStatusManager(); |
|
119 |
this.taskStatus = manager.createDefaultSimpleTaskStatus("Driver"); |
|
120 |
|
|
121 |
counterNewsOIDs = 0; |
|
122 |
|
|
123 |
File file = getDriverParameters().getFile(); |
|
124 |
resource = this.createResource( |
|
125 |
FileResource.NAME, |
|
126 |
new Object[] { file.getAbsolutePath() } |
|
127 |
); |
|
128 |
|
|
129 |
resource.addConsumer(this); |
|
130 |
initializeFeatureTypes(); |
|
131 |
} |
|
132 |
|
|
133 |
private OGRStoreParameters getDriverParameters() { |
|
134 |
return (OGRStoreParameters) this.getParameters(); |
|
135 |
} |
|
136 |
|
|
137 |
public String getProviderName() { |
|
138 |
return NAME; |
|
139 |
} |
|
140 |
|
|
141 |
public boolean allowWrite() { |
|
142 |
return false; |
|
143 |
} |
|
144 |
|
|
145 |
private String getFullFileName() { |
|
146 |
// Usar solo para mostrar mensajes en el logger. |
|
147 |
String s = "(unknow)"; |
|
148 |
try { |
|
149 |
s = getDriverParameters().getFile().getAbsolutePath(); |
|
150 |
} catch(Exception e2) { |
|
151 |
s = "(unknow)"; |
|
152 |
} |
|
153 |
return s; |
|
154 |
} |
|
155 |
|
|
156 |
public void open() throws OpenException { |
|
157 |
if (this.data != null) { |
|
158 |
return; |
|
159 |
} |
|
160 |
this.data = new ArrayList<FeatureProvider>(); |
|
161 |
resource.setData(new HashMap()); |
|
162 |
counterNewsOIDs = 0; |
|
163 |
try { |
|
164 |
loadFeatures(); |
|
165 |
} catch (RuntimeException e) { |
|
166 |
logger.warn("Can't load features from Driver '"+getFullFileName()+"'.", e); |
|
167 |
throw e; |
|
168 |
} catch (Exception e) { |
|
169 |
logger.warn("Can't load features from Driver '"+getFullFileName()+"'.", e); |
|
170 |
throw new RuntimeException(e); |
|
171 |
} |
|
172 |
} |
|
173 |
|
|
174 |
public DataServerExplorer getExplorer() throws ReadException { |
|
175 |
DataManager manager = DALLocator.getDataManager(); |
|
176 |
FilesystemServerExplorerParameters params; |
|
177 |
try { |
|
178 |
params = (FilesystemServerExplorerParameters) manager |
|
179 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
|
180 |
params.setRoot(this.getDriverParameters().getFile().getParent()); |
|
181 |
return manager.openServerExplorer(FilesystemServerExplorer.NAME,params); |
|
182 |
} catch (DataException e) { |
|
183 |
throw new ReadException(this.getProviderName(), e); |
|
184 |
} catch (ValidateDataParametersException e) { |
|
185 |
throw new ReadException(this.getProviderName(), e); |
|
186 |
} |
|
187 |
|
|
188 |
} |
|
189 |
|
|
190 |
public boolean closeResourceRequested(ResourceProvider resource) { |
|
191 |
return true; |
|
192 |
} |
|
193 |
|
|
194 |
public int getOIDType() { |
|
195 |
return DataTypes.LONG; |
|
196 |
} |
|
197 |
|
|
198 |
public boolean supportsAppendMode() { |
|
199 |
return false; |
|
200 |
} |
|
201 |
|
|
202 |
public void append(FeatureProvider featureProvider) { |
|
203 |
throw new UnsupportedOperationException(); |
|
204 |
} |
|
205 |
|
|
206 |
public void beginAppend() { |
|
207 |
throw new UnsupportedOperationException(); |
|
208 |
} |
|
209 |
|
|
210 |
public void endAppend() { |
|
211 |
throw new UnsupportedOperationException(); |
|
212 |
} |
|
213 |
|
|
214 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
215 |
throw new NotYetImplemented(); |
|
216 |
} |
|
217 |
|
|
218 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
219 |
throw new NotYetImplemented(); |
|
220 |
} |
|
221 |
|
|
222 |
public Object createNewOID() { |
|
223 |
return new Long(counterNewsOIDs++); |
|
224 |
} |
|
225 |
|
|
226 |
protected void initializeFeatureTypes() throws InitializeException { |
|
227 |
try { |
|
228 |
this.open(); |
|
229 |
} catch (OpenException e) { |
|
230 |
throw new InitializeException(this.getProviderName(), e); |
|
231 |
} |
|
232 |
} |
|
233 |
|
|
234 |
public Envelope getEnvelope() throws DataException { |
|
235 |
this.open(); |
|
236 |
if( this.envelope!= null ) { |
|
237 |
return this.envelope; |
|
238 |
} |
|
239 |
if( !this.need_calculate_envelope ) { |
|
240 |
return null; |
|
241 |
} |
|
242 |
FeatureStore fs = this.getFeatureStore(); |
|
243 |
FeatureType ft = fs.getDefaultFeatureType(); |
|
244 |
FeatureAttributeDescriptor fad = ft.getAttributeDescriptor(ft.getDefaultGeometryAttributeIndex()); |
|
245 |
|
|
246 |
try { |
|
247 |
this.envelope = GeometryLocator.getGeometryManager().createEnvelope(fad.getGeomType().getSubType()); |
|
248 |
fs.accept(new Visitor() { |
|
249 |
public void visit(Object obj) throws VisitCanceledException, BaseException { |
|
250 |
Feature f = (Feature) obj; |
|
251 |
Geometry geom = f.getDefaultGeometry(); |
|
252 |
envelope.add(geom.getEnvelope()); |
|
253 |
} |
|
254 |
}); |
|
255 |
} catch (BaseException e) { |
|
256 |
logger.warn("Can't calculate the envelope of GPX file '"+this.getFullName()+"'.",e); |
|
257 |
this.envelope = null; |
|
258 |
} |
|
259 |
|
|
260 |
this.need_calculate_envelope = false; |
|
261 |
return this.envelope; |
|
262 |
} |
|
263 |
|
|
264 |
public Object getDynValue(String name) throws DynFieldNotFoundException { |
|
265 |
// if( DataStore.METADATA_ENVELOPE.equalsIgnoreCase(name) ) { |
|
266 |
// try { |
|
267 |
// return this.getEnvelope(); |
|
268 |
// } catch (DataException e) { |
|
269 |
// return null; |
|
270 |
// } |
|
271 |
// } else { |
|
272 |
// if( DataStore.METADATA_CRS.equalsIgnoreCase(name) ) { |
|
273 |
// IProjection pro = DriverStoreParameters.getCRS(this.getDriverParameters()); |
|
274 |
// if (pro != null){ |
|
275 |
// return pro; |
|
276 |
// } |
|
277 |
// } |
|
278 |
// } |
|
279 |
return super.getDynValue(name); |
|
280 |
} |
|
281 |
|
|
282 |
|
|
283 |
public void resourceChanged(ResourceProvider resource) { |
|
284 |
this.getStoreServices().notifyChange( |
|
285 |
DataStoreNotification.RESOURCE_CHANGED, |
|
286 |
resource); |
|
287 |
} |
|
288 |
|
|
289 |
|
|
290 |
public Object getSourceId() { |
|
291 |
return this.getDriverParameters().getFile(); |
|
292 |
} |
|
293 |
|
|
294 |
public String getName() { |
|
295 |
String name = this.getDriverParameters().getFile().getName(); |
|
296 |
return FilenameUtils.getBaseName(name); |
|
297 |
} |
|
298 |
|
|
299 |
public String getFullName() { |
|
300 |
return this.getDriverParameters().getFile().getAbsolutePath(); |
|
301 |
} |
|
302 |
|
|
303 |
public ResourceProvider getResource() { |
|
304 |
return resource; |
|
305 |
} |
|
306 |
|
|
307 |
|
|
308 |
private void loadFeatures() throws IOException, DataException, |
|
309 |
CoercionException, CloneNotSupportedException { |
|
310 |
|
|
311 |
boolean bReadOnly = false; |
|
312 |
boolean bVerbose = false; |
|
313 |
File file = this.getDriverParameters().getFile(); |
|
314 |
String pszDataSource = file.getAbsolutePath(); |
|
315 |
|
|
316 |
DataSource poDS = ogr.Open(pszDataSource, !bReadOnly); |
|
317 |
if (poDS == null && !bReadOnly){ |
|
318 |
poDS = ogr.Open(pszDataSource, false); |
|
319 |
if (poDS == null && bVerbose){ |
|
320 |
logger.warn( "Had to open data source read-only."); |
|
321 |
} |
|
322 |
} |
|
323 |
|
|
324 |
if(poDS == null){ |
|
325 |
logger.warn(file +" -> Unable to open datasource " + |
|
326 |
"with the available drivers."); |
|
327 |
|
|
328 |
if(ogr.GetDriverCount() == 0){ |
|
329 |
logger.warn("ERROR: no drivers availables"); |
|
330 |
} |
|
331 |
|
|
332 |
} |
|
333 |
|
|
334 |
if(poDS != null){ |
|
335 |
Driver poDriver = poDS.GetDriver(); |
|
336 |
logger.warn(file + " -> Opened using driver '" + poDriver.GetName() + "' successfully."); |
|
337 |
|
|
338 |
// Initialize the feature types |
|
339 |
FeatureStoreProviderServices store = this.getStoreServices(); |
|
340 |
|
|
341 |
for(int ij=0; ij<poDS.GetLayerCount(); ij++){ |
|
342 |
Layer layer = poDS.GetLayer(ij); |
|
343 |
FeatureDefn layerDef = layer.GetLayerDefn(); |
|
344 |
|
|
345 |
String[] headers = new String[layerDef.GetFieldCount()]; |
|
346 |
int[] types = new int[layerDef.GetFieldCount()]; |
|
347 |
for(int ji=0; ji<layerDef.GetFieldCount(); ji++){ |
|
348 |
headers[ji] = layerDef.GetFieldDefn(ji).GetName(); |
|
349 |
types[ji] = layerDef.GetFieldDefn(ji).GetFieldType(); |
|
350 |
} |
|
351 |
|
|
352 |
EditableFeatureType edftype = this.getFeatureType(headers, types); |
|
353 |
String geomColumn = layer.GetGeometryColumn(); |
|
354 |
if(!StringUtils.isBlank(geomColumn)){ |
|
355 |
edftype.setDefaultGeometryAttributeName(layer.GetGeometryColumn()); |
|
356 |
}else{ |
|
357 |
edftype.setDefaultGeometryAttributeName("GEOM"); |
|
358 |
} |
|
359 |
|
|
360 |
FeatureType ftype = edftype.getNotEditableCopy(); |
|
361 |
List<FeatureType> ftypes = new ArrayList<FeatureType>(); |
|
362 |
ftypes.add(ftype); |
|
363 |
store.setFeatureTypes(ftypes, ftype); |
|
364 |
|
|
365 |
if ( ftype.getDefaultGeometryAttributeName() != null ) { |
|
366 |
this.need_calculate_envelope = true; |
|
367 |
} |
|
368 |
|
|
369 |
taskStatus.message("_loading"); |
|
370 |
int count = 0; |
|
371 |
int count_errors = 0; |
|
372 |
boolean ignore_errors = false; |
|
373 |
|
|
374 |
if(layer.GetFeatureCount()>0){ |
|
375 |
org.gdal.ogr.Feature row = layer.GetNextFeature(); |
|
376 |
while ( row != null ) { |
|
377 |
taskStatus.setCurValue(++count); |
|
378 |
FeatureProvider feature = this.createFeatureProvider(ftype); |
|
379 |
for ( int i = 0; i < row.GetFieldCount(); i++ ) { |
|
380 |
try { |
|
381 |
feature.set(i, this.getFieldValue(row, i)); |
|
382 |
} catch (RuntimeException ex) { |
|
383 |
if ( !ignore_errors ) { |
|
384 |
throw ex; |
|
385 |
} |
|
386 |
if ( count_errors++ < 10 ) { |
|
387 |
logger.warn("Can't load value of attribute " + i + " in row " + count + ".", ex); |
|
388 |
} |
|
389 |
if ( count_errors == 10 ) { |
|
390 |
logger.info("Too many errors, suppress messages."); |
|
391 |
} |
|
392 |
} |
|
393 |
} |
|
394 |
org.gdal.ogr.Geometry geom = row.GetGeometryRef(); |
|
395 |
if(geom != null){ |
|
396 |
Geometry geometry; |
|
397 |
try { |
|
398 |
geometry = GeometryLocator.getGeometryManager().createFrom(geom.ExportToWkt()); |
|
399 |
feature.setDefaultGeometry(geometry); |
|
400 |
} catch (CreateGeometryException e) { |
|
401 |
// TODO Auto-generated catch block |
|
402 |
e.printStackTrace(); |
|
403 |
} catch (LocatorException e) { |
|
404 |
// TODO Auto-generated catch block |
|
405 |
e.printStackTrace(); |
|
406 |
} catch (GeometryException e) { |
|
407 |
// TODO Auto-generated catch block |
|
408 |
e.printStackTrace(); |
|
409 |
} |
|
410 |
|
|
411 |
} |
|
412 |
this.addFeatureProvider(feature); |
|
413 |
row = layer.GetNextFeature(); |
|
414 |
} |
|
415 |
} |
|
416 |
|
|
417 |
taskStatus.terminate(); |
|
418 |
} |
|
419 |
} |
|
420 |
} |
|
421 |
|
|
422 |
|
|
423 |
private Object getFieldValue(org.gdal.ogr.Feature row, int i) { |
|
424 |
int gdalType = row.GetDefnRef().GetFieldDefn(i).GetFieldType(); |
|
425 |
switch(this.getFieldType(gdalType)){ |
|
426 |
case DataTypes.STRING: |
|
427 |
return row.GetFieldAsString(i); |
|
428 |
case DataTypes.INT: |
|
429 |
return row.GetFieldAsInteger(i); |
|
430 |
default: |
|
431 |
return row.GetFieldAsString(i); |
|
432 |
} |
|
433 |
} |
|
434 |
|
|
435 |
private EditableFeatureType getFeatureType(String headers[], int automaticTypes[]) { |
|
436 |
EditableFeatureType fType = getStoreServices().createFeatureType(this.getName()); |
|
437 |
fType.setHasOID(true); |
|
438 |
DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager(); |
|
439 |
|
|
440 |
FieldTypeParser[] fieldTypes = new FieldTypeParser[headers.length]; |
|
441 |
// |
|
442 |
// Calculamos cuales pueden ser los tipos de datos |
|
443 |
// |
|
444 |
for ( int i = 0; i < fieldTypes.length; i++ ) { |
|
445 |
fieldTypes[i] = new FieldTypeParser(headers[i], this.getFieldType(automaticTypes[i])); |
|
446 |
} |
|
447 |
|
|
448 |
// |
|
449 |
// Una vez ya sabemos los tipos de datos rellenamos el feature-type |
|
450 |
// |
|
451 |
for ( int i = 0; i < fieldTypes.length; i++ ) { |
|
452 |
EditableFeatureAttributeDescriptor fad = fType.add( |
|
453 |
fieldTypes[i].name, |
|
454 |
fieldTypes[i].type |
|
455 |
); |
|
456 |
fad.setSize(fieldTypes[i].size); |
|
457 |
fad.setAllowNull(fieldTypes[i].allowNulls); |
|
458 |
if ( fieldTypes[i].type == DataTypes.GEOMETRY |
|
459 |
&& fType.getDefaultGeometryAttributeName() == null ) { |
|
460 |
fType.setDefaultGeometryAttributeName(fieldTypes[i].name); |
|
461 |
} |
|
462 |
} |
|
463 |
EditableFeatureAttributeDescriptor attr = fType.add("GEOM", DataTypes.GEOMETRY); |
|
464 |
GeometryManager geommgr = GeometryLocator.getGeometryManager(); |
|
465 |
GeometryType gt; |
|
466 |
try { |
|
467 |
gt = geommgr.getGeometryType(Geometry.TYPES.GEOMETRY, Geometry.SUBTYPES.GEOM3D); |
|
468 |
|
|
469 |
attr.setGeometryType(gt); |
|
470 |
} catch (Exception e) { |
|
471 |
logger.warn("Can't set geometry type for the calculated field in GPX file '" + getFullFileName() + "'.", e); |
|
472 |
} |
|
473 |
return fType; |
|
474 |
} |
|
475 |
|
|
476 |
|
|
477 |
private int getFieldType(int gdalType) { |
|
478 |
switch(gdalType){ |
|
479 |
case 2: |
|
480 |
return DataTypes.FLOAT; |
|
481 |
case 11: |
|
482 |
return DataTypes.DATE; |
|
483 |
case 4: |
|
484 |
return DataTypes.STRING; |
|
485 |
default: |
|
486 |
return DataTypes.STRING; |
|
487 |
} |
|
488 |
} |
|
489 |
|
|
490 |
public String getDriver(int index){ |
|
491 |
return ogr.GetDriver(index).getName(); |
|
492 |
} |
|
493 |
|
|
494 |
public int getDriverCount(){ |
|
495 |
return ogr.GetDriverCount(); |
|
496 |
} |
|
497 |
|
|
498 |
public List<String> getAvailableDrivers(){ |
|
499 |
List<String> aux = new ArrayList<String>(); |
|
500 |
for(int iDriver = 0; iDriver < ogr.GetDriverCount(); iDriver++ ){ |
|
501 |
aux.add( ogr.GetDriver(iDriver).GetName() ); |
|
502 |
} |
|
503 |
return aux; |
|
504 |
} |
|
505 |
|
|
506 |
public String getOGRVersion(){ |
|
507 |
return gdal.VersionInfo(); |
|
508 |
} |
|
509 |
|
|
510 |
|
|
511 |
|
|
512 |
private class FieldTypeParser { |
|
513 |
|
|
514 |
public String name = null; |
|
515 |
public int type = DataTypes.STRING; |
|
516 |
public int size = 0; |
|
517 |
public boolean allowNulls = true; |
|
518 |
|
|
519 |
private String typename = "string"; |
|
520 |
|
|
521 |
FieldTypeParser(String name, int type) { |
|
522 |
this.name = name; |
|
523 |
this.type = type; |
|
524 |
} |
|
525 |
|
|
526 |
private int getType(String value) { |
|
527 |
DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager(); |
|
528 |
return dataTypesManager.getType(typename); |
|
529 |
} |
|
530 |
|
|
531 |
// El formato seria: |
|
532 |
// name[:typename[:size[:notnull|null]]] |
|
533 |
// name[__typename[__size[__notnull|null]]] |
|
534 |
// |
|
535 |
public boolean parse(String value) { |
|
536 |
String typename = null; |
|
537 |
String[] ss = null; |
|
538 |
if ( value.contains(":") ) { |
|
539 |
ss = value.split(":"); |
|
540 |
} else if ( value.contains("__") ) { |
|
541 |
ss = value.split("__"); |
|
542 |
} |
|
543 |
if ( ss == null ) { |
|
544 |
this.name = value; |
|
545 |
return true; |
|
546 |
} |
|
547 |
switch (ss.length) { |
|
548 |
case 4: |
|
549 |
if ( ss[3].length() > 0 ) { |
|
550 |
if ( "notnull".equalsIgnoreCase(ss[3]) ) { |
|
551 |
this.allowNulls = false; |
|
552 |
} else { |
|
553 |
this.allowNulls = true; |
|
554 |
} |
|
555 |
} |
|
556 |
case 3: |
|
557 |
if ( ss[2].length() > 0 ) { |
|
558 |
try { |
|
559 |
this.size = Integer.parseInt(ss[2]); |
|
560 |
} catch (Exception ex) { |
|
561 |
logger.warn("Ignore incorrect field size for field " + value + " in JExcel header of '" + getFullFileName() + "'.", ex); |
|
562 |
} |
|
563 |
} |
|
564 |
case 2: |
|
565 |
if ( ss[1].length() > 0 ) { |
|
566 |
this.typename = ss[1]; |
|
567 |
this.type = this.getType(this.typename); |
|
568 |
if ( this.type == DataTypes.INVALID ) { |
|
569 |
this.type = DataTypes.STRING; |
|
570 |
logger.info("Type '" + typename + "' not valid for attribute '" + value + "' in JExcel file '" + getFullFileName() + "'."); |
|
571 |
} |
|
572 |
} |
|
573 |
case 1: |
|
574 |
this.name = ss[0]; |
|
575 |
break; |
|
576 |
} |
|
577 |
|
|
578 |
if ( this.type != DataTypes.STRING ) { |
|
579 |
this.size = 0; |
|
580 |
} |
|
581 |
return true; |
|
582 |
} |
|
583 |
|
|
584 |
} |
|
585 |
|
|
586 |
} |
|
0 | 587 |
tags/org.gvsig.gdal-1.0.159/org.gvsig.gdal.app/org.gvsig.gdal.app.ogr.mainplugin/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.gdal.app</artifactId> |
|
6 |
<version>1.0.159</version> |
|
7 |
</parent> |
|
8 |
<artifactId>org.gvsig.gdal.app.ogr.mainplugin</artifactId> |
|
9 |
|
|
10 |
<properties> |
|
11 |
<gvsig.package.info.code>org.gvsig.gdal.app.ogr.mainplugin</gvsig.package.info.code> |
|
12 |
<gvsig.install.plugin>true</gvsig.install.plugin> |
|
13 |
<gvsig.package.info.name>Formats: OGR support</gvsig.package.info.name> |
|
14 |
<gvsig.package.info.categories>Formats,Vector</gvsig.package.info.categories> |
|
15 |
<gvsig.package.info.description>OGR formats: allows user to load files supported by OGR</gvsig.package.info.description> |
|
16 |
<gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.3.0-A-0</gvsig.package.info.dependencies> |
|
17 |
</properties> |
|
18 |
|
|
19 |
<dependencies> |
|
20 |
<dependency> |
|
21 |
<groupId>org.gvsig</groupId> |
|
22 |
<artifactId>org.gvsig.app.mainplugin</artifactId> |
|
23 |
</dependency> |
|
24 |
<dependency> |
|
25 |
<groupId>org.gvsig</groupId> |
|
26 |
<artifactId>org.gvsig.gdal.prov.ogr</artifactId> |
|
27 |
</dependency> |
|
28 |
</dependencies> |
|
29 |
|
|
30 |
</project> |
tags/org.gvsig.gdal-1.0.159/org.gvsig.gdal.app/org.gvsig.gdal.app.ogr.mainplugin/buildNumber.properties | ||
---|---|---|
1 |
#Sun Jan 16 23:26:39 CET 2022 |
|
2 |
buildNumber=144 |
tags/org.gvsig.gdal-1.0.159/org.gvsig.gdal.app/org.gvsig.gdal.app.ogr.mainplugin/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<!-- gvSIG. Desktop Geographic Information System. Copyright (C) 2007-2016 |
|
2 |
gvSIG Association. This program is free software; you can redistribute it |
|
3 |
and/or modify it under the terms of the GNU General Public License as published |
|
4 |
by the Free Software Foundation; either version 3 of the License, or (at |
|
5 |
your option) any later version. This program is distributed in the hope that |
|
6 |
it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
|
7 |
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
8 |
Public License for more details. You should have received a copy of the GNU |
|
9 |
General Public License along with this program; if not, write to the Free |
|
10 |
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
|
11 |
USA. For any additional information, do not hesitate to contact us at info |
|
12 |
AT gvsig.com, or visit our website www.gvsig.com. --> |
|
13 |
<assembly> |
|
14 |
<id>gvsig-plugin-package</id> |
|
15 |
<formats> |
|
16 |
<format>zip</format> |
|
17 |
</formats> |
|
18 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
19 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
20 |
<files> |
|
21 |
<file> |
|
22 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
23 |
<outputDirectory>lib</outputDirectory> |
|
24 |
</file> |
|
25 |
<file> |
|
26 |
<source>target/package.info</source> |
|
27 |
</file> |
|
28 |
</files> |
|
29 |
|
|
30 |
<fileSets> |
|
31 |
<fileSet> |
|
32 |
<directory>src/main/resources-plugin</directory> |
|
33 |
<outputDirectory>.</outputDirectory> |
|
34 |
</fileSet> |
|
35 |
</fileSets> |
|
36 |
|
|
37 |
|
|
38 |
<dependencySets> |
|
39 |
<dependencySet> |
|
40 |
<useProjectArtifact>false</useProjectArtifact> |
|
41 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
42 |
<outputDirectory>lib</outputDirectory> |
|
43 |
<includes> |
|
44 |
<include>org.gvsig:org.gvsig.gdal.prov.ogr</include> |
|
45 |
</includes> |
|
46 |
</dependencySet> |
|
47 |
</dependencySets> |
|
48 |
|
|
49 |
</assembly> |
|
50 |
|
|
51 |
|
tags/org.gvsig.gdal-1.0.159/org.gvsig.gdal.app/org.gvsig.gdal.app.ogr.mainplugin/src/main/java/org/gvsig/gdal/app/ogr/mainplugin/OGRExtension.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.app.ogr.mainplugin; |
|
25 |
|
|
26 |
import org.gvsig.andami.IconThemeHelper; |
|
27 |
import org.gvsig.andami.plugins.Extension; |
|
28 |
import org.gvsig.app.extension.AddLayer; |
|
29 |
import org.gvsig.gdal.app.ogr.mainplugin.gui.OGRWizarPanel; |
|
30 |
|
|
31 |
/** |
|
32 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
|
33 |
* |
|
34 |
*/ |
|
35 |
public class OGRExtension extends Extension { |
|
36 |
|
|
37 |
@Override |
|
38 |
public void execute(String arg0) { |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public void initialize() { |
|
43 |
AddLayer.addWizard(OGRWizarPanel.class); |
|
44 |
|
|
45 |
IconThemeHelper.registerIcon("ogrprovider", "ogr-dataexplorer-settings", this); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public boolean isEnabled() { |
|
50 |
return false; |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
public boolean isVisible() { |
|
55 |
return false; |
|
56 |
} |
|
57 |
|
|
58 |
} |
tags/org.gvsig.gdal-1.0.159/org.gvsig.gdal.app/org.gvsig.gdal.app.ogr.mainplugin/src/main/java/org/gvsig/gdal/app/ogr/mainplugin/gui/JOGRDataExplorer.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.app.ogr.mainplugin.gui; |
|
25 |
|
|
26 |
import java.util.List; |
|
27 |
|
|
28 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
29 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
30 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
31 |
import org.gvsig.tools.swing.api.Component; |
|
32 |
|
|
33 |
/** |
|
34 |
* |
|
35 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
|
36 |
* |
|
37 |
*/ |
|
38 |
public interface JOGRDataExplorer extends Component { |
|
39 |
|
|
40 |
/** |
|
41 |
* |
|
42 |
* @return List with selected layer names |
Also available in: Unified diff