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 / Ring2D.java @ 47346

History | View | Annotate | Download (5.35 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

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

    
33
import org.cresques.cts.ICoordTrans;
34

    
35
import org.gvsig.fmap.geom.Geometry;
36
import org.gvsig.fmap.geom.GeometryException;
37
import org.gvsig.fmap.geom.aggregate.MultiLine;
38
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
39
import org.gvsig.fmap.geom.jts.aggregate.MultiLine2D;
40
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon2D;
41
import org.gvsig.fmap.geom.jts.primitive.curve.line.BaseLine2D;
42
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line2D;
43
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2D;
44
import org.gvsig.fmap.geom.jts.util.JTSUtils;
45
import org.gvsig.fmap.geom.operation.GeometryOperationException;
46
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
47
import org.gvsig.fmap.geom.primitive.Ring;
48

    
49
/**
50
 * @author fdiaz
51
 *
52
 */
53
public class Ring2D extends BaseLine2D implements Ring {
54

    
55
    /**
56
     *
57
     */
58
    private static final long serialVersionUID = 6640426694359410404L;
59

    
60
    /**
61
     * @param subtype
62
     */
63
    public Ring2D() {
64
        super(Geometry.TYPES.RING);
65
    }
66

    
67
    /**
68
     *
69
     */
70
    public Ring2D(Coordinate[] coordinates) {
71
        super(Geometry.TYPES.RING, coordinates);
72
    }
73

    
74
    /* (non-Javadoc)
75
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
76
     */
77
    @Override
78
    public Geometry cloneGeometry() {
79
        Ring2D clone = new Ring2D(cloneCoordinates().toCoordinateArray());
80
        clone.setProjection(this.getProjection());
81
        return clone;
82
    }
83

    
84
    /* (non-Javadoc)
85
     * @see org.gvsig.fmap.geom.primitive.Line#toLines()
86
     */
87
    public MultiLine toLines() throws GeometryException {
88
        MultiLine multiLine = new MultiLine2D();
89
        multiLine.addPrimitive(new Line2D(coordinates.toCoordinateArray()));
90
        return multiLine;
91
    }
92

    
93
    /* (non-Javadoc)
94
     * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
95
     */
96
    public MultiPolygon toPolygons() throws GeometryException {
97
        MultiPolygon multiPolygon = new MultiPolygon2D();
98
        multiPolygon.addPrimitive(new Polygon2D(coordinates.toCoordinateArray()));
99
        return multiPolygon;
100
    }
101

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

    
112

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

    
121
          OffsetCurveBuilder ocb = new OffsetCurveBuilder(factory.getPrecisionModel(), bufParams);
122

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

    
126
          return new Ring2D(coords);
127
      }
128

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

    
134
          OffsetCurveBuilder ocb = new OffsetCurveBuilder(factory.getPrecisionModel(), bufParams);
135

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

    
139
          return new Ring2D(coords);
140
      }
141

    
142

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