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 @ 42441

History | View | Annotate | Download (4.28 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 java.util.Iterator;
26

    
27
import com.vividsolutions.jts.geom.Coordinate;
28
import com.vividsolutions.jts.geom.GeometryFactory;
29
import com.vividsolutions.jts.geom.LinearRing;
30
import com.vividsolutions.jts.geomgraph.Position;
31
import com.vividsolutions.jts.operation.buffer.BufferParameters;
32
import com.vividsolutions.jts.operation.buffer.OffsetCurveBuilder;
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.GeometryJTS;
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.Polygon;
48
import org.gvsig.fmap.geom.primitive.Ring;
49

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

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

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

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

    
75
    /* (non-Javadoc)
76
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
77
     */
78
    public Geometry cloneGeometry() {
79
        return new Ring2D(cloneCoordinates().toCoordinateArray());
80
    }
81

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

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

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

    
109

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

    
118
          OffsetCurveBuilder ocb = new OffsetCurveBuilder(factory.getPrecisionModel(), bufParams);
119

    
120
          Coordinate[] coordinates = jtsRing.getCoordinates();
121
          Coordinate[] coords = ocb.getRingCurve(coordinates, Position.LEFT, distance); // .getOffsetCurve(coordinates,
122

    
123
          return new Ring2D(coords);
124
      }
125
}