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 / MultiLine2D.java @ 42278
History | View | Annotate | Download (4.32 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.aggregate; |
24 |
|
25 |
import java.util.Iterator; |
26 |
|
27 |
import org.gvsig.fmap.geom.Geometry; |
28 |
import org.gvsig.fmap.geom.GeometryException; |
29 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
30 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
31 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
32 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line2D; |
33 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
34 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
35 |
import org.gvsig.fmap.geom.primitive.Polygon; |
36 |
import org.gvsig.fmap.geom.primitive.Primitive; |
37 |
|
38 |
|
39 |
/**
|
40 |
* @author fdiaz
|
41 |
*
|
42 |
*/
|
43 |
public class MultiLine2D extends AbstractMultiLine { |
44 |
|
45 |
/**
|
46 |
*
|
47 |
*/
|
48 |
private static final long serialVersionUID = 13422301639354098L; |
49 |
|
50 |
/**
|
51 |
* @param type
|
52 |
* @param subtype
|
53 |
*/
|
54 |
public MultiLine2D() {
|
55 |
super(Geometry.SUBTYPES.GEOM2D);
|
56 |
} |
57 |
|
58 |
/* (non-Javadoc)
|
59 |
* @see org.gvsig.fmap.geom.aggregate.MultiLine#toPoints()
|
60 |
*/
|
61 |
public MultiPoint toPoints() throws GeometryException { |
62 |
MultiPoint multiPoint = new MultiPoint2D();
|
63 |
for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
64 |
Line2D line = (Line2D) iterator.next(); |
65 |
MultiPoint points = line.toPoints(); |
66 |
multiPoint.ensureCapacity(multiPoint.getPrimitivesNumber()+points.getPrimitivesNumber()); |
67 |
for(int i=0; i<points.getPrimitivesNumber(); i++){ |
68 |
multiPoint.addPoint(points.getPointAt(i)); |
69 |
} |
70 |
} |
71 |
return multiPoint;
|
72 |
} |
73 |
|
74 |
/* (non-Javadoc)
|
75 |
* @see org.gvsig.fmap.geom.aggregate.MultiLine#toLines()
|
76 |
*/
|
77 |
public MultiLine toLines() throws GeometryException { |
78 |
return this; |
79 |
} |
80 |
|
81 |
/* (non-Javadoc)
|
82 |
* @see org.gvsig.fmap.geom.aggregate.MultiLine#toPolygons()
|
83 |
*/
|
84 |
public MultiPolygon toPolygons() throws GeometryException { |
85 |
MultiPolygon multiPolygon = new MultiPolygon2D();
|
86 |
for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) { |
87 |
Line2D line = (Line2D) iterator.next(); |
88 |
MultiPolygon polygons = line.toPolygons(); |
89 |
multiPolygon.ensureCapacity(multiPolygon.getPrimitivesNumber()+polygons.getPrimitivesNumber()); |
90 |
for(int i=0; i<polygons.getPrimitivesNumber(); i++){ |
91 |
multiPolygon.addSurface((Polygon)polygons.getPrimitiveAt(i));
|
92 |
} |
93 |
} |
94 |
return multiPolygon;
|
95 |
} |
96 |
|
97 |
/* (non-Javadoc)
|
98 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
99 |
*/
|
100 |
public Geometry cloneGeometry() {
|
101 |
MultiLine2D clone = new MultiLine2D();
|
102 |
return clonePrimitives(clone);
|
103 |
} |
104 |
|
105 |
/* (non-Javadoc)
|
106 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
107 |
*/
|
108 |
public int getDimension() { |
109 |
return 2; |
110 |
} |
111 |
|
112 |
/* (non-Javadoc)
|
113 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
|
114 |
*/
|
115 |
public boolean is3D() { |
116 |
return false; |
117 |
} |
118 |
|
119 |
/* (non-Javadoc)
|
120 |
* @see org.gvsig.fmap.geom.jts.aggregate.AbstractMultiLine#fixLine(org.gvsig.fmap.geom.primitive.Line)
|
121 |
*/
|
122 |
@Override
|
123 |
protected Primitive fixPrimitive(Primitive primitive) {
|
124 |
if(!(primitive instanceof Line2D)){ |
125 |
String message = "Only Line2D primitives can be added to a MultiLine2D"; |
126 |
notifyDeprecated(message); |
127 |
throw new UnsupportedOperationException(message); |
128 |
} |
129 |
return primitive;
|
130 |
} |
131 |
|
132 |
} |