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 / DefaultValidationStatus.java @ 42307
History | View | Annotate | Download (4.79 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 |
|
25 |
package org.gvsig.fmap.geom.jts; |
26 |
|
27 |
import com.vividsolutions.jts.geom.Coordinate; |
28 |
import com.vividsolutions.jts.operation.valid.TopologyValidationError; |
29 |
import org.gvsig.fmap.geom.Geometry; |
30 |
import org.gvsig.fmap.geom.GeometryLocator; |
31 |
import org.gvsig.fmap.geom.GeometryManager; |
32 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
33 |
import org.gvsig.fmap.geom.primitive.Point; |
34 |
import org.slf4j.Logger; |
35 |
import org.slf4j.LoggerFactory; |
36 |
|
37 |
public class DefaultValidationStatus implements Geometry.ValidationStatus { |
38 |
|
39 |
private static final Logger logger = LoggerFactory.getLogger(DefaultValidationStatus.class); |
40 |
|
41 |
private int statusCode = VALID; |
42 |
private Point problemLocation = null; |
43 |
private String message = null; |
44 |
|
45 |
public DefaultValidationStatus() {
|
46 |
|
47 |
} |
48 |
|
49 |
public DefaultValidationStatus(int code, String message) { |
50 |
this.statusCode = code;
|
51 |
this.message = message;
|
52 |
} |
53 |
|
54 |
public void setMesage(String message) { |
55 |
this.message = message;
|
56 |
} |
57 |
|
58 |
public void setStatusCode(int statusCode) { |
59 |
this.statusCode = statusCode;
|
60 |
} |
61 |
|
62 |
public void setValidationError(TopologyValidationError validationError) { |
63 |
if( validationError == null ) { |
64 |
statusCode = VALID; |
65 |
message = null;
|
66 |
problemLocation = null;
|
67 |
return;
|
68 |
} |
69 |
this.message = validationError.getMessage();
|
70 |
Coordinate coord = validationError.getCoordinate(); |
71 |
try {
|
72 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
73 |
if ( Double.isNaN(coord.z) ) { |
74 |
this.problemLocation = geomManager.createPoint(coord.x, coord.y, Geometry.SUBTYPES.GEOM2D);
|
75 |
} else {
|
76 |
this.problemLocation = geomManager.createPoint(coord.x, coord.y, Geometry.SUBTYPES.GEOM3D);
|
77 |
this.problemLocation.setCoordinateAt(2, coord.z); |
78 |
} |
79 |
} catch (CreateGeometryException ex) {
|
80 |
String coordstr;
|
81 |
try {
|
82 |
coordstr = coord.toString(); |
83 |
} catch (Exception ex1) { |
84 |
coordstr = "unknow";
|
85 |
} |
86 |
logger.warn("Can't create a point from jts Coordinate (" + coordstr + ").", ex); |
87 |
this.problemLocation = null; |
88 |
} |
89 |
switch (validationError.getErrorType()) {
|
90 |
case TopologyValidationError.DISCONNECTED_INTERIOR:
|
91 |
this.statusCode = DISCONNECTED_INTERIOR;
|
92 |
break;
|
93 |
case TopologyValidationError.DUPLICATE_RINGS:
|
94 |
this.statusCode = DUPLICATE_RINGS;
|
95 |
break;
|
96 |
case TopologyValidationError.HOLE_OUTSIDE_SHELL:
|
97 |
this.statusCode = HOLE_OUTSIDE_SHELL;
|
98 |
break;
|
99 |
case TopologyValidationError.INVALID_COORDINATE:
|
100 |
this.statusCode = INVALID_COORDINATE;
|
101 |
break;
|
102 |
case TopologyValidationError.NESTED_HOLES:
|
103 |
this.statusCode = NESTED_HOLES;
|
104 |
break;
|
105 |
case TopologyValidationError.NESTED_SHELLS:
|
106 |
this.statusCode = NESTED_SHELLS;
|
107 |
break;
|
108 |
case TopologyValidationError.RING_NOT_CLOSED:
|
109 |
this.statusCode = RING_NOT_CLOSED;
|
110 |
break;
|
111 |
case TopologyValidationError.RING_SELF_INTERSECTION:
|
112 |
this.statusCode = RING_SELF_INTERSECTION;
|
113 |
break;
|
114 |
case TopologyValidationError.SELF_INTERSECTION:
|
115 |
this.statusCode = SELF_INTERSECTION;
|
116 |
break;
|
117 |
case TopologyValidationError.TOO_FEW_POINTS:
|
118 |
this.statusCode = TOO_FEW_POINTS;
|
119 |
break;
|
120 |
default:
|
121 |
this.statusCode = UNKNOW;
|
122 |
break;
|
123 |
} |
124 |
} |
125 |
|
126 |
public boolean isValid() { |
127 |
return statusCode == VALID;
|
128 |
} |
129 |
|
130 |
public int getStatusCode() { |
131 |
return this.statusCode; |
132 |
} |
133 |
|
134 |
public Point getProblemLocation() { |
135 |
return this.problemLocation; |
136 |
} |
137 |
|
138 |
public String getMessage() { |
139 |
return this.message; |
140 |
} |
141 |
|
142 |
} |