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