svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.spi / src / main / java / org / gvsig / exportto / swing / spi / ExportGeometryUtils.java @ 43920
History | View | Annotate | Download (4.72 KB)
1 | 43920 | jjdelcerro | package org.gvsig.exportto.swing.spi; |
---|---|---|---|
2 | |||
3 | import org.gvsig.exportto.swing.spi.options.ExportGeometryOptions; |
||
4 | import org.cresques.cts.ICoordTrans; |
||
5 | import org.gvsig.fmap.geom.Geometry; |
||
6 | |||
7 | /**
|
||
8 | *
|
||
9 | * @author jjdelcerro
|
||
10 | */
|
||
11 | public class ExportGeometryUtils { |
||
12 | |||
13 | public static class FixGeometryStatus { |
||
14 | |||
15 | public static final int STATE_OK = 0; |
||
16 | public static final int STATE_SKIP = 1; |
||
17 | public static final int STATE_ABORT = 2; |
||
18 | |||
19 | private Geometry geometry;
|
||
20 | private final int state; |
||
21 | private String message; |
||
22 | |||
23 | public FixGeometryStatus(Geometry geometry, int state) { |
||
24 | this.geometry = geometry;
|
||
25 | this.state = state;
|
||
26 | } |
||
27 | |||
28 | public FixGeometryStatus(Geometry geometry) {
|
||
29 | this.geometry = geometry;
|
||
30 | this.state = STATE_OK;
|
||
31 | } |
||
32 | |||
33 | public FixGeometryStatus(int state) { |
||
34 | this.geometry = null; |
||
35 | this.state = state;
|
||
36 | } |
||
37 | |||
38 | public FixGeometryStatus(int state, String message) { |
||
39 | this.geometry = null; |
||
40 | this.state = state;
|
||
41 | this.message = message;
|
||
42 | } |
||
43 | |||
44 | private void setGeometry(Geometry geometry) { |
||
45 | this.geometry = geometry;
|
||
46 | } |
||
47 | |||
48 | public Geometry getGeometry() {
|
||
49 | return this.geometry; |
||
50 | } |
||
51 | |||
52 | public int getState() { |
||
53 | return state;
|
||
54 | } |
||
55 | |||
56 | public String getMessage() { |
||
57 | return this.message; |
||
58 | } |
||
59 | |||
60 | } |
||
61 | |||
62 | public static FixGeometryStatus fixGeometry( |
||
63 | ExportGeometryOptions options, |
||
64 | ICoordTrans coord_trans, |
||
65 | Geometry geometry |
||
66 | ) { |
||
67 | Geometry.ValidationStatus geometryCheck; |
||
68 | FixGeometryStatus status; |
||
69 | |||
70 | if (geometry == null) { |
||
71 | return new FixGeometryStatus(geometry); |
||
72 | } |
||
73 | switch (options.getGeometryChecks()) {
|
||
74 | case ExportGeometryOptions.CHECKGEOMETRY_CHECK_IF_CORRUPT:
|
||
75 | geometryCheck = geometry.getValidationStatus(); |
||
76 | if (geometryCheck.isValid()) {
|
||
77 | status = new FixGeometryStatus(geometry);
|
||
78 | break;
|
||
79 | } |
||
80 | switch (options.getGeometryChecksAction()) {
|
||
81 | case ExportGeometryOptions.CHECKGEOMETRYACTION_SET_GEOMETRY_TO_NULL:
|
||
82 | status = new FixGeometryStatus(null); |
||
83 | break;
|
||
84 | case ExportGeometryOptions.CHECKGEOMETRYACTION_SKIP_FEATURE:
|
||
85 | status = new FixGeometryStatus(FixGeometryStatus.STATE_SKIP, geometryCheck.getMessage());
|
||
86 | break;
|
||
87 | case ExportGeometryOptions.CHECKGEOMETRYACTION_ABORT:
|
||
88 | default:
|
||
89 | status = new FixGeometryStatus(FixGeometryStatus.STATE_ABORT, geometryCheck.getMessage());
|
||
90 | break;
|
||
91 | } |
||
92 | break;
|
||
93 | |||
94 | case ExportGeometryOptions.CHECKGEOMETRY_CHECK_IF_VALID:
|
||
95 | geometryCheck = geometry.getValidationStatus(); |
||
96 | if (geometryCheck.isValid()) {
|
||
97 | status = new FixGeometryStatus(geometry);
|
||
98 | break;
|
||
99 | } |
||
100 | Geometry g; |
||
101 | if (options.getTryToFixGeometry()) {
|
||
102 | g = geometry.makeValid(); |
||
103 | if (g != null) { |
||
104 | status = new FixGeometryStatus(g);
|
||
105 | break;
|
||
106 | } |
||
107 | } |
||
108 | switch (options.getGeometryChecksAction()) {
|
||
109 | case ExportGeometryOptions.CHECKGEOMETRYACTION_SET_GEOMETRY_TO_NULL:
|
||
110 | status = new FixGeometryStatus(null); |
||
111 | break;
|
||
112 | case ExportGeometryOptions.CHECKGEOMETRYACTION_SKIP_FEATURE:
|
||
113 | status = new FixGeometryStatus(FixGeometryStatus.STATE_SKIP, geometryCheck.getMessage());
|
||
114 | break;
|
||
115 | case ExportGeometryOptions.CHECKGEOMETRYACTION_ABORT:
|
||
116 | default:
|
||
117 | status = new FixGeometryStatus(FixGeometryStatus.STATE_ABORT, geometryCheck.getMessage());
|
||
118 | break;
|
||
119 | } |
||
120 | break;
|
||
121 | |||
122 | case ExportGeometryOptions.CHECKGEOMETRY_NONE:
|
||
123 | default:
|
||
124 | status = new FixGeometryStatus(geometry);
|
||
125 | break;
|
||
126 | } |
||
127 | if (coord_trans != null) { |
||
128 | if (status.getState() == FixGeometryStatus.STATE_OK) {
|
||
129 | if (status.getGeometry() != null) { |
||
130 | Geometry reproj_geom = status.getGeometry().cloneGeometry(); |
||
131 | reproj_geom.reProject(coord_trans); |
||
132 | status.setGeometry(reproj_geom); |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | return status;
|
||
137 | } |
||
138 | } |