-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainClass.java
109 lines (99 loc) · 3.44 KB
/
MainClass.java
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
101
102
103
104
105
106
107
108
109
import java.awt.Color;
import java.sql.*;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
import org.postgis.PGgeometry;
import database.*;
import geoexplorer.gui.CoordinateConverter;
import geoexplorer.gui.GeoMainFrame;
import geoexplorer.gui.LineString;
import geoexplorer.gui.MapPanel;
import geoexplorer.gui.Point;
public class MainClass {
public static String WayRequest = "SELECT ST_ASTEXT(ST_Transform(ways.linestring, 4326)) "
+ "FROM ways "
+ "WHERE ST_Intersects(ST_MakeEnvelope(5.7, 45.1, 5.8, 45.2, 4326), ST_Transform(ways.linestring, 4326)) ";
public static String pubRequest = "SELECT ST_ASTEXT(ST_Transform(ways.linestring, 4326)) "
+ "FROM ways "
+ "WHERE ST_Intersects(ST_MakeEnvelope(5.7, 45.1, 5.8, 45.2, 4326), ST_Transform(ways.linestring, 4326)) "
+ "AND ways.tags->'amenity' = 'bar';";
public static void main(String[] args){
//décommentez la question que vous voulez tester.
//Les temps peuvent être très long, (coté serveur?)
//question10();
//simpleRequest("Dom__ne _niversit%");
//question11();
// MapPanel.autoajust ne marche pas.. donc il faut scroller avec la souris pour bien voir la carte
//question12();
}
public static void question10(){
try {
PreparedStatement stmt;
stmt = Utils.getConnection().prepareStatement("SELECT COUNT(Id) FROM Users;");
ResultSet res = stmt.executeQuery();
res.next();
System.out.println("Nombe d'utilisateur :" + res.getInt(1));
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void simpleRequest(String name){
try {
PreparedStatement stmt;
String statement = "SELECT tags->'name',St_X(geom),St_Y(geom) FROM nodes WHERE tags->'name' LIKE '" + name + "';";
stmt = Utils.getConnection().prepareStatement(statement);
ResultSet res = stmt.executeQuery();
//res.next();
//System.out.println(res.getString(1) + " " + res.getString(2) + " " + res.getString(3));
while (res.next()) {
System.out.println(res.getString(1) + "; X = " + res.getFloat(2) + "; Y = " + res.getFloat(3));//((PGgeometry) res.getObject(2)).getGeometry());
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void question11(){
Scanner reader = new Scanner(System.in); // Reading from System.in
String line = "";
do{
line = reader.nextLine();
if(!line.equals("exit")){
simpleRequest(line);
}
}while(!line.equals("exit"));
System.out.println("exiting");
reader.close();
}
public static void question12(){
double centerX = 5.75;
double centerY = 45.15;
double mapWidth = 0.1;
MapPanel panel = new MapPanel(centerX,centerY,mapWidth);
List<LineString> ways = getWays();
ways.add(GraphicInterface.somePoints());
ways.stream().forEach(ls -> panel.addPrimitive(ls));
System.out.println(ways.size());
GeoMainFrame frame = new GeoMainFrame("display test",panel);
}
private static List<LineString> getWays(){
List<LineString> ways = new ArrayList();
try{
PreparedStatement stmt;
//TODO: mettre la bonne requete.
stmt = Utils.getConnection().prepareStatement(WayRequest);
ResultSet res = stmt.executeQuery();
while(res.next()){
ways.add(new LineString(res.getString(1), Color.BLACK));
stmt = Utils.getConnection().prepareStatement(pubRequest);
res = stmt.executeQuery();
while(res.next()){
ways.add(new LineString(res.getString(1), Color.RED));
}
return ways;
}catch(Exception e){
e.printStackTrace();
return null;
}
}
}