gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.base / src / main / java / org / gvsig / geoprocess / algorithm / base / util / JTSFacade.java @ 245
History | View | Annotate | Download (3.71 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2012 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 2
|
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 |
/* CVS MESSAGES:
|
25 |
*
|
26 |
* $Id: JTSFacade.java 12946 2007-08-07 15:08:11Z azabala $
|
27 |
* $Log$
|
28 |
* Revision 1.1 2007-08-07 15:08:11 azabala
|
29 |
* new version in cvs. centralizes all jts stuff
|
30 |
*
|
31 |
*
|
32 |
*/
|
33 |
package org.gvsig.geoprocess.algorithm.base.util; |
34 |
|
35 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
36 |
|
37 |
import com.vividsolutions.jts.geom.Geometry; |
38 |
import com.vividsolutions.jts.geom.GeometryCollection; |
39 |
import com.vividsolutions.jts.geom.GeometryFactory; |
40 |
import com.vividsolutions.jts.precision.EnhancedPrecisionOp; |
41 |
|
42 |
/**
|
43 |
*
|
44 |
* Instead of calling individual methods of JTS (JTS Topology Suite),
|
45 |
* this singleton facade allows gvSIG users to centralize all JTS computational
|
46 |
* geometry operations in one only class.
|
47 |
*
|
48 |
* This is useful to ensure certain operations
|
49 |
* (for example, geoprocessing operations could cause robustness problems, so JTS
|
50 |
* allows to use enhanced precission operations, this facade forces to use these
|
51 |
* enhanced precision operations)
|
52 |
*
|
53 |
* @author alvaro zabala
|
54 |
*
|
55 |
*/
|
56 |
public class JTSFacade { |
57 |
|
58 |
public static Geometry computeBuffer(Geometry originalGeometry, double distance){ |
59 |
return EnhancedPrecisionOp.buffer(originalGeometry, distance);
|
60 |
} |
61 |
|
62 |
public static Geometry difference(Geometry geom1, Geometry geom2){ |
63 |
return EnhancedPrecisionOp.difference(geom1, geom2);
|
64 |
} |
65 |
|
66 |
public static Geometry symDifference(Geometry geom1, Geometry geom2){ |
67 |
return EnhancedPrecisionOp.symDifference(geom1, geom2);
|
68 |
} |
69 |
|
70 |
public static Geometry union(Geometry geom1, Geometry geom2){ |
71 |
return EnhancedPrecisionOp.union(geom1, geom2);
|
72 |
} |
73 |
|
74 |
public static Geometry union(Geometry[] geomArray, int geometryType){ |
75 |
if(geomArray.length == 0) |
76 |
return null; |
77 |
if(geomArray.length == 1) |
78 |
return geomArray[0]; |
79 |
if(geometryType == TYPES.SURFACE ||
|
80 |
geometryType == TYPES.CIRCLE || |
81 |
geometryType == TYPES.ELLIPSE) { |
82 |
GeometryFactory fact = geomArray[0].getFactory();
|
83 |
Geometry geomCol = fact.createGeometryCollection(geomArray); |
84 |
return computeBuffer(geomCol, 0d); |
85 |
} else {
|
86 |
Geometry unionResult = geomArray[0];
|
87 |
for(int i = 1; i < geomArray.length; i++) |
88 |
unionResult = union(unionResult, geomArray[i]); |
89 |
return unionResult;
|
90 |
} |
91 |
} |
92 |
|
93 |
public static Geometry intersection(Geometry geom1, Geometry geom2){ |
94 |
return EnhancedPrecisionOp.intersection(geom1, geom2);
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* Checks a JTS geometry to be null or NIL.
|
99 |
* NIL in jts is used to represent particular cases of geometries.
|
100 |
* (for example, an interior buffer that collapses a geometry).
|
101 |
* NIL is managed with a zero lenght GeometryCollection
|
102 |
* @param geometry
|
103 |
* @return
|
104 |
*/
|
105 |
public static boolean checkNull(Geometry geometry){ |
106 |
if(geometry == null) |
107 |
return true; |
108 |
if(geometry instanceof GeometryCollection){ |
109 |
GeometryCollection col = (GeometryCollection)geometry; |
110 |
if(col.getNumGeometries() < 1) |
111 |
return true; |
112 |
} |
113 |
return false; |
114 |
} |
115 |
|
116 |
|
117 |
} |
118 |
|