Revision 379

View differences:

org.gvsig.lidar/tags/org.gvsig.lidar-1.0.7/org.gvsig.lidar.prov/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.lidar</artifactId>
6
		<version>1.0.7</version>
7
	</parent>
8
	<artifactId>org.gvsig.lidar.prov</artifactId>
9
	<packaging>pom</packaging>
10
	<name>org.gvsig.lidar.prov</name>
11
	<modules>
12
		<module>org.gvsig.lidar.prov.common</module>
13
		<module>org.gvsig.lidar.prov.whitebox</module>
14
		<module>org.gvsig.lidar.prov.jgrass</module>
15
	</modules>
16
</project>
org.gvsig.lidar/tags/org.gvsig.lidar-1.0.7/org.gvsig.lidar.prov/org.gvsig.lidar.prov.common/src/main/java/org/gvsig/lidar/prov/LASDataStoreProviderFactory.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.lidar.prov;
25

  
26
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory;
27
import org.gvsig.tools.dynobject.DynObject;
28

  
29
/**
30
 * LAS Data Store Provider factory to create parameters to create
31
 * specific server data explorers and specific data store providers.
32
 * 
33
 * @author <a href="mailto:cmartinez@scolab.es">Cesar Martinez Izquierdo</a>
34
 *
35
 */
36
public interface LASDataStoreProviderFactory extends FeatureStoreProviderFactory {
37

  
38
    /**
39
     * Creates specific parameters if factory can open connection object. If it
40
     * can not open, it will be return null.
41
     * 
42
     * @param connectionObject
43
     *            File or connection string to be opened
44
     * @return Data explorer parameters If this factory can open connection
45
     *         object it will be return specific parameters, otherwise return
46
     *         null.
47
     */
48
    public DynObject createParameters(Object connectionObject);
49

  
50
    /**
51
     * Creates specific data explorer parameters if factory can open connection
52
     * object. If it
53
     * can not open, it will be return null.
54
     * 
55
     * @param connectionObject
56
     *            File or connection string to be opened
57
     * @return Data explorer parameters If this factory can open connection
58
     *         object it will be return specific data explrer parameters,
59
     *         otherwise return
60
     *         null.
61
     */
62
    public DynObject createDataExplorerParameters(Object connectionObject);
63

  
64
}
org.gvsig.lidar/tags/org.gvsig.lidar-1.0.7/org.gvsig.lidar.prov/org.gvsig.lidar.prov.common/src/main/java/org/gvsig/lidar/prov/LASDataStoreParameters.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.lidar.prov;
25

  
26
import java.io.File;
27
import java.io.IOException;
28

  
29
import org.apache.commons.io.FileUtils;
30
import org.apache.commons.io.FilenameUtils;
31
import org.cresques.cts.ICRSFactory;
32
import org.cresques.cts.IProjection;
33
import org.gvsig.fmap.crs.CRSFactory;
34
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
35
import org.gvsig.fmap.dal.feature.EditableFeatureType;
36
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
37
import org.gvsig.fmap.dal.feature.FeatureType;
38
import static org.gvsig.fmap.dal.feature.NewFeatureStoreParameters.FEATURETYPE_PARAMTER_NAME;
39
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
40
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
41
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
42
import org.gvsig.tools.ToolsLocator;
43
import org.gvsig.tools.dynobject.DelegatedDynObject;
44
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
45

  
46
/**
47
 * 
48
 * @author <a href="mailto:cmartinez@scolab.es">Cesar Martinez Izquierdo</a>
49
 *
50
 */
51
class LASDataStoreParameters extends AbstractDataParameters
52
		implements FilesystemStoreParameters {
53

  
54
    public static final String FILE_PARAMETER_NAME = "file";
55

  
56
    public static final String CRS_PARAMETER_NAME = "CRS";
57
    
58
    public static final String POINT_DENSITY_PARAMETER_NAME = "PointDensity";
59
    
60
    /**
61
     * Simple method to load a subset of the data, useful for faster
62
     * visualization. The decimation parameter will only keep the n'th
63
     * point from the file. For instance, a value of 2 will skip half
64
     * of the points. A value of 3 will load 1/3 of the original points.
65
     * A value of 10 will load 1/10 of the original points.
66
     */
67
    public static final String THINNING_DIV_PARAMETER_NAME = "thinningDivisor";
68
    
69
    /**
70
     * An alternative method to load a subset of the data. This parameter
71
     * defines how many points should be loaded by square map unit.
72
     * For instance, a value of 0.1 on a layer using EPSG:25830 means that
73
     * 0.1 points should be loaded per square meter (100.000 points per
74
     * square kilometer). The same value for a layer using EPSG:4326 means
75
     * that 0.1 points should be loaded per square degree.
76
     * 
77
     * Note that this is an approximated method which assumes that points are
78
     * evenly separated on x and y axis. When resolution is defined,
79
     * the decimation parameter is ignored.
80
     * 
81
     */
82
    public static final String THINNING_RESOLUTION_PARAMETER_NAME = "thinningResolution";
83
    
84

  
85
    protected DelegatedDynObject parameters;
86

  
87
    public static final String DATASET_CREATION_OPTION_PARAMETER_NAME = "datasetCreationOptions";
88
    
89
    public static final String PARAMETERS_DEFINITION_NAME = "LASDataStoreParameters";
90
    
91
	public LASDataStoreParameters() {
92
		this(PARAMETERS_DEFINITION_NAME, "to be defined");
93
	}
94

  
95
    public LASDataStoreParameters(String providerName) {
96
    	this(PARAMETERS_DEFINITION_NAME, providerName);
97
    }
98
    
99
    public LASDataStoreParameters(String parametersDefinitionName, String providerName) {
100
        this.parameters =
101
            (DelegatedDynObject) ToolsLocator.getDynObjectManager().createDynObject(
102
                ToolsLocator.getPersistenceManager().getDefinition(parametersDefinitionName));
103
        this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, providerName);
104
    }
105

  
106
    @Override
107
	public String getDataStoreName() {
108
		return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME);
109
	}
110

  
111
    @Override
112
	public String getDescription() {
113
		return this.getDynClass().getDescription();
114
	}
115

  
116

  
117

  
118
    /**
119
     * @return File
120
     */
121
    @Override
122
    public File getFile() {
123
        return (File) this.getDynValue(FILE_PARAMETER_NAME);
124
    }
125

  
126
    /**
127
     * 
128
     * @return String
129
     */
130
    public IProjection getCRS() {
131
        return (IProjection) this.getDynValue(CRS_PARAMETER_NAME);
132
    }
133

  
134
    /**
135
     * @param file
136
     *            File
137
     */
138
    @Override
139
    public void setFile(File file) {
140
        this.setDynValue(FILE_PARAMETER_NAME, file);
141
        if (getCRS()==null) {
142
        	// only set CRS automatically if it has not been previously set
143
        	loadProj();
144
        }
145
    }
146
    
147
    private void loadProj() {
148
    	String wktString = readProj();
149
        if (wktString != null) {
150
            IProjection proj = CRSFactory.getCRSFactory().get(ICRSFactory.FORMAT_WKT, wktString);
151
            setCRS(proj);
152
        }
153
    }
154
    
155
	private String readProj(){
156
        File prjFile = getPrj();
157
        if (prjFile.exists()) {
158
            try {
159
                return FileUtils.readFileToString(prjFile);
160
            } catch (IOException e) {
161
                return null;
162
            }
163
        }
164
        return null;
165
	}
166
    
167
	/**
168
	 * Gets the .prj path corresponding to the .las file. It will
169
	 * always return a path if getFile is not null, even if none
170
	 * of the files actually exists. 
171
	 *  
172
	 * @return
173
	 */
174
    public File getPrj() {
175
    	File lasFile = getFile(); 
176
    	if (lasFile!=null) {
177
    		String path = lasFile.getPath();
178
    		String baseName = FilenameUtils.getFullPath(path) + FilenameUtils.getBaseName(path);
179
    		return new File(baseName + ".prj");
180
    	}
181
    	return null;
182
    }
183

  
184
    /**
185
     * 
186
     * @param crs
187
     */
188
    public void setCRS(IProjection crs) {
189
        this.setDynValue(CRS_PARAMETER_NAME, crs);
190
    }
191

  
192
    public int getDecimation() {
193
    	try {
194
    		this.hasDynValue(THINNING_DIV_PARAMETER_NAME);
195
    		return (int) this.getDynValue(THINNING_DIV_PARAMETER_NAME);
196
    	}
197
    	catch (Exception ex) {}
198
    	return 0;
199
    }
200
    
201
    public double getResolution() {
202
    	try {
203
    		this.hasDynValue(THINNING_RESOLUTION_PARAMETER_NAME);
204
    		return (double) this.getDynValue(THINNING_RESOLUTION_PARAMETER_NAME);
205
    	}
206
    	catch (Exception ex) {}
207
    	return 0.0d;
208
    }
209
    
210
    public boolean isValid() {
211
        if (this.getFile() != null && this.getFile().exists()) {
212
            return true;
213
        }
214
        return false;
215
    }
216

  
217
    @Override
218
    protected DelegatedDynObject getDelegatedDynObject() {
219
        return parameters;
220
    }
221

  
222
    public void setDefaultFeatureType(FeatureType defaultFeatureType) {
223
        this.setDynValue(FEATURETYPE_PARAMTER_NAME, defaultFeatureType);
224
    }
225

  
226
    public EditableFeatureType getDefaultFeatureType() {
227
        return (EditableFeatureType) this.getDynValue(FEATURETYPE_PARAMTER_NAME);
228
    }
229
    
230
	@Override
231
	public void validate() throws ValidateDataParametersException {
232
		fixParameters();
233
		super.validate();
234
	}
235
    
236
    public void fixParameters() {
237
    	try {
238
    		EditableFeatureType featureType = getDefaultFeatureType();    
239
    		if (featureType != null) {
240
    			FeatureAttributeDescriptor geometryAttribute =
241
    					featureType.getAttributeDescriptor(featureType.getDefaultGeometryAttributeName());
242
    			if (geometryAttribute != null) {
243
    				//If the CRS parameter has not been fixed, but there is
244
    				//a geometric attribute with the CRS, this attribute
245
    				//can be used.
246
    				if (getCRS() == null) {
247
    					setCRS(geometryAttribute.getSRS());
248
    				}
249
    			}
250
    		}
251
    	}
252
    	catch (DynFieldNotFoundException ex) {
253
    		// we are not creating a new NewFeatureStoreParameters,
254
    		// we can safely ignore the error
255
    	}
256
    }
257

  
258
}
org.gvsig.lidar/tags/org.gvsig.lidar-1.0.7/org.gvsig.lidar.prov/org.gvsig.lidar.prov.common/src/main/java/org/gvsig/lidar/prov/LASNewStoreParameters.java
1

  
2
package org.gvsig.lidar.prov;
3

  
4
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
5

  
6

  
7
public class LASNewStoreParameters extends LASDataStoreParameters implements NewFeatureStoreParameters {
8

  
9
    public LASNewStoreParameters(String NAME) {
10
        super(NAME);
11
    }
12
    
13
}
org.gvsig.lidar/tags/org.gvsig.lidar-1.0.7/org.gvsig.lidar.prov/org.gvsig.lidar.prov.common/src/main/java/org/gvsig/lidar/prov/LASUnsupportedFormatException.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.lidar.prov;
25

  
26
import java.util.Map;
27

  
28
import org.gvsig.fmap.dal.exception.DataException;
29

  
30
/**
31
 * 
32
 * @author <a href="mailto:cmartinez@scolab.es">Cesar Martinez Izquierdo</a>
33
 *
34
 */
35
@SuppressWarnings("unchecked")
36
public class LASUnsupportedFormatException extends DataException {
37

  
38
    private static final long serialVersionUID = -2670314598211236837L;
39

  
40
    private final static String MESSAGE =
41
        "Unsupported vectorial format. There is no LAS 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 LASUnsupportedFormatException(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 LASUnsupportedFormatException(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 LASUnsupportedFormatException(String connectionString) {
82
        super(MESSAGE, KEY, serialVersionUID);
83
        this.values.put("connectionString", connectionString);
84
    }
85

  
86
}
org.gvsig.lidar/tags/org.gvsig.lidar-1.0.7/org.gvsig.lidar.prov/org.gvsig.lidar.prov.common/src/main/java/org/gvsig/lidar/prov/LASDataStoreProvider.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.lidar.prov;
25

  
26
import java.io.File;
27
import java.util.Iterator;
28

  
29
import org.apache.commons.io.FileUtils;
30
import org.gvsig.fmap.dal.DataStore;
31
import org.gvsig.fmap.dal.DataStoreParameters;
32
import org.gvsig.fmap.dal.DataTypes;
33
import org.gvsig.fmap.dal.exception.CloseException;
34
import org.gvsig.fmap.dal.exception.DataException;
35
import org.gvsig.fmap.dal.exception.InitializeException;
36
import org.gvsig.fmap.dal.exception.OpenException;
37
import org.gvsig.fmap.dal.exception.ReadRuntimeException;
38
import org.gvsig.fmap.dal.feature.FeatureQuery;
39
import org.gvsig.fmap.dal.feature.FeatureSet;
40
import org.gvsig.fmap.dal.feature.FeatureStore;
41
import org.gvsig.fmap.dal.feature.FeatureType;
42
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
43
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider;
44
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
45
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
46
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider;
47
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
48
import org.gvsig.fmap.dal.resource.ResourceAction;
49
import org.gvsig.fmap.dal.resource.exception.ResourceException;
50
import org.gvsig.fmap.dal.resource.exception.ResourceExecuteException;
51
import org.gvsig.fmap.dal.resource.file.FileResource;
52
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer;
53
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
54
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
55
import org.gvsig.fmap.geom.GeometryLocator;
56
import org.gvsig.fmap.geom.GeometryManager;
57
import org.gvsig.fmap.geom.primitive.Envelope;
58
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
59
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
60
import org.gvsig.tools.dispose.DisposableIterator;
61
import org.gvsig.tools.dynobject.DynObject;
62
import org.gvsig.tools.exception.BaseException;
63
import org.slf4j.Logger;
64
import org.slf4j.LoggerFactory;
65

  
66
/**
67
 * 
68
 * @author <a href="mailto:cmartinez@scolab.es">Cesar Martinez Izquierdo</a>
69
 *
70
 */
71
public abstract class LASDataStoreProvider extends AbstractFeatureStoreProvider implements
72
    FeatureStoreProvider, ResourceConsumer {
73

  
74
    private static final Logger LOG = LoggerFactory.getLogger(LASDataStoreProvider.class);
75
    
76
    public static final String GEOM_FIELD="GEOM";
77
    public static final String CLASS_FIELD="CLASSIFICATION";
78
    public static final String POINTX_FIELD="POINTX";
79
    public static final String POINTY_FIELD="POINTY";
80
    public static final String POINTZ_FIELD="POINTZ";
81
    public static final String TIME_FIELD="TIME";
82
    public static final String WEEKTIME_FIELD="WEEKTIME";
83
    public static final String COLOR_FIELD="COLOR";
84
    public static final String INTENSITY_FIELD="INTENSITY";
85
    public static final String RETURNNUM_FIELD="RETURNNUM";
86
    public static final String NUMRETURNS_FIELD="NUMRETURNS";
87

  
88
    protected File file;
89

  
90
    protected Envelope envelope = null;
91

  
92
    protected ResourceProvider resourceProvider;
93

  
94
    protected boolean opened = false;
95
    protected long counterNewsOIDs = -1;
96
    
97
    protected  GeometryManager gm;
98
    
99
    protected double decimation = 1.0d;
100
    protected double resolution = 0.0d;
101
 
102
    protected LASDataStoreProvider(DataStoreParameters dataParameters,
103
        DataStoreProviderServices storeServices, DynObject metadata) throws InitializeException {
104
        super(dataParameters, storeServices, metadata);
105

  
106
        // Set CRS parameter to metadata
107
        this.setDynValue(DataStore.METADATA_CRS, dataParameters.getDynValue(DataStore.METADATA_CRS));
108
        file = (File) dataParameters.getDynValue(LASDataStoreParameters.FILE_PARAMETER_NAME);
109
        
110
        if (dataParameters instanceof LASDataStoreParameters) {
111
        	LASDataStoreParameters lasParameters = (LASDataStoreParameters) dataParameters;
112
        	decimation = (double) lasParameters.getDecimation();
113
        	if (decimation<1) {
114
        		decimation = 1;
115
        	}
116
        	resolution = lasParameters.getResolution();
117
        }
118

  
119
        getResource().addConsumer(this);
120
        this.gm = GeometryLocator.getGeometryManager();
121
        try {
122
            this.open();
123
        } catch (OpenException e) {
124
            throw new InitializeException(getProviderName(), e);
125
        }
126
    }
127
    
128
    /*
129
    public FeatureProvider createFeatureProvider(FeatureType type) throws DataException {
130
        return new DBFFeatureProvider(this, type);
131
    }*/
132

  
133
    @Override
134
    public String getFullName() {
135
    	return getName();
136
    }
137

  
138
    @Override
139
    public String getName() {
140
        return getLASParameters().getFile().getName();
141
    }
142

  
143
    @Override
144
    public boolean allowWrite() {
145
    	return false;
146
    }
147

  
148
    @Override
149
    public ResourceProvider getResource() {
150
        if (this.resourceProvider == null) {
151
            try {
152
                this.resourceProvider =
153
                    this.createResource(FileResource.NAME, new Object[] { getLASParameters()
154
                        .getFile().getAbsolutePath() });
155
            } catch (InitializeException e) {
156
                throw new ReadRuntimeException(String.format(
157
                    "Can not create file resource with %1s path", getLASParameters().getFile()
158
                        .getAbsolutePath()), e);
159
            }
160
        }
161

  
162
        return resourceProvider;
163
    }
164

  
165
    @Override
166
    public Object getSourceId() {
167
        return this.getLASParameters().getFile();
168
    }
169

  
170
    @Override
171
    public void open() throws OpenException {
172
    	// FIXME: should this method be synchronized?
173
        if (opened == false) {
174
            try {
175
            	this.opened = loadFeatureType();
176
                updateDecimationFromResolution();
177
            } catch (BaseException e) {
178
                LOG.error("Can not load feature type", e);
179
                throw new OpenException(getFullName(), e);
180
            }
181
        }
182
    }
183
    
184
    protected void updateDecimationFromResolution() {
185
    	if (resolution>0.0d) {
186
    		try {
187
				double width = getEnvelope().getLength(0);
188
				double height = getEnvelope().getLength(1);
189
				long count = getFeatureCount();
190
				double origResolution = ((count/width)/height); // divide twice instead of multiply denominator to avoid overflow of the product
191
				double calculatedDecimation = origResolution/resolution;
192
				if (calculatedDecimation>1) {
193
					decimation = calculatedDecimation;
194
				}
195
				else {
196
					decimation = 1;
197
				}
198
			} catch (DataException e) {
199
				// TODO Auto-generated catch block
200
				e.printStackTrace();
201
			}
202
    		
203
    	}
204
    		
205
    }
206

  
207
    protected abstract boolean loadFeatureType() throws LASUnsupportedFormatException,
208
        GeometryTypeNotSupportedException, GeometryTypeNotValidException, DataException;
209
    
210
    
211
    @SuppressWarnings("rawtypes")
212
    @Override
213
    public void performChanges(Iterator deleteds, Iterator inserteds,
214
            Iterator updateds, Iterator originalFeatureTypesUpdated)
215
            throws PerformEditingException {
216

  
217
        try {
218
            final FeatureStore store
219
                    = this.getStoreServices().getFeatureStore();
220
            getResource().closeRequest();
221
            getResource().execute(new ResourceAction() {
222

  
223
                public Object run() throws Exception {
224
                    FeatureSet set = null;
225
                    DisposableIterator iter = null;
226
                    try {
227
                        set = store.getFeatureSet();
228
                        LASDataStoreParameters params = (LASDataStoreParameters) getParameters();
229
                        LASDataStoreParameters tmpParams
230
                                = (LASDataStoreParameters) params.getCopy();
231

  
232
                        File tmp_file = File.createTempFile(
233
                                "tmp_" + System.currentTimeMillis(), ".las");
234
                        tmp_file.deleteOnExit();
235

  
236
                        tmpParams.setFile(tmp_file);
237
                        /*
238
                        writer.begin(tmpParams, store.getDefaultFeatureType(),
239
                                set.getSize());
240

  
241
                        iter = set.fastIterator();
242
                        while (iter.hasNext()) {
243
                            Feature feature = (Feature) iter.next();
244
                            writer.append(feature);
245
                        }
246

  
247
                        writer.end();
248
						*/
249
                        try {
250
                            close();
251
                        } catch (CloseException e1) {
252
                            throw new PerformEditingException(getProviderName(), e1);
253
                        }
254
                        params.getFile().delete();
255

  
256
                        File target_file = params.getFile();
257
                        if (target_file.exists()) {
258
                            target_file.delete();
259
                        }
260
                        tmp_file.renameTo(target_file);
261

  
262
                        if (tmp_file.exists() && !target_file.exists()) {
263
                            // Renaming failed, let's simply copy.
264
                            // We assume we cannot delete it, but we
265
                            // used deleteOnExit and it's
266
                            // temporary, so no problem
267
                            LOG.info("Warning: copying tmp file instead of renaming: "
268
                                    + target_file.getName());
269
                            FileUtils.copyFile(tmp_file, target_file);
270
                        }
271
                        
272
                        getResource().notifyChanges();
273
                        loadFeatureType();
274
                    } finally {
275
                        if (set != null) {
276
                            set.dispose();
277
                        }
278
                        if (iter != null) {
279
                            iter.dispose();
280
                        }
281
                    }
282
                    return null;
283
                }
284
            });
285
        } catch (ResourceExecuteException | ResourceException e) {
286
            throw new PerformEditingException(this.getProviderName(), e);
287
        }
288

  
289
        this.counterNewsOIDs = -1;
290
    }
291

  
292
    @Override
293
    public Object createNewOID() {
294
        if (this.counterNewsOIDs < 0) {
295
            try {
296
                this.counterNewsOIDs = this.getFeatureCount();
297
            } catch (DataException e) {
298
                e.printStackTrace();
299
            }
300

  
301
        } else {
302
            this.counterNewsOIDs++;
303
        }
304
        return new Long(counterNewsOIDs);
305
    }
306

  
307
    @Override
308
    public FeatureSetProvider createSet(FeatureQuery query, FeatureType featureType)
309
        throws DataException {
310
        open();
311
        return new LASFetureSetProvider(this, query, featureType);
312
    }
313

  
314
    @Override
315
    public int getOIDType() {
316
        return DataTypes.LONG;
317
    }
318

  
319
    @Override
320
    protected FeatureProvider internalGetFeatureProviderByReference(
321
        FeatureReferenceProviderServices reference, FeatureType featureType)
322
        throws DataException {
323

  
324
    	return internalGetFeatureProviderByIndex(((Long) reference.getOID()).longValue(), featureType);
325
    }
326
    
327
    public abstract FeatureProvider internalGetFeatureProviderByIndex(
328
    		long index, FeatureType featureType)
329
    				throws DataException;
330

  
331
    protected LASOpenStoreParameters getLASParameters() {
332
        return (LASOpenStoreParameters) this.getParameters();
333
    }
334
}
org.gvsig.lidar/tags/org.gvsig.lidar-1.0.7/org.gvsig.lidar.prov/org.gvsig.lidar.prov.common/src/main/java/org/gvsig/lidar/prov/LASFetureSetProvider.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.lidar.prov;
25

  
26
import org.gvsig.fmap.dal.exception.DataException;
27
import org.gvsig.fmap.dal.feature.FeatureQuery;
28
import org.gvsig.fmap.dal.feature.FeatureType;
29
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureProviderIterator;
30
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureSetProvider;
31
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider;
32
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider;
33
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
34
import org.gvsig.tools.ToolsLocator;
35
import org.gvsig.tools.exception.BaseException;
36
import org.slf4j.Logger;
37
import org.slf4j.LoggerFactory;
38

  
39
/**
40
 * 
41
 * @author <a href="mailto:cmartinez@scolab.es">Cesar Martinez Izquierdo</a>
42
 *
43
 */
44
public class LASFetureSetProvider extends AbstractFeatureSetProvider implements FeatureSetProvider {
45

  
46
    private static final Logger LOG = LoggerFactory.getLogger(LASFetureSetProvider.class);
47

  
48
    private static final String regularExpresion =
49
        "\\s*ST_intersects[(]\\s*ST_GeomFromText[(]\\s*'([^']*)'\\s*,\\s*'([^']*)'\\s*[)],\\s*(?s).*";
50

  
51
    /**
52
     * @param store
53
     *            Source of this feature set
54
     * @param query
55
     *            Query
56
     * @param featureType
57
     *            Featuretype requested
58
     */
59
    public LASFetureSetProvider(AbstractFeatureStoreProvider store, FeatureQuery query,
60
        FeatureType featureType) {
61
        super(store, query, featureType);
62
    }
63

  
64
    @Override
65
    public boolean canFilter() {
66
        return false;
67
    }
68

  
69
    @Override
70
    public boolean canOrder() {
71
        return false;
72
    }
73

  
74
    @Override
75
    public boolean canIterateFromIndex() {
76
        return true;
77
    }
78

  
79
    @Override
80
    public long getSize() throws DataException {
81
        return getStore().getFeatureCount(); // FIXME
82
    }
83

  
84
    @Override
85
    public boolean isEmpty() throws DataException {
86
        return getSize() == 0;
87
    }
88

  
89
    @Override
90
    protected AbstractFeatureProviderIterator createIterator(long index) throws DataException {
91
        return createFastIterator(index);
92
    }
93

  
94
    @Override
95
    protected AbstractFeatureProviderIterator createFastIterator(long index) throws DataException {
96
        return new LASFastIterator(getStore(), index);
97
    }
98

  
99
    @Override
100
    protected void doDispose() throws BaseException {
101
    }
102

  
103
    class LASFastIterator extends AbstractFeatureProviderIterator {
104

  
105
        private long index;
106

  
107
        public LASFastIterator(FeatureStoreProvider storeProvider, long index)
108
            throws LASUnsupportedFormatException {
109
            super(storeProvider);
110
            ToolsLocator.getDisposableManager().bind(storeProvider);
111
            this.index = index;
112
        }
113

  
114
        @Override
115
        public void remove() {
116
        	throw new UnsupportedOperationException();
117
        }
118

  
119
        @Override
120
        protected Object internalNext() {
121
        	
122
        	try {
123
				return ((LASDataStoreProvider)this.getDataStoreProvider()).internalGetFeatureProviderByIndex(index++, getFeatureType());
124
			} catch (DataException e) {
125
				// TODO Auto-generated catch block
126
				e.printStackTrace();
127
			}
128
        	return null;
129
        }
130

  
131
        @Override
132
        protected boolean internalHasNext() {
133
            try {
134
				return index < ((LASDataStoreProvider)this.getDataStoreProvider()).getFeatureCount() ? true : false;
135
			} catch (DataException e) {
136
				e.printStackTrace();
137
			}
138
            return false;
139
        }
140

  
141
        @Override
142
        protected void doDispose() throws BaseException {
143
            ToolsLocator.getDisposableManager().release(getStore());
144
        }
145
    }
146
}
org.gvsig.lidar/tags/org.gvsig.lidar-1.0.7/org.gvsig.lidar.prov/org.gvsig.lidar.prov.common/src/main/java/org/gvsig/lidar/prov/LASOpenStoreParameters.java
1

  
2
package org.gvsig.lidar.prov;
3

  
4
import org.gvsig.fmap.dal.feature.OpenFeatureStoreParameters;
5

  
6
public class LASOpenStoreParameters extends LASDataStoreParameters implements OpenFeatureStoreParameters {
7

  
8
    public LASOpenStoreParameters(String NAME) {
9
        super(NAME);
10
    }
11
    
12
}
org.gvsig.lidar/tags/org.gvsig.lidar-1.0.7/org.gvsig.lidar.prov/org.gvsig.lidar.prov.common/src/main/java/org/gvsig/lidar/prov/ConversionUtils.java
1
package org.gvsig.lidar.prov;
2

  
3
public class ConversionUtils {
4
    
5
    private static final int RED_MASK = 255 << 16;
6
    private static final int GREEN_MASK = 255 << 8;
7
    private static final int BLUE_MASK = 255;
8

  
9
    /**
10
     * GPS time as GPS timestamp = LAS  GPS adjusted time + 1000000000
11
     * GPS time as Unix timestamp = GPS time as GPS timestamp + 315964800
12
     * UTC time as Unix timestamp = GPS time as Unix timestamp + leap seconds
13
     * As leap seconds depend on the actual date being converted, we'll ignore them
14
     * Therefore, we'll use the following constant
15
     * UNIX TIME = LAS GPS adjusted time + LAS_TIME_TO_UNIX_TIME,
16
     * where LAS_TIME_TO_UNIX_TIME = 1000000000 + 315964800 = 1315964800
17
     */
18
    final public static long LAS_TIME_TO_UNIX_TIME = 1315964800;
19
    
20
    /**
21
     * Converts red, green and blue values to a RGB int as defined
22
     * by java.awt.Color(int) constructor.
23
     * 
24
     */
25
    public static int rgbToInt(int red, int green, int blue) {
26
    	return (red << 16) | (green << 8) | blue;
27
    }
28
    
29
    /**
30
     * Converts a RGB int as defined by java.awt.Color(int) constructor
31
     * to separate red, green and blue values
32
     * 
33
     * @returns an array containing the red, green and blue values
34
     */
35
    public static int[] intToRgb(int rgb) {
36
    	int[] rgbArray = new int[3];
37
    	rgbArray[0] = (rgb & RED_MASK) >> 16;
38
        rgbArray[1] = (rgb & GREEN_MASK) >> 8;
39
    	rgbArray[2] = rgb & BLUE_MASK;
40
    	return rgbArray;
41
    }
42
}
org.gvsig.lidar/tags/org.gvsig.lidar-1.0.7/org.gvsig.lidar.prov/org.gvsig.lidar.prov.common/src/main/resources/org/gvsig/lidar/prov/LASDataStoreParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
	<version>1.0.0</version>
4
	<classes>
5
		<class name="LASDataStoreParameters">
6
			<extends>
7
				<class namespace="dal" name="ProviderParameters" />
8
			</extends>
9
			<description>Parameters needed to open LAS stores
10
			</description>
11
			<fields>
12
				<field name="CRS" type="crs" mandatory="true" group="Basic">
13
					<description>Coordinate reference system used</description>
14
				</field>
15
				<field name="file" type="file" mandatory="true" group="Basic">
16
					<description>LAS file</description>
17
				</field>
18
				<field name="thinningDivisor" type="integer" mandatory="false" group="Basic">
19
					<description>Loads only 1 of every n points (1/n), e.g. thinningDivisor=10 loads 10% of total points</description>
20
				</field>
21
				<field name="thinningResolution" type="double" mandatory="false" group="Advanced">
22
					<description>Loads n points per square map unit (e.g. 0.0001 points/m2 on a projected layer or 100 points/km2)</description>
23
				</field>
24
			</fields>
25
		</class>
26
	</classes>
27
</definitions>  
org.gvsig.lidar/tags/org.gvsig.lidar-1.0.7/org.gvsig.lidar.prov/org.gvsig.lidar.prov.common/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.lidar.prov</artifactId>
6
		<version>1.0.7</version>
7
	</parent>
8
	<artifactId>org.gvsig.lidar.prov.common</artifactId>
9
	<name>org.gvsig.lidar.prov.common</name>
10
	<dependencies>
11
		<dependency>
12
			<groupId>org.gvsig</groupId>
13
			<artifactId>org.gvsig.fmap.dal.file.lib</artifactId>
14
		</dependency>
15
		<dependency>
16
			<groupId>org.gvsig</groupId>
17
			<artifactId>org.gvsig.fmap.dal.spi</artifactId>
18
			<scope>compile</scope>
19
		</dependency>
20
		<dependency>
21
			<groupId>org.gvsig</groupId>
22
			<artifactId>org.gvsig.tools.lib</artifactId>
23
			<scope>compile</scope>
24
		</dependency>
25
                <dependency>
26
                        <groupId>commons-io</groupId>
27
                        <artifactId>commons-io</artifactId>
28
                </dependency>
29
	</dependencies>
30
</project>
0 31

  
org.gvsig.lidar/tags/org.gvsig.lidar-1.0.7/org.gvsig.lidar.prov/org.gvsig.lidar.prov.jgrass/src/main/resources/org/gvsig/lidar/prov/jgrasstools/JGrassLASMetadata.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="JGrassLASDataStoreProvider" namespace="Metadata">
10
      <extends>
11
      	<class namespace="Metadata" name="SpatialProvider"/>
12
      </extends>
13
      <description>Metadata of a LIDAR LAS provider</description>
14
      <fields>
15
      </fields>
16
    </class>
17

  
18
  </classes>
19
</definitions>  
org.gvsig.lidar/tags/org.gvsig.lidar-1.0.7/org.gvsig.lidar.prov/org.gvsig.lidar.prov.jgrass/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.lidar.prov.jgrasstools.JGrassLASLibrary
org.gvsig.lidar/tags/org.gvsig.lidar-1.0.7/org.gvsig.lidar.prov/org.gvsig.lidar.prov.jgrass/src/main/java/org/gvsig/lidar/prov/jgrasstools/JGrassLASFilesystemServerProvider.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.lidar.prov.jgrasstools;
25

  
26
import java.io.File;
27

  
28
import org.cresques.cts.IProjection;
29
import org.gvsig.fmap.dal.DALLocator;
30
import org.gvsig.fmap.dal.DataServerExplorer;
31
import org.gvsig.fmap.dal.DataStoreParameters;
32
import org.gvsig.fmap.dal.NewDataStoreParameters;
33
import org.gvsig.fmap.dal.exception.CreateException;
34
import org.gvsig.fmap.dal.exception.DataException;
35
import org.gvsig.fmap.dal.exception.InitializeException;
36
import org.gvsig.fmap.dal.exception.RemoveException;
37
import org.gvsig.fmap.dal.feature.EditableFeatureType;
38
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
39
import org.gvsig.fmap.dal.resource.ResourceAction;
40
import org.gvsig.fmap.dal.resource.file.FileResource;
41
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer;
42
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
43
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider;
44
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider;
45
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices;
46
import org.gvsig.fmap.geom.Geometry.TYPES;
47
import org.gvsig.lidar.prov.LASNewStoreParameters;
48
import org.gvsig.lidar.prov.LASOpenStoreParameters;
49
import org.slf4j.Logger;
50
import org.slf4j.LoggerFactory;
51

  
52
/**
53
 * 
54
 * @author <a href="mailto:cmartinez@scolab.es">Cesar Martinez Izquierdo</a>
55
 *
56
 */
57
public class JGrassLASFilesystemServerProvider extends AbstractFilesystemServerExplorerProvider implements
58
    FilesystemServerExplorerProvider, ResourceConsumer {
59

  
60
    private static final Logger LOG = LoggerFactory.getLogger(JGrassLASFilesystemServerProvider.class);
61

  
62
    private FilesystemServerExplorerProviderServices serverExplorer;
63

  
64
    @Override
65
    public String getDataStoreProviderName() {
66
        return JGrassLASDataStoreProvider.NAME;
67
    }
68

  
69
    @Override
70
    public String getDescription() {
71
        return JGrassLASDataStoreProvider.DESCRIPTION;
72
    }
73

  
74
    @Override
75
    public boolean accept(File pathname) {
76
    	return (pathname.getName().toLowerCase().endsWith(".las"));
77
    }
78

  
79
    @Override
80
    public boolean closeResourceRequested(ResourceProvider resource) {
81
        // Do nothing
82
        return true;
83
    }
84

  
85
    @Override
86
    public void resourceChanged(ResourceProvider resource) {
87
        // Do nothing
88
    }
89

  
90
    @Override
91
    public void initialize(FilesystemServerExplorerProviderServices serverExplorer) {
92
        this.serverExplorer = serverExplorer;
93
    }
94

  
95
    @Override
96
    public boolean canCreate() {
97
    	return true;
98
    }
99

  
100
    @Override
101
    public void create(NewDataStoreParameters parameters, boolean overwrite) throws CreateException {
102
    	if (parameters instanceof LASOpenStoreParameters) {
103

  
104
            final LASOpenStoreParameters newLASDataStoreParameters =
105
                (LASOpenStoreParameters) parameters;
106

  
107
            final File file = newLASDataStoreParameters.getFile();
108

  
109
            if (file.isFile() && file.exists()) {
110
                if (overwrite) {
111
                    // Deleting existing file
112
                    try {
113
                        this.remove(newLASDataStoreParameters);
114
                    } catch (RemoveException e) {
115
                        throw new CreateException("Can not overwrite file", e);
116
                    }
117
                } else {
118
                    throw new CreateException(file.getAbsolutePath(), new IllegalArgumentException(
119
                        String.format("%1s exists and overwrite option is false",
120
                            file.getAbsolutePath())));
121
                }
122
            }
123

  
124
            try {
125
                final FileResource resource =
126
                    (FileResource) serverExplorer.getServerExplorerProviderServices()
127
                        .createResource(FileResource.NAME, new Object[] { file.getAbsolutePath() });
128

  
129
                resource.addConsumer(this);
130
                resource.execute(new ResourceAction() {
131

  
132
                    @Override
133
                    public Object run() throws Exception {
134

  
135
                        FeatureAttributeDescriptor geometryAttribute =
136
                            newLASDataStoreParameters.getDefaultFeatureType()
137
                                .getDefaultGeometryAttribute();
138
                        
139
                        if (geometryAttribute != null) {
140
                        	if (TYPES.POINT!=geometryAttribute.getGeomType().getType()) {
141
                        		throw new IllegalArgumentException(
142
                                        "LAS files can only store points.");
143
                        	}
144

  
145
                            IProjection projection = geometryAttribute.getSRS();
146
                            if (projection == null && newLASDataStoreParameters.getCRS() != null) {
147
                                projection = newLASDataStoreParameters.getCRS();
148
                            }
149
                        }
150
                        EditableFeatureType featureType = newLASDataStoreParameters.getDefaultFeatureType();
151
                        JGrassLASWriter writer = new JGrassLASWriter(newLASDataStoreParameters, featureType, null);                                            
152
                        writer.open();
153
                        writer.close();
154
                        return null;
155
                    }
156
                });
157
            } catch (InitializeException e) {
158
                throw new CreateException("Can not create file resource to create it", e);
159
            }
160
        }
161

  
162
    }
163

  
164
    @Override
165
    public NewDataStoreParameters getCreateParameters() throws DataException {
166
    	LASNewStoreParameters newParameters = new LASNewStoreParameters(JGrassLASDataStoreProvider.NAME);
167
        EditableFeatureType editableFeatureType = DALLocator.getDataManager().createFeatureType();
168
        newParameters.setDefaultFeatureType(editableFeatureType);
169
        return newParameters;
170
    }
171

  
172
    @Override
173
    public void remove(DataStoreParameters parameters) throws RemoveException {
174

  
175
        if (parameters instanceof LASOpenStoreParameters) {
176

  
177
        	LASOpenStoreParameters newLASDataStoreParameters =
178
                (LASOpenStoreParameters) parameters;
179

  
180
            final File file = newLASDataStoreParameters.getFile();
181

  
182
            if (!file.exists() && !file.canWrite()) {
183
                throw new RemoveException(file.getAbsolutePath(), new IllegalArgumentException(
184
                    String.format("%1s does not exist", file.getAbsolutePath())));
185
            }
186

  
187
            try {
188
                final FileResource resource =
189
                    (FileResource) serverExplorer.getServerExplorerProviderServices()
190
                        .createResource(FileResource.NAME, new Object[] { file.getAbsolutePath() });
191

  
192
                resource.addConsumer(this);
193
                resource.execute(new ResourceAction() {
194

  
195
                    @Override
196
                    public Object run() throws Exception {
197
                        resource.closeRequest();
198
                        file.delete();
199
                        return null;
200
                    }
201
                });
202
                resource.addConsumer(this);
203
            } catch (InitializeException e) {
204
                throw new RemoveException("Can not create file resource to remove it", e);
205
            }
206
        }
207
    }
208

  
209
    @Override
210
    public boolean canCreate(NewDataStoreParameters parameters) {
211
    	
212
        if (parameters instanceof LASNewStoreParameters) {
213

  
214
        	LASNewStoreParameters newLASDataStoreParameters =
215
                (LASNewStoreParameters) parameters;
216

  
217
                File file = newLASDataStoreParameters.getFile();
218
                if (file != null && file.canWrite()) {
219
                    return true;
220
                }
221

  
222
                FeatureAttributeDescriptor geometryAttribute =
223
                    newLASDataStoreParameters.getDefaultFeatureType()
224
                        .getDefaultGeometryAttribute();
225

  
226
                if (geometryAttribute != null) {
227
                	if (TYPES.POINT!=geometryAttribute.getGeomType().getType()) {
228
                		throw new IllegalArgumentException(
229
                                "LAS files can only store points.");
230
                	}
231

  
232
            }
233
        }
234
        return false;
235
    }
236
    
237
    @Override
238
	public int getMode() {
239
		return DataServerExplorer.MODE_GEOMETRY|DataServerExplorer.MODE_FEATURE;
240
	}
241
}
org.gvsig.lidar/tags/org.gvsig.lidar-1.0.7/org.gvsig.lidar.prov/org.gvsig.lidar.prov.jgrass/src/main/java/org/gvsig/lidar/prov/jgrasstools/JGrassLASDataStoreProviderFactory.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.lidar.prov.jgrasstools;
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.serverexplorer.filesystem.FilesystemServerExplorerParameters;
36
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
37
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
38
import org.gvsig.lidar.prov.LASDataStoreProviderFactory;
39
import org.gvsig.lidar.prov.LASOpenStoreParameters;
40
import org.gvsig.tools.dynobject.DynObject;
41

  
42
/**
43
 * 
44
 * @author <a href="mailto:cmartinez@scolab.es">Cesar Martinez Izquierdo</a>
45
 *
46
 */
47
public class JGrassLASDataStoreProviderFactory extends AbstractFeatureStoreProviderFactory implements
48
    LASDataStoreProviderFactory {
49

  
50
    /**
51
     * @param name
52
     *            Name of factory
53
     * @param description
54
     *            Description of factory
55
     */
56
    public JGrassLASDataStoreProviderFactory(String name, String description) {
57
        super(name, description);
58
    }
59

  
60
    @Override
61
    public DataStoreProvider createProvider(DataParameters dataParameters,
62
        DataStoreProviderServices providerServices) throws InitializeException {
63
        return new JGrassLASDataStoreProvider((DataStoreParameters) dataParameters, providerServices);
64
    }
65

  
66
    @Override
67
    public DynObject createParameters() {
68
        return new LASOpenStoreParameters(JGrassLASDataStoreProvider.NAME);
69
    }
70

  
71
    public int allowMultipleGeometryTypes() {
72
        return NO;
73
    }
74

  
75
    public int allowEditableFeatureType() {
76
        return NO;
77
    }
78

  
79
    @SuppressWarnings("rawtypes")
80
    public List getSupportedDataTypes() {
81

  
82
        List<Integer> supportedDataTypes = new ArrayList<Integer>();
83

  
84
        supportedDataTypes.add(DataTypes.BOOLEAN);
85
        supportedDataTypes.add(DataTypes.DATE);
86
        supportedDataTypes.add(DataTypes.FLOAT);
87
        supportedDataTypes.add(DataTypes.DOUBLE);
88
        supportedDataTypes.add(DataTypes.STRING);
89
        supportedDataTypes.add(DataTypes.INT);
90
        supportedDataTypes.add(DataTypes.LONG);
91
        supportedDataTypes.add(DataTypes.BYTE);
92
        supportedDataTypes.add(DataTypes.TIME);
93
        supportedDataTypes.add(DataTypes.TIMESTAMP);
94

  
95
        return supportedDataTypes;
96
    }
97

  
98
    @SuppressWarnings("rawtypes")
99
    public List getSupportedGeometryTypesSubtypes() {
100
        List<Integer> supportedSubtypes = new ArrayList<Integer>();
101
        supportedSubtypes.add(SUBTYPES.GEOM3D);
102
        return supportedSubtypes;
103
    }
104

  
105
    public boolean allowsMandatoryAttributes() {
106
        return false;
107
    }
108

  
109
    public boolean allowsPrimaryKeyAttributes() {
110
        return false;
111
    }
112

  
113
    public int useLocalIndexesCanImprovePerformance() {
114
        return YES;
115
    }
116

  
117
    @Override
118
    public DynObject createDataExplorerParameters(Object connectionString) {
119
    	return new FilesystemServerExplorerParameters();
120
    }
121

  
122
    @Override
123
    public DynObject createParameters(Object connectionObject) {
124
        return createParameters();
125
    }
126

  
127
}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff