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