gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.base / src / main / java / org / gvsig / geoprocess / algorithm / base / util / JTSFacade.java @ 175
History | View | Annotate | Download (4 KB)
1 |
/*
|
---|---|
2 |
* Created on 23-abr-2007
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: JTSFacade.java 12946 2007-08-07 15:08:11Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.1 2007-08-07 15:08:11 azabala
|
49 |
* new version in cvs. centralizes all jts stuff
|
50 |
*
|
51 |
*
|
52 |
*/
|
53 |
package org.gvsig.geoprocess.algorithm.base.util; |
54 |
|
55 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
56 |
|
57 |
import com.vividsolutions.jts.geom.Geometry; |
58 |
import com.vividsolutions.jts.geom.GeometryCollection; |
59 |
import com.vividsolutions.jts.geom.GeometryFactory; |
60 |
import com.vividsolutions.jts.precision.EnhancedPrecisionOp; |
61 |
|
62 |
/**
|
63 |
*
|
64 |
* Instead of calling individual methods of JTS (JTS Topology Suite),
|
65 |
* this singleton facade allows gvSIG users to centralize all JTS computational
|
66 |
* geometry operations in one only class.
|
67 |
*
|
68 |
* This is useful to ensure certain operations
|
69 |
* (for example, geoprocessing operations could cause robustness problems, so JTS
|
70 |
* allows to use enhanced precission operations, this facade forces to use these
|
71 |
* enhanced precision operations)
|
72 |
*
|
73 |
* @author alvaro zabala
|
74 |
*
|
75 |
*/
|
76 |
public class JTSFacade { |
77 |
|
78 |
public static Geometry computeBuffer(Geometry originalGeometry, double distance){ |
79 |
return EnhancedPrecisionOp.buffer(originalGeometry, distance);
|
80 |
} |
81 |
|
82 |
public static Geometry difference(Geometry geom1, Geometry geom2){ |
83 |
return EnhancedPrecisionOp.difference(geom1, geom2);
|
84 |
} |
85 |
|
86 |
public static Geometry symDifference(Geometry geom1, Geometry geom2){ |
87 |
return EnhancedPrecisionOp.symDifference(geom1, geom2);
|
88 |
} |
89 |
|
90 |
public static Geometry union(Geometry geom1, Geometry geom2){ |
91 |
return EnhancedPrecisionOp.union(geom1, geom2);
|
92 |
} |
93 |
|
94 |
public static Geometry union(Geometry[] geomArray, int geometryType){ |
95 |
if(geomArray.length == 0) |
96 |
return null; |
97 |
if(geomArray.length == 1) |
98 |
return geomArray[0]; |
99 |
if(geometryType == TYPES.SURFACE ||
|
100 |
geometryType == TYPES.CIRCLE || |
101 |
geometryType == TYPES.ELLIPSE) { |
102 |
GeometryFactory fact = geomArray[0].getFactory();
|
103 |
Geometry geomCol = fact.createGeometryCollection(geomArray); |
104 |
return computeBuffer(geomCol, 0d); |
105 |
} else {
|
106 |
Geometry unionResult = geomArray[0];
|
107 |
for(int i = 1; i < geomArray.length; i++) |
108 |
unionResult = union(unionResult, geomArray[i]); |
109 |
return unionResult;
|
110 |
} |
111 |
} |
112 |
|
113 |
public static Geometry intersection(Geometry geom1, Geometry geom2){ |
114 |
return EnhancedPrecisionOp.intersection(geom1, geom2);
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* Checks a JTS geometry to be null or NIL.
|
119 |
* NIL in jts is used to represent particular cases of geometries.
|
120 |
* (for example, an interior buffer that collapses a geometry).
|
121 |
* NIL is managed with a zero lenght GeometryCollection
|
122 |
* @param geometry
|
123 |
* @return
|
124 |
*/
|
125 |
public static boolean checkNull(Geometry geometry){ |
126 |
if(geometry == null) |
127 |
return true; |
128 |
if(geometry instanceof GeometryCollection){ |
129 |
GeometryCollection col = (GeometryCollection)geometry; |
130 |
if(col.getNumGeometries() < 1) |
131 |
return true; |
132 |
} |
133 |
return false; |
134 |
} |
135 |
|
136 |
|
137 |
} |
138 |
|