Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / util / ArrayListCoordinateSequence.java @ 42697

History | View | Annotate | Download (5.74 KB)

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

    
25
import java.util.ArrayList;
26
import java.util.Collection;
27

    
28
import com.vividsolutions.jts.geom.Coordinate;
29
import com.vividsolutions.jts.geom.CoordinateSequence;
30
import com.vividsolutions.jts.geom.Envelope;
31

    
32
import org.gvsig.fmap.geom.jts.MCoordinate;
33

    
34
/**
35
 * @author fdiaz
36
 *
37
 */
38
public class ArrayListCoordinateSequence extends ArrayList<com.vividsolutions.jts.geom.Coordinate> implements com.vividsolutions.jts.geom.CoordinateSequence {
39

    
40

    
41
    /**
42
     *
43
     */
44
    private static final long serialVersionUID = -6406449425908120065L;
45

    
46
    /**
47
     *
48
     */
49
    public ArrayListCoordinateSequence(Collection<com.vividsolutions.jts.geom.Coordinate> coordinates) {
50
        super(coordinates);
51
    }
52

    
53
    /**
54
    *
55
    */
56
   public ArrayListCoordinateSequence() {
57
       super();
58
   }
59

    
60
    /* (non-Javadoc)
61
     * @see com.vividsolutions.jts.geom.CoordinateSequence#getDimension()
62
     */
63
    public int getDimension() {
64

    
65
        // FIXME: ?Esto es correcto?????
66

    
67
        com.vividsolutions.jts.geom.Coordinate c = get(0);
68
        if(c instanceof MCoordinate){
69
            if(Double.isNaN(c.z)){
70
                return 3;
71
            } else {
72
                return 4;
73
            }
74
        } else {
75
            if(Double.isNaN(c.z)){
76
                return 2;
77
            } else {
78
                return 3;
79
            }
80
        }
81
    }
82

    
83
    /* (non-Javadoc)
84
     * @see com.vividsolutions.jts.geom.CoordinateSequence#getCoordinate(int)
85
     */
86
    public com.vividsolutions.jts.geom.Coordinate getCoordinate(int i) {
87
        return (com.vividsolutions.jts.geom.Coordinate) get(i);
88
    }
89

    
90
    /* (non-Javadoc)
91
     * @see com.vividsolutions.jts.geom.CoordinateSequence#getCoordinateCopy(int)
92
     */
93
    public com.vividsolutions.jts.geom.Coordinate getCoordinateCopy(int i) {
94
        return (com.vividsolutions.jts.geom.Coordinate) ((com.vividsolutions.jts.geom.Coordinate)get(i)).clone();
95
    }
96

    
97
    /* (non-Javadoc)
98
     * @see com.vividsolutions.jts.geom.CoordinateSequence#getCoordinate(int, com.vividsolutions.jts.geom.Coordinate)
99
     */
100
    public void getCoordinate(int index, com.vividsolutions.jts.geom.Coordinate coord) {
101
        com.vividsolutions.jts.geom.Coordinate c = ((com.vividsolutions.jts.geom.Coordinate) get(index));
102
        coord.x = c.x;
103
        coord.y = c.y;
104
        coord.z = c.z;
105
        if(coord instanceof MCoordinate)  {
106
            if (c instanceof MCoordinate){
107
                ((MCoordinate)coord).m = ((MCoordinate)c).m;
108
            } else {
109
                ((MCoordinate)coord).m = Double.NaN;
110
            }
111
        }
112
    }
113

    
114
    /* (non-Javadoc)
115
     * @see com.vividsolutions.jts.geom.CoordinateSequence#getX(int)
116
     */
117
    public double getX(int index) {
118
        return ((com.vividsolutions.jts.geom.Coordinate) get(index)).x;
119
    }
120

    
121
    /* (non-Javadoc)
122
     * @see com.vividsolutions.jts.geom.CoordinateSequence#getY(int)
123
     */
124
    public double getY(int index) {
125
        return ((com.vividsolutions.jts.geom.Coordinate) get(index)).y;
126
    }
127

    
128
    /* (non-Javadoc)
129
     * @see com.vividsolutions.jts.geom.CoordinateSequence#getOrdinate(int, int)
130
     */
131
    public double getOrdinate(int index, int ordinateIndex) {
132
       com.vividsolutions.jts.geom.Coordinate c = ((com.vividsolutions.jts.geom.Coordinate) get(index));
133
       switch (ordinateIndex) {
134
          case CoordinateSequence.X:  return c.x;
135
          case CoordinateSequence.Y:  return c.y;
136
          case CoordinateSequence.Z:  return c.z;
137
          case CoordinateSequence.M:
138
              if(c instanceof MCoordinate)  {
139
                  return ((MCoordinate)c).m;
140
              }
141
        }
142
        return Double.NaN;
143
    }
144

    
145
    /* (non-Javadoc)
146
     * @see com.vividsolutions.jts.geom.CoordinateSequence#setOrdinate(int, int, double)
147
     */
148
    public void setOrdinate(int index, int ordinateIndex, double value) {
149
        ((com.vividsolutions.jts.geom.Coordinate) get(index)).setOrdinate(ordinateIndex, value);
150
    }
151

    
152
    /* (non-Javadoc)
153
     * @see com.vividsolutions.jts.geom.CoordinateSequence#toCoordinateArray()
154
     */
155
    public com.vividsolutions.jts.geom.Coordinate[] toCoordinateArray() {
156
        return ((com.vividsolutions.jts.geom.Coordinate[])(this.toArray(new Coordinate[this.size()])));
157
    }
158

    
159
    /* (non-Javadoc)
160
     * @see com.vividsolutions.jts.geom.CoordinateSequence#expandEnvelope(com.vividsolutions.jts.geom.Envelope)
161
     */
162
    public Envelope expandEnvelope(Envelope env) {
163
        for (int i = 0; i < this.size(); i++) {
164
            env.expandToInclude((com.vividsolutions.jts.geom.Coordinate) get(i));
165
        }
166
        return env;
167
    }
168

    
169
    @Override
170
    public Object clone() {
171
        ArrayListCoordinateSequence cloned = new ArrayListCoordinateSequence();
172
        for(com.vividsolutions.jts.geom.Coordinate item: this) {
173
            cloned.add((com.vividsolutions.jts.geom.Coordinate)item.clone());
174
        }
175
        return cloned;
176
    }
177
}