1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| package model;
import geocoder.GeoLocation;
import java.awt.Color;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class GenererLesSommets
{
/**
* Tableau de Sommet
*/
private ArrayList<Sommet> villesSommets = new ArrayList<Sommet>();
/**
* Nom du fichier
*/
private String nomFichier;
public GenererLesSommets(String nom)
{
this.nomFichier = nom;
}
public ArrayList<Sommet> getSommets()
{
return villesSommets;
}
/**
* methode pour lire un fichier et remplir le tableau de Sommet
*/
public void lireEtGenererSommet()
{
File fichier = new File(nomFichier);
Scanner lecteur = null;
try
{
lecteur = new Scanner(fichier);
}
catch (FileNotFoundException e1)
{
e1.printStackTrace();
System.exit(1);
}
String nomVille;
while (lecteur.hasNext())
{
nomVille = lecteur.nextLine();
GeoLocation geoLocation;
try
{
geoLocation = new GeoLocation(nomVille);
double latitude = geoLocation.getLatitude();
double longitude = geoLocation.getLongitude();
/**on a besoin des coordonées d'un point dans la base (x,y) de pixels*/
double latitudeo = -5.518799; // ici les coordonnées gps du coin supérieur gauche de la fenêtre
double longitudeo = 50.750359;
double latitude1 = 5.6781; // ici les coordonées gps du coin inférieur droit de la fenêtre
double longitude1 = 41.738528;
/**sachant que la fenêtre est de dimension 800x800**/
double x = (latitude - latitudeo)/(latitude1 - latitudeo) *800 ; // je fais les régressions linéaires suivantes
double y = (longitude - longitudeo)/(longitude1 - longitudeo)*800; // et je suis censé obtenir les coordonnées dans la base de pixels
/** ici que ça coince ! j'obtiens des points à l'extérieur de la fenêtre*/
villesSommets.add(new Sommet(x, y, nomVille));
}
catch (IOException e)
{
e.printStackTrace();
System.exit(1);
}
}
}
@Override
public String toString()
{
return villesSommets.toString();
}
public static void main(String[] args)
{
GenererLesSommets g = new GenererLesSommets("cities.txt");
g.lireEtGenererSommet();
System.out.println(g.toString());
}
} |
Partager