Revision 1800
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.216/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/buildNumber.properties | ||
---|---|---|
1 |
#Fri Nov 25 00:44:09 CET 2022 |
|
2 |
buildNumber=2318 |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.216/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/resources-plugin/config.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<plugin-config> |
|
3 |
|
|
4 |
<depends plugin-name="org.gvsig.app.mainplugin" /> |
|
5 |
<depends plugin-name="org.gvsig.exportto.app.mainplugin" /> |
|
6 |
<depends plugin-name="org.gvsig.gpe.app.mainplugin" /> |
|
7 |
|
|
8 |
<libraries library-dir="lib"/> |
|
9 |
<resourceBundle name="text"/> |
|
10 |
<extensions> |
|
11 |
<extension class-name="org.gvsig.andami.LibraryExtension" |
|
12 |
description="" |
|
13 |
active="true" |
|
14 |
priority="1"> |
|
15 |
</extension> |
|
16 |
</extensions> |
|
17 |
</plugin-config> |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.216/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.216/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.216/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.216/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 |
File parametersFile = getParameters().getEvaluatedFile(); |
|
91 |
explorerParams.setRoot(parametersFile.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 |
"GPE" |
|
110 |
); |
|
111 |
((HasAFile) newStoreParameters).setFile(this.getParameters().getEvaluatedFile()); |
|
112 |
|
|
113 |
newStoreParameters.setDynValue("CRS", this.getParameters().getTargetProjection()); |
|
114 |
// Usamos el featureType por defecto del KML |
|
115 |
return newStoreParameters; |
|
116 |
} catch (DataException ex) { |
|
117 |
throw new ExportException(ex); |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
@Override |
|
122 |
protected OpenDataStoreParameters createTargetOpenStoreParameters() throws ExportException { |
|
123 |
try { |
|
124 |
DataManager dataManager = DALLocator.getDataManager(); |
|
125 |
OpenFeatureStoreParameters openStoreParameters = (OpenFeatureStoreParameters) dataManager.createStoreParameters("GPE"); |
|
126 |
((HasAFile) openStoreParameters).setFile(getParameters().getEvaluatedFile()); |
|
127 |
openStoreParameters.setDynValue("CRS", this.getParameters().getTargetProjection()); |
|
128 |
return openStoreParameters; |
|
129 |
} catch (DataException ex) { |
|
130 |
throw new ExportException(ex); |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
@Override |
|
135 |
public ExportKMLParameters getParameters() { |
|
136 |
return (ExportKMLParameters) super.getParameters(); |
|
137 |
} |
|
138 |
|
|
139 |
@Override |
|
140 |
public void export( |
|
141 |
FeatureSet featureSet) throws ExportException { |
|
142 |
DataServerExplorer explorer = this.createServerExplorer(); |
|
143 |
NewFeatureStoreParameters params = (NewFeatureStoreParameters) this.createTargetNewStoreParameters(); |
|
144 |
|
|
145 |
String providerName = params.getDataStoreName(); |
|
146 |
String explorerName = explorer.getProviderName(); |
|
147 |
|
|
148 |
File outFile = this.getParameters().getEvaluatedFile(); //kmlFile; |
|
149 |
FeatureSet featureStore = featureSet; |
|
150 |
|
|
151 |
FLyrVect vectorLayer = null; |
|
152 |
String mimeType = this.getParameters().getMimeType(); //mtype; |
|
153 |
boolean useLabels = this.getParameters().getUseLabels(); //doLabels; |
|
154 |
boolean attsAsBalloon = this.getParameters().getAttsAsBalloon(); |
|
155 |
ArrayList<ICoordTrans> ICoordTrans; |
|
156 |
|
|
157 |
List<ICoordTrans> transfList = new ArrayList<ICoordTrans>(); |
|
158 |
|
|
159 |
ICoordTrans ct = this.getParameters().getSourceTransformation(); //vlayer.getCoordTrans(); |
|
160 |
IProjection targetproj = this.getParameters().getTargetProjection(); |
|
161 |
// if (reprojectTo4326) { |
|
162 |
// 8 |
|
163 |
// targetproj = CRSFactory.getCRS("EPSG:4326"); |
|
164 |
// if (ct == null) { |
|
165 |
// transfList.add(this.getParameters().getSourceProjection().getCT(targetproj)); |
|
166 |
// } else { |
|
167 |
// transfList.add(ct); |
|
168 |
// transfList.add(ct.getPDest().getCT(targetproj)); |
|
169 |
// } |
|
170 |
// } else { |
|
171 |
if (ct == null) { |
|
172 |
if (targetproj == null) { |
|
173 |
targetproj = this.getParameters().getSourceProjection(); |
|
174 |
} |
|
175 |
ct = this.getParameters().getSourceProjection().getCT(targetproj); |
|
176 |
transfList.add(ct); |
|
177 |
} else { |
|
178 |
targetproj = ct.getPDest(); |
|
179 |
transfList.add(ct); |
|
180 |
} |
|
181 |
|
|
182 |
IGPEWriterHandler wh = null; |
|
183 |
FileOutputStream fos = null; |
|
184 |
String srs = targetproj.getAbrev(); |
|
185 |
|
|
186 |
String[] fldNames = null; |
|
187 |
Envelope env = null; |
|
188 |
long count = 0; |
|
189 |
FeatureType ftype; |
|
190 |
|
|
191 |
try { |
|
192 |
count = featureSet.getSize(); |
|
193 |
this.getTaskStatus().setRangeOfValues(0, count); |
|
194 |
if (this.getParameters().getExportAttributes().isActive()) { |
|
195 |
ftype = this.getParameters().getExportAttributes().getTargetFeatureType(); |
|
196 |
} else { |
|
197 |
ftype = featureStore.getDefaultFeatureType(); |
|
198 |
} |
|
199 |
fldNames = getAttributes(ftype); |
|
200 |
env = GeometryLocator.getGeometryManager().createEnvelope(Geometry.SUBTYPES.GEOM2D); |
|
201 |
this.initEnvelope(env, featureSet); |
|
202 |
} catch (DataException | CreateEnvelopeException | LocatorException e) { |
|
203 |
throw new ExportException(e); |
|
204 |
} |
|
205 |
|
|
206 |
try { |
|
207 |
env = reproject(env, transfList); |
|
208 |
} catch (CreateEnvelopeException ex) { |
|
209 |
throw new ExportException(ex); |
|
210 |
} |
|
211 |
|
|
212 |
Rectangle2D rect = new Rectangle2D.Double( |
|
213 |
env.getMinimum(0), |
|
214 |
env.getMinimum(1), |
|
215 |
env.getLength(0), |
|
216 |
env.getLength(1)); |
|
217 |
|
|
218 |
File fixedFile = outFile; |
|
219 |
try { |
|
220 |
|
|
221 |
if (!outFile.getAbsolutePath().toLowerCase().endsWith( |
|
222 |
"." + this.getFileExtension().toLowerCase())) { |
|
223 |
|
|
224 |
fixedFile = new File(outFile.getAbsolutePath() + "." + getFileExtension()); |
|
225 |
} |
|
226 |
|
|
227 |
wh = GPELocator.getGPEManager().createWriterByMimeType(mimeType); |
|
228 |
fos = new FileOutputStream(fixedFile); |
|
229 |
|
|
230 |
wh.setOutputStream(fos); |
|
231 |
wh.initialize(); |
|
232 |
// ========================================== |
|
233 |
wh.startLayer(null, null, fixedFile.getName(), null, srs); |
|
234 |
// ============== Styles ============= |
|
235 |
Map<ISymbol, KmlStyle> symsty = null; |
|
236 |
IXmlStreamWriter xmlw = getXmlStreamWriter(wh); |
|
237 |
if (true && xmlw != null && vectorLayer instanceof FLyrVect) { |
|
238 |
symsty = StyleUtils.getSymbolStyles((FLyrVect) vectorLayer, |
|
239 |
featureSet, |
|
240 |
attsAsBalloon, |
|
241 |
fldNames); |
|
242 |
Iterator<KmlStyle> iter = symsty.values().iterator(); |
|
243 |
KmlStyle sty = null; |
|
244 |
while (iter.hasNext()) { |
|
245 |
sty = iter.next(); |
|
246 |
writeStyle(xmlw, sty); |
|
247 |
} |
|
248 |
} |
|
249 |
// ========================================== |
|
250 |
wh.startBbox(null, new CoordinatesSequenceBbox(rect), srs); |
|
251 |
wh.endBbox(); |
|
252 |
// ============= Writing feature ============ |
|
253 |
IVectorLegend legend; |
|
254 |
if (vectorLayer instanceof FLyrVect) { |
|
255 |
legend = (IVectorLegend) ((FLyrVect) vectorLayer).getLegend(); |
|
256 |
} else { |
|
257 |
legend = null; |
|
258 |
} |
|
259 |
writeFeatures(wh, xmlw, featureSet, fldNames, symsty, legend, transfList); |
|
260 |
|
|
261 |
// writeFeatures(wh, xmlw, featureSet, fldNames, symsty, |
|
262 |
// (IVectorLegend) vectorLayer.getLegend()); |
|
263 |
// ========================================== |
|
264 |
wh.endLayer(); |
|
265 |
// ========================================== |
|
266 |
wh.close(); |
|
267 |
fos.close(); |
|
268 |
} catch (Exception exc) { |
|
269 |
throw new ExportException(exc); |
|
270 |
} |
|
271 |
|
|
272 |
this.getTaskStatus().setCurValue(count); |
|
273 |
// this.finishAction(fixedFile, targetproj); |
|
274 |
this.getTaskStatus().terminate(); |
|
275 |
this.getTaskStatus().remove(); |
|
276 |
|
|
277 |
} |
|
278 |
|
|
279 |
private String[] getAttributes(FeatureType ftype) { |
|
280 |
|
|
281 |
FeatureAttributeDescriptor[] atts = ftype.getAttributeDescriptors(); |
|
282 |
|
|
283 |
FeatureAttributeDescriptor desc = null; |
|
284 |
List<String> list = new ArrayList<String>(); |
|
285 |
for (int i = 0; i < atts.length; i++) { |
|
286 |
desc = atts[i]; |
|
287 |
if (desc.getDataType().getType() != DataTypes.GEOMETRY) { |
|
288 |
list.add(desc.getName()); |
|
289 |
} |
|
290 |
} |
|
291 |
return list.toArray(new String[0]); |
|
292 |
} |
|
293 |
|
|
294 |
private Geometry reproject(Geometry geom, List<ICoordTrans> transfList) { |
|
295 |
|
|
296 |
int sz = transfList.size(); |
|
297 |
if (sz == 0) { |
|
298 |
return geom; |
|
299 |
} else { |
|
300 |
Geometry resp = geom.cloneGeometry(); |
|
301 |
for (int i = 0; i < sz; i++) { |
|
302 |
resp.reProject(transfList.get(i)); |
|
303 |
} |
|
304 |
return resp; |
|
305 |
} |
|
306 |
|
|
307 |
} |
|
308 |
|
|
309 |
public String getFileExtension() { |
|
310 |
return "kml"; |
|
311 |
} |
|
312 |
|
|
313 |
// private void finishAction(File kmlfile, IProjection proj) |
|
314 |
// throws ExportException { |
|
315 |
// |
|
316 |
// this.createTargetOpenStoreParameters() |
|
317 |
// |
|
318 |
// if (exporttoServiceFinishAction != null) { |
|
319 |
// |
|
320 |
// /* |
|
321 |
// * Export is done. We notify with a SHPStoreParameters, |
|
322 |
// * not with the NewSHPParameters we have used: |
|
323 |
// */ |
|
324 |
// DataManagerProviderServices dataman |
|
325 |
// = (DataManagerProviderServices) DALLocator.getDataManager(); |
|
326 |
// |
|
327 |
// DataStoreParameters dsp = null; |
|
328 |
// try { |
|
329 |
// dsp = dataman.createStoreParameters("GPE"); |
|
330 |
// } catch (Exception e) { |
|
331 |
// throw new ExportException(e); //"Cannot add resulting kml file to view", e); |
|
332 |
// } |
|
333 |
// |
|
334 |
// dsp.setDynValue("File", kmlfile); |
|
335 |
// dsp.setDynValue("CRS", proj); |
|
336 |
// |
|
337 |
// try { |
|
338 |
// dsp.validate(); |
|
339 |
// } catch (ValidateDataParametersException e) { |
|
340 |
// throw new ExportException(e); |
|
341 |
// } |
|
342 |
// exporttoServiceFinishAction.finished(kmlfile.getName(), dsp); |
|
343 |
// } |
|
344 |
// } |
|
345 |
private void writeStyle(IXmlStreamWriter xmlw, KmlStyle sty) throws IOException { |
|
346 |
|
|
347 |
xmlw.writeStartElement(Kml2_1_Tags.STYLE); |
|
348 |
xmlw.writeStartAttribute(Kml2_1_Tags.ID); |
|
349 |
xmlw.writeValue(sty.getId()); |
|
350 |
xmlw.writeEndAttributes(); |
|
351 |
sty.writeXml(xmlw); |
|
352 |
xmlw.writeEndElement(); |
|
353 |
} |
|
354 |
|
|
355 |
private IXmlStreamWriter getXmlStreamWriter(IGPEWriterHandler wh) { |
|
356 |
|
|
357 |
IGPEWriterHandlerImplementor imple = wh.getImplementor(); |
|
358 |
if (!(imple instanceof GPEKmlWriterHandlerImplementor)) { |
|
359 |
/* |
|
360 |
* Unexpected class |
|
361 |
*/ |
|
362 |
return null; |
|
363 |
} |
|
364 |
GPEKmlWriterHandlerImplementor kmlimple = null; |
|
365 |
kmlimple = (GPEKmlWriterHandlerImplementor) imple; |
|
366 |
IXmlStreamWriter xmlw = kmlimple.getXMLStreamWriter(); |
|
367 |
return xmlw; |
|
368 |
} |
|
369 |
|
|
370 |
private void writeFeatures( |
|
371 |
IGPEWriterHandler gwh, |
|
372 |
IXmlStreamWriter xmlw, |
|
373 |
FeatureSet fset, |
|
374 |
String[] fieldNames, |
|
375 |
Map<ISymbol, KmlStyle> symsty, |
|
376 |
IVectorLegend lege, |
|
377 |
List<ICoordTrans> transfList) throws Exception { |
|
378 |
|
|
379 |
GeometryToGPEWriter gw = new GeometryToGPEWriter(gwh); |
|
380 |
DisposableIterator diter = fset.fastIterator(); |
|
381 |
Feature feat = null; |
|
382 |
long count = 0; |
|
383 |
this.getTaskStatus().setCurValue(count); |
|
384 |
ISymbol sym = null; |
|
385 |
int nullGeometries = 0; |
|
386 |
while (diter.hasNext()) { |
|
387 |
feat = (Feature) diter.next(); |
|
388 |
try { |
|
389 |
if (lege instanceof IVectorLegend) { |
|
390 |
sym = lege.getSymbolByFeature(feat); |
|
391 |
} |
|
392 |
} catch (MapContextException mce) { |
|
393 |
logger.info("While getting legend symbol.", mce); |
|
394 |
} |
|
395 |
KmlStyle kmlStyle; |
|
396 |
try { |
|
397 |
kmlStyle = symsty.get(sym); |
|
398 |
} catch (Exception e) { |
|
399 |
kmlStyle = null; |
|
400 |
} |
|
401 |
|
|
402 |
if (!writeFeature(feat, gwh, xmlw, gw, count, fieldNames, kmlStyle, transfList)) { |
|
403 |
nullGeometries++; |
|
404 |
}; |
|
405 |
count++; |
|
406 |
this.getTaskStatus().setCurValue(count); |
|
407 |
} |
|
408 |
if (nullGeometries > 0) { |
|
409 |
logger.warn("Can't export " + nullGeometries + " features because source geometries are null."); |
|
410 |
} |
|
411 |
diter.dispose(); |
|
412 |
} |
|
413 |
|
|
414 |
private boolean writeFeature( |
|
415 |
Feature feat, |
|
416 |
IGPEWriterHandler gwh, |
|
417 |
IXmlStreamWriter xmlw, |
|
418 |
GeometryToGPEWriter gw, |
|
419 |
long index, |
|
420 |
String[] fieldNames, |
|
421 |
KmlStyle ksty, |
|
422 |
List<ICoordTrans> transfList) throws IOException { |
|
423 |
|
|
424 |
Geometry geom = feat.getDefaultGeometry(); |
|
425 |
|
|
426 |
if (geom == null) { |
|
427 |
return false; |
|
428 |
} |
|
429 |
|
|
430 |
String strindex = String.valueOf(index); |
|
431 |
|
|
432 |
if (this.getParameters().getUseLabels()) { |
|
433 |
String lbl = getLabelForFeature(feat); |
|
434 |
gwh.startFeature(strindex, "FEATURE", lbl); |
|
435 |
} else { |
|
436 |
gwh.startFeature(strindex, "FEATURE", ""); |
|
437 |
} |
|
438 |
// ========================= |
|
439 |
// Style |
|
440 |
if (ksty != null) { |
|
441 |
xmlw.writeStartElement(Kml2_1_Tags.STYLEURL); |
|
442 |
xmlw.writeValue("#" + ksty.getId()); |
|
443 |
xmlw.writeEndElement(); |
|
444 |
} |
|
445 |
// ===== Balloon ============ |
|
446 |
if (this.getParameters().getAttsAsBalloon()) { |
|
447 |
writeBalloon(xmlw, feat, fieldNames); |
|
448 |
} |
|
449 |
|
|
450 |
// ============= Geometry |
|
451 |
|
|
452 |
/* |
|
453 |
* This has no effect if reprojection is not necessary |
|
454 |
*/ |
|
455 |
geom = reproject(geom, transfList); |
|
456 |
gw.writeGeometry(geom, this.getParameters().getUseLabels()); |
|
457 |
// ============= Attributes |
|
458 |
Object val = null; |
|
459 |
String fldname = null; |
|
460 |
for (int i = 0; i < fieldNames.length; i++) { |
|
461 |
val = feat.get(fieldNames[i]); |
|
462 |
fldname = fieldNames[i].replace(' ', '_'); |
|
463 |
gwh.startElement("", fldname, val == null ? "" : val.toString()); |
|
464 |
gwh.endElement(); |
|
465 |
} |
|
466 |
// ========================= |
|
467 |
gwh.endFeature(); |
|
468 |
return true; |
|
469 |
} |
|
470 |
|
|
471 |
private String getLabelForFeature(Feature feat) { |
|
472 |
return ""; |
|
473 |
|
|
474 |
// if (this.vectorLayer.isLabeled()) { |
|
475 |
// |
|
476 |
// String[] flds = vectorLayer.getLabelingStrategy().getUsedFields(); |
|
477 |
// int n = Math.min(flds.length, 2); |
|
478 |
// if (n == 0) { |
|
479 |
// return ""; |
|
480 |
// } else { |
|
481 |
// String resp = ""; |
|
482 |
// Object val = null; |
|
483 |
// if (n == 1) { |
|
484 |
// val = feat.get(flds[0]); |
|
485 |
// resp = (val == null) ? "" : val.toString(); |
|
486 |
// } else { |
|
487 |
// // n == 2 |
|
488 |
// val = feat.get(flds[0]); |
|
489 |
// resp = (val == null) ? "" : val.toString(); |
|
490 |
// val = feat.get(flds[1]); |
|
491 |
// resp = (val == null) ? resp : resp + ", " + val.toString(); |
|
492 |
// } |
|
493 |
// return resp; |
|
494 |
// } |
|
495 |
// |
|
496 |
// } else { |
|
497 |
// return ""; |
|
498 |
// } |
|
499 |
} |
|
500 |
|
|
501 |
private void writeBalloon(IXmlStreamWriter xmlw, Feature feat, String[] fieldNames) |
|
502 |
throws IOException { |
|
503 |
|
|
504 |
xmlw.writeStartElement(Kml2_1_Tags.EXTENDED_DATA); |
|
505 |
String fldrep = null; |
|
506 |
Object val = null; |
|
507 |
for (int i = 0; i < fieldNames.length; i++) { |
|
508 |
fldrep = fieldNames[i].replace(' ', '_'); |
|
509 |
xmlw.writeStartElement(Kml2_1_Tags.DATA); |
|
510 |
// Att ===================================================== |
|
511 |
xmlw.writeStartAttribute(null, "name"); |
|
512 |
xmlw.writeValue(fldrep); |
|
513 |
xmlw.writeEndAttributes(); |
|
514 |
// Value ===================================================== |
|
515 |
xmlw.writeStartElement(Kml2_1_Tags.VALUE); |
|
516 |
val = feat.get(fieldNames[i]); |
|
517 |
xmlw.writeValue(val == null ? "" : val.toString()); |
|
518 |
xmlw.writeEndElement(); |
|
519 |
// ============================================= |
|
520 |
xmlw.writeEndElement(); |
|
521 |
} |
|
522 |
xmlw.writeEndElement(); |
|
523 |
|
|
524 |
/* |
|
525 |
* |
|
526 |
<ExtendedData> |
|
527 |
<Data name="holeNumber"> |
|
528 |
<value>1</value> |
|
529 |
</Data> |
|
530 |
<Data name="holeYardage"> |
|
531 |
<value>234</value> |
|
532 |
</Data> |
|
533 |
<Data name="holePar"> |
|
534 |
<value>4</value> |
|
535 |
</Data> |
|
536 |
</ExtendedData> |
|
537 |
* |
|
538 |
*/ |
|
539 |
} |
|
540 |
|
|
541 |
private Envelope reproject(Envelope env, List<ICoordTrans> transfList) throws CreateEnvelopeException { |
|
542 |
|
|
543 |
int sz = transfList.size(); |
|
544 |
if (sz == 0) { |
|
545 |
return env; |
|
546 |
} else { |
|
547 |
Envelope resp = env; |
|
548 |
try { |
|
549 |
for (int i = 0; i < sz; i++) { |
|
550 |
resp = resp.convert(transfList.get(i)); |
|
551 |
} |
|
552 |
} catch (Exception exc) { |
|
553 |
|
|
554 |
// If this process fails, we'll use "emergency values": |
|
555 |
GeometryManager gm = GeometryLocator.getGeometryManager(); |
|
556 |
double[] min = new double[2]; |
|
557 |
double[] max = new double[2]; |
|
558 |
IProjection targetproj = this.getParameters().getTargetProjection(); |
|
559 |
if (targetproj.isProjected()) { |
|
560 |
min = new double[]{-20000000, -20000000}; |
|
561 |
max = new double[]{20000000, 20000000}; |
|
562 |
} else { |
|
563 |
min = new double[]{-180, -90}; |
|
564 |
max = new double[]{180, 90}; |
|
565 |
} |
|
566 |
|
|
567 |
resp = gm.createEnvelope( |
|
568 |
min[0], min[1], |
|
569 |
max[0], max[1], |
|
570 |
Geometry.SUBTYPES.GEOM2D); |
|
571 |
|
|
572 |
} |
|
573 |
return resp; |
|
574 |
} |
|
575 |
} |
|
576 |
|
|
577 |
private void initEnvelope(Envelope env, FeatureSet featureSet) { |
|
578 |
for (Feature feature : featureSet) { |
|
579 |
Geometry geometry = feature.getDefaultGeometry(); |
|
580 |
if (geometry != null && geometry.isValid()) { |
|
581 |
env.add(geometry); |
|
582 |
} |
|
583 |
} |
|
584 |
} |
|
585 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.216/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.ExportParametersFile; |
|
4 |
import org.gvsig.export.ExportParametersGeometry; |
|
5 |
|
|
6 |
/** |
|
7 |
* |
|
8 |
* @author jjdelcerro |
|
9 |
*/ |
|
10 |
public interface ExportKMLParameters extends ExportParametersGeometry, ExportParametersFile { |
|
11 |
public String getMimeType(); |
|
12 |
public void setMimeType(String value); |
|
13 |
public boolean getUseLabels(); |
|
14 |
public void setUseLabels(boolean value); |
|
15 |
public boolean getAttsAsBalloon(); |
|
16 |
public void setAttsAsBalloon(boolean value); |
|
17 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.216/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/service/ExportKMLParametersImpl.java | ||
---|---|---|
1 |
package org.gvsig.gpe.exportto.kml.service; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import org.apache.commons.io.FilenameUtils; |
|
5 |
import org.cresques.cts.IProjection; |
|
6 |
import org.gvsig.export.spi.AbstractExportParametersGeometryFile; |
|
7 |
import org.gvsig.export.spi.ExportServiceFactory; |
|
8 |
import org.gvsig.fmap.crs.CRSFactory; |
|
9 |
|
|
10 |
/** |
|
11 |
* |
|
12 |
* @author osc |
|
13 |
*/ |
|
14 |
public class ExportKMLParametersImpl |
|
15 |
extends AbstractExportParametersGeometryFile |
|
16 |
implements ExportKMLParameters |
|
17 |
{ |
|
18 |
private String mimeType = null; |
|
19 |
private boolean useLabels = false; |
|
20 |
private boolean attsAsBalloon = false; |
|
21 |
|
|
22 |
private File file; |
|
23 |
|
|
24 |
public ExportKMLParametersImpl(ExportServiceFactory factory) { |
|
25 |
super(factory); |
|
26 |
IProjection targetproj = CRSFactory.getCRS("EPSG:4326"); |
|
27 |
this.setTargetProjection(targetproj); |
|
28 |
this.getExportAttributes().setActive(true); |
|
29 |
this.fileHelper.setFileExtension(".kml"); |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public String getServiceName() { |
|
34 |
return ExportKMLServiceFactory.SERVICE_NAME; |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
public String getMimeType() { |
|
39 |
return this.mimeType; |
|
40 |
} |
|
41 |
|
|
42 |
@Override |
|
43 |
public boolean getUseLabels() { |
|
44 |
return this.useLabels; |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
public boolean getAttsAsBalloon() { |
|
49 |
return this.attsAsBalloon; |
|
50 |
} |
|
51 |
|
|
52 |
// @Override |
|
53 |
// public File getFile() { |
|
54 |
// return this.file; |
|
55 |
// } |
|
56 |
// |
|
57 |
// @Override |
|
58 |
// public void setFile(File file) { |
|
59 |
// this.file = new File(FilenameUtils.removeExtension(file.getAbsolutePath()) + ".kml"); |
|
60 |
// } |
|
61 |
|
|
62 |
@Override |
|
63 |
public void setUseLabels(boolean value) { |
|
64 |
this.useLabels = value; |
|
65 |
} |
|
66 |
|
|
67 |
@Override |
|
68 |
public void setAttsAsBalloon(boolean value) { |
|
69 |
this.attsAsBalloon = value; |
|
70 |
} |
|
71 |
|
|
72 |
@Override |
|
73 |
public void setMimeType(String value) { |
|
74 |
this.mimeType = value; |
|
75 |
} |
|
76 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.216/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.216/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 |
/* |
|
102 |
public KmlBalloonStyle getBalloonStyle() { |
|
103 |
return balloonStyle; |
|
104 |
} |
|
105 |
*/ |
|
106 |
} |
|
107 |
|
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.216/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/style/KmlBalloonStyle.java | ||
---|---|---|
1 |
package org.gvsig.gpe.exportto.kml.style; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.prov.kml.utils.Kml2_1_Tags; |
|
6 |
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter; |
|
7 |
|
|
8 |
|
|
9 |
/** |
|
10 |
* Balloon style to show when user clicks on marker. |
|
11 |
* Currently not used because CDDATA is not written properly |
|
12 |
* (writer escapes it) |
|
13 |
* |
|
14 |
* @author jldominguez |
|
15 |
* |
|
16 |
*/ |
|
17 |
public class KmlBalloonStyle extends KmlStyle { |
|
18 |
|
|
19 |
private String[] fields = new String[0]; |
|
20 |
|
|
21 |
public KmlBalloonStyle(String[] flds, String id) { |
|
22 |
setId(id); |
|
23 |
if (flds != null) { |
|
24 |
fields = flds; |
|
25 |
} |
|
26 |
} |
|
27 |
|
|
28 |
public void writeXml(IXmlStreamWriter writer) throws IOException { |
|
29 |
|
|
30 |
writer.writeStartElement(Kml2_1_Tags.BALLOON_STYLE); |
|
31 |
writer.writeStartElement(Kml2_1_Tags.TEXT); |
|
32 |
|
|
33 |
// ==================================== |
|
34 |
String cddata = "<![CDATA["; |
|
35 |
cddata = cddata + htmlTable(); |
|
36 |
cddata = cddata + "]]>"; |
|
37 |
// ==================================== |
|
38 |
writer.writeValue(cddata); |
|
39 |
writer.writeEndElement(); |
|
40 |
writer.writeEndElement(); |
|
41 |
|
|
42 |
/* |
|
43 |
<Style id="golf-balloon-style"> |
|
44 |
<BalloonStyle> |
|
45 |
<text> |
|
46 |
<![CDATA[ |
|
47 |
<table> |
|
48 |
<tr><td>This is $[name]</td><td> : </td><td>This is $[name]</td></tr> |
|
49 |
<tr><td>This is hole $[holeNumber]</td><td> : </td><td>This is $[name]</td></tr> |
|
50 |
<tr><td>The par for this hole is $[holePar]</td><td> : </td><td>This is $[name]</td></tr> |
|
51 |
<tr><td>The yardage is $[holeYardage]</td><td> : </td><td><b>This is $[name]</b></td></tr> |
|
52 |
</table> |
|
53 |
]]> |
|
54 |
</text> |
|
55 |
</BalloonStyle> |
|
56 |
</Style> |
|
57 |
*/ |
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
} |
|
62 |
|
|
63 |
private String htmlTable() { |
|
64 |
|
|
65 |
String resp = "<table>\n"; |
|
66 |
String aux = null; |
|
67 |
String auxrep = null; |
|
68 |
for (int i=0; i<fields.length; i++) { |
|
69 |
aux = fields[i]; |
|
70 |
auxrep = aux.replace(' ', '_'); |
|
71 |
auxrep = "$[" + auxrep + "]"; |
|
72 |
resp = resp + "<tr><td>" + aux + "</td><td> : </td><td><b>" + auxrep + "</b></td></tr>\n"; |
|
73 |
} |
|
74 |
resp = resp + "</table>\n"; |
|
75 |
return resp; |
|
76 |
} |
|
77 |
|
|
78 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.216/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/style/KmlLineStyle.java | ||
---|---|---|
1 |
package org.gvsig.gpe.exportto.kml.style; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.prov.kml.utils.Kml2_1_Tags; |
|
6 |
import org.gvsig.gpe.prov.kml.utils.KmlUtilsParser; |
|
7 |
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter; |
|
8 |
|
|
9 |
public class KmlLineStyle extends KmlColorStyle { |
|
10 |
public float getWidth() { |
|
11 |
return width; |
|
12 |
} |
|
13 |
|
|
14 |
public void setWidth(float width) { |
|
15 |
this.width = width; |
|
16 |
} |
|
17 |
|
|
18 |
protected float width = 1; |
|
19 |
|
|
20 |
@Override |
|
21 |
public void writeXml(IXmlStreamWriter writer) throws IOException { |
|
22 |
writer.writeStartElement(Kml2_1_Tags.LINE_STYLE); |
|
23 |
|
|
24 |
writer.writeStartElement(Kml2_1_Tags.COLOR); |
|
25 |
writer.writeValue(KmlUtilsParser.fromColorToABGR(color)); |
|
26 |
writer.writeEndElement(); |
|
27 |
writer.writeStartElement(Kml2_1_Tags.WIDTH); |
|
28 |
writer.writeValue(width); |
|
29 |
writer.writeEndElement(); |
|
30 |
|
|
31 |
writer.writeEndElement(); |
|
32 |
} |
|
33 |
|
|
34 |
|
|
35 |
} |
|
36 |
|
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.216/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/style/KmlPolygonStyle.java | ||
---|---|---|
1 |
package org.gvsig.gpe.exportto.kml.style; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.prov.kml.utils.Kml2_1_Tags; |
|
6 |
import org.gvsig.gpe.prov.kml.utils.KmlUtilsParser; |
|
7 |
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter; |
|
8 |
|
|
9 |
/** |
|
10 |
* @author Francisco Jos? Pe?arrubia (fjp@scolab.es) |
|
11 |
* |
|
12 |
* To convert from a symbol to a polygon style we will need a PolygonStyle |
|
13 |
* and a LineStyle if the outline has some width or to specify the color |
|
14 |
* @see @KmlCompoundStyle |
|
15 |
*/ |
|
16 |
public class KmlPolygonStyle extends KmlColorStyle { |
|
17 |
protected boolean fill = true; |
|
18 |
protected boolean outline; |
|
19 |
|
|
20 |
public boolean isFill() { |
|
21 |
return fill; |
|
22 |
} |
|
23 |
|
|
24 |
public void setFill(boolean fill) { |
|
25 |
this.fill = fill; |
|
26 |
} |
|
27 |
|
|
28 |
public boolean isOutline() { |
|
29 |
return outline; |
|
30 |
} |
|
31 |
|
|
32 |
public void setOutline(boolean outline) { |
|
33 |
this.outline = outline; |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
public void writeXml(IXmlStreamWriter writer) throws IOException { |
|
38 |
writer.writeStartElement(Kml2_1_Tags.POLY_STYLE); |
|
39 |
|
|
40 |
writer.writeStartElement(Kml2_1_Tags.COLOR); |
|
41 |
writer.writeValue(KmlUtilsParser.fromColorToABGR(color)); |
|
42 |
writer.writeEndElement(); |
|
43 |
if (!fill) { |
|
44 |
writer.writeStartElement(Kml2_1_Tags.POLY_FILL); |
|
45 |
writer.writeValue(0); |
|
46 |
writer.writeEndElement(); |
|
47 |
} |
|
48 |
if (outline) { |
|
49 |
writer.writeStartElement(Kml2_1_Tags.POLY_OUTLINE); |
|
50 |
writer.writeValue(1); |
|
51 |
writer.writeEndElement(); |
|
52 |
} |
|
53 |
|
|
54 |
writer.writeEndElement(); |
|
55 |
|
|
56 |
} |
|
57 |
|
|
58 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.216/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/style/KmlIconStyle.java | ||
---|---|---|
1 |
package org.gvsig.gpe.exportto.kml.style; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.prov.kml.utils.Kml2_1_Tags; |
|
6 |
import org.gvsig.gpe.prov.kml.utils.KmlUtilsParser; |
|
7 |
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter; |
|
8 |
|
|
9 |
public class KmlIconStyle extends KmlColorStyle { |
|
10 |
|
|
11 |
protected float heading = 0; |
|
12 |
protected String href = null; |
|
13 |
protected float scale = 1; |
|
14 |
|
|
15 |
public float getScale() { |
|
16 |
return scale; |
|
17 |
} |
|
18 |
|
|
19 |
public void setScale(float scale) { |
|
20 |
this.scale = scale; |
|
21 |
} |
|
22 |
|
|
23 |
|
|
24 |
public void writeXml(IXmlStreamWriter writer) throws IOException { |
|
25 |
writer.writeStartElement(Kml2_1_Tags.ICON_STYLE); |
|
26 |
|
|
27 |
writer.writeStartElement(Kml2_1_Tags.COLOR); |
|
28 |
writer.writeValue(KmlUtilsParser.fromColorToABGR(color)); |
|
29 |
writer.writeEndElement(); |
|
30 |
|
|
31 |
writer.writeStartElement(Kml2_1_Tags.HEADING); |
|
32 |
writer.writeValue(heading); |
|
33 |
writer.writeEndElement(); |
|
34 |
|
|
35 |
if (scale != 1) { |
|
36 |
writer.writeStartElement(Kml2_1_Tags.SCALE); |
|
37 |
writer.writeValue(scale); |
|
38 |
writer.writeEndElement(); |
|
39 |
} |
|
40 |
if (href != null) { |
|
41 |
writer.writeStartElement(Kml2_1_Tags.ICON); |
|
42 |
writer.writeStartElement(Kml2_1_Tags.HREF); |
|
43 |
writer.writeValue(href); |
|
44 |
writer.writeEndElement(); |
|
45 |
|
|
46 |
writer.writeEndElement(); |
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
writer.writeEndElement(); |
|
51 |
|
|
52 |
|
|
53 |
} |
|
54 |
|
|
55 |
public float getHeading() { |
|
56 |
return heading; |
|
57 |
} |
|
58 |
|
|
59 |
public void setHeading(float heading) { |
|
60 |
this.heading = heading; |
|
61 |
} |
|
62 |
|
|
63 |
public String getHref() { |
|
64 |
return href; |
|
65 |
} |
|
66 |
|
|
67 |
public void setHref(String href) { |
|
68 |
this.href = href; |
|
69 |
} |
|
70 |
|
|
71 |
} |
|
72 |
|
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.216/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/style/StyleUtils.java | ||
---|---|---|
1 |
package org.gvsig.gpe.exportto.kml.style; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.HashMap; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Map; |
|
7 |
|
|
8 |
import org.gvsig.fmap.dal.exception.DataException; |
|
9 |
import org.gvsig.fmap.dal.feature.Feature; |
|
10 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
11 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
12 |
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend; |
|
13 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
|
14 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
15 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
|
16 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
17 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
|
18 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IPictureMarkerSymbol; |
|
19 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
20 |
|
|
21 |
|
|
22 |
public class StyleUtils { |
|
23 |
|
|
24 |
public static Map<ISymbol, KmlStyle> getSymbolStyles( |
|
25 |
FLyrVect vlayer, |
|
26 |
FeatureSet fset, |
|
27 |
boolean balloon, |
|
28 |
String[] flds) throws Exception { |
|
29 |
|
|
30 |
boolean preventMarker = false; |
|
31 |
|
|
32 |
IVectorLegend leg = (IVectorLegend) vlayer.getLegend(); |
|
33 |
Map<ISymbol, KmlStyle> resp = new HashMap<ISymbol, KmlStyle>(); |
|
34 |
|
|
35 |
ISymbol defaultSym = leg.getDefaultSymbol(); |
|
36 |
KmlStyle defaultStyle = getStyle(defaultSym); |
|
37 |
if (defaultSym != null && defaultStyle != null) { |
|
38 |
/* |
|
39 |
* This is used to set an empty icon style because |
|
40 |
* the geometry is not originally a point or multipoint |
|
41 |
*/ |
|
42 |
preventMarker = !(defaultStyle instanceof KmlIconStyle); |
|
43 |
KmlCompoundStyle cs = new KmlCompoundStyle(); |
|
44 |
cs.addStyle(defaultStyle); |
|
45 |
if (balloon) { |
|
46 |
// Not used, see javadoc of KmlBalloonStyle |
|
47 |
// cs.addStyle(new KmlBalloonStyle(flds, "balloonStyle")); |
|
48 |
} |
|
49 |
if (preventMarker) { |
|
50 |
cs.addStyle(new KmlIconStyle()); |
|
51 |
} |
|
52 |
cs.setId("defaultStyle"); |
|
53 |
resp.put(defaultSym, cs); |
|
54 |
} |
|
55 |
|
|
56 |
if (leg instanceof IClassifiedVectorLegend) { |
|
57 |
|
|
58 |
IClassifiedVectorLegend cLeg = (IClassifiedVectorLegend) leg; |
|
59 |
ISymbol[] symbolsAux = cLeg.getSymbols(); |
|
60 |
if (fset == null || symbolsAux.length < fset.getSize()) { |
|
61 |
|
|
62 |
for (int i=0; i < symbolsAux.length; i++) { |
|
63 |
ISymbol s = symbolsAux[i]; |
|
64 |
KmlStyle style = getStyle(s); |
|
65 |
if (s != null && style != null) { |
|
66 |
preventMarker = !(style instanceof KmlIconStyle); |
|
67 |
KmlCompoundStyle cs = new KmlCompoundStyle(); |
|
68 |
cs.addStyle(style); |
|
69 |
if (balloon) { |
|
70 |
// Not used, see javadoc of KmlBalloonStyle |
|
71 |
// cs.addStyle(new KmlBalloonStyle(flds, "bs" + Integer.toString(i))); |
|
72 |
} |
|
73 |
if (preventMarker) { |
|
74 |
cs.addStyle(new KmlIconStyle()); |
|
75 |
} |
|
76 |
cs.setId(Integer.toString(i)); |
|
77 |
resp.put(s, cs); |
|
78 |
} |
|
79 |
} |
|
80 |
} else { |
|
81 |
DisposableIterator diter = null; |
|
82 |
diter = fset.fastIterator(); |
|
83 |
Feature feat = null; |
|
84 |
int ind = 0; |
|
85 |
while (diter.hasNext()) { |
|
86 |
feat = (Feature) diter.next(); |
|
87 |
ISymbol s = leg.getSymbolByFeature(feat); |
|
88 |
KmlStyle style = getStyle(s); |
|
89 |
if (s != null && style != null) { |
|
90 |
preventMarker = !(style instanceof KmlIconStyle); |
|
91 |
KmlCompoundStyle cs = new KmlCompoundStyle(); |
|
92 |
cs.addStyle(style); |
|
93 |
if (balloon) { |
|
94 |
// Not used, see javadoc of KmlBalloonStyle |
|
95 |
// cs.addStyle(new KmlBalloonStyle(flds, "bs" + Integer.toString(ind))); |
|
96 |
} |
|
97 |
if (preventMarker) { |
|
98 |
cs.addStyle(new KmlIconStyle()); |
|
99 |
} |
|
100 |
cs.setId(Integer.toString(ind)); |
|
101 |
resp.put(s, cs); |
|
102 |
ind++; |
|
103 |
} |
|
104 |
} |
|
105 |
} |
|
106 |
} |
|
107 |
return resp; |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* Returns null if it cannot be rendered in KML |
|
112 |
* |
|
113 |
* @param s |
|
114 |
* @return |
|
115 |
*/ |
|
116 |
public static KmlStyle getStyle(ISymbol s) { |
|
117 |
|
|
118 |
if (s == null) { |
|
119 |
return null; |
|
120 |
} |
|
121 |
|
|
122 |
if (s instanceof IPictureMarkerSymbol) { |
|
123 |
IPictureMarkerSymbol pms = (IPictureMarkerSymbol) s; |
|
124 |
String str = pms.getSource().toString(); |
|
125 |
if (str != null && str.indexOf("http") == 0) { |
|
126 |
KmlIconStyle icoStyle = new KmlIconStyle(); |
|
127 |
icoStyle.setColor(((IMarkerSymbol) s).getColor()); |
|
128 |
icoStyle.setHref(str); |
|
129 |
float angKml = (float) radToKmlDeg(((IMarkerSymbol) s).getRotation()); |
|
130 |
icoStyle.setHeading(angKml); |
|
131 |
return icoStyle; |
|
132 |
} else { |
|
133 |
// Simple marker not supported |
|
134 |
return null; |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
138 |
if (s instanceof ILineSymbol) { |
|
139 |
ILineSymbol lSym = (ILineSymbol) s; |
|
140 |
KmlLineStyle lStyle = new KmlLineStyle(); |
|
141 |
lStyle.setColor(lSym.getColor()); |
|
142 |
lStyle.setWidth((float) lSym.getLineWidth()); |
|
143 |
return lStyle; |
|
144 |
} |
|
145 |
|
|
146 |
if (s instanceof IFillSymbol) { |
|
147 |
|
|
148 |
IFillSymbol fSym = (IFillSymbol) s; |
|
149 |
KmlCompoundStyle cStyle = new KmlCompoundStyle(); |
|
150 |
KmlLineStyle lStyle = new KmlLineStyle(); |
|
151 |
ILineSymbol lSym = fSym.getOutline(); |
|
152 |
lStyle.setColor(lSym.getColor()); |
|
153 |
lStyle.setWidth((float) lSym.getLineWidth()); |
|
154 |
|
|
155 |
KmlPolygonStyle fStyle = new KmlPolygonStyle(); |
|
156 |
fStyle.setColor(fSym.getFillColor()); |
|
157 |
fStyle.setOutline(fSym.hasOutline()); |
|
158 |
fStyle.setFill(fSym.hasFill()); |
|
159 |
|
|
160 |
cStyle.addStyle(lStyle); |
|
161 |
cStyle.addStyle(fStyle); |
|
162 |
return cStyle; |
|
163 |
} |
|
164 |
// Not supported |
|
165 |
return null; |
|
166 |
} |
|
167 |
|
|
168 |
|
|
169 |
public static double kmlDegToRad(double angleDegree) { |
|
170 |
double deg = 90 - angleDegree; |
|
171 |
return Math.toRadians(deg); |
|
172 |
} |
|
173 |
|
|
174 |
public static double radToKmlDeg(double rad) { |
|
175 |
double angleDegree = Math.toDegrees(rad); |
|
176 |
double deg = 90 - angleDegree; |
|
177 |
if (deg >= 360) { |
|
178 |
deg = deg - 360; |
|
179 |
} |
|
180 |
if (deg < 0) { |
|
181 |
deg = deg + 360; |
|
182 |
} |
|
183 |
return deg; |
|
184 |
} |
|
185 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.216/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/style/KmlColorStyle.java | ||
---|---|---|
1 |
package org.gvsig.gpe.exportto.kml.style; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
|
|
5 |
public abstract class KmlColorStyle extends KmlStyle { |
|
6 |
protected Color color = new Color(220, 10, 20, 80); |
|
7 |
|
|
8 |
public Color getColor() { |
|
9 |
return color; |
|
10 |
} |
|
11 |
|
|
12 |
public void setColor(Color color) { |
|
13 |
this.color = color; |
|
14 |
} |
|
15 |
} |
org.gvsig.gpe/library/tags/org.gvsig.gpe-2.1.216/org.gvsig.gpe.exportto/org.gvsig.gpe.exportto.kml/src/main/java/org/gvsig/gpe/exportto/kml/style/KmlLabelStyle.java | ||
---|---|---|
1 |
package org.gvsig.gpe.exportto.kml.style; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.prov.kml.utils.Kml2_1_Tags; |
|
6 |
import org.gvsig.gpe.prov.kml.utils.KmlUtilsParser; |
|
7 |
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter; |
|
8 |
|
|
9 |
/** |
|
10 |
* @author Francisco Jos? Pe?arrubia (fjp@scolab.es) |
|
11 |
* |
|
12 |
* Labels are exported as features. Google Earth will render the attribute <name> |
Also available in: Unified diff