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 @ 42464
History | View | Annotate | Download (4.78 KB)
1 | 42274 | fdiaz | /* 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 | 42441 | fdiaz | 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 | 42274 | fdiaz | |
32 | 42464 | fdiaz | import org.cresques.cts.ICoordTrans; |
33 | |||
34 | 42274 | fdiaz | 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.Line3D; |
||
44 | import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3DM; |
||
45 | import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D; |
||
46 | import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3DM; |
||
47 | 42283 | fdiaz | import org.gvsig.fmap.geom.jts.util.JTSUtils; |
48 | 42441 | fdiaz | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
49 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
50 | 42274 | fdiaz | import org.gvsig.fmap.geom.primitive.Ring; |
51 | |||
52 | |||
53 | /**
|
||
54 | * @author fdiaz
|
||
55 | *
|
||
56 | */
|
||
57 | public class Ring3DM extends BaseLine3D implements Ring { |
||
58 | |||
59 | /**
|
||
60 | *
|
||
61 | */
|
||
62 | private static final long serialVersionUID = 1826148807887112314L; |
||
63 | |||
64 | /**
|
||
65 | */
|
||
66 | 42283 | fdiaz | public Ring3DM() {
|
67 | super(Geometry.TYPES.RING);
|
||
68 | 42274 | fdiaz | } |
69 | |||
70 | /**
|
||
71 | * @param coordinates
|
||
72 | */
|
||
73 | public Ring3DM(Coordinate[] coordinates) { |
||
74 | 42326 | fdiaz | super(Geometry.TYPES.RING, coordinates);
|
75 | 42274 | fdiaz | } |
76 | |||
77 | /* (non-Javadoc)
|
||
78 | * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
||
79 | */
|
||
80 | public Geometry cloneGeometry() {
|
||
81 | 42283 | fdiaz | return new Ring3DM(cloneCoordinates().toCoordinateArray()); |
82 | 42274 | fdiaz | } |
83 | |||
84 | |||
85 | /* (non-Javadoc)
|
||
86 | * @see org.gvsig.fmap.geom.primitive.Line#toLines()
|
||
87 | */
|
||
88 | public MultiLine toLines() throws GeometryException { |
||
89 | MultiLine multiLine = new MultiLine3DM();
|
||
90 | multiLine.addPrimitive(new Line3DM(coordinates.toCoordinateArray()));
|
||
91 | return multiLine;
|
||
92 | } |
||
93 | |||
94 | /* (non-Javadoc)
|
||
95 | * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
|
||
96 | */
|
||
97 | public MultiPolygon toPolygons() throws GeometryException { |
||
98 | MultiPolygon multiPolygon = new MultiPolygon3DM();
|
||
99 | multiPolygon.addPrimitive(new Polygon3DM(coordinates.toCoordinateArray()));
|
||
100 | return multiPolygon;
|
||
101 | } |
||
102 | |||
103 | 42283 | fdiaz | /*
|
104 | * (non-Javadoc)
|
||
105 | *
|
||
106 | * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
|
||
107 | */
|
||
108 | public com.vividsolutions.jts.geom.Geometry getJTS() {
|
||
109 | return JTSUtils.createJTSLinearRing(coordinates);
|
||
110 | } |
||
111 | 42441 | fdiaz | |
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 Ring3DM(coords); |
||
126 | } |
||
127 | 42464 | fdiaz | |
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 | 42274 | fdiaz | } |