Merge remote-tracking branch 'origin/master'
Conflicts: src/main/java/hello/agh/edu/bazy/dbApi/gis/GisDbApi.java
This commit is contained in:
commit
d4d431433a
7 files changed
+30
-84
No files matched your search
@@ -1,9 +1,8 @@
|
||||
package hello.agh.edu.bazy.controllers;
|
||||
|
||||
import hello.agh.edu.bazy.path.APIServicePaths;
|
||||
import hello.agh.edu.bazy.dbApi.gis.GisDbApi;
|
||||
import hello.agh.edu.bazy.model.Location;
|
||||
import hello.agh.edu.bazy.row.gis.GisLamp;
|
||||
import hello.agh.edu.bazy.path.APIServicePaths;
|
||||
import hello.agh.edu.bazy.row.gis.GisPoint;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -24,7 +23,7 @@ public class GisController {
|
||||
|
||||
@RequestMapping(APIServicePaths.GET_ALL_LAMPS)
|
||||
@ResponseBody
|
||||
List<GisLamp> getLamps() {
|
||||
List<GisPoint> getLamps() {
|
||||
return gisDbApi.getAllLamps();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package hello.agh.edu.bazy.dbApi.gis;
|
||||
|
||||
import hello.agh.edu.bazy.postgresql.gis.GisDataSource;
|
||||
import hello.agh.edu.bazy.row.gis.GisLamp;
|
||||
import hello.agh.edu.bazy.row.gis.GisPoint;
|
||||
import hello.agh.edu.bazy.row.mappers.gis.GisRowMapperForLamps;
|
||||
import hello.agh.edu.bazy.row.mappers.gis.PointRowMapper;
|
||||
import hello.agh.edu.bazy.row.mappers.gis.PolygonRowMapper;
|
||||
import hello.agh.edu.bazy.row.mappers.gis.PolygonsRowMapper;
|
||||
@@ -18,9 +16,9 @@ import java.util.List;
|
||||
@Component
|
||||
public class GisDbApi {
|
||||
|
||||
private static final String GET_LAMPS = "SELECT osm_id,tags,st_transform(way,4326) FROM planet_osm_point WHERE highway='street_lamp'";
|
||||
private static final String GET_LAMPS = "SELECT gis_points_id,tags,st_transform(way,4326) FROM gis_points WHERE highway='street_lamp';";
|
||||
private static String PUT_LAMP = "INSERT INTO public.gis_points(gis_points_id, way, highway) VALUES (@, st_geomfromtext('POINT(@ @)',4326), 'street_lamp');";
|
||||
private static final String GET_LAMP = "SELECT st_transform(way,900913) FROM gis_points WHERE gis_points_id = ?;";
|
||||
private static final String GET_LAMP = "SELECT gis_points_id,st_transform(way,900913) FROM gis_points WHERE gis_points_id = ?;";
|
||||
private static final String DELETE_LAMP = "DELETE FROM public.gis_points WHERE gis_points_id = ?";
|
||||
private static final String GET_POLYGONS = "SELECT st_transform(way,900913) as polygon FROM gis_polygons;";
|
||||
private static final String GET_POLYGON = "SELECT st_transform(way,900913) as polygon FROM gis_polygons WHERE gis_polygons_id = ?";
|
||||
@@ -42,8 +40,8 @@ public class GisDbApi {
|
||||
return gisJdbcTemplate.update(DELETE_LAMP, id);
|
||||
}
|
||||
|
||||
public List<GisLamp> getAllLamps() {
|
||||
return gisJdbcTemplate.query(GET_LAMPS, new GisRowMapperForLamps());
|
||||
public List<GisPoint> getAllLamps() {
|
||||
return gisJdbcTemplate.query(GET_LAMPS, new PointRowMapper());
|
||||
}
|
||||
|
||||
public List<GisPoint> getLamp(long id) {
|
||||
@@ -51,10 +49,12 @@ public class GisDbApi {
|
||||
}
|
||||
|
||||
public int putLamp(long id, double x, double y) {
|
||||
PUT_LAMP = PUT_LAMP.replaceFirst("@", Long.toString(id));
|
||||
PUT_LAMP = PUT_LAMP.replaceFirst("@", Double.toString(x));
|
||||
PUT_LAMP = PUT_LAMP.replaceFirst("@", Double.toString(y));
|
||||
return gisJdbcTemplate.update(PUT_LAMP, x, y);
|
||||
String sql = String.copyValueOf(PUT_LAMP.toCharArray());
|
||||
sql = sql.replaceFirst("@", Long.toString(id));
|
||||
sql = sql.replaceFirst("@", Double.toString(x));
|
||||
sql = sql.replaceFirst("@", Double.toString(y));
|
||||
System.out.print(PUT_LAMP);
|
||||
return gisJdbcTemplate.update(sql);
|
||||
}
|
||||
|
||||
public List<List<GisPoint>> getPolygons(){
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package hello.agh.edu.bazy.row.gis;
|
||||
|
||||
/**
|
||||
* Created by mar on 24.01.15.
|
||||
*/
|
||||
public class GisLamp {
|
||||
private final long id;
|
||||
private final double x;
|
||||
private final double y;
|
||||
private String tag;
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public GisLamp(long id, double x, double y) {
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public GisLamp(long id, double x, double y, String tag) {
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,22 @@ package hello.agh.edu.bazy.row.gis;
|
||||
* Created by Marcin on 2015-01-25.
|
||||
*/
|
||||
public class GisPoint {
|
||||
private long id;
|
||||
private double x;
|
||||
private double y;
|
||||
|
||||
public GisPoint(double x, double y) {
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public GisPoint(long id, double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package hello.agh.edu.bazy.row.mappers.gis;
|
||||
|
||||
import hello.agh.edu.bazy.row.gis.GisLamp;
|
||||
import org.postgis.PGgeometry;
|
||||
import org.postgis.Point;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created by mar on 22.01.15.
|
||||
*/
|
||||
public class GisRowMapperForLamps implements RowMapper<GisLamp> {
|
||||
|
||||
private static final String COORDINATE_COLUM_NNAME = "st_transform";
|
||||
private static final String OSM_ID = "osm_id";
|
||||
private static final String TAG = "tags";
|
||||
@Override
|
||||
public GisLamp mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
PGgeometry geometry = (PGgeometry)rs.getObject(COORDINATE_COLUM_NNAME);
|
||||
|
||||
return new GisLamp(rs.getLong(OSM_ID),
|
||||
((Point) geometry.getGeometry()).getX(),
|
||||
((Point) geometry.getGeometry()).getY(),rs.getString(TAG));
|
||||
}
|
||||
}
|
||||
@@ -13,12 +13,15 @@ import java.sql.SQLException;
|
||||
*/
|
||||
public class PointRowMapper implements RowMapper<GisPoint> {
|
||||
private static final String ST_AS_TEXT = "st_transform";
|
||||
private static final String GIS_POINTS_ID = "gis_points_id";
|
||||
|
||||
@Override
|
||||
public GisPoint mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
PGgeometry geometry = (PGgeometry)rs.getObject(ST_AS_TEXT);
|
||||
PGgeometry geometry = (PGgeometry) rs.getObject(ST_AS_TEXT);
|
||||
|
||||
|
||||
return new GisPoint(
|
||||
rs.getLong(GIS_POINTS_ID),
|
||||
((Point) geometry.getGeometry()).getX(),
|
||||
((Point) geometry.getGeometry()).getY());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package hello.agh.edu.bazy.dbApi.gis;
|
||||
|
||||
import hello.agh.edu.bazy.row.gis.GisLamp;
|
||||
import hello.agh.edu.bazy.row.gis.GisPoint;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -26,8 +26,8 @@ public class gisTest {
|
||||
try {
|
||||
api.setGisJdbcTemplate(gisJdbcTemplate);
|
||||
|
||||
List<GisLamp> lamps = api.getAllLamps();
|
||||
for (GisLamp gisLamp : lamps) {
|
||||
List<GisPoint> lamps = api.getAllLamps();
|
||||
for (GisPoint gisLamp : lamps) {
|
||||
System.out.println(gisLamp.getId() + " " + gisLamp.getX() + ", " + gisLamp.getY());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in new issue
Block a user