Statistics
| Revision:

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

History | View | Annotate | Download (6.24 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 org.cresques.cts.IProjection;
27
import org.gvsig.fmap.geom.aggregate.MultiLine;
28
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
29
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
30
import org.gvsig.fmap.geom.exception.CreateGeometryException;
31
import org.gvsig.fmap.geom.primitive.Envelope;
32
import org.gvsig.fmap.geom.primitive.Line;
33
import org.gvsig.fmap.geom.primitive.Point;
34
import org.gvsig.fmap.geom.primitive.Polygon;
35

    
36
/**
37
 *
38
 * @author jjdelcerro
39
 */
40
public class GeometryUtils {
41

    
42
    private GeometryUtils() {
43
        
44
    }
45
    
46
    public static boolean isSubtype(int geomTypeParent, int geomTypeChild) {
47
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
48
        return geomManager.isSubtype(geomTypeParent, geomTypeChild);
49
    }
50
    
51
    public static Envelope createEnvelope(int subType) {
52
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
53
        try {
54
            return geomManager.createEnvelope(subType);
55
        } catch (CreateEnvelopeException ex) {
56
            return null;
57
        }
58
    }
59
    
60
    public static Line createLine(int subType) {
61
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
62
        try {
63
            return geomManager.createLine(subType);
64
        } catch (CreateGeometryException ex) {
65
            return null;
66
        }
67
    }
68
    
69
    public static MultiLine createMultiLine(int subType) {
70
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
71
        try {
72
            return geomManager.createMultiLine(subType);
73
        } catch (CreateGeometryException ex) {
74
            return null;
75
        }
76
    }
77
    
78
    public static Polygon createPolygon(int subType) {
79
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
80
        try {
81
            return geomManager.createPolygon(subType);
82
        } catch (CreateGeometryException ex) {
83
            return null;
84
        }
85
    }
86
        
87
    public static MultiPolygon createMultiPolygon(int subType) {
88
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
89
        try {
90
            return geomManager.createMultiPolygon(subType);
91
        } catch (CreateGeometryException ex) {
92
            return null;
93
        }
94
    }
95
        
96
    public static Point createPoint(double x, double y) {
97
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
98
        try {
99
            return geomManager.createPoint(x, y, Geometry.SUBTYPES.GEOM2D);
100
        } catch (CreateGeometryException ex) {
101
            return null;
102
        }
103
    }
104
    
105
    public static Point createPoint(double x, double y, double z) {
106
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
107
        try {
108
            Point p = geomManager.createPoint(x, y, Geometry.SUBTYPES.GEOM3D);
109
            p.setCoordinateAt(Geometry.DIMENSIONS.Z, z);
110
            return p;
111
        } catch (CreateGeometryException ex) {
112
            return null;
113
        }
114
    }
115
    
116
    public static Point createPoint(double x, double y, double z, double m) {
117
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
118
        try {
119
            Point p = geomManager.createPoint(x, y, Geometry.SUBTYPES.GEOM3DM);
120
            p.setCoordinateAt(Geometry.DIMENSIONS.Z, z);
121
            p.setCoordinateAt(p.getDimension()-1, m);
122
            return p;
123
        } catch (CreateGeometryException ex) {
124
            return null;
125
        }
126
    }
127
    
128
    public static Geometry createFrom(Object data) {
129
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
130
        try {
131
            return geomManager.createFrom(data);
132
        } catch (GeometryException ex) {
133
            return null;
134
        }
135
    }
136
    
137
    public static Geometry createFrom(String wkt, String srs) {
138
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
139
        try {
140
            return geomManager.createFrom(wkt, srs);
141
        } catch (GeometryException ex) {
142
            return null;
143
        }
144
    }
145

    
146
    public static Geometry createFrom(String wkt, IProjection srs) {
147
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
148
        try {
149
            return geomManager.createFrom(wkt, srs);
150
        } catch (GeometryException ex) {
151
            return null;
152
        }
153
    }
154
    
155
    public static Geometry createFrom(String wkt) {
156
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
157
        try {
158
            return geomManager.createFrom(wkt);
159
        } catch (GeometryException ex) {
160
            return null;
161
        }
162
    }
163
    
164
    public static Object convertTo(Geometry geom, String format) {
165
        try {
166
            return geom.convertTo(format);
167
        } catch (Exception ex) {
168
            return null;
169
        }
170
    }
171
        
172
    public static String toWKT(Geometry geom) {
173
        try {
174
            return geom.convertToWKT();
175
        } catch (Exception ex) {
176
            return null;
177
        }
178
    }
179

    
180
    public static byte[] toWKB(Geometry geom) {
181
        try {
182
            return geom.convertToWKB();
183
        } catch (Exception ex) {
184
            return null;
185
        }
186
    }
187
    
188
    public static boolean intersects(Geometry geom1, Geometry geom2) {
189
        try {
190
            return geom1.intersects(geom2);
191
        } catch (Exception ex) {
192
            return false;
193
        }
194
    }
195

    
196
    
197
}