Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.operation / src / main / java / org / gvsig / fmap / geom / operation / isCCW / IsCCW.java @ 40767

History | View | Annotate | Download (3.53 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.geom.operation.isCCW;
25

    
26
import java.awt.geom.PathIterator;
27

    
28
import org.gvsig.fmap.geom.Geometry;
29
import org.gvsig.fmap.geom.GeometryLocator;
30
import org.gvsig.fmap.geom.GeometryManager;
31
import org.gvsig.fmap.geom.operation.GeometryOperation;
32
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
33
import org.gvsig.fmap.geom.operation.GeometryOperationException;
34
import org.gvsig.fmap.geom.primitive.GeneralPathX;
35
import org.gvsig.fmap.geom.util.Converter;
36

    
37
import com.vividsolutions.jts.algorithm.CGAlgorithms;
38
import com.vividsolutions.jts.geom.Coordinate;
39
import com.vividsolutions.jts.geom.CoordinateList;
40

    
41
/**
42
 * This class checks if the first part from the General Path of a complex geometry is CCW.
43
 * @return Boolean <code>true<code> if is CCW
44
 * @author Carlos S?nchez Peri??n <a href = "mailto:csanchez@prodevelop.es"> e-mail </a>
45
 */
46
public class IsCCW extends GeometryOperation{
47
    public static final String NAME = "isCCW";
48
    private static GeometryManager geomManager = GeometryLocator.getGeometryManager();
49
    public static final int CODE = geomManager.getGeometryOperationCode(NAME);
50
        
51
        private GeneralPathX generalPathX = null;        
52
        
53
        public int getOperationIndex() {
54
                return CODE;
55
        }
56

    
57
        public Object invoke(Geometry geom, GeometryOperationContext ctx) throws GeometryOperationException {
58
                generalPathX = geom.getGeneralPath();
59
                if(generalPathX == null){
60
                        //if there isn't path the operation hasn't sense.
61
                        return null;
62
            }
63
                PathIterator theIterator = generalPathX.getPathIterator(null, geomManager.getFlatness()); //polyLine.getPathIterator(null, flatness);
64
                double[] theData = new double[6];
65
        Coordinate first = null;
66
        CoordinateList coordList = new CoordinateList();
67
        Coordinate c1;
68
        boolean bFirst = true;
69
                while (!theIterator.isDone()) {
70
                        //while not done
71
                        int type = theIterator.currentSegment(theData);
72
                switch (type)
73
                {
74
                case GeneralPathX.SEG_MOVETO:
75
                        c1= new Coordinate(theData[0], theData[1]);
76
                        if (bFirst == false) // Ya tenemos la primera parte.
77
                                break;
78
                        if (bFirst)
79
                        {
80
                                bFirst=false;
81
                                first = c1;
82
                        }
83
                        coordList.add(c1, true);
84
                        break;
85
                case GeneralPathX.SEG_LINETO:
86
                        c1= new Coordinate(theData[0], theData[1]);
87
                        coordList.add(c1, true);
88
                        break;
89

    
90
                }
91
                theIterator.next();
92
                }
93
                coordList.add(first, true);
94
                return new Boolean(CGAlgorithms.isCCW(coordList.toCoordinateArray()));
95
        }
96

    
97
}