Revision 290

View differences:

org.gvsig.lidar/trunk/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.1-SNAPSHOT</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/trunk/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/trunk/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/trunk/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 LASDataStoreParameters getLASParameters() {
332
        return (LASDataStoreParameters) this.getParameters();
333
    }
334
}
org.gvsig.lidar/trunk/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/trunk/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/trunk/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/trunk/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.DataStoreParameters;
35
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
36
import org.gvsig.fmap.dal.feature.EditableFeatureType;
37
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
38
import org.gvsig.fmap.dal.feature.FeatureType;
39
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
40
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
41
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
42
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
43
import org.gvsig.tools.ToolsLocator;
44
import org.gvsig.tools.dynobject.DelegatedDynObject;
45
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
46

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

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

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

  
86
    protected DelegatedDynObject parameters;
87

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

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

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

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

  
115

  
116

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

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

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

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

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

  
215
    @Override
216
    protected DelegatedDynObject getDelegatedDynObject() {
217
        return parameters;
218
    }
219

  
220
    @Override
221
    public void setDefaultFeatureType(FeatureType defaultFeatureType) {
222
        this.setDynValue(FEATURETYPE_PARAMTER_NAME, defaultFeatureType);
223
    }
224

  
225
    @Override
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/trunk/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.1-SNAPSHOT</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>
org.gvsig.lidar/trunk/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.LASDataStoreParameters;
48
import org.gvsig.lidar.prov.LASDataStoreProvider;
49
import org.jgrasstools.gears.io.las.core.v_1_0.LasWriter;
50
import org.slf4j.Logger;
51
import org.slf4j.LoggerFactory;
52

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

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

  
63
    private FilesystemServerExplorerProviderServices serverExplorer;
64

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

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

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

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

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

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

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

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

  
105
            final LASDataStoreParameters newLASDataStoreParameters =
106
                (LASDataStoreParameters) parameters;
107

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

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

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

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

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

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

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

  
163
    }
164

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

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

  
176
        if (parameters instanceof LASDataStoreParameters) {
177

  
178
        	LASDataStoreParameters newLASDataStoreParameters =
179
                (LASDataStoreParameters) parameters;
180

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

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

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

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

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

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

  
215
        	LASDataStoreParameters newLASDataStoreParameters =
216
                (LASDataStoreParameters) parameters;
217

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

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

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

  
233
            }
234
        }
235
        return false;
236
    }
237
    
238
    @Override
239
	public int getMode() {
240
		return DataServerExplorer.MODE_GEOMETRY|DataServerExplorer.MODE_FEATURE;
241
	}
242
}
org.gvsig.lidar/trunk/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.LASDataStoreParameters;
39
import org.gvsig.lidar.prov.LASDataStoreProviderFactory;
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 LASDataStoreParameters(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
}
org.gvsig.lidar/trunk/org.gvsig.lidar.prov/org.gvsig.lidar.prov.jgrass/src/main/java/org/gvsig/lidar/prov/jgrasstools/JGrassLASWriter.java
1
package org.gvsig.lidar.prov.jgrasstools;
2

  
3
import java.io.File;
4
import java.util.Date;
5

  
6
import org.apache.commons.io.FileUtils;
7
import org.cresques.cts.ICRSFactory;
8
import org.cresques.cts.IProjection;
9
import org.gvsig.fmap.dal.exception.CloseException;
10
import org.gvsig.fmap.dal.exception.DataException;
11
import org.gvsig.fmap.dal.exception.OpenException;
12
import org.gvsig.fmap.dal.exception.WriteException;
13
import org.gvsig.fmap.dal.feature.Feature;
14
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
15
import org.gvsig.fmap.dal.feature.FeatureSet;
16
import org.gvsig.fmap.dal.feature.FeatureType;
17
import org.gvsig.fmap.geom.Geometry.TYPES;
18
import org.gvsig.fmap.geom.primitive.Envelope;
19
import org.gvsig.fmap.geom.primitive.Point;
20
import org.gvsig.lidar.prov.ConversionUtils;
21
import org.gvsig.lidar.prov.LASDataStoreParameters;
22
import org.gvsig.lidar.prov.LASDataStoreProvider;
23
import org.gvsig.tools.dispose.DisposableIterator;
24
import org.gvsig.tools.dispose.DisposeUtils;
25
import org.jgrasstools.gears.io.las.core.ALasWriter;
26
import org.jgrasstools.gears.io.las.core.LasRecord;
27
import org.jgrasstools.gears.io.las.core.liblas.LiblasWriter;
28
import org.jgrasstools.gears.io.las.core.v_1_0.LasWriter;
29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

  
32
public class JGrassLASWriter {
33
	protected LASDataStoreParameters params;
34
	protected Envelope outEnvelope;
35
	protected FeatureType fType;
36
	private int geomIndex, colorIdx, classificationIdx, weektimeIdx, gpstimeIdx, intensityIdx, returnNumIdx, numberOfReturnsIdx;
37
	protected ALasWriter writer = null;
38
	protected LasRecord record = null;
39
	double[] scale = null;
40
	double[] offset = null;
41
	int pointFormat = -1;
42
	
43
	private static final Logger LOG = LoggerFactory.getLogger(JGrassLASWriter.class);
44
	
45
	public JGrassLASWriter(LASDataStoreParameters outParams, FeatureType featType, Envelope outEnvelope) throws DataException {
46
		this.params = outParams;
47
		this.outEnvelope = outEnvelope;
48
		this.fType = featType;
49
	}
50
	
51
	protected ALasWriter getWriter() throws CantCreateWriterException {
52
		if (writer==null) {
53

  
54
			try{
55
				if (ALasWriter.supportsNative()) {
56
					writer = new LiblasWriter(this.params.getFile(), null);
57
				}
58
				else {
59
					writer = new LasWriter(this.params.getFile(), null);
60
				}
61
			} catch (Exception exc) {
62
				throw new CantCreateWriterException("Can't create LAS writer", exc, "Can't create LAS writer", -1);
63
			}
64
		}
65
		return writer;
66
	}
67
	
68
	protected int getPointFormat() {
69
		if (this.pointFormat!=-1) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff