Statistics
| Revision:

svn-gvsig-desktop / branches / org.gvsig.desktop-cvsgis1 / 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 / MultiLine3DM.java @ 45267

History | View | Annotate | Download (6.11 KB)

1 42269 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
import java.awt.Shape;
26
import java.awt.geom.AffineTransform;
27 42271 fdiaz
import java.util.Iterator;
28 42269 fdiaz
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.fmap.geom.GeometryException;
31
import org.gvsig.fmap.geom.aggregate.MultiLine;
32
import org.gvsig.fmap.geom.aggregate.MultiPoint;
33
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
34 42441 fdiaz
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line2D;
35 42271 fdiaz
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3DM;
36 42441 fdiaz
import org.gvsig.fmap.geom.operation.GeometryOperationException;
37
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
38 42271 fdiaz
import org.gvsig.fmap.geom.primitive.Polygon;
39
import org.gvsig.fmap.geom.primitive.Primitive;
40 42269 fdiaz
41
42
/**
43
 * @author fdiaz
44
 *
45
 */
46
public class MultiLine3DM extends AbstractMultiLine {
47
48
    /**
49
     *
50
     */
51
    private static final long serialVersionUID = 6657425096939727574L;
52
53
    /**
54
     * @param type
55
     * @param subtype
56
     */
57
    public MultiLine3DM() {
58
        super(Geometry.SUBTYPES.GEOM3DM);
59
    }
60
61
    /* (non-Javadoc)
62
     * @see org.gvsig.fmap.geom.aggregate.MultiLine#toPoints()
63
     */
64
    public MultiPoint toPoints() throws GeometryException {
65 42271 fdiaz
        MultiPoint multiPoint = new MultiPoint3DM();
66
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
67
            Line3DM line = (Line3DM) iterator.next();
68
            MultiPoint points = line.toPoints();
69
            multiPoint.ensureCapacity(multiPoint.getPrimitivesNumber()+points.getPrimitivesNumber());
70
            for(int i=0; i<points.getPrimitivesNumber(); i++){
71
                multiPoint.addPoint(points.getPointAt(i));
72
            }
73
        }
74
        return multiPoint;
75 42269 fdiaz
    }
76
77
    /* (non-Javadoc)
78
     * @see org.gvsig.fmap.geom.aggregate.MultiLine#toLines()
79
     */
80
    public MultiLine toLines() throws GeometryException {
81 42271 fdiaz
        return this;
82 42269 fdiaz
    }
83
84
    /* (non-Javadoc)
85
     * @see org.gvsig.fmap.geom.aggregate.MultiLine#toPolygons()
86
     */
87
    public MultiPolygon toPolygons() throws GeometryException {
88 42271 fdiaz
        MultiPolygon multiPolygon = new MultiPolygon3DM();
89
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
90
            Line3DM line = (Line3DM) iterator.next();
91
            MultiPolygon polygons = line.toPolygons();
92
            multiPolygon.ensureCapacity(multiPolygon.getPrimitivesNumber()+polygons.getPrimitivesNumber());
93
            for(int i=0; i<polygons.getPrimitivesNumber(); i++){
94
                multiPolygon.addSurface((Polygon)polygons.getPrimitiveAt(i));
95
            }
96
        }
97
        return multiPolygon;
98 42269 fdiaz
    }
99
100
    /* (non-Javadoc)
101
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
102
     */
103
    public Geometry cloneGeometry() {
104 42274 fdiaz
        MultiLine3DM clone = new MultiLine3DM();
105
        return clonePrimitives(clone);
106 42269 fdiaz
    }
107
108
109
    /* (non-Javadoc)
110
     * @see org.gvsig.fmap.geom.Geometry#getDimension()
111
     */
112
    public int getDimension() {
113 42274 fdiaz
        return 4;
114 42269 fdiaz
    }
115
116
    /* (non-Javadoc)
117
     * @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
118
     */
119
    public Shape getShape(AffineTransform affineTransform) {
120
        // TODO Auto-generated method stub
121
        return null;
122
    }
123
124
    /* (non-Javadoc)
125
     * @see org.gvsig.fmap.geom.Geometry#getShape()
126
     */
127
    public Shape getShape() {
128
        // TODO Auto-generated method stub
129
        return null;
130
    }
131
132
    /* (non-Javadoc)
133
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
134
     */
135
    public boolean is3D() {
136
        return true;
137
    }
138
139 42271 fdiaz
140
    /* (non-Javadoc)
141
     * @see org.gvsig.fmap.geom.jts.aggregate.AbstractMultiLine#fixLine(org.gvsig.fmap.geom.primitive.Line)
142
     */
143
    @Override
144 42283 fdiaz
    protected Geometry fixPrimitive(Primitive primitive) {
145
        if(primitive instanceof Line3DM){
146
            return primitive;
147 42271 fdiaz
        }
148 42283 fdiaz
149
        if(primitive.getGeometryType().getSubType() == Geometry.SUBTYPES.GEOM3DM){
150
            try {
151
                return primitive.toLines();
152
            } catch (GeometryException e) {
153
                String message = "Can't convert primitive to lines";
154 45267 jjdelcerro
                LOGGER.warn(message);
155 42283 fdiaz
                throw new RuntimeException(message);
156
            }
157
        }
158
159
        String message = "Only 3DM primitives can be fixed to MultiLine3DM";
160
        notifyDeprecated(message);
161
        throw new UnsupportedOperationException(message);
162 42271 fdiaz
    }
163 42441 fdiaz
164
    /* (non-Javadoc)
165
     * @see org.gvsig.fmap.geom.Geometry#transform(java.awt.geom.AffineTransform)
166
     */
167
    public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
168
        MultiLine3DM result = new MultiLine3DM();
169
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
170
            Primitive primitive = (Primitive) iterator.next();
171
            Geometry offset = primitive.offset(distance);
172
            if(offset instanceof MultiLine){
173
                MultiLine multiOffset = (MultiLine)offset;
174
                for(int i=0; i<multiOffset.getPrimitivesNumber(); i++){
175
                    result.addPrimitive(multiOffset.getPrimitiveAt(i));
176
                }
177
            } else {
178
                result.addPrimitive((Primitive)primitive.offset(distance));
179
            }
180
        }
181
        return result;
182
    }
183 42269 fdiaz
}