Statistics
| Revision:

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 / MultiLine3DM.java @ 45425

History | View | Annotate | Download (6.11 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.awt.Shape;
26
import java.awt.geom.AffineTransform;
27
import java.util.Iterator;
28

    
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
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line2D;
35
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3DM;
36
import org.gvsig.fmap.geom.operation.GeometryOperationException;
37
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
38
import org.gvsig.fmap.geom.primitive.Polygon;
39
import org.gvsig.fmap.geom.primitive.Primitive;
40

    
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
        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
    }
76

    
77
    /* (non-Javadoc)
78
     * @see org.gvsig.fmap.geom.aggregate.MultiLine#toLines()
79
     */
80
    public MultiLine toLines() throws GeometryException {
81
        return this;
82
    }
83

    
84
    /* (non-Javadoc)
85
     * @see org.gvsig.fmap.geom.aggregate.MultiLine#toPolygons()
86
     */
87
    public MultiPolygon toPolygons() throws GeometryException {
88
        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
    }
99

    
100
    /* (non-Javadoc)
101
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
102
     */
103
    public Geometry cloneGeometry() {
104
        MultiLine3DM clone = new MultiLine3DM();
105
        return clonePrimitives(clone);
106
    }
107

    
108

    
109
    /* (non-Javadoc)
110
     * @see org.gvsig.fmap.geom.Geometry#getDimension()
111
     */
112
    public int getDimension() {
113
        return 4;
114
    }
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

    
140
    /* (non-Javadoc)
141
     * @see org.gvsig.fmap.geom.jts.aggregate.AbstractMultiLine#fixLine(org.gvsig.fmap.geom.primitive.Line)
142
     */
143
    @Override
144
    protected Geometry fixPrimitive(Primitive primitive) {
145
        if(primitive instanceof Line3DM){
146
            return primitive;
147
        }
148

    
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
                LOGGER.warn(message);
155
                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
    }
163

    
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
}