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 / aggregate / AbstractMultiLine.java @ 47432
History | View | Annotate | Download (4.46 KB)
1 | 42267 | 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.aggregate; |
||
24 | |||
25 | 47101 | fdiaz | import com.vividsolutions.jts.geom.LineString; |
26 | 42358 | fdiaz | import java.util.Collections; |
27 | 42274 | fdiaz | import java.util.Iterator; |
28 | 42283 | fdiaz | import org.gvsig.fmap.geom.Geometry; |
29 | 42267 | fdiaz | import org.gvsig.fmap.geom.aggregate.MultiLine; |
30 | 42274 | fdiaz | import org.gvsig.fmap.geom.jts.GeometryJTS; |
31 | import org.gvsig.fmap.geom.jts.util.JTSUtils; |
||
32 | 42281 | fdiaz | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
33 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
34 | 47101 | fdiaz | import org.gvsig.fmap.geom.primitive.Point; |
35 | 42274 | fdiaz | import org.gvsig.fmap.geom.primitive.Primitive; |
36 | 42267 | fdiaz | |
37 | |||
38 | /**
|
||
39 | * @author fdiaz
|
||
40 | *
|
||
41 | */
|
||
42 | public abstract class AbstractMultiLine extends AbstractMultiCurve implements MultiLine { |
||
43 | |||
44 | /**
|
||
45 | *
|
||
46 | */
|
||
47 | private static final long serialVersionUID = 3585059833766514177L; |
||
48 | |||
49 | public AbstractMultiLine(int subtype) { |
||
50 | 42283 | fdiaz | super(Geometry.TYPES.MULTILINE, subtype);
|
51 | 42267 | fdiaz | } |
52 | |||
53 | 42274 | fdiaz | |
54 | 44612 | jjdelcerro | @Override
|
55 | 42274 | fdiaz | public com.vividsolutions.jts.geom.Geometry getJTS() {
|
56 | 42283 | fdiaz | LineString[] lineStrings = new LineString[primitives.size()]; |
57 | for(int i=0; i<primitives.size(); i++){ |
||
58 | lineStrings[i]=(LineString) ((GeometryJTS)primitives.get(i)).getJTS(); |
||
59 | 42274 | fdiaz | } |
60 | 42283 | fdiaz | return JTSUtils.createJTSMultiLineString(lineStrings);
|
61 | 42274 | fdiaz | } |
62 | |||
63 | 44612 | jjdelcerro | @Override
|
64 | public Geometry force2D() throws GeometryOperationNotSupportedException, GeometryOperationException { |
||
65 | MultiLine2D other = new MultiLine2D();
|
||
66 | other.setProjection(this.getProjection());
|
||
67 | other.ensureCapacity(primitives.size()); |
||
68 | for (Primitive primitive : primitives) {
|
||
69 | 47432 | fdiaz | other.addPrimitive((Primitive)primitive.forceSubtype(Geometry.SUBTYPES.GEOM2D)); |
70 | 44612 | jjdelcerro | } |
71 | return other;
|
||
72 | } |
||
73 | |||
74 | @Override
|
||
75 | 47432 | fdiaz | public Geometry force2DM() throws GeometryOperationNotSupportedException, GeometryOperationException { |
76 | MultiLine2DM other = new MultiLine2DM();
|
||
77 | other.setProjection(this.getProjection());
|
||
78 | other.ensureCapacity(primitives.size()); |
||
79 | for (Primitive primitive : primitives) {
|
||
80 | other.addPrimitive((Primitive)primitive.forceSubtype(Geometry.SUBTYPES.GEOM2DM)); |
||
81 | } |
||
82 | return other;
|
||
83 | } |
||
84 | |||
85 | @Override
|
||
86 | public Geometry force3D() throws GeometryOperationNotSupportedException, GeometryOperationException { |
||
87 | MultiLine3D other = new MultiLine3D();
|
||
88 | other.setProjection(this.getProjection());
|
||
89 | other.ensureCapacity(primitives.size()); |
||
90 | for (Primitive primitive : primitives) {
|
||
91 | other.addPrimitive((Primitive)primitive.forceSubtype(Geometry.SUBTYPES.GEOM3D)); |
||
92 | } |
||
93 | return other;
|
||
94 | } |
||
95 | |||
96 | @Override
|
||
97 | public Geometry force3DM() throws GeometryOperationNotSupportedException, GeometryOperationException { |
||
98 | MultiLine3DM other = new MultiLine3DM();
|
||
99 | other.setProjection(this.getProjection());
|
||
100 | other.ensureCapacity(primitives.size()); |
||
101 | for (Primitive primitive : primitives) {
|
||
102 | other.addPrimitive((Primitive)primitive.forceSubtype(Geometry.SUBTYPES.GEOM3DM)); |
||
103 | } |
||
104 | return other;
|
||
105 | } |
||
106 | |||
107 | @Override
|
||
108 | 42281 | fdiaz | public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException { |
109 | for (Iterator iterator = primitives.iterator(); iterator.hasNext();) { |
||
110 | ((GeometryJTS)iterator.next()).flip(); |
||
111 | } |
||
112 | 42358 | fdiaz | Collections.reverse(primitives);
|
113 | 42281 | fdiaz | } |
114 | 47101 | fdiaz | |
115 | @Override
|
||
116 | public double getPathLength(Point point) { |
||
117 | return JTSUtils.getPathLengthFromLine(this, point); |
||
118 | } |
||
119 | |||
120 | @Override
|
||
121 | public Point extractPoint(double length) { |
||
122 | return JTSUtils.extractPointFromLine(this, length); |
||
123 | } |
||
124 | |||
125 | 42267 | fdiaz | } |