poprawki, zmana na wyswietlanie lamp
This commit is contained in:
1 parent
27c0c7fbd1
commit
3c3cbbfbc5
5 files changed
+55
-24
No files matched your search
+6
-9
@@ -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<org.postgis.Point> getAllObjectCoordinates(String object) {
|
||||
return gisJdbcTemplate.query(GET_ALL_LAMPS_COORDINATES,new Object[]{object},new GisRowMapperForObject());
|
||||
public List<GisLamp> getAllLamps(String object) {
|
||||
return gisJdbcTemplate.query(GET_ALL_LAMPS_COORDINATES,new Object[]{object},new GisRowMapperForLamps());
|
||||
}
|
||||
|
||||
|
||||
public void setGisJdbcTemplate(JdbcTemplate gisJdbcTemplate) {
|
||||
this.gisJdbcTemplate = gisJdbcTemplate;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+7
-4
@@ -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<org.postgis.Point> {
|
||||
public class GisRowMapperForLamps implements RowMapper<GisLamp> {
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
<bean id="objectJdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<property name="dataSource" ref="objectsDataSource"/>
|
||||
</bean>
|
||||
<bean class="hello.agh.edu.bazy.gis.dbApi.GisdbApi" id="gisdbApi">
|
||||
<bean class="hello.agh.edu.bazy.dbApi.gis.GisdbApi" id="gisdbApi">
|
||||
<property name="gisJdbcTemplate" ref="gisJdbcTemplate"/>
|
||||
</bean>
|
||||
</beans>
|
||||
+17
-10
@@ -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<org.postgis.Point> points = api.getAllObjectCoordinates("street_lamp");
|
||||
List<org.postgis.Point> 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<String> types = api.getAllBuldingsType();
|
||||
for(String elem:types){
|
||||
System.out.println(elem);
|
||||
}
|
||||
} catch (Exception e){
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user