private void write(final String filename) {
   // init kml
   this.mainKml = this.kmlObjectFactory.createKmlType();
   this.mainDoc = this.kmlObjectFactory.createDocumentType();
   this.mainKml.setAbstractFeatureGroup(this.kmlObjectFactory.createDocument(mainDoc));
   // create a folder
   this.mainFolder = this.kmlObjectFactory.createFolderType();
   this.mainFolder.setName("Matsim Data");
   this.mainDoc.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(this.mainFolder));
   // the writer
   this.writer = new KMZWriter(filename);
   Set<Plan> planSetBig = filterPlans();
   log.info("Found " + planSetBig.size() + " relevant plans");
   int i = 0;
   int max = 50;
   Set<Plan> planSet = new HashSet<Plan>(max);
   for (Plan p : planSetBig) {
     planSet.add(p);
     i++;
     if (i > max) break;
   }
   try {
     // add the matsim logo to the kml
     ScreenOverlayType logo = MatsimKMLLogo.writeMatsimKMLLogo(writer);
     this.mainFolder
         .getAbstractFeatureGroup()
         .add(this.kmlObjectFactory.createScreenOverlay(logo));
     KmlPlansWriter plansWriter =
         new KmlPlansWriter(
             this.scenario.getNetwork(),
             TransformationFactory.getCoordinateTransformation(
                 this.scenario.getConfig().global().getCoordinateSystem(),
                 TransformationFactory.WGS84),
             this.writer,
             this.mainDoc);
     FolderType plansFolder = plansWriter.getPlansFolder(planSet);
     this.mainFolder
         .getAbstractFeatureGroup()
         .add(this.kmlObjectFactory.createFolder(plansFolder));
   } catch (IOException e) {
     log.error("Cannot create kmz or logo.", e);
   }
   this.writer.writeMainKml(this.mainKml);
   this.writer.close();
   log.info("Plans written to kmz: " + filename);
 }
Example #2
0
  public void writeFile() {

    String outputFile = this.outputDirectory + "/" + this.kmzFileName;

    ObjectFactory LocalkmlObjectFactory = new ObjectFactory();

    // create main file and document

    DocumentType mainDoc = LocalkmlObjectFactory.createDocumentType();
    mainDoc.setId("mainDoc");
    mainDoc.setOpen(Boolean.TRUE);

    KmlType mainKml = LocalkmlObjectFactory.createKmlType();
    mainKml.setAbstractFeatureGroup(LocalkmlObjectFactory.createDocument(mainDoc));

    // create a folder
    FolderType mainFolder = LocalkmlObjectFactory.createFolderType();
    mainFolder.setId("actsFolder");
    mainFolder.setName("Matsim Data");
    mainFolder.setOpen(Boolean.TRUE);
    mainDoc.getAbstractFeatureGroup().add(LocalkmlObjectFactory.createFolder(mainFolder));

    // create the writer
    KMZWriter writer = new KMZWriter(outputFile);

    this.styleFactory = new MyKmlStyleFactory(writer, mainDoc);
    this.networkFeatureFactory = new MyFeatureFactory(this.coordinateTransform);

    try {

      // add the MATSim logo to the kml
      ScreenOverlayType logo = MatsimKMLLogo.writeMatsimKMLLogo(writer);
      mainFolder.getAbstractFeatureGroup().add(LocalkmlObjectFactory.createScreenOverlay(logo));

      // add the person's activity links to the kml
      if (this.writeActivities) {
        createActivityLinks();

        Collection<FolderType> activityFolderCollection = getActivities();

        for (FolderType activityFolder : activityFolderCollection) {
          if (activityFolder != null) {
            activityFolder.setVisibility(Boolean.FALSE);
            mainFolder
                .getAbstractFeatureGroup()
                .add(LocalkmlObjectFactory.createFolder(activityFolder));
          }
        }
      }

      // add the person's activity links to the kml
      if (this.writeActivityLinks) {
        createActivityLinks();
        FolderType activityLinksFolder =
            getActivityLinksFolder(this.createActivityLinks(), "Activity Links of Person ");
        if (activityLinksFolder != null) {
          activityLinksFolder.setVisibility(Boolean.FALSE);
          mainFolder
              .getAbstractFeatureGroup()
              .add(LocalkmlObjectFactory.createFolder(activityLinksFolder));
        }
      }

    } catch (IOException e) {
      log.error("Cannot create kmz or logo.", e);
    }
    writer.writeMainKml(mainKml);
    writer.close();
    log.info("... finished");
  }