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

History | View | Annotate | Download (4.65 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.cresques.cts.ICoordTrans;
35

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

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

    
58
    /**
59
     *
60
     */
61
    private static final long serialVersionUID = 6640426694359410404L;
62

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

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

    
77
    /* (non-Javadoc)
78
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
79
     */
80
    public Geometry cloneGeometry() {
81
        return new Ring2D(cloneCoordinates().toCoordinateArray());
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
        return JTSUtils.createJTSLinearRing(coordinates);
109
    }
110

    
111

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

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

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

    
125
          return new Ring2D(coords);
126
      }
127

    
128

    
129
      /* (non-Javadoc)
130
       * @see org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#reProject(org.cresques.cts.ICoordTrans)
131
       */
132
      @Override
133
      public void reProject(ICoordTrans ct) {
134
          super.reProject(ct);
135
          if (coordinates.size()>=2 && !isClosed()) {
136
              closePrimitive();
137
          }
138
      }
139
}