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