svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.api / src / main / java / org / gvsig / fmap / geom / GeometryUtils.java @ 44192
History | View | Annotate | Download (7.02 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.geom; |
25 |
|
26 |
import java.util.logging.Level; |
27 |
import java.util.logging.Logger; |
28 |
import org.cresques.cts.IProjection; |
29 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
30 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
31 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
32 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
33 |
import org.gvsig.fmap.geom.primitive.Envelope; |
34 |
import org.gvsig.fmap.geom.primitive.Line; |
35 |
import org.gvsig.fmap.geom.primitive.Point; |
36 |
import org.gvsig.fmap.geom.primitive.Polygon; |
37 |
import org.gvsig.fmap.geom.type.GeometryType; |
38 |
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
39 |
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
40 |
|
41 |
/**
|
42 |
*
|
43 |
* @author jjdelcerro
|
44 |
*/
|
45 |
@SuppressWarnings("UseSpecificCatch") |
46 |
public class GeometryUtils { |
47 |
|
48 |
private GeometryUtils() {
|
49 |
|
50 |
} |
51 |
|
52 |
public static GeometryType getGeometryType(int geometryType, int geometrySubType) { |
53 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
54 |
try {
|
55 |
return geomManager.getGeometryType(geometryType, geometrySubType);
|
56 |
} catch (Exception ex) { |
57 |
return null; |
58 |
} |
59 |
} |
60 |
|
61 |
public static boolean isSubtype(int geomTypeParent, int geomTypeChild) { |
62 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
63 |
return geomManager.isSubtype(geomTypeParent, geomTypeChild);
|
64 |
} |
65 |
|
66 |
public static Envelope createEnvelope(int subType) { |
67 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
68 |
try {
|
69 |
return geomManager.createEnvelope(subType);
|
70 |
} catch (CreateEnvelopeException ex) {
|
71 |
return null; |
72 |
} |
73 |
} |
74 |
|
75 |
public static Line createLine(int subType) { |
76 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
77 |
try {
|
78 |
return geomManager.createLine(subType);
|
79 |
} catch (CreateGeometryException ex) {
|
80 |
return null; |
81 |
} |
82 |
} |
83 |
|
84 |
public static MultiLine createMultiLine(int subType) { |
85 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
86 |
try {
|
87 |
return geomManager.createMultiLine(subType);
|
88 |
} catch (CreateGeometryException ex) {
|
89 |
return null; |
90 |
} |
91 |
} |
92 |
|
93 |
public static Polygon createPolygon(int subType) { |
94 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
95 |
try {
|
96 |
return geomManager.createPolygon(subType);
|
97 |
} catch (CreateGeometryException ex) {
|
98 |
return null; |
99 |
} |
100 |
} |
101 |
|
102 |
public static MultiPolygon createMultiPolygon(int subType) { |
103 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
104 |
try {
|
105 |
return geomManager.createMultiPolygon(subType);
|
106 |
} catch (CreateGeometryException ex) {
|
107 |
return null; |
108 |
} |
109 |
} |
110 |
|
111 |
public static Point createPoint(double x, double y) { |
112 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
113 |
try {
|
114 |
return geomManager.createPoint(x, y, Geometry.SUBTYPES.GEOM2D);
|
115 |
} catch (CreateGeometryException ex) {
|
116 |
return null; |
117 |
} |
118 |
} |
119 |
|
120 |
public static Point createPoint(double x, double y, double z) { |
121 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
122 |
try {
|
123 |
Point p = geomManager.createPoint(x, y, Geometry.SUBTYPES.GEOM3D);
|
124 |
p.setCoordinateAt(Geometry.DIMENSIONS.Z, z); |
125 |
return p;
|
126 |
} catch (CreateGeometryException ex) {
|
127 |
return null; |
128 |
} |
129 |
} |
130 |
|
131 |
public static Point createPoint(double x, double y, double z, double m) { |
132 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
133 |
try {
|
134 |
Point p = geomManager.createPoint(x, y, Geometry.SUBTYPES.GEOM3DM);
|
135 |
p.setCoordinateAt(Geometry.DIMENSIONS.Z, z); |
136 |
p.setCoordinateAt(p.getDimension()-1, m);
|
137 |
return p;
|
138 |
} catch (CreateGeometryException ex) {
|
139 |
return null; |
140 |
} |
141 |
} |
142 |
|
143 |
public static Geometry createFrom(Object data) { |
144 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
145 |
try {
|
146 |
return geomManager.createFrom(data);
|
147 |
} catch (GeometryException ex) {
|
148 |
return null; |
149 |
} |
150 |
} |
151 |
|
152 |
public static Geometry createFrom(String wkt, String srs) { |
153 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
154 |
try {
|
155 |
return geomManager.createFrom(wkt, srs);
|
156 |
} catch (GeometryException ex) {
|
157 |
return null; |
158 |
} |
159 |
} |
160 |
|
161 |
public static Geometry createFrom(String wkt, IProjection srs) { |
162 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
163 |
try {
|
164 |
return geomManager.createFrom(wkt, srs);
|
165 |
} catch (GeometryException ex) {
|
166 |
return null; |
167 |
} |
168 |
} |
169 |
|
170 |
public static Geometry createFrom(String wkt) { |
171 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
172 |
try {
|
173 |
return geomManager.createFrom(wkt);
|
174 |
} catch (GeometryException ex) {
|
175 |
return null; |
176 |
} |
177 |
} |
178 |
|
179 |
public static Object convertTo(Geometry geom, String format) { |
180 |
try {
|
181 |
return geom.convertTo(format);
|
182 |
} catch (Exception ex) { |
183 |
return null; |
184 |
} |
185 |
} |
186 |
|
187 |
public static String toWKT(Geometry geom) { |
188 |
try {
|
189 |
return geom.convertToWKT();
|
190 |
} catch (Exception ex) { |
191 |
return null; |
192 |
} |
193 |
} |
194 |
|
195 |
public static byte[] toWKB(Geometry geom) { |
196 |
try {
|
197 |
return geom.convertToWKB();
|
198 |
} catch (Exception ex) { |
199 |
return null; |
200 |
} |
201 |
} |
202 |
|
203 |
public static byte[] toEWKB(Geometry geom) { |
204 |
try {
|
205 |
return geom.convertToEWKB();
|
206 |
} catch (Exception ex) { |
207 |
return null; |
208 |
} |
209 |
} |
210 |
|
211 |
public static boolean intersects(Geometry geom1, Geometry geom2) { |
212 |
try {
|
213 |
return geom1.intersects(geom2);
|
214 |
} catch (Exception ex) { |
215 |
return false; |
216 |
} |
217 |
} |
218 |
|
219 |
|
220 |
} |