final Kml kml = new Kml(); Document document = kml.createAndSetDocument(); listForms = formDAO.getAll(); for (Form list : listForms){ document.createAndAddPlacemark() .withName(String.valueOf(list.getId())) .withDescription(list.toStringKML()) .createAndSetPoint().addToCoordinates(-20.3978398, -43.5146653); } kml.setFeature(document); kml.marshal(new File("test.kml"));
/** * Internal method * */ private void addKmzFile(Kml kmzFile, ZipOutputStream out, boolean mainfile) throws IOException { String fileName = null; if (((kmzFile.getFeature() == null)||(kmzFile.getFeature().getName() == null))||(kmzFile.getFeature().getName().length() == 0)) { fileName = (("noFeatureNameSet"+ missingNameCounter ++)+".kml"); } else { fileName = kmzFile.getFeature().getName(); if (!fileName.endsWith(".kml")) { fileName += ".kml"; } } if (mainfile) { fileName = "doc.kml"; } out.putNextEntry(new ZipEntry(URLEncoder.encode(fileName, "UTF-8"))); kmzFile.marshal(out); out.closeEntry(); }
public boolean marshalAsKmz( @NotNull String name, Kml... additionalFiles) throws IOException { ZipOutputStream out = new ZipOutputStream(new FileOutputStream(name)); out.setComment("KMZ-file created with Java API for KML. Visit us: http://code.google.com/p/javaapiforkml/"); this.addKmzFile(this, out, true); for (Kml kml: additionalFiles) { this.addKmzFile(kml, out, false); } out.close(); missingNameCounter = 1; return false; }
Marshaller m = JAXBContext.newInstance(new Class[] { Kml.class }).createMarshaller(); m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true ); m.setProperty( Marshaller.JAXB_FRAGMENT, false ); m.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8"); final Kml kml = new Kml(); kml.createAndSetPlacemark() .withName("London, UK").withOpen(Boolean.TRUE) .createAndSetPoint().addToCoordinates(-0.126236, 51.500152); StringWriter sw = new StringWriter(); m.marshal(kml,sw); String s1 = sw.toString(); System.out.println(s1);
public Kml buildKMLDocument() { // prepare kml, document and folder Kml kml = new Kml(); Document document = kml.createAndSetDocument(); Map formatOptions = context.getRequest().getFormatOptions(); String kmltitle = (String) formatOptions.get("kmltitle"); if(kmltitle == null) { kmltitle = context.getMapContent().getTitle(); } document.setName(kmltitle); // get the callbacks for the document and let them loose List<KmlDecorator> decorators = context.getDecoratorsForClass(Document.class); for (KmlDecorator decorator : decorators) { document = (Document) decorator.decorate(document, context); if (document == null) { throw new ServiceException("Coding error in decorator " + decorator + ", document objects cannot be set to null"); } } encodeDocumentContents(document); return kml; }
/** * Create an instance of {@link Kml} * */ public static Kml createKml() { return new Kml(); }
/** * fluent setter * @see #setFeature(Feature) * * @param feature * required parameter */ public Kml withFeature(final Feature feature) { this.setFeature(feature); return this; }
final Kml kml = new Kml(); final Folder folder = new Folder(); kml.setFeature(folder); folder.setName("Folder.kml"); folder.setOpen(true); final Placemark placemark1 = new Placemark().withId("1") .withName("Folder object 1 (Placemark)"); folder.getFeature().add(placemark1); final Placemark placemark2 = new Placemark().withId("2") .withName("Folder object 2 (Placemark)"); folder.getFeature().add(placemark2); List<Feature> features = folder.getFeature(); System.out.println(features); // dumps two features for(int i=features.size()-1; i >= 0; i--) { Feature f = features.get(i); if("1".equals(f.getId())) { // this removes feature with id = "1" features.remove(i); break; } } System.out.println(features); // folder now only has one item
final Folder folder = kml.createAndSetFolder() .withName(worksheet.getTitle()).withOpen(true); LookAt lookat = new LookAt(); kml.marshal(out); String test = out.toString(); Writer outUTF8;
/** * Java to KML * The object graph is marshalled to a File object. * The object is not saved as a zipped .kmz file. * @see marshalKmz(String, Kml...) * */ public boolean marshal(final File filename) throws FileNotFoundException { OutputStream out = new FileOutputStream(filename); return this.marshal(out); }
Assert.assertNotNull(is); Kml kml = Kml.unmarshal(is); Feature feature = kml.getFeature(); parseFeature(feature);
/** * Builds a lazily evaluated KML document given a encoding context * * @param context * @return */ public Kml buildKMLDocument(KmlEncodingContext context) { // prepare kml, document and folder Kml kml = new Kml(); Document document = kml.createAndSetDocument(); String kmltitle = (String) context.getRequest().getFormatOptions().get("kmltitle"); document.setName(kmltitle); // get the callbacks for the document and let them loose List<KmlDecorator> decorators = context.getDecoratorsForClass(Document.class); for (KmlDecorator decorator : decorators) { document = (Document) decorator.decorate(document, context); if (document == null) { throw new ServiceException("Coding error in decorator " + decorator + ", document objects cannot be set to null"); } } // create a generator that will generate a folder and feature dumps/ground overlays for each // layer SequenceFactory<Feature> generatorFactory = new PlainFolderSequenceFactory(context); SequenceList<Feature> folders = new SequenceList<Feature>(generatorFactory); context.addFeatures(document, folders); return kml; }
/** * Create an instance of {@link Kml} * */ public static Kml createKml() { return new Kml(); }
/** * fluent setter * @see #setFeature(Feature) * * @param feature * required parameter */ public Kml withFeature(final Feature feature) { this.setFeature(feature); return this; }
public File publishKML() throws FileNotFoundException { File outputFile = new File(ContextParametersRegistry.getInstance().getDefault().getParameterValue(ContextParameter.KML_PUBLISH_DIR) + worksheet.getTitle() + ".kml"); final Kml kml = KmlFactory.createKml(); final Folder folder = kml.createAndSetFolder() .withName(worksheet.getTitle()).withOpen(true); kml.marshal(outputFile); logger.info("KML file published. Location:" + outputFile.getAbsolutePath());
/** * Java to KML * The object graph is marshalled to a File object. * The object is not saved as a zipped .kmz file. * @see marshalKmz(String, Kml...) * */ public boolean marshal(final File filename) throws FileNotFoundException { OutputStream out = new FileOutputStream(filename); return this.marshal(out); }
throws IOException { Kml kml = new Kml(); Document document = kml.createAndSetDocument(); Folder folder = document.createAndAddFolder(); GroundOverlay go = folder.createAndAddGroundOverlay();
final Kml __balloonKML = new Kml();
/** * Creates a new instance of {@link ScreenOverlay} and set it to feature. * * This method is a short version for: * <code> * ScreenOverlay screenOverlay = new ScreenOverlay(); * this.setFeature(screenOverlay); </code> * * */ public ScreenOverlay createAndSetScreenOverlay() { ScreenOverlay newValue = new ScreenOverlay(); this.setFeature(newValue); return newValue; }
/** * Internal method * */ private void addKmzFile(Kml kmzFile, ZipOutputStream out, boolean mainfile) throws IOException { String fileName = null; if (((kmzFile.getFeature() == null)||(kmzFile.getFeature().getName() == null))||(kmzFile.getFeature().getName().length() == 0)) { fileName = (("noFeatureNameSet"+ missingNameCounter ++)+".kml"); } else { fileName = kmzFile.getFeature().getName(); if (!fileName.endsWith(".kml")) { fileName += ".kml"; } } if (mainfile) { fileName = "doc.kml"; } out.putNextEntry(new ZipEntry(URLEncoder.encode(fileName, "UTF-8"))); kmzFile.marshal(out); out.closeEntry(); }