Statistics
| Revision:

gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.merge / src / main / java / org / gvsig / geoprocess / algorithm / merge / MergeOperation.java @ 237

History | View | Annotate | Download (2.81 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007,2012 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
package org.gvsig.geoprocess.algorithm.merge;
22

    
23
import es.unex.sextante.core.Sextante;
24
import es.unex.sextante.dataObjects.IVectorLayer;
25

    
26
import org.gvsig.fmap.dal.exception.DataException;
27
import org.gvsig.fmap.dal.feature.EditableFeature;
28
import org.gvsig.fmap.dal.feature.Feature;
29
import org.gvsig.fmap.geom.exception.CreateGeometryException;
30
import org.gvsig.geoprocess.algorithm.base.core.GeometryOperation;
31
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer;
32

    
33
/**
34
 * Builds a geometry with the intersection between two layers
35
 * 
36
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
37
 */
38
public class MergeOperation extends GeometryOperation {
39
        private IVectorLayer                     layer            = null;
40

    
41
        public MergeOperation(IVectorLayer layer) {
42
                this.layer = layer;
43
        }
44

    
45
        /**
46
         * Computes intersection between the geometry and the overlay layer. The fields of the
47
         * intersected features will be added.
48
         * @param g
49
         * @param featureInput
50
         * @return
51
         */
52
        public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature featureInput) {
53
                if(g == null)
54
                        return lastEditFeature;
55
                
56
                try {
57
                        if(inFeatureStore == ((FlyrVectIVectorLayer)layer).getFeatureStore())
58
                                lastEditFeature = persister.addFeature(featureInput, g);
59
                        else
60
                                lastEditFeature = persister.addDifferentFieldFeature(featureInput, g);
61
                } catch (CreateGeometryException e) {
62
                        Sextante.addErrorToLog(e);
63
                } catch (DataException e) {
64
                        Sextante.addErrorToLog(e);
65
                }
66
                
67
                return lastEditFeature;
68
        }
69
        
70
        /**
71
         * clips feature's geometry with the clipping geometry, preserving
72
         * feature's original attributes.
73
         * If feature's geometry doesn't touch clipping geometry, it will be
74
         * ignored.
75
         */
76
        public void invoke(org.gvsig.fmap.geom.Geometry g, EditableFeature featureInput) {
77
                try {
78
                        lastEditFeature = persister.addGeometryToExistingFeature(featureInput, g);
79
                } catch (CreateGeometryException e) {
80
                        Sextante.addErrorToLog(e);
81
                } catch (DataException e) {
82
                        Sextante.addErrorToLog(e);
83
                }
84
        }
85
}
86