From 3c3cbbfbc50b9251fac6f0728b1c683af7a19812 Mon Sep 17 00:00:00 2001 From: mar Date: Sat, 24 Jan 2015 20:06:51 +0100 Subject: [PATCH] poprawki, zmana na wyswietlanie lamp --- .../{gis/dbApi => dbApi/gis}/GisdbApi.java | 15 +++++------ .../java/hello/agh/edu/bazy/row/GisLamp.java | 24 +++++++++++++++++ ...rObject.java => GisRowMapperForLamps.java} | 11 +++++--- src/main/resources/database-blueprint.xml | 2 +- .../{gis/dbApi => dbApi/gis}/gisTest.java | 27 ++++++++++++------- 5 files changed, 55 insertions(+), 24 deletions(-) rename src/main/java/hello/agh/edu/bazy/{gis/dbApi => dbApi/gis}/GisdbApi.java (56%) create mode 100644 src/main/java/hello/agh/edu/bazy/row/GisLamp.java rename src/main/java/hello/agh/edu/bazy/row/mappers/{GisRowMapperForObject.java => GisRowMapperForLamps.java} (54%) rename src/test/java/hello/agh/edu/bazy/{gis/dbApi => dbApi/gis}/gisTest.java (61%) diff --git a/src/main/java/hello/agh/edu/bazy/gis/dbApi/GisdbApi.java b/src/main/java/hello/agh/edu/bazy/dbApi/gis/GisdbApi.java similarity index 56% rename from src/main/java/hello/agh/edu/bazy/gis/dbApi/GisdbApi.java rename to src/main/java/hello/agh/edu/bazy/dbApi/gis/GisdbApi.java index 5f76f86..2c421cc 100644 --- a/src/main/java/hello/agh/edu/bazy/gis/dbApi/GisdbApi.java +++ b/src/main/java/hello/agh/edu/bazy/dbApi/gis/GisdbApi.java @@ -1,9 +1,8 @@ -package hello.agh.edu.bazy.gis.dbApi; +package hello.agh.edu.bazy.dbApi.gis; -import hello.agh.edu.bazy.row.mappers.GisRowMapperForObject; -import org.postgresql.geometric.PGpoint; +import hello.agh.edu.bazy.row.GisLamp; +import hello.agh.edu.bazy.row.mappers.GisRowMapperForLamps; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.geo.Point; import org.springframework.jdbc.core.JdbcTemplate; import java.util.List; @@ -13,16 +12,14 @@ import java.util.List; */ public class GisdbApi { - private static final String GET_ALL_LAMPS_COORDINATES = "SELECT st_astext(st_transform(way,4326)) FROM gis_backup.planet_osm_point WHERE highway=?"; - + private static final String GET_ALL_LAMPS_COORDINATES = "SELECT st_transform(way,4326) FROM gis_backup.planet_osm_point WHERE highway='street_lamp'"; @Autowired JdbcTemplate gisJdbcTemplate; - public List getAllObjectCoordinates(String object) { - return gisJdbcTemplate.query(GET_ALL_LAMPS_COORDINATES,new Object[]{object},new GisRowMapperForObject()); + public List getAllLamps(String object) { + return gisJdbcTemplate.query(GET_ALL_LAMPS_COORDINATES,new Object[]{object},new GisRowMapperForLamps()); } - public void setGisJdbcTemplate(JdbcTemplate gisJdbcTemplate) { this.gisJdbcTemplate = gisJdbcTemplate; } diff --git a/src/main/java/hello/agh/edu/bazy/row/GisLamp.java b/src/main/java/hello/agh/edu/bazy/row/GisLamp.java new file mode 100644 index 0000000..76084af --- /dev/null +++ b/src/main/java/hello/agh/edu/bazy/row/GisLamp.java @@ -0,0 +1,24 @@ +package hello.agh.edu.bazy.row; + +import org.postgis.Point; + +/** + * Created by mar on 24.01.15. + */ +public class GisLamp { + private final long id; + private final Point location; + + public GisLamp(long id, Point location) { + this.id = id; + this.location = location; + } + + public long getId() { + return id; + } + + public Point getLocation() { + return location; + } +} diff --git a/src/main/java/hello/agh/edu/bazy/row/mappers/GisRowMapperForObject.java b/src/main/java/hello/agh/edu/bazy/row/mappers/GisRowMapperForLamps.java similarity index 54% rename from src/main/java/hello/agh/edu/bazy/row/mappers/GisRowMapperForObject.java rename to src/main/java/hello/agh/edu/bazy/row/mappers/GisRowMapperForLamps.java index 6434732..4931c0e 100644 --- a/src/main/java/hello/agh/edu/bazy/row/mappers/GisRowMapperForObject.java +++ b/src/main/java/hello/agh/edu/bazy/row/mappers/GisRowMapperForLamps.java @@ -1,6 +1,8 @@ package hello.agh.edu.bazy.row.mappers; +import hello.agh.edu.bazy.row.GisLamp; import org.postgis.PGgeometry; +import org.postgis.Point; import org.springframework.jdbc.core.RowMapper; import java.sql.ResultSet; import java.sql.SQLException; @@ -8,13 +10,14 @@ import java.sql.SQLException; /** * Created by mar on 22.01.15. */ -public class GisRowMapperForObject implements RowMapper { +public class GisRowMapperForLamps implements RowMapper { private static final String COORDINATE_COLUM_NNAME = "st_transform"; - + private static final String OSM_ID = "osm_id"; @Override - public org.postgis.Point mapRow(ResultSet rs, int rowNum) throws SQLException { + public GisLamp mapRow(ResultSet rs, int rowNum) throws SQLException { PGgeometry geometry = (PGgeometry)rs.getObject(COORDINATE_COLUM_NNAME); - return (org.postgis.Point) geometry.getGeometry(); + + return new GisLamp(rs.getLong(OSM_ID),(Point) geometry.getGeometry()); } } diff --git a/src/main/resources/database-blueprint.xml b/src/main/resources/database-blueprint.xml index eaf9b9f..f99825a 100644 --- a/src/main/resources/database-blueprint.xml +++ b/src/main/resources/database-blueprint.xml @@ -25,7 +25,7 @@ - + \ No newline at end of file diff --git a/src/test/java/hello/agh/edu/bazy/gis/dbApi/gisTest.java b/src/test/java/hello/agh/edu/bazy/dbApi/gis/gisTest.java similarity index 61% rename from src/test/java/hello/agh/edu/bazy/gis/dbApi/gisTest.java rename to src/test/java/hello/agh/edu/bazy/dbApi/gis/gisTest.java index 1a751b9..dd6d69a 100644 --- a/src/test/java/hello/agh/edu/bazy/gis/dbApi/gisTest.java +++ b/src/test/java/hello/agh/edu/bazy/dbApi/gis/gisTest.java @@ -1,19 +1,13 @@ -package hello.agh.edu.bazy.gis.dbApi; +package hello.agh.edu.bazy.dbApi.gis; import org.junit.Test; -import org.postgresql.geometric.PGpoint; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Configurable; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.data.geo.Point; import org.springframework.jdbc.core.JdbcTemplate; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.sql.SQLException; -import java.util.Arrays; import java.util.List; /** @@ -26,18 +20,31 @@ public class gisTest { JdbcTemplate gisJdbcTemplate; @Test - public void gisConnectionTest() throws SQLException { + public void gisConnectionTestAndGetAllObjectCoordinates() throws SQLException { GisdbApi api = new GisdbApi(); try { api.setGisJdbcTemplate(gisJdbcTemplate); - List points = api.getAllObjectCoordinates("street_lamp"); + List points = api.getAllLamps("street_lamp"); for (org.postgis.Point point : points) { System.out.println(point.x + " " + point.y); } } catch (Exception e) { - throw e; } } + + @Test + public void gisGetBuldingsTypes(){ + GisdbApi api = new GisdbApi(); + try{ + api.setGisJdbcTemplate(gisJdbcTemplate); + List types = api.getAllBuldingsType(); + for(String elem:types){ + System.out.println(elem); + } + } catch (Exception e){ + throw e; + } + } }