Permalink
Browse files

Refactored Postgis Data Source

  • Loading branch information...
1 parent 40fbee7 commit b9994f09b717335f5794fb0bb751dc5d030da217 @varunpant committed Mar 19, 2013
@@ -65,13 +65,10 @@ public PostGisDataSource(String query) {
System.out.println(pst);
rs = pst.executeQuery();
while (rs.next()) {
- String wkt = rs.getString("geom");
- String[] points = wkt.replace("POINT(", "").replace(")", "").split(" "); //:!
double weight = rs.getDouble("weight");
- double longitude = Double.parseDouble(points[1]);//x
- double latitude = Double.parseDouble(points[0]); //y
-
- PointLatLng pt = new PointLatLng(latitude, longitude, weight);
+ double longitude = rs.getDouble("longitude");//x
+ double latitude = rs.getDouble("latitude"); //y
+ PointLatLng pt = new PointLatLng(longitude, latitude, weight);
llList.add(pt);
}
} catch (Exception ex) {
@@ -20,40 +20,43 @@
public static void main(String[] args) throws Exception {
if (dataManager == null) {
-
ThemeManager.init(classpathResource.getPath() + "res/etc/");
-
//HeatMapDataSource dataSource = getFileDataSource();
//HeatMapDataSource dataSource = getQuadTreeDataSource();
HeatMapDataSource dataSource = getPostGisDataSource();
dataManager = new DataManager(dataSource);
-
System.out.println("======================================= Initialised =======================================");
}
-
Server server = new Server(8080);
server.setHandler(new TileHandler());
server.start();
server.join();
}
+
/*
Gets PostGIS data source.
* */
private static PostGisDataSource getPostGisDataSource() {
- String query = "SELECT ST_AsText(\"wkb_geometry\") as geom ,\"offences\" as weight FROM crimedata WHERE \"wkb_geometry\" @ ST_MakeEnvelope(?,?,?,?,4326)";
+ //In this query aliases(longitude,latitude,weight) must remain as shown, the actual table name ,geometry column name and weight column name can change .
+ String query = "SELECT ST_X(geom) as longitude," +
+ "ST_Y(geom) as latitude" +
+ "weight as weight from spatialTable where geom @ ST_MakeEnvelope(?,?,?,?,4326)";
+
return new PostGisDataSource(query);
}
+
/*
Gets File tree data source.
* */
private static FileDataSource getFileDataSource() {
return new FileDataSource(classpathResource.getPath() + "points.txt");
}
+
/*
- Gets quad tree data source.
- * */
+ Gets quad tree data source.
+ * */
private static QuadTreeDataSource getQuadTreeDataSource() {
return new QuadTreeDataSource(classpathResource.getPath() + "points.txt");
}

0 comments on commit b9994f0

Please sign in to comment.