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 / primitive / curve / line / BaseLine3DM.java @ 42309
History | View | Annotate | Download (6.1 KB)
1 | 42260 | fdiaz | /* 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.primitive.curve.line; |
||
24 | |||
25 | 42283 | fdiaz | import java.util.ArrayList; |
26 | 42269 | fdiaz | import java.util.Iterator; |
27 | |||
28 | 42260 | fdiaz | import com.vividsolutions.jts.geom.Coordinate; |
29 | 42267 | fdiaz | import com.vividsolutions.jts.geom.CoordinateSequence; |
30 | 42260 | fdiaz | |
31 | import org.gvsig.fmap.geom.Geometry; |
||
32 | 42269 | fdiaz | import org.gvsig.fmap.geom.GeometryException; |
33 | import org.gvsig.fmap.geom.aggregate.MultiLine; |
||
34 | import org.gvsig.fmap.geom.aggregate.MultiPoint; |
||
35 | import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
||
36 | 42304 | fdiaz | import org.gvsig.fmap.geom.jts.MCoordinate; |
37 | 42269 | fdiaz | import org.gvsig.fmap.geom.jts.aggregate.MultiLine3DM; |
38 | import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3DM; |
||
39 | import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3DM; |
||
40 | 42260 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.point.Point3D; |
41 | import org.gvsig.fmap.geom.jts.primitive.point.Point3DM; |
||
42 | 42269 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3DM; |
43 | 42267 | fdiaz | import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
44 | 42304 | fdiaz | import org.gvsig.fmap.geom.jts.util.JTSUtils; |
45 | 42267 | fdiaz | import org.gvsig.fmap.geom.jts.util.ReadOnlyCoordinates; |
46 | 42260 | fdiaz | import org.gvsig.fmap.geom.primitive.Point; |
47 | |||
48 | |||
49 | /**
|
||
50 | * @author fdiaz
|
||
51 | *
|
||
52 | */
|
||
53 | 42270 | fdiaz | public abstract class BaseLine3DM extends AbstractLine { |
54 | 42260 | fdiaz | |
55 | /**
|
||
56 | *
|
||
57 | */
|
||
58 | private static final long serialVersionUID = 1765763899814153661L; |
||
59 | |||
60 | /**
|
||
61 | * @param subtype
|
||
62 | */
|
||
63 | 42270 | fdiaz | protected BaseLine3DM() {
|
64 | 42260 | fdiaz | super(Geometry.SUBTYPES.GEOM3DM);
|
65 | 42283 | fdiaz | this.coordinates = new ArrayListCoordinateSequence(new ArrayList<Coordinate>()); |
66 | 42260 | fdiaz | } |
67 | |||
68 | /**
|
||
69 | *
|
||
70 | */
|
||
71 | 42270 | fdiaz | public BaseLine3DM(Coordinate[] coordinates) { |
72 | 42260 | fdiaz | this();
|
73 | this.coordinates = new ArrayListCoordinateSequence(new ReadOnlyCoordinates(coordinates)); |
||
74 | 42267 | fdiaz | if(coordinates.length<1){ |
75 | anyVertex = new Point3DM(0,0,0,0); |
||
76 | } else {
|
||
77 | Coordinate coordinate = coordinates[0];
|
||
78 | anyVertex = new Point3DM(coordinate.x, coordinate.y, coordinate.z, coordinate.getOrdinate(CoordinateSequence.M));
|
||
79 | } |
||
80 | |||
81 | 42260 | fdiaz | } |
82 | |||
83 | 42304 | fdiaz | /**
|
84 | * @param polygon
|
||
85 | * @param coordinates
|
||
86 | */
|
||
87 | public BaseLine3DM(int type, Coordinate[] coordinates) { |
||
88 | super(type, Geometry.SUBTYPES.GEOM3DM);
|
||
89 | initializeCoordinates(coordinates); |
||
90 | } |
||
91 | 42260 | fdiaz | |
92 | 42283 | fdiaz | /**
|
93 | 42304 | fdiaz | * @param coordinates
|
94 | */
|
||
95 | private void initializeCoordinates(Coordinate[] coordinates) { |
||
96 | this.coordinates = new ArrayListCoordinateSequence(new ReadOnlyCoordinates(coordinates)); |
||
97 | if(coordinates.length<1){ |
||
98 | anyVertex = new Point3DM(0,0,0,0); |
||
99 | } else {
|
||
100 | Coordinate coordinate = coordinates[0];
|
||
101 | anyVertex = new Point3DM(coordinate.x, coordinate.y, coordinate.z, coordinate.getOrdinate(CoordinateSequence.M));
|
||
102 | } |
||
103 | } |
||
104 | |||
105 | /**
|
||
106 | 42283 | fdiaz | * @param polygon
|
107 | */
|
||
108 | public BaseLine3DM(int type) { |
||
109 | super(type, Geometry.SUBTYPES.GEOM3DM);
|
||
110 | this.coordinates = new ArrayListCoordinateSequence(new ArrayList<Coordinate>()); |
||
111 | } |
||
112 | |||
113 | 42260 | fdiaz | /* (non-Javadoc)
|
114 | * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double)
|
||
115 | */
|
||
116 | public void addVertex(double x, double y) { |
||
117 | this.addVertex(x, y, 0);; |
||
118 | } |
||
119 | |||
120 | /* (non-Javadoc)
|
||
121 | * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double, double)
|
||
122 | */
|
||
123 | public void addVertex(double x, double y, double z) { |
||
124 | 42309 | fdiaz | this.coordinates.add(new Point3DM(x, y, z, 0).getJTSCoordinate()); |
125 | 42260 | fdiaz | } |
126 | |||
127 | /* (non-Javadoc)
|
||
128 | * @see org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org.gvsig.fmap.geom.primitive.Point)
|
||
129 | */
|
||
130 | @Override
|
||
131 | protected Point fixPoint(Point point) { |
||
132 | if (point instanceof Point3DM) { |
||
133 | return point;
|
||
134 | } else if (point instanceof Point3D) { |
||
135 | return new Point3DM(point.getX(), point.getY(), ((Point3D)point).getZ(), 0); |
||
136 | } else {
|
||
137 | return new Point3DM(point.getX(), point.getY(), 0, 0); |
||
138 | } |
||
139 | } |
||
140 | |||
141 | 42269 | fdiaz | /* (non-Javadoc)
|
142 | * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
|
||
143 | */
|
||
144 | public MultiPoint toPoints() throws GeometryException { |
||
145 | MultiPoint multiPoint = new MultiPoint3DM();
|
||
146 | 42271 | fdiaz | multiPoint.ensureCapacity(coordinates.size()); |
147 | for (Iterator<Coordinate> iterator = coordinates.iterator(); iterator.hasNext();) { |
||
148 | 42269 | fdiaz | Coordinate coordinate = (Coordinate) iterator.next(); |
149 | multiPoint.addPoint(new Point3DM(coordinate));
|
||
150 | } |
||
151 | return multiPoint;
|
||
152 | } |
||
153 | |||
154 | /*
|
||
155 | * (non-Javadoc)
|
||
156 | *
|
||
157 | * @see org.gvsig.fmap.geom.primitive.Line#toLines()
|
||
158 | */
|
||
159 | public MultiLine toLines() throws GeometryException { |
||
160 | MultiLine multiLine = new MultiLine3DM();
|
||
161 | multiLine.addPrimitive(this);
|
||
162 | return multiLine;
|
||
163 | } |
||
164 | |||
165 | /*
|
||
166 | * (non-Javadoc)
|
||
167 | *
|
||
168 | * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
|
||
169 | */
|
||
170 | public MultiPolygon toPolygons() throws GeometryException { |
||
171 | MultiPolygon multiPolygon = new MultiPolygon3DM();
|
||
172 | Polygon3DM polygon = new Polygon3DM(coordinates.toCoordinateArray());
|
||
173 | multiPolygon.addPrimitive(polygon); |
||
174 | return multiPolygon;
|
||
175 | } |
||
176 | 42283 | fdiaz | |
177 | |||
178 | /* (non-Javadoc)
|
||
179 | * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getVertex(int)
|
||
180 | */
|
||
181 | public Point getVertex(int index) { |
||
182 | Point3DM vertex = new Point3DM(this.coordinates.get(index)); |
||
183 | anyVertex = vertex; |
||
184 | return vertex;
|
||
185 | } |
||
186 | 42260 | fdiaz | } |