Revision 577

View differences:

org.gvsig.lidar/tags/org.gvsig.lidar-1.0.18/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.18</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.18/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.18/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.18/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.18/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.18/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.18/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.18/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.18/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.18/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.18/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.18</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.18/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.18/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.18/org.gvsig.lidar.prov/org.gvsig.lidar.prov.jgrass/src/main/java/org/gvsig/lidar/prov/jgrasstools/JGrassLASDataStoreProvider.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
import java.io.IOException;
28
import java.util.ArrayList;
29
import java.util.Collection;
30
import java.util.Date;
31
import java.util.Iterator;
32
import java.util.List;
33
import java.util.Set;
34

  
35
import org.apache.commons.io.FileUtils;
36
import org.gvsig.fmap.dal.DALLocator;
37
import org.gvsig.fmap.dal.DataStore;
38
import org.gvsig.fmap.dal.DataStoreParameters;
39
import org.gvsig.fmap.dal.DataTypes;
40
import org.gvsig.fmap.dal.FileHelper;
41
import org.gvsig.fmap.dal.exception.DataException;
42
import org.gvsig.fmap.dal.exception.InitializeException;
43
import org.gvsig.fmap.dal.exception.OpenException;
44
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
45
import org.gvsig.fmap.dal.feature.EditableFeatureType;
46
import org.gvsig.fmap.dal.feature.Feature;
47
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
48
import org.gvsig.fmap.dal.feature.FeatureSet;
49
import org.gvsig.fmap.dal.feature.FeatureType;
50
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException;
51
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
52
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider;
53
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
54
import org.gvsig.fmap.dal.resource.ResourceAction;
55
import org.gvsig.fmap.dal.resource.exception.ResourceException;
56
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
57
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
58
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
59
import org.gvsig.fmap.geom.Geometry.TYPES;
60
import org.gvsig.fmap.geom.GeometryLocator;
61
import org.gvsig.fmap.geom.GeometryManager;
62
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
63
import org.gvsig.fmap.geom.exception.CreateGeometryException;
64
import org.gvsig.fmap.geom.primitive.Envelope;
65
import org.gvsig.fmap.geom.primitive.Point;
66
import org.gvsig.fmap.geom.type.GeometryType;
67
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
68
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
69
import org.gvsig.lidar.prov.LASDataStoreProvider;
70
import org.gvsig.lidar.prov.ConversionUtils;
71
import org.gvsig.lidar.prov.LASUnsupportedFormatException;
72
import org.gvsig.tools.dispose.DisposableIterator;
73
import org.gvsig.tools.dynobject.DynObject;
74
import org.gvsig.tools.exception.BaseException;
75
import org.jgrasstools.gears.io.las.core.ALasReader;
76
import org.jgrasstools.gears.io.las.core.ILasHeader;
77
import org.jgrasstools.gears.io.las.core.LasRecord;
78
import org.jgrasstools.gears.io.las.core.liblas.LiblasReader;
79
import org.jgrasstools.gears.io.las.core.v_1_0.LasReader;
80
import org.opengis.metadata.Identifier;
81
import org.opengis.metadata.extent.Extent;
82
import org.opengis.referencing.crs.CoordinateReferenceSystem;
83
import org.opengis.referencing.cs.CoordinateSystem;
84
import org.opengis.util.GenericName;
85
import org.opengis.util.InternationalString;
86
import org.slf4j.Logger;
87
import org.slf4j.LoggerFactory;
88

  
89
import org.gvsig.lidar.prov.LASOpenStoreParameters;
90

  
91
/**
92
 * 
93
 * @author <a href="mailto:cmartinez@scolab.es">Cesar Martinez Izquierdo</a>
94
 *
95
 */
96
public class JGrassLASDataStoreProvider extends LASDataStoreProvider {
97

  
98
    private static final Logger LOG = LoggerFactory.getLogger(JGrassLASDataStoreProvider.class);
99

  
100
    public static final String NAME = "JGrassLASDataStoreProvider";
101

  
102
    public static final String DESCRIPTION = "LIDAR LAS file (jgrasstools)";
103
    
104
    public static final String METADATA_DEFINITION_NAME = "JGrassLASDataStoreProvider";
105

  
106
    protected ALasReader reader = null;
107

  
108
    protected JGrassLASDataStoreProvider(DataStoreParameters dataParameters,
109
        DataStoreProviderServices storeServices, DynObject metadata) throws InitializeException {
110
        super(dataParameters, storeServices, metadata);
111
    }
112

  
113
    protected JGrassLASDataStoreProvider(DataStoreParameters dataParameters,
114
        DataStoreProviderServices storeServices) throws InitializeException {
115
    	
116
    	super(dataParameters, storeServices, FileHelper
117
    	        .newMetadataContainer(METADATA_DEFINITION_NAME));
118
    }
119
    
120
    @Override
121
    public String getFullName() {
122
    	return getName();
123
    }
124

  
125
    @Override
126
    public String getName() {
127
        return getLASParameters().getFile().getName();
128
    }
129

  
130
    @Override
131
    public String getProviderName() {
132
        return NAME;
133
    }
134

  
135
    @Override
136
    public boolean allowWrite() {
137
    	return true;
138
    }
139

  
140
    protected boolean loadFeatureType() throws LASUnsupportedFormatException,
141
        GeometryTypeNotSupportedException, GeometryTypeNotValidException, DataException {
142

  
143
        return (boolean) getResource().execute(new ResourceAction() {
144

  
145
            @Override
146
            public Object run() throws Exception {
147
            	EditableFeatureType editableFeatureType = DALLocator.getDataManager().createFeatureType();
148
                editableFeatureType.setHasOID(true);
149
                EditableFeatureAttributeDescriptor attributeDescriptor = editableFeatureType.add("GEOM",  DataTypes.GEOMETRY);
150
                
151
                GeometryManager geometryManager = GeometryLocator.getGeometryManager();
152
                GeometryType geometryType =
153
                        geometryManager.getGeometryType(
154
                        		TYPES.POINT, SUBTYPES.GEOM3D);
155
                attributeDescriptor.setGeometryType(geometryType);
156
                if (getLASParameters().getCRS()!=null) {
157
                	attributeDescriptor.setSRS(getLASParameters().getCRS());
158
                }
159
                editableFeatureType.setDefaultGeometryAttributeName(JGrassLASDataStoreProvider.GEOM_FIELD);
160
                attributeDescriptor =
161
                        editableFeatureType.add(CLASS_FIELD, DataTypes.BYTE);
162
                attributeDescriptor =
163
                        editableFeatureType.add(POINTX_FIELD, DataTypes.DOUBLE);
164
                attributeDescriptor =
165
                        editableFeatureType.add(POINTY_FIELD, DataTypes.DOUBLE);
166
                attributeDescriptor =
167
                        editableFeatureType.add(POINTZ_FIELD, DataTypes.DOUBLE);
168
                attributeDescriptor =
169
                        editableFeatureType.add(INTENSITY_FIELD, DataTypes.INT);
170
                attributeDescriptor =
171
                        editableFeatureType.add(RETURNNUM_FIELD, DataTypes.BYTE);
172
                attributeDescriptor =
173
                        editableFeatureType.add(NUMRETURNS_FIELD, DataTypes.BYTE);
174
                
175
                ILasHeader header = getReader().getHeader();
176
                if (header.hasRGB()) {
177
                	attributeDescriptor =
178
                            editableFeatureType.add(COLOR_FIELD, DataTypes.INT);
179
                }
180
                if (header.hasGpsTime()) {
181
                	if (header.getGpsTimeType()==1) {
182
                		// Show adjusted standard GPS time as a Java Date
183
                		attributeDescriptor = editableFeatureType.add(TIME_FIELD, DataTypes.DATE);
184
                	}
185
                	else {
186
                		// Show GPS week time as a plain long, as we don't have enough context to translate it to a real date
187
                		attributeDescriptor = editableFeatureType.add(WEEKTIME_FIELD, DataTypes.LONG);
188
                	}
189
                }
190

  
191
                FeatureType featureType = editableFeatureType.getNotEditableCopy();
192
                if (featureType.getDefaultSRS() != null) {
193
                    setDynValue(DataStore.METADATA_CRS, featureType.getDefaultSRS());
194
                }
195

  
196
                List<FeatureType> featureTypes = new ArrayList<FeatureType>(1);
197
                featureTypes.add(featureType);
198

  
199
                getStoreServices().setFeatureTypes(featureTypes, featureType);
200
                
201
                return true;
202
            }
203
        });
204
    }
205

  
206
    public FeatureProvider internalGetFeatureProviderByIndex(
207
    		long index, FeatureType featureType)
208
    				throws DataException {
209
    	
210
    	long decimatedIndex = (long) Math.floor(index * decimation);
211
    	FeatureProvider featureProvider = this.createFeatureProvider(featureType);
212
    	featureProvider.setOID(new Long(decimatedIndex));
213
    	LasRecord record;
214
		try {
215
			record = getReader().getPointAt(decimatedIndex);
216
		} catch (IOException e1) {
217
			throw new FeatureIndexException("Error accessing record", e1,
218
					"Error accessing record", -1);
219
		}
220
		if (featureType.getAttributeDescriptor(GEOM_FIELD)!=null) {
221
			try {
222
				Point p = (Point) this.gm.create(TYPES.POINT, SUBTYPES.GEOM3D);
223
				p.setCoordinateAt(0, record.x);
224
				p.setCoordinateAt(1, record.y);
225
				p.setCoordinateAt(2, record.z);
226
				featureProvider.set(GEOM_FIELD, p);
227
			} catch (CreateGeometryException e) {
228
				// TODO Auto-generated catch block
229
				e.printStackTrace();
230
			}
231
		}
232
    	if (featureType.getAttributeDescriptor(POINTX_FIELD)!=null) {
233
    		featureProvider.set(POINTX_FIELD, record.x);
234
    	}
235
    	if (featureType.getAttributeDescriptor(POINTY_FIELD)!=null) {
236
    		featureProvider.set(POINTY_FIELD, record.y);
237
    	}
238
    	if (featureType.getAttributeDescriptor(POINTZ_FIELD)!=null) {
239
    		featureProvider.set(POINTZ_FIELD, record.z);
240
    	}
241
    	if (featureType.getAttributeDescriptor(CLASS_FIELD)!=null) {
242
    		featureProvider.set(CLASS_FIELD, record.classification);
243
    	}
244
    	if (featureType.getAttributeDescriptor(INTENSITY_FIELD)!=null) {
245
    		featureProvider.set(INTENSITY_FIELD, (int)record.intensity);
246
    	}
247
    	if (featureType.getAttributeDescriptor(RETURNNUM_FIELD)!=null) {
248
    		featureProvider.set(RETURNNUM_FIELD, (byte)record.returnNumber);
249
    	}
250
    	if (featureType.getAttributeDescriptor(NUMRETURNS_FIELD)!=null) {
251
    		featureProvider.set(NUMRETURNS_FIELD, (byte) record.numberOfReturns);
252
    	}
253
    	if (featureType.getAttributeDescriptor(TIME_FIELD)!=null) {
254
    		long las_time  = (long)record.gpsTime;
255
    		// file uses LAS 1.2/1.3/1.4 adjusted GPS Time
256
    		// convert to unix time and build a Date object
257
    		Date unix_time = new Date(las_time + ConversionUtils.LAS_TIME_TO_UNIX_TIME);
258
			featureProvider.set(TIME_FIELD, unix_time);
259
    	}
260
    	if (featureType.getAttributeDescriptor(WEEKTIME_FIELD)!=null) {
261
    		// LAS 1.0, 1.1 gps week time, we handle it as a plain long.
262
    		// It could be translated to Unix time using the following formulas:
263
    		// seconds_per_week = 604800
264
    		// las_gps_time = las_week_time + ( week_number_from_6_1_1980 * seconds_per_week)
265
    		// unix_time = las_gps_time + 315964800
266
    		long las_time  = (long)record.gpsTime;
267
    		featureProvider.set(WEEKTIME_FIELD, new Long(las_time));
268
    	}
269
    	if (featureType.getAttributeDescriptor(COLOR_FIELD)!=null) {
270

  
271
    		int red = record.color[0];
272
    		int green = record.color[1];
273
    		int blue = record.color[2];
274
    		// RGB value representing the color in the default sRGB ColorModel.
275
    		// (Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue).
276
    		featureProvider.set(COLOR_FIELD, ConversionUtils.rgbToInt(red, green, blue));
277
    	}
278
    	return featureProvider;
279
    }
280
    
281
    protected synchronized ALasReader getReader() throws LASUnsupportedFormatException, OpenException {
282
        if (this.reader == null) {
283
        	/**
284
        	 * We create a fake geoapi CRS, because providing a null CRS to JGrasstools readers
285
        	 * causes errors if the .prj file exists and the dependences are not satisfied
286
        	 */
287
        	CoordinateReferenceSystemFakeImpl crs = new CoordinateReferenceSystemFakeImpl();
288
        	try {
289
        		if (ALasReader.supportsNative()) {
290
        			reader = new LiblasReader(file, crs);
291
        			LOG.info("JGrass LiblasReader loaded");
292
        		}
293
        	} catch (Exception exc) {
294
        		LOG.debug("Error loading native liblas reader", exc);
295
        	}
296
        	if (reader==null) {
297
        		try {
298
        			reader = new LasReader(file, crs);
299
        			LOG.info("JGrass LasReader loaded");
300
        		}
301
        		catch (Exception e) {
302
        			throw new OpenException("Error loading Java JGrass LAS reader", e);
303
        		}
304
        	}
305
        	try {
306
        		reader.open();
307
        	} catch (Exception e) {
308
        		throw new OpenException("Error opening JGrass LAS reader", e);
309
        	}
310
        }
311
        return this.reader;
312
    }
313
    
314
    /*
315
     * Lazy envelope initialization
316
     */
317
    @Override
318
    public Envelope getEnvelope() throws DataException {
319
    	
320
        open();
321
        if (this.envelope == null) {
322
        	Envelope env;
323
			try {
324
				env = this.gm.createEnvelope(SUBTYPES.GEOM3D);
325
	        	Point p1 = (Point) this.gm.create(TYPES.POINT, SUBTYPES.GEOM3D);
326
	        	Point p2 = (Point) this.gm.create(TYPES.POINT, SUBTYPES.GEOM3D);
327
	        	// FIXME: do we need to consider projection for upper & lower corner?
328
	        	ILasHeader header = getReader().getHeader();
329
	        	double[] env3d = header.getRawDataEnvelope();
330
	        	p1.setCoordinateAt(0, env3d[0]);
331
	        	p1.setCoordinateAt(1, env3d[1]);
332
	        	p1.setCoordinateAt(2, env3d[2]);
333
	        	p2.setCoordinateAt(0, env3d[3]);
334
	        	p2.setCoordinateAt(1, env3d[4]);
335
	        	p2.setCoordinateAt(2, env3d[5]);
336
	        	env.setLowerCorner(p1);
337
	        	env.setUpperCorner(p2);
338
	        	this.envelope = env;
339
			} catch (CreateEnvelopeException e) {
340
				// TODO Auto-generated catch block
341
				e.printStackTrace();
342
			} catch (CreateGeometryException e) {
343
				// TODO Auto-generated catch block
344
				e.printStackTrace();
345
			}
346

  
347
        }
348
        return this.envelope;
349
    }
350

  
351

  
352
    @Override
353
    public long getFeatureCount() throws DataException {
354
        open();
355
        return ((Number) getResource().execute(new ResourceAction() {
356

  
357
            @Override
358
            public Object run() throws Exception {
359
            	long count = getReader().getHeader().getRecordsCount();
360
            	if (decimation>1.0d) {
361
            		count = (long) Math.floor((count/decimation));
362
            	}
363
            	return count;
364
            }
365
        })).longValue();
366
    }
367
    
368
    @Override
369
    protected void doDispose() throws BaseException {
370
        super.doDispose();
371
        getResource().removeConsumer(this);
372
        this.resourceProvider = null;
373
        this.gm = null;
374
        this.envelope = null;
375
        this.opened = false;
376
        try { this.reader.close(); } catch (Exception e) {}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff