예제 #1
0
 public static Kml create(File albumFile, String albumName) {
   if (!albumFile.exists()) {
     albumFile.mkdirs();
   }
   Kml kml = new Kml();
   Folder root = new Folder();
   root.setName(albumName);
   kml.addFolder(root);
   return kml;
 }
예제 #2
0
 public static void writeKml(File albumFile, Kml kml) throws IOException {
   final File kmlFile = new File(albumFile, KML_FILE_NAME);
   if (!kmlFile.exists()) {
     kmlFile.createNewFile();
   }
   FileUtils.writeText(kml.toKML(), kmlFile);
 }
예제 #3
0
  public static KmzParseResult parse(File albumFile) {
    final KmzParseResult result = new KmzParseResult();
    result.isValid = false;

    final File kmlFile = new File(albumFile, KML_FILE_NAME);
    if (kmlFile == null || !kmlFile.exists()) {
      return result;
    }

    try {
      /**
       * You probably don't want IDs auto-generated when you're loading a document. You can always
       * turn it back on later. NOTE: KML updates will only work for objects that have an ID (either
       * autogenerated or assigned).
       */
      Configuration.properties.setProperty(Configuration.GENERATE_IDS, Configuration.OFF);
      final Kml kml = KMLParser.parse(kmlFile);

      final String albumAbsPath = albumFile.getAbsolutePath();
      final long albumId = Long.valueOf(albumFile.getName());

      // Get folder
      Folder albumFolder = kml.getFolder();
      if (albumFolder != null) {

        // Get name
        result.albumName = albumFolder.getName();
        result.isValid = true;

        // Iterate placemarks
        result.pictures = new ArrayList();
        Placemark[] placemarks = albumFolder.getPlacemarks();
        for (int i = 0; i < placemarks.length; ++i) {
          Placemark placemark = placemarks[i];

          // Get image path and text from description
          String[] imageAndText = toImageAndText(placemark.getDescription());
          if (imageAndText[0] != null) {

            // Without an image, it is not interesting
            String pictureRelPath = imageAndText[0];

            // Make sure the resource file is present
            if (new File(albumFile, pictureRelPath).exists()) {

              // Get point for coordinates
              Point point = placemark.getPoint();
              if (point != null) {

                // Get coordinates
                double[] latLon = toLatLon(point.getCoordinates());
                double latitude = latLon[0];
                double longitude = latLon[1];
                if (latitude != Constants.NO_GEO_TAG && longitude != Constants.NO_GEO_TAG) {

                  // Without coordinates, it is not interesting

                  // Get time
                  long date = toTime(placemark.getTimeStamp());

                  // Get description
                  String description = imageAndText[1];
                  if (description == null) {
                    description = "";
                  }

                  final String nameId = pictureRelPath.toLowerCase().replaceAll(Constants.JPG, "");
                  final Picture picture =
                      new Picture(Long.valueOf(nameId), true, latitude, longitude, date);
                  picture.setMiniPath(albumAbsPath + "/" + pictureRelPath);
                  picture.setGroupId(albumId);
                  picture.setDescription(description);
                  result.pictures.add(picture);
                }
              }
            }
          }
        }
      }
    } catch (IOException e) {
      result.isValid = false;
    } catch (XmlPullParserException e) {
      result.isValid = false;
    }
    return result;
  }