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