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 / primitive / ring / Ring3DM.java @ 45762

History | View | Annotate | Download (6.51 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.primitive.ring;
24

    
25
import com.vividsolutions.jts.geom.Coordinate;
26
import com.vividsolutions.jts.geom.GeometryFactory;
27
import com.vividsolutions.jts.geom.LinearRing;
28
import com.vividsolutions.jts.geomgraph.Position;
29
import com.vividsolutions.jts.operation.buffer.BufferParameters;
30
import com.vividsolutions.jts.operation.buffer.OffsetCurveBuilder;
31

    
32
import org.cresques.cts.ICoordTrans;
33

    
34
import org.gvsig.fmap.geom.Geometry;
35
import org.gvsig.fmap.geom.GeometryException;
36
import org.gvsig.fmap.geom.aggregate.MultiLine;
37
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
38
import org.gvsig.fmap.geom.jts.aggregate.MultiLine2D;
39
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3DM;
40
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon2D;
41
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3DM;
42
import org.gvsig.fmap.geom.jts.primitive.curve.line.BaseLine3D;
43
import org.gvsig.fmap.geom.jts.primitive.curve.line.BaseLine3DM;
44
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line2DM;
45
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D;
46
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3DM;
47
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D;
48
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3DM;
49
import org.gvsig.fmap.geom.jts.util.JTSUtils;
50
import org.gvsig.fmap.geom.operation.GeometryOperationException;
51
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
52
import org.gvsig.fmap.geom.primitive.Ring;
53

    
54

    
55
/**
56
 * @author fdiaz
57
 *
58
 */
59
public class Ring3DM extends BaseLine3DM implements Ring {
60

    
61
    /**
62
     *
63
     */
64
    private static final long serialVersionUID = 1826148807887112314L;
65

    
66
    /**
67
     */
68
    public Ring3DM() {
69
        super(Geometry.TYPES.RING);
70
    }
71

    
72
    /**
73
     * @param coordinates
74
     */
75
    public Ring3DM(Coordinate[] coordinates) {
76
        super(Geometry.TYPES.RING, coordinates);
77
        closePrimitive();
78
    }
79

    
80
    /* (non-Javadoc)
81
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
82
     */
83
    public Geometry cloneGeometry() {
84
        return new Ring3DM(cloneCoordinates().toCoordinateArray());
85
    }
86

    
87

    
88
    /* (non-Javadoc)
89
     * @see org.gvsig.fmap.geom.primitive.Line#toLines()
90
     */
91
    public MultiLine toLines() throws GeometryException {
92
        MultiLine multiLine = new MultiLine3DM();
93
        multiLine.addPrimitive(new Line3DM(coordinates.toCoordinateArray()));
94
        return multiLine;
95
    }
96

    
97
    /* (non-Javadoc)
98
     * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
99
     */
100
    public MultiPolygon toPolygons() throws GeometryException {
101
        MultiPolygon multiPolygon = new MultiPolygon3DM();
102
        multiPolygon.addPrimitive(new Polygon3DM(coordinates.toCoordinateArray()));
103
        return multiPolygon;
104
    }
105

    
106
    /*
107
     * (non-Javadoc)
108
     *
109
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
110
     */
111
    public com.vividsolutions.jts.geom.Geometry getJTS() {
112
        return JTSUtils.createJTSLinearRing(coordinates);
113
    }
114

    
115
    /* (non-Javadoc)
116
    * @see org.gvsig.fmap.geom.Geometry#offset(double)
117
    */
118
      public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
119
          com.vividsolutions.jts.geom.LinearRing jtsRing = (LinearRing) getJTS();
120
          GeometryFactory factory = jtsRing.getFactory();
121
          BufferParameters bufParams = JTSUtils.getBufferParameters();
122

    
123
          OffsetCurveBuilder ocb = new OffsetCurveBuilder(factory.getPrecisionModel(), bufParams);
124

    
125
          Coordinate[] coordinates = jtsRing.getCoordinates();
126
          Coordinate[] coords = ocb.getRingCurve(coordinates, Position.LEFT, distance); // .getOffsetCurve(coordinates,
127

    
128
          return new Ring3DM(coords);
129
      }
130

    
131
      public Geometry offset(int joinStyle, double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
132
          com.vividsolutions.jts.geom.LinearRing jtsRing = (LinearRing) getJTS();
133
          GeometryFactory factory = jtsRing.getFactory();
134
          BufferParameters bufParams = JTSUtils.getBufferParameters(joinStyle, BufferParameters.CAP_FLAT);
135

    
136
          OffsetCurveBuilder ocb = new OffsetCurveBuilder(factory.getPrecisionModel(), bufParams);
137

    
138
          Coordinate[] coordinates = jtsRing.getCoordinates();
139
          Coordinate[] coords = ocb.getRingCurve(coordinates, Position.LEFT, distance); // .getOffsetCurve(coordinates,
140

    
141
          return new Ring3DM(coords);
142
      }
143

    
144

    
145
      /* (non-Javadoc)
146
       * @see org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#reProject(org.cresques.cts.ICoordTrans)
147
       */
148
      @Override
149
      public void reProject(ICoordTrans ct) {
150
          super.reProject(ct);
151
          if (coordinates.size()>=2 && !isClosed()) {
152
              closePrimitive();
153
          }
154
      }
155

    
156
      @Override
157
      public boolean equals(Object obj) {
158
          boolean res = super.equals(obj);
159
          if(res && obj instanceof Ring3DM){
160
              Ring3DM other = (Ring3DM)obj;
161
              if(this.getNumVertices() != other.getNumVertices()){
162
                  return false;
163
              }
164
              for(int i=0; i < this.getNumVertices(); i++){
165
                  Coordinate coordinate = this.coordinates.get(i);
166
                  Coordinate otherCoordinate = other.coordinates.get(i);
167
                  if (otherCoordinate.getOrdinate(2) != coordinate.getOrdinate(2)) {
168
                      return false;
169
                  }
170
                  if (otherCoordinate.getOrdinate(3) != coordinate.getOrdinate(3)) {
171
                      return false;
172
                  }
173
              }
174
              return true;
175
          } else {
176
              return false;
177
          }
178
      }
179
}