Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGPE-gvSIG / src / org / gvsig / fmap / drivers / gpe / model / GPECurve.java @ 27067

History | View | Annotate | Download (3.45 KB)

1
package org.gvsig.fmap.drivers.gpe.model;
2

    
3
import java.util.ArrayList;
4

    
5
import com.iver.cit.gvsig.fmap.core.FPolyline3D;
6
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
7
import com.iver.cit.gvsig.fmap.core.Handler;
8
import com.iver.cit.gvsig.fmap.core.IGeometry;
9
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
10

    
11
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
12
 *
13
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
14
 *
15
 * This program is free software; you can redistribute it and/or
16
 * modify it under the terms of the GNU General Public License
17
 * as published by the Free Software Foundation; either version 2
18
 * of the License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
28
 *
29
 * For more information, contact:
30
 *
31
 *  Generalitat Valenciana
32
 *   Conselleria d'Infraestructures i Transport
33
 *   Av. Blasco Ib??ez, 50
34
 *   46010 VALENCIA
35
 *   SPAIN
36
 *
37
 *      +34 963862235
38
 *   gvsig@gva.es
39
 *      www.gvsig.gva.es
40
 *
41
 *    or
42
 *
43
 *   IVER T.I. S.A
44
 *   Salamanca 50
45
 *   46005 Valencia
46
 *   Spain
47
 *
48
 *   +34 963163400
49
 *   dac@iver.es
50
 */
51
/* CVS MESSAGES:
52
 *
53
 * $Id$
54
 * $Log$
55
 *
56
 */
57
/**
58
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
59
 */
60
public class GPECurve extends GPEGeometry{
61
        private ArrayList segments = null;
62
        
63
        public GPECurve(String id, IGeometry geometry, String srs) {
64
                super(id, geometry, srs);                
65
                segments = new ArrayList();
66
        }
67
        
68
        public GPECurve(String id, String srs) {
69
                this(id, null, srs);                
70
        }
71
        
72
        /**
73
         * Adds a segment 
74
         * @param segment
75
         * The segment to add
76
         */
77
        public void addSegment(GPEGeometry segment){
78
                segments.add(segment);
79
        }
80
        
81
        /**
82
         * Gets a segment
83
         * @param i
84
         * The segment position
85
         * @return
86
         * A Segment
87
         */
88
        public GPEGeometry getSegmentAt(int i){
89
                return (GPEGeometry)segments.get(i);
90
        }
91
        
92
        /**
93
         * @return the number of seg
94
         */
95
        public int getSegmentsSize(){
96
                return segments.size();
97
        }
98
        
99
        /**
100
         * @return the geometry
101
         */
102
        public IGeometry getIGeometry() {
103
                IGeometry geom = super.getIGeometry();
104
                if (geom != null){
105
                        return geom;
106
                }
107
                GeneralPathX gpx = new GeneralPathX();
108
                int zLength = 0;
109
                boolean startPoint = true;
110
                for (int i=0 ; i<segments.size() ; i++){
111
                        IGeometry segment = ((GPEGeometry)segments.get(i)).getIGeometry();
112
                        Handler[] handlers = ((FPolyline3D)segment.getInternalShape()).getSelectHandlers();
113
                        zLength = zLength + handlers.length;
114
                        for (int j=0 ; j<handlers.length ; j++){
115
                                if (startPoint){
116
                                        gpx.moveTo(handlers[j].getPoint().getX(),
117
                                                        handlers[j].getPoint().getY());
118
                                        startPoint = false;
119
                                }else{
120
                                        gpx.lineTo(handlers[j].getPoint().getX(),
121
                                                        handlers[j].getPoint().getY());
122
                                }
123
                        }
124
                }
125
                //Copy the z coordinate
126
                double[] z = new double[zLength];
127
                int k = 0;
128
                for (int i=0 ; i<segments.size() ; i++){
129
                        IGeometry segment = ((GPEGeometry)segments.get(i)).getIGeometry();
130
                        double[] zAux = ((FPolyline3D)segment.getInternalShape()).getZs();
131
                        System.arraycopy(zAux, 0, z, k, zAux.length);
132
                        k = k + zAux.length;
133
                }
134
                geometry = ShapeFactory.createPolyline3D(gpx, z);
135
                return geometry;
136
        }        
137

    
138
}