Revision 969
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.89/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/buildNumber.properties | ||
---|---|---|
1 |
#Tue Oct 15 23:47:24 CEST 2019 |
|
2 |
buildNumber=2191 |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.89/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.gpe.exportto.kml.ExportKMLLibrary |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.89/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<!-- |
|
2 |
|
|
3 |
gvSIG. Desktop Geographic Information System. |
|
4 |
|
|
5 |
Copyright (C) 2007-2013 gvSIG Association. |
|
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
|
8 |
modify it under the terms of the GNU General Public License |
|
9 |
as published by the Free Software Foundation; either version 3 |
|
10 |
of the License, or (at your option) any later version. |
|
11 |
|
|
12 |
This program is distributed in the hope that it will be useful, |
|
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
GNU General Public License for more details. |
|
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
|
18 |
along with this program; if not, write to the Free Software |
|
19 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
20 |
MA 02110-1301, USA. |
|
21 |
|
|
22 |
For any additional information, do not hesitate to contact us |
|
23 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
24 |
|
|
25 |
--> |
|
26 |
<assembly> |
|
27 |
<id>gvsig-plugin-package</id> |
|
28 |
<formats> |
|
29 |
<format>zip</format> |
|
30 |
</formats> |
|
31 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
32 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
33 |
<files> |
|
34 |
<file> |
|
35 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
36 |
<outputDirectory>lib</outputDirectory> |
|
37 |
</file> |
|
38 |
<file> |
|
39 |
<source>target/package.info</source> |
|
40 |
</file> |
|
41 |
</files> |
|
42 |
|
|
43 |
<fileSets> |
|
44 |
<fileSet> |
|
45 |
<directory>src/main/resources-plugin</directory> |
|
46 |
<outputDirectory>.</outputDirectory> |
|
47 |
</fileSet> |
|
48 |
</fileSets> |
|
49 |
|
|
50 |
<dependencySets> |
|
51 |
<dependencySet> |
|
52 |
<useProjectArtifact>false</useProjectArtifact> |
|
53 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
54 |
<outputDirectory>lib</outputDirectory> |
|
55 |
<includes> |
|
56 |
<include>org.gvsig:org.gvsig.gpe.exportto.generic</include> |
|
57 |
</includes> |
|
58 |
</dependencySet> |
|
59 |
</dependencySets> |
|
60 |
|
|
61 |
</assembly> |
|
62 |
|
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.89/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/swing/ExportKMLPanels.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package org.gvsig.gpe.exportto.kml.swing; |
|
7 |
|
|
8 |
import org.gvsig.export.ExportParameters; |
|
9 |
import org.gvsig.export.swing.ExportSwingLocator; |
|
10 |
import org.gvsig.export.swing.JExportProcessPanel; |
|
11 |
import org.gvsig.export.swing.spi.AbstractExportPanels; |
|
12 |
import org.gvsig.export.swing.spi.ExportPanels; |
|
13 |
import org.gvsig.export.swing.spi.ExportPanelsFactory; |
|
14 |
import org.gvsig.export.swing.spi.ExportPanelsManager; |
|
15 |
import org.gvsig.gpe.exportto.kml.swing.panels.KMLPanel; |
|
16 |
|
|
17 |
/** |
|
18 |
* |
|
19 |
* @author osc |
|
20 |
*/ |
|
21 |
public class ExportKMLPanels |
|
22 |
extends AbstractExportPanels |
|
23 |
implements ExportPanels { |
|
24 |
|
|
25 |
ExportKMLPanels( |
|
26 |
ExportPanelsFactory factory, |
|
27 |
JExportProcessPanel processPanel, |
|
28 |
ExportParameters parameters |
|
29 |
) { |
|
30 |
super(factory, processPanel, parameters); |
|
31 |
this.initPanels(); |
|
32 |
} |
|
33 |
|
|
34 |
private void initPanels() { |
|
35 |
ExportPanelsManager manager = ExportSwingLocator.getExportPanelsManager(); |
|
36 |
|
|
37 |
this.add( |
|
38 |
new KMLPanel( |
|
39 |
this.getProcessPanel(), |
|
40 |
this.getParameters() |
|
41 |
) |
|
42 |
); |
|
43 |
this.add(manager.createStandardPanel( |
|
44 |
ExportPanelsManager.PANEL_ATTRIBUTES_SELECTION, |
|
45 |
this.getProcessPanel(), |
|
46 |
this.getParameters() |
|
47 |
) |
|
48 |
); |
|
49 |
|
|
50 |
this.add(manager.createStandardPanel( |
|
51 |
ExportPanelsManager.PANEL_SELECT_OUTPUT_FILE, |
|
52 |
this.getProcessPanel(), |
|
53 |
this.getParameters() |
|
54 |
) |
|
55 |
); |
|
56 |
} |
|
57 |
|
|
58 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.89/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/swing/ExportKMLPanelsFactory.java | ||
---|---|---|
1 |
package org.gvsig.gpe.exportto.kml.swing; |
|
2 |
|
|
3 |
import org.gvsig.export.ExportParameters; |
|
4 |
import org.gvsig.export.swing.JExportProcessPanel; |
|
5 |
import org.gvsig.export.swing.spi.AbstractExportPanelsFactory; |
|
6 |
import org.gvsig.export.swing.spi.ExportPanels; |
|
7 |
import org.gvsig.export.swing.spi.ExportPanelsFactory; |
|
8 |
import org.gvsig.gpe.exportto.kml.service.ExportKMLServiceFactory; |
|
9 |
|
|
10 |
/** |
|
11 |
* |
|
12 |
* @author jjdelcerro |
|
13 |
*/ |
|
14 |
public class ExportKMLPanelsFactory |
|
15 |
extends AbstractExportPanelsFactory |
|
16 |
implements ExportPanelsFactory { |
|
17 |
|
|
18 |
public ExportKMLPanelsFactory() { |
|
19 |
super(ExportKMLServiceFactory.SERVICE_NAME); |
|
20 |
} |
|
21 |
|
|
22 |
@Override |
|
23 |
public ExportPanels createPanels(JExportProcessPanel processPanel, ExportParameters parameters) { |
|
24 |
return new ExportKMLPanels(this, processPanel, parameters); |
|
25 |
} |
|
26 |
|
|
27 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.89/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/swing/panels/KMLPanelView.java | ||
---|---|---|
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 |
package org.gvsig.gpe.exportto.kml.swing.panels; |
|
25 |
|
|
26 |
import java.awt.BorderLayout; |
|
27 |
import java.awt.FlowLayout; |
|
28 |
import java.awt.GridBagConstraints; |
|
29 |
import java.awt.GridBagLayout; |
|
30 |
import java.awt.Insets; |
|
31 |
import java.util.ArrayList; |
|
32 |
|
|
33 |
import javax.swing.JCheckBox; |
|
34 |
import javax.swing.JComboBox; |
|
35 |
import javax.swing.JComponent; |
|
36 |
import javax.swing.JLabel; |
|
37 |
import javax.swing.JPanel; |
|
38 |
|
|
39 |
import org.slf4j.Logger; |
|
40 |
import org.slf4j.LoggerFactory; |
|
41 |
|
|
42 |
//import org.gvsig.exportto.swing.ExporttoSwingLocator; |
|
43 |
//import org.gvsig.exportto.swing.ExporttoSwingManager; |
|
44 |
//import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException; |
|
45 |
//import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel; |
|
46 |
import org.gvsig.gpe.lib.api.writer.IGPEWriterHandler; |
|
47 |
import org.gvsig.gpe.lib.spi.GPEProviderLocator; |
|
48 |
import org.gvsig.tools.ToolsLocator; |
|
49 |
import org.gvsig.tools.i18n.I18nManager; |
|
50 |
|
|
51 |
|
|
52 |
/** |
|
53 |
* |
|
54 |
* This addditional panel lets user choose KML |
|
55 |
* version and other options. |
|
56 |
* |
|
57 |
* @author gvSIG Team |
|
58 |
* @version $Id$ |
|
59 |
* |
|
60 |
*/ |
|
61 |
public class KMLPanelView extends JPanel { |
|
62 |
|
|
63 |
private static final long serialVersionUID = -3278172717881233447L; |
|
64 |
|
|
65 |
private static final Logger LOG = LoggerFactory.getLogger(KMLPanelView.class); |
|
66 |
|
|
67 |
private boolean offerLabels = false; |
|
68 |
private boolean offerReproj = true; |
|
69 |
|
|
70 |
private JCheckBox labelsChk = null; |
|
71 |
private JCheckBox reproChk = null; |
|
72 |
private JCheckBox balloonsChk = null; |
|
73 |
|
|
74 |
private JComboBox versionCombo = null; |
|
75 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
76 |
|
|
77 |
public KMLPanelView() { |
|
78 |
initializePanel(); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Initializer |
|
83 |
*/ |
|
84 |
protected void initializePanel() { |
|
85 |
setLayout(new BorderLayout()); |
|
86 |
add(createPanel(), BorderLayout.CENTER); |
|
87 |
} |
|
88 |
|
|
89 |
private JPanel createPanel() { |
|
90 |
|
|
91 |
JPanel jpanel1 = new JPanel(); |
|
92 |
jpanel1.setLayout(new BorderLayout()); |
|
93 |
|
|
94 |
FlowLayout fl = new FlowLayout(FlowLayout.LEFT); |
|
95 |
JPanel topPanel = new JPanel(fl); |
|
96 |
// ==================================================== |
|
97 |
JPanel gridPanel = new JPanel(); |
|
98 |
gridPanel.setLayout(new GridBagLayout()); |
|
99 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
100 |
|
|
101 |
gbc.anchor = GridBagConstraints.WEST; |
|
102 |
gbc.insets = new Insets(3, 3, 3, 3); |
|
103 |
|
|
104 |
gbc.gridx = 0; |
|
105 |
gbc.gridy = 0; |
|
106 |
gbc.gridwidth = 3; |
|
107 |
gridPanel.add(new JLabel(i18n.getTranslation("kml_Choose_KML_version")), gbc); |
|
108 |
gbc.gridx = 3; |
|
109 |
gbc.gridwidth = 3; |
|
110 |
gridPanel.add(getVersionsCombo(), gbc); |
|
111 |
// ===================== |
|
112 |
gbc.gridx = 0; |
|
113 |
gbc.gridy = 1; |
|
114 |
gbc.gridwidth = 1; |
|
115 |
gridPanel.add(getBalloonsCheckbox(), gbc); |
|
116 |
gbc.gridx = 1; |
|
117 |
gbc.gridwidth = 5; |
|
118 |
gridPanel.add(new JLabel(i18n.getTranslation( |
|
119 |
"kml_Show_attributes_in_balloon")), gbc); |
|
120 |
// ===================== |
|
121 |
gbc.gridx = 0; |
|
122 |
gbc.gridy = 2; |
|
123 |
gbc.gridwidth = 1; |
|
124 |
getLabelsCheckbox(offerLabels); |
|
125 |
//gridPanel.add(getLabelsCheckbox(offerLabels), gbc); |
|
126 |
gbc.gridx = 1; |
|
127 |
gbc.gridwidth = 5; |
|
128 |
JLabel lbl_lbl = new JLabel(i18n.getTranslation("" + |
|
129 |
"kml_Use_labels_Label_point_will_be_added_to_non_points")); |
|
130 |
lbl_lbl.setEnabled(offerLabels); |
|
131 |
//gridPanel.add(lbl_lbl, gbc); |
|
132 |
// ==================================================== |
|
133 |
// gbc.gridx = 0; |
|
134 |
// gbc.gridy = 2; |
|
135 |
// gbc.gridwidth = 1; |
|
136 |
// gridPanel.add(getReproCheckbox(offerReproj), gbc); |
|
137 |
// gbc.gridx = 1; |
|
138 |
// gbc.gridwidth = 5; |
|
139 |
// JLabel rep_lbl = new JLabel(i18n.getTranslation( |
|
140 |
// "kml_Force_to_EPSG_4326")); |
|
141 |
// rep_lbl.setEnabled(offerReproj); |
|
142 |
// gridPanel.add(rep_lbl, gbc); |
|
143 |
// ==================================================== |
|
144 |
topPanel.add(gridPanel); |
|
145 |
jpanel1.add(topPanel, BorderLayout.NORTH); |
|
146 |
return jpanel1; |
|
147 |
} |
|
148 |
|
|
149 |
// public String getMimeType() { |
|
150 |
// IGPEWriterHandler item = (IGPEWriterHandler) this.versionCombo.getItemAt(0); |
|
151 |
// String longn = item.getFormat(); |
|
152 |
// return longn; |
|
153 |
// } |
|
154 |
|
|
155 |
public String getMimeType() { |
|
156 |
Object obj = this.getVersionsCombo().getSelectedItem(); |
|
157 |
if (obj instanceof FormatListItem) { |
|
158 |
return ((FormatListItem) obj).getLongFormat(); |
|
159 |
} else { |
|
160 |
return null; |
|
161 |
} |
|
162 |
} |
|
163 |
public boolean getUseLabels() { |
|
164 |
return this.labelsChk.isSelected(); |
|
165 |
} |
|
166 |
|
|
167 |
public boolean getAttsAsBalloon() { |
|
168 |
return this.balloonsChk.isSelected(); |
|
169 |
} |
|
170 |
|
|
171 |
public boolean getReprojectTo4326() { |
|
172 |
return this.reproChk.isSelected(); |
|
173 |
} |
|
174 |
|
|
175 |
private JCheckBox getLabelsCheckbox(boolean enabled) { |
|
176 |
|
|
177 |
if (labelsChk == null) { |
|
178 |
labelsChk = new JCheckBox(""); |
|
179 |
labelsChk.setSelected(false); |
|
180 |
labelsChk.setEnabled(enabled); |
|
181 |
} |
|
182 |
return labelsChk; |
|
183 |
} |
|
184 |
|
|
185 |
private JCheckBox getReproCheckbox(boolean enabled) { |
|
186 |
|
|
187 |
if (reproChk == null) { |
|
188 |
reproChk = new JCheckBox(""); |
|
189 |
reproChk.setSelected(true); |
|
190 |
reproChk.setEnabled(enabled); |
|
191 |
} |
|
192 |
return reproChk; |
|
193 |
} |
|
194 |
|
|
195 |
private JCheckBox getBalloonsCheckbox() { |
|
196 |
|
|
197 |
if (balloonsChk == null) { |
|
198 |
balloonsChk = new JCheckBox(""); |
|
199 |
balloonsChk.setSelected(false); |
|
200 |
} |
|
201 |
return balloonsChk; |
|
202 |
} |
|
203 |
|
|
204 |
|
|
205 |
private JComboBox getVersionsCombo() { |
|
206 |
|
|
207 |
if (versionCombo == null) { |
|
208 |
versionCombo = new JComboBox(); |
|
209 |
ArrayList list = GPEProviderLocator.getGPEProviderManager().getWriterHandlerByFormat("kml"); |
|
210 |
IGPEWriterHandler item = null; |
|
211 |
String longn = null; |
|
212 |
String shortn = null; |
|
213 |
for (int i=0; i<list.size(); i++) { |
|
214 |
item = (IGPEWriterHandler) list.get(i); |
|
215 |
longn = item.getFormat(); |
|
216 |
shortn = getShortWithVersion(longn); |
|
217 |
if (longn != null && shortn != null) { |
|
218 |
versionCombo.addItem(new FormatListItem(longn, shortn)); |
|
219 |
} |
|
220 |
} |
|
221 |
} |
|
222 |
return versionCombo; |
|
223 |
} |
|
224 |
|
|
225 |
public String getPanelTitle() { |
|
226 |
return i18n.getTranslation("kml_KML_options"); |
|
227 |
} |
|
228 |
|
|
229 |
public boolean isValidPanel() { |
|
230 |
return getLongFormat() != null; |
|
231 |
} |
|
232 |
|
|
233 |
|
|
234 |
/** |
|
235 |
* Returns null if not valid format |
|
236 |
*/ |
|
237 |
private String getShortWithVersion(String fmt) { |
|
238 |
// Example: "text/xml; subtype=gml/2.1.2" => "gml" |
|
239 |
if (fmt == null) { |
|
240 |
return null; |
|
241 |
} |
|
242 |
String[] parts = fmt.split(";"); |
|
243 |
String aux = ""; |
|
244 |
if (parts.length > 1) { |
|
245 |
aux = parts[1].trim(); |
|
246 |
} else { |
|
247 |
return null; |
|
248 |
} |
|
249 |
parts = aux.split("="); |
|
250 |
if (parts.length > 1) { |
|
251 |
aux = parts[1].trim(); |
|
252 |
// Example: aux = "gml/2.1.2" |
|
253 |
aux = aux.replaceAll("/", " "); |
|
254 |
return aux.toUpperCase(); |
|
255 |
} else { |
|
256 |
return null; |
|
257 |
} |
|
258 |
} |
|
259 |
|
|
260 |
public void enterPanel() { |
|
261 |
|
|
262 |
} |
|
263 |
|
|
264 |
public JComponent asJComponent() { |
|
265 |
return this; |
|
266 |
} |
|
267 |
|
|
268 |
public class FormatListItem { |
|
269 |
|
|
270 |
private String longName = ""; |
|
271 |
private String shortName = ""; |
|
272 |
|
|
273 |
public FormatListItem(String longname, String shortname) { |
|
274 |
longName = longname; |
|
275 |
shortName = shortname; |
|
276 |
} |
|
277 |
|
|
278 |
public String toString() { |
|
279 |
return shortName; |
|
280 |
} |
|
281 |
|
|
282 |
public String getLongFormat() { |
|
283 |
return longName; |
|
284 |
} |
|
285 |
} |
|
286 |
|
|
287 |
// ================================================== |
|
288 |
// ================================================== |
|
289 |
|
|
290 |
public String getLongFormat() { |
|
291 |
Object obj = this.getVersionsCombo().getSelectedItem(); |
|
292 |
if (obj instanceof FormatListItem) { |
|
293 |
return ((FormatListItem) obj).getLongFormat(); |
|
294 |
} else { |
|
295 |
return null; |
|
296 |
} |
|
297 |
} |
|
298 |
|
|
299 |
public boolean useLabels() { |
|
300 |
return this.getLabelsCheckbox(false).isSelected(); |
|
301 |
} |
|
302 |
|
|
303 |
public boolean useBalloons() { |
|
304 |
return this.getBalloonsCheckbox().isSelected(); |
|
305 |
} |
|
306 |
|
|
307 |
public boolean mustReprojectToEpsg4326() { |
|
308 |
return this.getReproCheckbox(true).isSelected(); |
|
309 |
} |
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.89/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/swing/panels/KMLPanel.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package org.gvsig.gpe.exportto.kml.swing.panels; |
|
7 |
|
|
8 |
import javax.swing.JComponent; |
|
9 |
import org.gvsig.export.ExportParameters; |
|
10 |
import org.gvsig.export.swing.JExportProcessPanel; |
|
11 |
import org.gvsig.export.swing.spi.ExportPanel; |
|
12 |
import org.gvsig.export.swing.spi.ExportPanelValidationException; |
|
13 |
import org.gvsig.gpe.exportto.kml.service.ExportKMLParameters; |
|
14 |
import org.gvsig.tools.ToolsLocator; |
|
15 |
import org.gvsig.tools.i18n.I18nManager; |
|
16 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
17 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
|
18 |
|
|
19 |
/** |
|
20 |
* |
|
21 |
* @author osc |
|
22 |
*/ |
|
23 |
public class KMLPanel |
|
24 |
extends KMLPanelView |
|
25 |
implements ExportPanel |
|
26 |
{ |
|
27 |
|
|
28 |
// private static final Logger LOG = LoggerFactory.getLogger(SelectSimplifiedExport.class); |
|
29 |
|
|
30 |
private final ExportKMLParameters parameters; |
|
31 |
private final JExportProcessPanel processPanel; |
|
32 |
|
|
33 |
public KMLPanel(JExportProcessPanel processPanel, ExportParameters parameters) { |
|
34 |
super(); |
|
35 |
this.processPanel = processPanel; |
|
36 |
this.parameters = (ExportKMLParameters) parameters; |
|
37 |
this.initComponents(); |
|
38 |
} |
|
39 |
|
|
40 |
private void initComponents() { |
|
41 |
//Default value |
|
42 |
//this.chkUseSimplifiedExport.setSelected(parameters.getUseSimplifiedExport()); |
|
43 |
|
|
44 |
this.translate(); |
|
45 |
} |
|
46 |
|
|
47 |
private void translate() { |
|
48 |
ToolsSwingManager i18nc = ToolsSwingLocator.getToolsSwingManager(); |
|
49 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
50 |
// |
|
51 |
// i18nc.translate(this.lblUseSimplifiedExport); |
|
52 |
// String s = i18n.getTranslation(this.lblUseSimplifiedExportDescription.getText()); |
|
53 |
// s = "<html>" + s.replace("\n","<br>\n") + "</html>"; |
|
54 |
// this.lblUseSimplifiedExportDescription.setText(s); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public String getIdPanel() { |
|
59 |
return this.getClass().getSimpleName(); |
|
60 |
} |
|
61 |
|
|
62 |
@Override |
|
63 |
public String getTitlePanel() { |
|
64 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
65 |
return i18nManager.getTranslation("kml_Select_KML_Options"); |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public boolean validatePanel() throws ExportPanelValidationException { |
|
70 |
return true; |
|
71 |
} |
|
72 |
|
|
73 |
@Override |
|
74 |
public void enterPanel() { |
|
75 |
|
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public void nextPanel() { |
|
80 |
this.parameters.setMimeType(this.getMimeType()); |
|
81 |
this.parameters.setAttsAsBalloon(this.getAttsAsBalloon()); |
|
82 |
this.parameters.setUseLabels(this.getUseLabels()); |
|
83 |
} |
|
84 |
|
|
85 |
@Override |
|
86 |
public void previousPanel() { |
|
87 |
|
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public JComponent asJComponent() { |
|
92 |
|
|
93 |
return super.asJComponent(); |
|
94 |
} |
|
95 |
|
|
96 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.89/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/ExportKMLLibrary.java | ||
---|---|---|
1 |
package org.gvsig.gpe.exportto.kml; |
|
2 |
|
|
3 |
import org.gvsig.export.ExportLibrary; |
|
4 |
import org.gvsig.export.ExportLocator; |
|
5 |
import org.gvsig.export.spi.ExportServiceManager; |
|
6 |
import org.gvsig.export.swing.ExportSwingLibrary; |
|
7 |
import org.gvsig.export.swing.ExportSwingLocator; |
|
8 |
import org.gvsig.export.swing.spi.ExportPanelsManager; |
|
9 |
import org.gvsig.gpe.exportto.kml.service.ExportKMLServiceFactory; |
|
10 |
import org.gvsig.gpe.exportto.kml.swing.ExportKMLPanelsFactory; |
|
11 |
import org.gvsig.tools.library.AbstractLibrary; |
|
12 |
import org.gvsig.tools.library.LibraryException; |
|
13 |
|
|
14 |
/** |
|
15 |
* |
|
16 |
* @author jjdelcerro |
|
17 |
*/ |
|
18 |
public class ExportKMLLibrary extends AbstractLibrary { |
|
19 |
|
|
20 |
@Override |
|
21 |
public void doRegistration() { |
|
22 |
registerAsServiceOf(ExportSwingLibrary.class); |
|
23 |
registerAsServiceOf(ExportLibrary.class); |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
protected void doInitialize() throws LibraryException { |
|
28 |
// Nothing to do |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
protected void doPostInitialize() throws LibraryException { |
|
33 |
ExportServiceManager manager = ExportLocator.getServiceManager(); |
|
34 |
ExportPanelsManager swingManager = ExportSwingLocator.getExportPanelsManager(); |
|
35 |
|
|
36 |
manager.register(new ExportKMLServiceFactory()); |
|
37 |
ExportKMLPanelsFactory panel = new ExportKMLPanelsFactory(); |
|
38 |
swingManager.register(panel); |
|
39 |
} |
|
40 |
|
|
41 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.89/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/service/ExportKMLServiceFactory.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package org.gvsig.gpe.exportto.kml.service; |
|
7 |
|
|
8 |
import org.gvsig.export.ExportParameters; |
|
9 |
import org.gvsig.export.spi.AbstractExportServiceFactory; |
|
10 |
|
|
11 |
/** |
|
12 |
* |
|
13 |
* @author osc |
|
14 |
*/ |
|
15 |
public class ExportKMLServiceFactory extends AbstractExportServiceFactory |
|
16 |
{ |
|
17 |
|
|
18 |
public static final String SERVICE_NAME = "KML"; |
|
19 |
|
|
20 |
public ExportKMLServiceFactory() { |
|
21 |
super( |
|
22 |
SERVICE_NAME, |
|
23 |
"KML file", |
|
24 |
"KML file" |
|
25 |
); |
|
26 |
} |
|
27 |
|
|
28 |
@Override |
|
29 |
public ExportKMLService createService(ExportParameters parameters) { |
|
30 |
ExportKMLService service = new ExportKMLService(this, (ExportKMLParameters) parameters); |
|
31 |
return service; |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public ExportKMLParameters createParameters() { |
|
36 |
ExportKMLParameters parameters = new ExportKMLParametersImpl(this); |
|
37 |
return parameters; |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public boolean hasTabularSupport() { |
|
42 |
return true; |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public boolean hasVectorialSupport() { |
|
47 |
return true; |
|
48 |
} |
|
49 |
|
|
50 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.89/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/service/ExportKMLService.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package org.gvsig.gpe.exportto.kml.service; |
|
7 |
|
|
8 |
import java.awt.geom.Rectangle2D; |
|
9 |
import java.io.File; |
|
10 |
import java.io.FileOutputStream; |
|
11 |
import java.io.IOException; |
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.Iterator; |
|
14 |
import java.util.List; |
|
15 |
import java.util.Map; |
|
16 |
import org.cresques.cts.ICoordTrans; |
|
17 |
import org.cresques.cts.IProjection; |
|
18 |
import org.gvsig.export.ExportException; |
|
19 |
import org.gvsig.export.ExportParameters; |
|
20 |
import org.gvsig.export.spi.AbstractExportService; |
|
21 |
import org.gvsig.export.spi.ExportService; |
|
22 |
import org.gvsig.export.spi.ExportServiceFactory; |
|
23 |
import org.gvsig.fmap.crs.CRSFactory; |
|
24 |
import org.gvsig.fmap.dal.DALLocator; |
|
25 |
import org.gvsig.fmap.dal.DataManager; |
|
26 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
27 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
28 |
import org.gvsig.fmap.dal.OpenDataStoreParameters; |
|
29 |
import org.gvsig.fmap.dal.exception.DataException; |
|
30 |
import org.gvsig.fmap.dal.feature.Feature; |
|
31 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
32 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
33 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
34 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
35 |
import org.gvsig.fmap.dal.feature.OpenFeatureStoreParameters; |
|
36 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
|
37 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
|
38 |
import org.gvsig.fmap.geom.DataTypes; |
|
39 |
import org.gvsig.fmap.geom.Geometry; |
|
40 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
41 |
import org.gvsig.fmap.geom.GeometryManager; |
|
42 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
|
43 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
44 |
import org.gvsig.fmap.mapcontext.MapContextException; |
|
45 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
46 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
|
47 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
48 |
import org.gvsig.gpe.exportto.generic.util.CoordinatesSequenceBbox; |
|
49 |
import org.gvsig.gpe.exportto.generic.util.GeometryToGPEWriter; |
|
50 |
import org.gvsig.gpe.exportto.kml.style.KmlStyle; |
|
51 |
import org.gvsig.gpe.exportto.kml.style.StyleUtils; |
|
52 |
import org.gvsig.gpe.lib.api.GPELocator; |
|
53 |
import org.gvsig.gpe.lib.api.writer.IGPEWriterHandler; |
|
54 |
import org.gvsig.gpe.lib.api.writer.IGPEWriterHandlerImplementor; |
|
55 |
import org.gvsig.gpe.prov.kml.utils.Kml2_1_Tags; |
|
56 |
import org.gvsig.gpe.prov.kml.writer.GPEKmlWriterHandlerImplementor; |
|
57 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
58 |
import org.gvsig.tools.locator.LocatorException; |
|
59 |
import org.gvsig.tools.util.HasAFile; |
|
60 |
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter; |
|
61 |
import org.slf4j.Logger; |
|
62 |
import org.slf4j.LoggerFactory; |
|
63 |
|
|
64 |
/** |
|
65 |
* |
|
66 |
* @author osc |
|
67 |
*/ |
|
68 |
public class ExportKMLService extends AbstractExportService |
|
69 |
implements ExportService { |
|
70 |
|
|
71 |
private static Logger logger = LoggerFactory.getLogger(ExportKMLService.class); |
|
72 |
|
|
73 |
ExportKMLService(ExportServiceFactory factory, ExportParameters parameters) { |
|
74 |
super(factory, parameters); |
|
75 |
} |
|
76 |
|
|
77 |
@Override |
|
78 |
protected DataServerExplorer createServerExplorer() throws ExportException { |
|
79 |
|
|
80 |
DataManager dataManager = DALLocator.getDataManager(); |
|
81 |
|
|
82 |
FilesystemServerExplorerParameters explorerParams; |
|
83 |
try { |
|
84 |
explorerParams |
|
85 |
= (FilesystemServerExplorerParameters) dataManager |
|
86 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
|
87 |
} catch (Exception e) { |
|
88 |
throw new ExportException(e); |
|
89 |
} |
|
90 |
|
|
91 |
explorerParams.setRoot(this.getParameters().getFile().getParent()); |
|
92 |
|
|
93 |
FilesystemServerExplorer explorer; |
|
94 |
try { |
|
95 |
explorer = (FilesystemServerExplorer) dataManager.openServerExplorer( |
|
96 |
"FilesystemExplorer", explorerParams |
|
97 |
); |
|
98 |
return explorer; |
|
99 |
} catch (Exception e) { |
|
100 |
throw new ExportException(e); |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
@Override |
|
105 |
protected NewDataStoreParameters createTargetNewStoreParameters() throws ExportException { |
|
106 |
try { |
|
107 |
FilesystemServerExplorer explorer = (FilesystemServerExplorer) this.createServerExplorer(); |
|
108 |
NewFeatureStoreParameters newStoreParameters = (NewFeatureStoreParameters) explorer.getAddParameters( |
|
109 |
this.getParameters().getFile() |
|
110 |
); |
|
111 |
newStoreParameters.setDynValue("CRS", this.getParameters().getTargetProjection()); |
|
112 |
// Usamos el featureType por defecto del KML |
|
113 |
return newStoreParameters; |
|
114 |
} catch (DataException ex) { |
|
115 |
throw new ExportException(ex); |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
@Override |
|
120 |
protected OpenDataStoreParameters createTargetOpenStoreParameters() throws ExportException { |
|
121 |
try { |
|
122 |
DataManager dataManager = DALLocator.getDataManager(); |
|
123 |
OpenFeatureStoreParameters openStoreParameters = (OpenFeatureStoreParameters) dataManager.createStoreParameters("GPE"); |
|
124 |
((HasAFile) openStoreParameters).setFile(getParameters().getFile()); |
|
125 |
openStoreParameters.setDynValue("CRS", this.getParameters().getTargetProjection()); |
|
126 |
return openStoreParameters; |
|
127 |
} catch (DataException ex) { |
|
128 |
throw new ExportException(ex); |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
@Override |
|
133 |
public ExportKMLParameters getParameters() { |
|
134 |
return (ExportKMLParameters) super.getParameters(); |
|
135 |
} |
|
136 |
|
|
137 |
@Override |
|
138 |
public void export( |
|
139 |
FeatureSet featureSet) throws ExportException { |
|
140 |
DataServerExplorer explorer = this.createServerExplorer(); |
|
141 |
NewFeatureStoreParameters params = (NewFeatureStoreParameters) this.createTargetNewStoreParameters(); |
|
142 |
|
|
143 |
String providerName = params.getDataStoreName(); |
|
144 |
String explorerName = explorer.getProviderName(); |
|
145 |
|
|
146 |
File outFile = this.getParameters().getFile(); //kmlFile; |
|
147 |
FeatureSet featureStore = featureSet; |
|
148 |
|
|
149 |
FLyrVect vectorLayer = null; |
|
150 |
String mimeType = this.getParameters().getMimeType(); //mtype; |
|
151 |
boolean useLabels = this.getParameters().getUseLabels(); //doLabels; |
|
152 |
boolean attsAsBalloon = this.getParameters().getAttsAsBalloon(); |
|
153 |
ArrayList<ICoordTrans> ICoordTrans; |
|
154 |
|
|
155 |
List<ICoordTrans> transfList = new ArrayList<ICoordTrans>(); |
|
156 |
|
|
157 |
ICoordTrans ct = this.getParameters().getSourceTransformation(); //vlayer.getCoordTrans(); |
|
158 |
IProjection targetproj = this.getParameters().getTargetProjection(); |
|
159 |
// if (reprojectTo4326) { |
|
160 |
// 8 |
|
161 |
// targetproj = CRSFactory.getCRS("EPSG:4326"); |
|
162 |
// if (ct == null) { |
|
163 |
// transfList.add(this.getParameters().getSourceProjection().getCT(targetproj)); |
|
164 |
// } else { |
|
165 |
// transfList.add(ct); |
|
166 |
// transfList.add(ct.getPDest().getCT(targetproj)); |
|
167 |
// } |
|
168 |
// } else { |
|
169 |
if (ct == null) { |
|
170 |
if (targetproj == null) { |
|
171 |
targetproj = this.getParameters().getSourceProjection(); |
|
172 |
} |
|
173 |
ct = this.getParameters().getSourceProjection().getCT(targetproj); |
|
174 |
transfList.add(ct); |
|
175 |
} else { |
|
176 |
targetproj = ct.getPDest(); |
|
177 |
transfList.add(ct); |
|
178 |
} |
|
179 |
|
|
180 |
IGPEWriterHandler wh = null; |
|
181 |
FileOutputStream fos = null; |
|
182 |
String srs = targetproj.getAbrev(); |
|
183 |
|
|
184 |
String[] fldNames = null; |
|
185 |
Envelope env = null; |
|
186 |
long count = 0; |
|
187 |
FeatureType ftype; |
|
188 |
|
|
189 |
try { |
|
190 |
count = featureSet.getSize(); |
|
191 |
this.getTaskStatus().setRangeOfValues(0, count); |
|
192 |
if (this.getParameters().getExportAttributes().isActive()) { |
|
193 |
ftype = this.getParameters().getExportAttributes().getTargetFeatureType(); |
|
194 |
} else { |
|
195 |
ftype = featureStore.getDefaultFeatureType(); |
|
196 |
} |
|
197 |
fldNames = getAttributes(ftype); |
|
198 |
env = GeometryLocator.getGeometryManager().createEnvelope(Geometry.SUBTYPES.GEOM2D); |
|
199 |
this.initEnvelope(env, featureSet); |
|
200 |
} catch (DataException | CreateEnvelopeException | LocatorException e) { |
|
201 |
throw new ExportException(e); |
|
202 |
} |
|
203 |
|
|
204 |
try { |
|
205 |
env = reproject(env, transfList); |
|
206 |
} catch (CreateEnvelopeException ex) { |
|
207 |
throw new ExportException(ex); |
|
208 |
} |
|
209 |
|
|
210 |
Rectangle2D rect = new Rectangle2D.Double( |
|
211 |
env.getMinimum(0), |
|
212 |
env.getMinimum(1), |
|
213 |
env.getLength(0), |
|
214 |
env.getLength(1)); |
|
215 |
|
|
216 |
File fixedFile = outFile; |
|
217 |
try { |
|
218 |
|
|
219 |
if (!outFile.getAbsolutePath().toLowerCase().endsWith( |
|
220 |
"." + this.getFileExtension().toLowerCase())) { |
|
221 |
|
|
222 |
fixedFile = new File(outFile.getAbsolutePath() + "." + getFileExtension()); |
|
223 |
} |
|
224 |
|
|
225 |
wh = GPELocator.getGPEManager().createWriterByMimeType(mimeType); |
|
226 |
fos = new FileOutputStream(fixedFile); |
|
227 |
|
|
228 |
wh.setOutputStream(fos); |
|
229 |
wh.initialize(); |
|
230 |
// ========================================== |
|
231 |
wh.startLayer(null, null, fixedFile.getName(), null, srs); |
|
232 |
// ============== Styles ============= |
|
233 |
Map<ISymbol, KmlStyle> symsty = null; |
|
234 |
IXmlStreamWriter xmlw = getXmlStreamWriter(wh); |
|
235 |
if (true && xmlw != null && vectorLayer instanceof FLyrVect) { |
|
236 |
symsty = StyleUtils.getSymbolStyles((FLyrVect) vectorLayer, |
|
237 |
featureSet, |
|
238 |
attsAsBalloon, |
|
239 |
fldNames); |
|
240 |
Iterator<KmlStyle> iter = symsty.values().iterator(); |
|
241 |
KmlStyle sty = null; |
|
242 |
while (iter.hasNext()) { |
|
243 |
sty = iter.next(); |
|
244 |
writeStyle(xmlw, sty); |
|
245 |
} |
|
246 |
} |
|
247 |
// ========================================== |
|
248 |
wh.startBbox(null, new CoordinatesSequenceBbox(rect), srs); |
|
249 |
wh.endBbox(); |
|
250 |
// ============= Writing feature ============ |
|
251 |
IVectorLegend legend; |
|
252 |
if (vectorLayer instanceof FLyrVect) { |
|
253 |
legend = (IVectorLegend) ((FLyrVect) vectorLayer).getLegend(); |
|
254 |
} else { |
|
255 |
legend = null; |
|
256 |
} |
|
257 |
writeFeatures(wh, xmlw, featureSet, fldNames, symsty, legend, transfList); |
|
258 |
|
|
259 |
// writeFeatures(wh, xmlw, featureSet, fldNames, symsty, |
|
260 |
// (IVectorLegend) vectorLayer.getLegend()); |
|
261 |
// ========================================== |
|
262 |
wh.endLayer(); |
|
263 |
// ========================================== |
|
264 |
wh.close(); |
|
265 |
fos.close(); |
|
266 |
} catch (Exception exc) { |
|
267 |
throw new ExportException(exc); |
|
268 |
} |
|
269 |
|
|
270 |
this.getTaskStatus().setCurValue(count); |
|
271 |
// this.finishAction(fixedFile, targetproj); |
|
272 |
this.getTaskStatus().terminate(); |
|
273 |
this.getTaskStatus().remove(); |
|
274 |
|
|
275 |
} |
|
276 |
|
|
277 |
private String[] getAttributes(FeatureType ftype) { |
|
278 |
|
|
279 |
FeatureAttributeDescriptor[] atts = ftype.getAttributeDescriptors(); |
|
280 |
|
|
281 |
FeatureAttributeDescriptor desc = null; |
|
282 |
List<String> list = new ArrayList<String>(); |
|
283 |
for (int i = 0; i < atts.length; i++) { |
|
284 |
desc = atts[i]; |
|
285 |
if (desc.getDataType().getType() != DataTypes.GEOMETRY) { |
|
286 |
list.add(desc.getName()); |
|
287 |
} |
|
288 |
} |
|
289 |
return list.toArray(new String[0]); |
|
290 |
} |
|
291 |
|
|
292 |
private Geometry reproject(Geometry geom, List<ICoordTrans> transfList) { |
|
293 |
|
|
294 |
int sz = transfList.size(); |
|
295 |
if (sz == 0) { |
|
296 |
return geom; |
|
297 |
} else { |
|
298 |
Geometry resp = geom.cloneGeometry(); |
|
299 |
for (int i = 0; i < sz; i++) { |
|
300 |
resp.reProject(transfList.get(i)); |
|
301 |
} |
|
302 |
return resp; |
|
303 |
} |
|
304 |
|
|
305 |
} |
|
306 |
|
|
307 |
public String getFileExtension() { |
|
308 |
return "kml"; |
|
309 |
} |
|
310 |
|
|
311 |
// private void finishAction(File kmlfile, IProjection proj) |
|
312 |
// throws ExportException { |
|
313 |
// |
|
314 |
// this.createTargetOpenStoreParameters() |
|
315 |
// |
|
316 |
// if (exporttoServiceFinishAction != null) { |
|
317 |
// |
|
318 |
// /* |
|
319 |
// * Export is done. We notify with a SHPStoreParameters, |
|
320 |
// * not with the NewSHPParameters we have used: |
|
321 |
// */ |
|
322 |
// DataManagerProviderServices dataman |
|
323 |
// = (DataManagerProviderServices) DALLocator.getDataManager(); |
|
324 |
// |
|
325 |
// DataStoreParameters dsp = null; |
|
326 |
// try { |
|
327 |
// dsp = dataman.createStoreParameters("GPE"); |
|
328 |
// } catch (Exception e) { |
|
329 |
// throw new ExportException(e); //"Cannot add resulting kml file to view", e); |
|
330 |
// } |
|
331 |
// |
|
332 |
// dsp.setDynValue("File", kmlfile); |
|
333 |
// dsp.setDynValue("CRS", proj); |
|
334 |
// |
|
335 |
// try { |
|
336 |
// dsp.validate(); |
|
337 |
// } catch (ValidateDataParametersException e) { |
|
338 |
// throw new ExportException(e); |
|
339 |
// } |
|
340 |
// exporttoServiceFinishAction.finished(kmlfile.getName(), dsp); |
|
341 |
// } |
|
342 |
// } |
|
343 |
private void writeStyle(IXmlStreamWriter xmlw, KmlStyle sty) throws IOException { |
|
344 |
|
|
345 |
xmlw.writeStartElement(Kml2_1_Tags.STYLE); |
|
346 |
xmlw.writeStartAttribute(Kml2_1_Tags.ID); |
|
347 |
xmlw.writeValue(sty.getId()); |
|
348 |
xmlw.writeEndAttributes(); |
|
349 |
sty.writeXml(xmlw); |
|
350 |
xmlw.writeEndElement(); |
|
351 |
} |
|
352 |
|
|
353 |
private IXmlStreamWriter getXmlStreamWriter(IGPEWriterHandler wh) { |
|
354 |
|
|
355 |
IGPEWriterHandlerImplementor imple = wh.getImplementor(); |
|
356 |
if (!(imple instanceof GPEKmlWriterHandlerImplementor)) { |
|
357 |
/* |
|
358 |
* Unexpected class |
|
359 |
*/ |
|
360 |
return null; |
|
361 |
} |
|
362 |
GPEKmlWriterHandlerImplementor kmlimple = null; |
|
363 |
kmlimple = (GPEKmlWriterHandlerImplementor) imple; |
|
364 |
IXmlStreamWriter xmlw = kmlimple.getXMLStreamWriter(); |
|
365 |
return xmlw; |
|
366 |
} |
|
367 |
|
|
368 |
private void writeFeatures( |
|
369 |
IGPEWriterHandler gwh, |
|
370 |
IXmlStreamWriter xmlw, |
|
371 |
FeatureSet fset, |
|
372 |
String[] fieldNames, |
|
373 |
Map<ISymbol, KmlStyle> symsty, |
|
374 |
IVectorLegend lege, |
|
375 |
List<ICoordTrans> transfList) throws Exception { |
|
376 |
|
|
377 |
GeometryToGPEWriter gw = new GeometryToGPEWriter(gwh); |
|
378 |
DisposableIterator diter = fset.fastIterator(); |
|
379 |
Feature feat = null; |
|
380 |
long count = 0; |
|
381 |
this.getTaskStatus().setCurValue(count); |
|
382 |
ISymbol sym = null; |
|
383 |
int nullGeometries = 0; |
|
384 |
while (diter.hasNext()) { |
|
385 |
feat = (Feature) diter.next(); |
|
386 |
try { |
|
387 |
if (lege instanceof IVectorLegend) { |
|
388 |
sym = lege.getSymbolByFeature(feat); |
|
389 |
} |
|
390 |
} catch (MapContextException mce) { |
|
391 |
logger.info("While getting legend symbol.", mce); |
|
392 |
} |
|
393 |
KmlStyle kmlStyle; |
|
394 |
try { |
|
395 |
kmlStyle = symsty.get(sym); |
|
396 |
} catch (Exception e) { |
|
397 |
kmlStyle = null; |
|
398 |
} |
|
399 |
|
|
400 |
if (!writeFeature(feat, gwh, xmlw, gw, count, fieldNames, kmlStyle, transfList)) { |
|
401 |
nullGeometries++; |
|
402 |
}; |
|
403 |
count++; |
|
404 |
this.getTaskStatus().setCurValue(count); |
|
405 |
} |
|
406 |
if (nullGeometries > 0) { |
|
407 |
logger.warn("Can't export " + nullGeometries + " features because source geometries are null."); |
|
408 |
} |
|
409 |
diter.dispose(); |
|
410 |
} |
|
411 |
|
|
412 |
private boolean writeFeature( |
|
413 |
Feature feat, |
|
414 |
IGPEWriterHandler gwh, |
|
415 |
IXmlStreamWriter xmlw, |
|
416 |
GeometryToGPEWriter gw, |
|
417 |
long index, |
|
418 |
String[] fieldNames, |
|
419 |
KmlStyle ksty, |
|
420 |
List<ICoordTrans> transfList) throws IOException { |
|
421 |
|
|
422 |
Geometry geom = feat.getDefaultGeometry(); |
|
423 |
|
|
424 |
if (geom == null) { |
|
425 |
return false; |
|
426 |
} |
|
427 |
|
|
428 |
String strindex = String.valueOf(index); |
|
429 |
|
|
430 |
if (this.getParameters().getUseLabels()) { |
|
431 |
String lbl = getLabelForFeature(feat); |
|
432 |
gwh.startFeature(strindex, "FEATURE", lbl); |
|
433 |
} else { |
|
434 |
gwh.startFeature(strindex, "FEATURE", ""); |
|
435 |
} |
|
436 |
// ========================= |
|
437 |
// Style |
|
438 |
if (ksty != null) { |
|
439 |
xmlw.writeStartElement(Kml2_1_Tags.STYLEURL); |
|
440 |
xmlw.writeValue("#" + ksty.getId()); |
|
441 |
xmlw.writeEndElement(); |
|
442 |
} |
|
443 |
// ===== Balloon ============ |
|
444 |
if (this.getParameters().getAttsAsBalloon()) { |
|
445 |
writeBalloon(xmlw, feat, fieldNames); |
|
446 |
} |
|
447 |
|
|
448 |
// ============= Geometry |
|
449 |
|
|
450 |
/* |
|
451 |
* This has no effect if reprojection is not necessary |
|
452 |
*/ |
|
453 |
geom = reproject(geom, transfList); |
|
454 |
gw.writeGeometry(geom, this.getParameters().getUseLabels()); |
|
455 |
// ============= Attributes |
|
456 |
Object val = null; |
|
457 |
String fldname = null; |
|
458 |
for (int i = 0; i < fieldNames.length; i++) { |
|
459 |
val = feat.get(fieldNames[i]); |
|
460 |
fldname = fieldNames[i].replace(' ', '_'); |
|
461 |
gwh.startElement("", fldname, val == null ? "" : val.toString()); |
|
462 |
gwh.endElement(); |
|
463 |
} |
|
464 |
// ========================= |
|
465 |
gwh.endFeature(); |
|
466 |
return true; |
|
467 |
} |
|
468 |
|
|
469 |
private String getLabelForFeature(Feature feat) { |
|
470 |
return ""; |
|
471 |
|
|
472 |
// if (this.vectorLayer.isLabeled()) { |
|
473 |
// |
|
474 |
// String[] flds = vectorLayer.getLabelingStrategy().getUsedFields(); |
|
475 |
// int n = Math.min(flds.length, 2); |
|
476 |
// if (n == 0) { |
|
477 |
// return ""; |
|
478 |
// } else { |
|
479 |
// String resp = ""; |
|
480 |
// Object val = null; |
|
481 |
// if (n == 1) { |
|
482 |
// val = feat.get(flds[0]); |
|
483 |
// resp = (val == null) ? "" : val.toString(); |
|
484 |
// } else { |
|
485 |
// // n == 2 |
|
486 |
// val = feat.get(flds[0]); |
|
487 |
// resp = (val == null) ? "" : val.toString(); |
|
488 |
// val = feat.get(flds[1]); |
|
489 |
// resp = (val == null) ? resp : resp + ", " + val.toString(); |
|
490 |
// } |
|
491 |
// return resp; |
|
492 |
// } |
|
493 |
// |
|
494 |
// } else { |
|
495 |
// return ""; |
|
496 |
// } |
|
497 |
} |
|
498 |
|
|
499 |
private void writeBalloon(IXmlStreamWriter xmlw, Feature feat, String[] fieldNames) |
|
500 |
throws IOException { |
|
501 |
|
|
502 |
xmlw.writeStartElement(Kml2_1_Tags.EXTENDED_DATA); |
|
503 |
String fldrep = null; |
|
504 |
Object val = null; |
|
505 |
for (int i = 0; i < fieldNames.length; i++) { |
|
506 |
fldrep = fieldNames[i].replace(' ', '_'); |
|
507 |
xmlw.writeStartElement(Kml2_1_Tags.DATA); |
|
508 |
// Att ===================================================== |
|
509 |
xmlw.writeStartAttribute(null, "name"); |
|
510 |
xmlw.writeValue(fldrep); |
|
511 |
xmlw.writeEndAttributes(); |
|
512 |
// Value ===================================================== |
|
513 |
xmlw.writeStartElement(Kml2_1_Tags.VALUE); |
|
514 |
val = feat.get(fieldNames[i]); |
|
515 |
xmlw.writeValue(val == null ? "" : val.toString()); |
|
516 |
xmlw.writeEndElement(); |
|
517 |
// ============================================= |
|
518 |
xmlw.writeEndElement(); |
|
519 |
} |
|
520 |
xmlw.writeEndElement(); |
|
521 |
|
|
522 |
/* |
|
523 |
* |
|
524 |
<ExtendedData> |
|
525 |
<Data name="holeNumber"> |
|
526 |
<value>1</value> |
|
527 |
</Data> |
|
528 |
<Data name="holeYardage"> |
|
529 |
<value>234</value> |
|
530 |
</Data> |
|
531 |
<Data name="holePar"> |
|
532 |
<value>4</value> |
|
533 |
</Data> |
|
534 |
</ExtendedData> |
|
535 |
* |
|
536 |
*/ |
|
537 |
} |
|
538 |
|
|
539 |
private Envelope reproject(Envelope env, List<ICoordTrans> transfList) throws CreateEnvelopeException { |
|
540 |
|
|
541 |
int sz = transfList.size(); |
|
542 |
if (sz == 0) { |
|
543 |
return env; |
|
544 |
} else { |
|
545 |
Envelope resp = env; |
|
546 |
try { |
|
547 |
for (int i = 0; i < sz; i++) { |
|
548 |
resp = resp.convert(transfList.get(i)); |
|
549 |
} |
|
550 |
} catch (Exception exc) { |
|
551 |
|
|
552 |
// If this process fails, we'll use "emergency values": |
|
553 |
GeometryManager gm = GeometryLocator.getGeometryManager(); |
|
554 |
double[] min = new double[2]; |
|
555 |
double[] max = new double[2]; |
|
556 |
IProjection targetproj = this.getParameters().getTargetProjection(); |
|
557 |
if (targetproj.isProjected()) { |
|
558 |
min = new double[]{-20000000, -20000000}; |
|
559 |
max = new double[]{20000000, 20000000}; |
|
560 |
} else { |
|
561 |
min = new double[]{-180, -90}; |
|
562 |
max = new double[]{180, 90}; |
|
563 |
} |
|
564 |
|
|
565 |
resp = gm.createEnvelope( |
|
566 |
min[0], min[1], |
|
567 |
max[0], max[1], |
|
568 |
Geometry.SUBTYPES.GEOM2D); |
|
569 |
|
|
570 |
} |
|
571 |
return resp; |
|
572 |
} |
|
573 |
} |
|
574 |
|
|
575 |
private void initEnvelope(Envelope env, FeatureSet featureSet) { |
|
576 |
for (Feature feature : featureSet) { |
|
577 |
Geometry geometry = feature.getDefaultGeometry(); |
|
578 |
if (geometry != null && geometry.isValid()) { |
|
579 |
env.add(geometry); |
|
580 |
} |
|
581 |
} |
|
582 |
} |
|
583 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.89/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/service/ExportKMLParameters.java | ||
---|---|---|
1 |
package org.gvsig.gpe.exportto.kml.service; |
|
2 |
|
|
3 |
//import org.gvsig.export.dbf.service.ExportDBFParameters; |
|
4 |
import org.gvsig.export.ExportParametersGeometry; |
|
5 |
import org.gvsig.tools.util.HasAFile; |
|
6 |
|
|
7 |
/** |
|
8 |
* |
|
9 |
* @author jjdelcerro |
|
10 |
*/ |
|
11 |
public interface ExportKMLParameters extends ExportParametersGeometry, HasAFile { |
|
12 |
public String getMimeType(); |
|
13 |
public void setMimeType(String value); |
|
14 |
public boolean getUseLabels(); |
|
15 |
public void setUseLabels(boolean value); |
|
16 |
public boolean getAttsAsBalloon(); |
|
17 |
public void setAttsAsBalloon(boolean value); |
|
18 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.89/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/service/ExportKMLParametersImpl.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package org.gvsig.gpe.exportto.kml.service; |
|
7 |
|
|
8 |
import java.io.File; |
|
9 |
import org.apache.commons.io.FilenameUtils; |
|
10 |
import org.cresques.cts.IProjection; |
|
11 |
import org.gvsig.export.spi.AbstractExportParametersGeometry; |
|
12 |
import org.gvsig.export.spi.ExportServiceFactory; |
|
13 |
import org.gvsig.fmap.crs.CRSFactory; |
|
14 |
|
|
15 |
/** |
|
16 |
* |
|
17 |
* @author osc |
|
18 |
*/ |
|
19 |
public class ExportKMLParametersImpl |
|
20 |
extends AbstractExportParametersGeometry |
|
21 |
implements ExportKMLParameters |
|
22 |
{ |
|
23 |
private String mimeType = null; |
|
24 |
private boolean useLabels = false; |
|
25 |
private boolean attsAsBalloon = false; |
|
26 |
|
|
27 |
private File file; |
|
28 |
|
|
29 |
public ExportKMLParametersImpl(ExportServiceFactory factory) { |
|
30 |
super(factory); |
|
31 |
IProjection targetproj = CRSFactory.getCRS("EPSG:4326"); |
|
32 |
this.setTargetProjection(targetproj); |
|
33 |
this.getExportAttributes().setActive(true); |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
public String getServiceName() { |
|
38 |
return ExportKMLServiceFactory.SERVICE_NAME; |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public String getMimeType() { |
|
43 |
return this.mimeType; |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public boolean getUseLabels() { |
|
48 |
return this.useLabels; |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public boolean getAttsAsBalloon() { |
|
53 |
return this.attsAsBalloon; |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public File getFile() { |
|
58 |
return this.file; |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public void setFile(File file) { |
|
63 |
this.file = new File(FilenameUtils.removeExtension(file.getAbsolutePath()) + ".kml"); |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public void setUseLabels(boolean value) { |
|
68 |
this.useLabels = value; |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public void setAttsAsBalloon(boolean value) { |
|
73 |
this.attsAsBalloon = value; |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public void setMimeType(String value) { |
|
78 |
this.mimeType = value; |
|
79 |
} |
|
80 |
|
|
81 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.89/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/style/KmlCompoundStyle.java | ||
---|---|---|
1 |
package org.gvsig.gpe.exportto.kml.style; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter; |
|
8 |
|
|
9 |
public class KmlCompoundStyle extends KmlStyle { |
|
10 |
|
|
11 |
protected KmlIconStyle iconStyle = null; |
|
12 |
protected KmlLineStyle lineStyle = null; |
|
13 |
protected KmlPolygonStyle polygonStyle = null; |
|
14 |
protected KmlLabelStyle labelStyle = null; |
|
15 |
// protected KmlBalloonStyle balloonStyle = null; |
|
16 |
|
|
17 |
|
|
18 |
public void writeXml(IXmlStreamWriter writer) throws IOException { |
|
19 |
if (iconStyle != null) |
|
20 |
iconStyle.writeXml(writer); |
|
21 |
if (lineStyle != null) |
|
22 |
lineStyle.writeXml(writer); |
|
23 |
if (polygonStyle != null) |
|
24 |
polygonStyle.writeXml(writer); |
|
25 |
if (labelStyle != null) |
|
26 |
labelStyle.writeXml(writer); |
|
27 |
/* |
|
28 |
if (balloonStyle != null) |
|
29 |
balloonStyle.writeXml(writer); |
|
30 |
*/ |
|
31 |
} |
|
32 |
|
|
33 |
public void addStyles(List<KmlStyle> list) { |
|
34 |
|
|
35 |
if (list != null) { |
|
36 |
for (int i=0; i<list.size(); i++) { |
|
37 |
addStyle(list.get(i)); |
|
38 |
} |
|
39 |
} |
|
40 |
} |
|
41 |
|
|
42 |
|
|
43 |
public List<KmlStyle> getStyles() { |
|
44 |
|
|
45 |
List<KmlStyle> resp = new ArrayList<KmlStyle>(); |
|
46 |
if (iconStyle != null) { |
|
47 |
resp.add(iconStyle); |
|
48 |
} |
|
49 |
if (lineStyle != null) { |
|
50 |
resp.add(lineStyle); |
|
51 |
} |
|
52 |
if (polygonStyle != null) { |
|
53 |
resp.add(polygonStyle); |
|
54 |
} |
|
55 |
if (labelStyle != null) { |
|
56 |
resp.add(labelStyle); |
|
57 |
} |
|
58 |
return resp; |
|
59 |
} |
|
60 |
|
|
61 |
|
|
62 |
public void addStyle(KmlStyle sty) { |
|
63 |
if (sty instanceof KmlIconStyle) { |
|
64 |
this.iconStyle = (KmlIconStyle) sty; |
|
65 |
return; |
|
66 |
} |
|
67 |
if (sty instanceof KmlLineStyle) { |
|
68 |
this.lineStyle = (KmlLineStyle) sty; |
|
69 |
return; |
|
70 |
} |
|
71 |
if (sty instanceof KmlPolygonStyle) { |
|
72 |
this.polygonStyle = (KmlPolygonStyle) sty; |
|
73 |
return; |
|
74 |
} |
|
75 |
if (sty instanceof KmlLabelStyle) { |
|
76 |
this.labelStyle = (KmlLabelStyle) sty; |
|
77 |
return; |
|
78 |
} |
|
79 |
if (sty instanceof KmlCompoundStyle) { |
|
80 |
this.addStyles(((KmlCompoundStyle) sty).getStyles()); |
|
81 |
return; |
|
82 |
} |
|
83 |
} |
|
84 |
|
|
85 |
public KmlIconStyle getIconStyle() { |
|
86 |
return iconStyle; |
|
87 |
} |
|
88 |
|
|
89 |
public KmlLineStyle getLineStyle() { |
|
90 |
return lineStyle; |
|
91 |
} |
|
92 |
|
|
93 |
public KmlPolygonStyle getPolygonStyle() { |
|
94 |
return polygonStyle; |
|
95 |
} |
|
96 |
|
|
97 |
public KmlLabelStyle getLabelStyle() { |
|
98 |
return labelStyle; |
|
99 |
} |
|
100 |
|
|
101 |
/* |
Also available in: Unified diff