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 @ 44612
History | View | Annotate | Download (5.84 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 |
public ArrayListCoordinateSequence(int initialCapacity) { |
61 |
super(initialCapacity);
|
62 |
} |
63 |
|
64 |
/* (non-Javadoc)
|
65 |
* @see com.vividsolutions.jts.geom.CoordinateSequence#getDimension()
|
66 |
*/
|
67 |
public int getDimension() { |
68 |
|
69 |
// FIXME: ?Esto es correcto?????
|
70 |
|
71 |
com.vividsolutions.jts.geom.Coordinate c = get(0);
|
72 |
if(c instanceof MCoordinate){ |
73 |
if(Double.isNaN(c.z)){ |
74 |
return 3; |
75 |
} else {
|
76 |
return 4; |
77 |
} |
78 |
} else {
|
79 |
if(Double.isNaN(c.z)){ |
80 |
return 2; |
81 |
} else {
|
82 |
return 3; |
83 |
} |
84 |
} |
85 |
} |
86 |
|
87 |
/* (non-Javadoc)
|
88 |
* @see com.vividsolutions.jts.geom.CoordinateSequence#getCoordinate(int)
|
89 |
*/
|
90 |
public com.vividsolutions.jts.geom.Coordinate getCoordinate(int i) { |
91 |
return (com.vividsolutions.jts.geom.Coordinate) get(i);
|
92 |
} |
93 |
|
94 |
/* (non-Javadoc)
|
95 |
* @see com.vividsolutions.jts.geom.CoordinateSequence#getCoordinateCopy(int)
|
96 |
*/
|
97 |
public com.vividsolutions.jts.geom.Coordinate getCoordinateCopy(int i) { |
98 |
return (com.vividsolutions.jts.geom.Coordinate) ((com.vividsolutions.jts.geom.Coordinate)get(i)).clone();
|
99 |
} |
100 |
|
101 |
/* (non-Javadoc)
|
102 |
* @see com.vividsolutions.jts.geom.CoordinateSequence#getCoordinate(int, com.vividsolutions.jts.geom.Coordinate)
|
103 |
*/
|
104 |
public void getCoordinate(int index, com.vividsolutions.jts.geom.Coordinate coord) { |
105 |
com.vividsolutions.jts.geom.Coordinate c = ((com.vividsolutions.jts.geom.Coordinate) get(index)); |
106 |
coord.x = c.x; |
107 |
coord.y = c.y; |
108 |
coord.z = c.z; |
109 |
if(coord instanceof MCoordinate) { |
110 |
if (c instanceof MCoordinate){ |
111 |
((MCoordinate)coord).m = ((MCoordinate)c).m; |
112 |
} else {
|
113 |
((MCoordinate)coord).m = Double.NaN;
|
114 |
} |
115 |
} |
116 |
} |
117 |
|
118 |
/* (non-Javadoc)
|
119 |
* @see com.vividsolutions.jts.geom.CoordinateSequence#getX(int)
|
120 |
*/
|
121 |
public double getX(int index) { |
122 |
return ((com.vividsolutions.jts.geom.Coordinate) get(index)).x;
|
123 |
} |
124 |
|
125 |
/* (non-Javadoc)
|
126 |
* @see com.vividsolutions.jts.geom.CoordinateSequence#getY(int)
|
127 |
*/
|
128 |
public double getY(int index) { |
129 |
return ((com.vividsolutions.jts.geom.Coordinate) get(index)).y;
|
130 |
} |
131 |
|
132 |
/* (non-Javadoc)
|
133 |
* @see com.vividsolutions.jts.geom.CoordinateSequence#getOrdinate(int, int)
|
134 |
*/
|
135 |
public double getOrdinate(int index, int ordinateIndex) { |
136 |
com.vividsolutions.jts.geom.Coordinate c = ((com.vividsolutions.jts.geom.Coordinate) get(index)); |
137 |
switch (ordinateIndex) {
|
138 |
case CoordinateSequence.X: return c.x; |
139 |
case CoordinateSequence.Y: return c.y; |
140 |
case CoordinateSequence.Z: return c.z; |
141 |
case CoordinateSequence.M:
|
142 |
if(c instanceof MCoordinate) { |
143 |
return ((MCoordinate)c).m;
|
144 |
} |
145 |
} |
146 |
return Double.NaN; |
147 |
} |
148 |
|
149 |
/* (non-Javadoc)
|
150 |
* @see com.vividsolutions.jts.geom.CoordinateSequence#setOrdinate(int, int, double)
|
151 |
*/
|
152 |
public void setOrdinate(int index, int ordinateIndex, double value) { |
153 |
((com.vividsolutions.jts.geom.Coordinate) get(index)).setOrdinate(ordinateIndex, value); |
154 |
} |
155 |
|
156 |
/* (non-Javadoc)
|
157 |
* @see com.vividsolutions.jts.geom.CoordinateSequence#toCoordinateArray()
|
158 |
*/
|
159 |
public com.vividsolutions.jts.geom.Coordinate[] toCoordinateArray() { |
160 |
return ((com.vividsolutions.jts.geom.Coordinate[])(this.toArray(new Coordinate[this.size()]))); |
161 |
} |
162 |
|
163 |
/* (non-Javadoc)
|
164 |
* @see com.vividsolutions.jts.geom.CoordinateSequence#expandEnvelope(com.vividsolutions.jts.geom.Envelope)
|
165 |
*/
|
166 |
public Envelope expandEnvelope(Envelope env) {
|
167 |
for (int i = 0; i < this.size(); i++) { |
168 |
env.expandToInclude((com.vividsolutions.jts.geom.Coordinate) get(i)); |
169 |
} |
170 |
return env;
|
171 |
} |
172 |
|
173 |
@Override
|
174 |
public Object clone() { |
175 |
ArrayListCoordinateSequence cloned = new ArrayListCoordinateSequence();
|
176 |
for(com.vividsolutions.jts.geom.Coordinate item: this) { |
177 |
cloned.add((com.vividsolutions.jts.geom.Coordinate)item.clone()); |
178 |
} |
179 |
return cloned;
|
180 |
} |
181 |
} |