Package projet

Source Code of projet.EcrireKml

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package projet;

import de.micromata.opengis.kml.v_2_2_0.*;
import isovaleur.Segment;
import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.*;





/**
*
* @author Walid
*/
public class EcrireKml {
   
   
    public static void writeKml(String fichier, String fichierKML) throws FileNotFoundException, IOException{
        Kml kml = KmlFactory.createKml();
        ArrayList<Feature> features = new ArrayList<Feature>();
        Document document = KmlFactory.createDocument();
        GroundOverlay groundOverlay = KmlFactory.createGroundOverlay();
        try{
            InputStream ips=new FileInputStream(fichier);
      InputStreamReader ipsr=new InputStreamReader(ips);
      BufferedReader br=new BufferedReader(ipsr);
      String ligne;
            Placemark plMark = KmlFactory.createPlacemark();
            Style style = KmlFactory.createStyle();
            IconStyle iconStyle = KmlFactory.createIconStyle();
            Icon icon = KmlFactory.createIcon();
            icon.setHref("earth.png");
            iconStyle.setIcon(icon);
            style.setIconStyle(iconStyle);
            ArrayList<StyleSelector> listStyles = new ArrayList<StyleSelector>();
            style.setIconStyle(iconStyle);
            listStyles.add(style);
            plMark.setStyleSelector(listStyles);
            features.add(plMark);
            while((ligne=br.readLine())!=null){
                String [ ] inter = ligne.split(";");
                if(inter.length == 5){
                    Placemark placemark = KmlFactory.createPlacemark();
                    placemark.setName(inter[0]);
                    placemark.setVisibility(true);
                    placemark.setOpen(false);
                    placemark.setDescription("Concentration de particules: " + inter[4]);
                    placemark.setStyleUrl("styles.kml#jugh_style");
               
                    Point point = KmlFactory.createPoint();
                    point.setExtrude(false);
                    point.setAltitudeMode(AltitudeMode.CLAMP_TO_GROUND);
                    //Add <coordinates>9.444652669565212,51.30473589438118,0<coordinates>.
               
                    point.getCoordinates().add(new Coordinate(inter[1].replace(",", ".") + "," + virguleTopoint(inter[2]) + "," + inter[3]));

                    placemark.setGeometry(point);      // <-- point is registered at placemark ownership.
                    features.add(placemark);
                    //kml.setFeature(placemark);
                }
               
               
               
            }
            document.setFeature(features);
            kml.setFeature(document);
            br.close();
           
        }
        catch (Exception e){
    System.out.println(e.toString());
               
  }
       
        try {
            kml.marshal(new File(fichierKML));           // <-- Print the KML structure to the console.
        } catch (FileNotFoundException ex) {
            Logger.getLogger(EcrireKml.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
       
       
        public static void writeKml(String fichier, String fichierKML, DonneesAgreg d, Horaire instantDebut) throws FileNotFoundException, IOException{
        DonneesGeo donneesCour;
        int idImage = 0;
        Kml kml = KmlFactory.createKml();
        ArrayList<Feature> features = new ArrayList<Feature>();
        Document document = KmlFactory.createDocument();
       
        for(int i = 0; i < d.getDonneesGeo().get(0).getConcentrationsHoraires().size(); i++){
                GroundOverlay groundOverlay = KmlFactory.createGroundOverlay();
                TimeStamp timeStamp = KmlFactory.createTimeStamp();
                timeStamp.setWhen(instantDebut.toString());
                Icon icon = KmlFactory.createIcon();
                String nomImage = "images/earth" + i + ".png";
                icon.setHref(nomImage);
                LatLonBox latLonBox = KmlFactory.createLatLonBox();
                latLonBox.setNorth(InterShepard.longitudeMax(d.getDonneesGeo()));
                latLonBox.setSouth(InterShepard.longitudeMin(d.getDonneesGeo()));
                latLonBox.setEast(InterShepard.latitudeMax(d.getDonneesGeo()));
                latLonBox.setWest(InterShepard.latitudeMin(d.getDonneesGeo()));
                latLonBox.setRotation(90.);
                groundOverlay.setTimePrimitive(timeStamp);
                groundOverlay.setIcon(icon);
                groundOverlay.setLatLonBox(latLonBox);
                features.add(groundOverlay);
                idImage ++;
                Placemark iso;
               
                LineString lineString;
                //lineString.setAltitudeMode(AltitudeMode.RELATIVE_TO_GROUND);
                ArrayList<Coordinate> coord;
                Iterator<Segment> it1 = d.getIso1().iterator();
                while(it1.hasNext()){
                    iso = KmlFactory.createPlacemark();
                    iso.setTimePrimitive(timeStamp);
                    lineString = KmlFactory.createLineString();
                    lineString.setAltitudeMode(AltitudeMode.RELATIVE_TO_GROUND);
                    coord= new ArrayList<Coordinate>();
                    Segment s = it1.next();
                    coord.add(new Coordinate(s.getY1(), s.getX1()));
                    coord.add(new Coordinate(s.getY2(), s.getX2()));
                    lineString.setCoordinates(coord);
                    iso.setGeometry(lineString);
                    features.add(iso);
                }
               
                Iterator<Segment> it2 = d.getIso2().iterator();
                while(it2.hasNext()){
                    iso = KmlFactory.createPlacemark();
                    iso.setTimePrimitive(timeStamp);
                    lineString = KmlFactory.createLineString();
                    lineString.setAltitudeMode(AltitudeMode.RELATIVE_TO_GROUND);
                    coord= new ArrayList<Coordinate>();
                    Segment s = it2.next();
                    coord.add(new Coordinate(s.getY1(), s.getX1()));
                    coord.add(new Coordinate(s.getY2(), s.getX2()));
                    lineString.setCoordinates(coord);
                    iso.setGeometry(lineString);
                    features.add(iso);
                }
                Iterator<Segment> it3 = d.getIso3().iterator();
                while(it3.hasNext()){
                    iso = KmlFactory.createPlacemark();
                    iso.setTimePrimitive(timeStamp);
                    lineString = KmlFactory.createLineString();
                    lineString.setAltitudeMode(AltitudeMode.RELATIVE_TO_GROUND);
                    coord= new ArrayList<Coordinate>();
                    Segment s = it3.next();
                    coord.add(new Coordinate(s.getY1(), s.getX1()));
                    coord.add(new Coordinate(s.getY2(), s.getX2()));
                    lineString.setCoordinates(coord);
                    iso.setGeometry(lineString);
                    features.add(iso);
                }
               
               
               
            instantDebut.incr();
        }
        try{
            InputStream ips=new FileInputStream(fichier);
      InputStreamReader ipsr=new InputStreamReader(ips);
      BufferedReader br=new BufferedReader(ipsr);
      String ligne;
            Placemark plMark = KmlFactory.createPlacemark();
            Style style = KmlFactory.createStyle();
            IconStyle iconStyle = KmlFactory.createIconStyle();
            Icon icon = KmlFactory.createIcon();
            icon.setHref("earth.png");
            iconStyle.setIcon(icon);
            style.setIconStyle(iconStyle);
            ArrayList<StyleSelector> listStyles = new ArrayList<StyleSelector>();
            style.setIconStyle(iconStyle);
            listStyles.add(style);
            plMark.setStyleSelector(listStyles);
            features.add(plMark);
            while((ligne=br.readLine())!=null){
                String [ ] inter = ligne.split(";");
                if(inter.length == 5){
                    Placemark placemark = KmlFactory.createPlacemark();
                    placemark.setName(inter[0]);
                    placemark.setVisibility(true);
                    placemark.setOpen(false);
                    placemark.setDescription("Concentration de particules: " + inter[4]);
                    placemark.setStyleUrl("styles.kml#jugh_style");
               
                    Point point = KmlFactory.createPoint();
                    point.setExtrude(false);
                    point.setAltitudeMode(AltitudeMode.CLAMP_TO_GROUND);
                    //Add <coordinates>9.444652669565212,51.30473589438118,0<coordinates>.
               
                    point.getCoordinates().add(new Coordinate(inter[1].replace(",", ".") + "," + virguleTopoint(inter[2]) + "," + inter[3]));

                    placemark.setGeometry(point);      // <-- point is registered at placemark ownership.
                    features.add(placemark);
                    //kml.setFeature(placemark);
                }
               
               
               
            }
            document.setFeature(features);
            kml.setFeature(document);
            br.close();
           
        }
        catch (Exception e){
    System.out.println(e.toString());
               
  }
       
        try {
            kml.marshal(new File(fichierKML));           // <-- Print the KML structure to the console.
        } catch (FileNotFoundException ex) {
            Logger.getLogger(EcrireKml.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
     
   
   
       
    public static String virguleTopoint(String s){
       
        String [] inter = s.split(",");
        return inter[0]+"."+inter[1];
    }
   
   
   
    public static void ecrireKml2(){
        Kml kml = KmlFactory.createKml();
        // Create <Placemark> and set values.
        Placemark placemark = KmlFactory.createPlacemark();
        placemark.setName("Java User Group Hessen - JUGH!");
        placemark.setVisibility(true);
        placemark.setOpen(false);
        placemark.setDescription("die Java User Group Hessen");
        placemark.setStyleUrl("styles.kml#jugh_style");

        // Create <Point> and set values.
        Point point = KmlFactory.createPoint();
        point.setExtrude(false);
        point.setAltitudeMode(AltitudeMode.CLAMP_TO_GROUND);
        // Add <coordinates>9.444652669565212,51.30473589438118,0<coordinates>.
        point.getCoordinates().add(new Coordinate("9.444652669565212,51.30473589438118,0"));
       
        placemark.setGeometry(point);      // <-- point is registered at placemark ownership.
        kml.setFeature(placemark);         // <-- placemark is registered at kml ownership.
        try {
            kml.marshal(new File("HelloKml.kml"));           // <-- Print the KML structure to the console.
        } catch (FileNotFoundException ex) {
            Logger.getLogger(EcrireKml.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
   
    public static void main(String[] args) throws FileNotFoundException, IOException {
       writeKml("donnees_projet/donneesExtraites.txt", "donnees.kml");
    }
   
}
TOP

Related Classes of projet.EcrireKml

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.