全局更新
This commit is contained in:
parent
b6a8f049ec
commit
2d068611ad
8
src/main/java/com/gis3c/dao/PostGISDao.java
Normal file
8
src/main/java/com/gis3c/dao/PostGISDao.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package com.gis3c.dao;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface PostGISDao {
|
||||||
|
public void CommonCreateTable(Map<String,Object> tableStructure);
|
||||||
|
public void CreateSpatialIndex(Map<String,Object> params);
|
||||||
|
}
|
||||||
29
src/main/java/com/gis3c/dao/impl/PostGISDaoImpl.java
Normal file
29
src/main/java/com/gis3c/dao/impl/PostGISDaoImpl.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.gis3c.dao.impl;
|
||||||
|
|
||||||
|
import com.gis3c.dao.PostGISDao;
|
||||||
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
|
import org.mybatis.spring.support.SqlSessionDaoSupport;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class PostGISDaoImpl extends SqlSessionDaoSupport implements PostGISDao {
|
||||||
|
@Resource(name="sqlSessionFactory_GIS")
|
||||||
|
private SqlSessionFactory sqlSessionFactory;
|
||||||
|
@PostConstruct
|
||||||
|
public void injectSessionFactory(){
|
||||||
|
super.setSqlSessionFactory(sqlSessionFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void CommonCreateTable(Map<String,Object> tableStructure){
|
||||||
|
getSqlSession().update("PostGISSql.commonCreateTable",tableStructure);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void CreateSpatialIndex(String tableName){
|
||||||
|
getSqlSession().update("PostGISSql.createSpatialIndex",tableName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +0,0 @@
|
|||||||
package com.gis3c.demo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Administrator on 2016/12/27.
|
|
||||||
*/
|
|
||||||
public interface Hello {
|
|
||||||
public String SayHello();
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
package com.gis3c.demo.impl;
|
|
||||||
import com.gis3c.demo.Hello;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component("hello")
|
|
||||||
public class HelloImpl implements Hello{
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String SayHello(){
|
|
||||||
return getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public void setName(
|
|
||||||
// @Value(value = "#{configProperties['gis.name']}")
|
|
||||||
@Value(value = "HUKEKUAN") String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
73
src/main/java/com/gis3c/postgis/PostGISHandler.java
Normal file
73
src/main/java/com/gis3c/postgis/PostGISHandler.java
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
package com.gis3c.postgis;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.CallableStatement;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.apache.ibatis.type.JdbcType;
|
||||||
|
import org.apache.ibatis.type.MappedTypes;
|
||||||
|
import org.apache.ibatis.type.TypeHandler;
|
||||||
|
import org.geotools.data.postgis.WKBAttributeIO;
|
||||||
|
|
||||||
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
|
import com.vividsolutions.jts.geom.GeometryCollection;
|
||||||
|
import com.vividsolutions.jts.geom.LineString;
|
||||||
|
import com.vividsolutions.jts.geom.MultiLineString;
|
||||||
|
import com.vividsolutions.jts.geom.MultiPoint;
|
||||||
|
import com.vividsolutions.jts.geom.MultiPolygon;
|
||||||
|
import com.vividsolutions.jts.geom.Point;
|
||||||
|
import com.vividsolutions.jts.geom.Polygon;
|
||||||
|
import com.vividsolutions.jts.io.ParseException;
|
||||||
|
import com.vividsolutions.jts.io.WKBReader;
|
||||||
|
|
||||||
|
@MappedTypes({ Point.class, LineString.class, Polygon.class, MultiPoint.class, MultiLineString.class, MultiPolygon.class,
|
||||||
|
Envelope.class,GeometryCollection.class,Geometry.class })
|
||||||
|
public class PostGISHandler implements TypeHandler<Geometry> {
|
||||||
|
private static WKBReader wKBReader = new WKBReader();
|
||||||
|
private static WKBAttributeIO wKBAttributeIO = new WKBAttributeIO();
|
||||||
|
@Override
|
||||||
|
public void setParameter(PreparedStatement ps, int i, Geometry parameter,JdbcType jdbcType)
|
||||||
|
throws SQLException {
|
||||||
|
try {
|
||||||
|
wKBAttributeIO.write(ps, i, parameter);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new SQLException(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Geometry getResult(ResultSet rs, String columnName)throws SQLException {
|
||||||
|
Geometry resultGeometry = null;
|
||||||
|
try {
|
||||||
|
resultGeometry = wKBReader.read(WKBReader.hexToBytes(rs.getObject(columnName).toString()));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new SQLException(e.getMessage());
|
||||||
|
}
|
||||||
|
return resultGeometry;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Geometry getResult(ResultSet rs, int columnIndex)throws SQLException {
|
||||||
|
Geometry resultGeometry = null;
|
||||||
|
try {
|
||||||
|
resultGeometry = wKBReader.read(WKBReader.hexToBytes(rs.getObject(columnIndex).toString()));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new SQLException(e.getMessage());
|
||||||
|
}
|
||||||
|
return resultGeometry;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Geometry getResult(CallableStatement cs, int columnIndex)throws SQLException {
|
||||||
|
Geometry resultGeometry = null;
|
||||||
|
try {
|
||||||
|
resultGeometry = wKBReader.read(WKBReader.hexToBytes(cs.getObject(columnIndex).toString()));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new SQLException(e.getMessage());
|
||||||
|
}
|
||||||
|
return resultGeometry;
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/main/java/com/gis3c/service/PostGISService.java
Normal file
8
src/main/java/com/gis3c/service/PostGISService.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package com.gis3c.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface PostGISService {
|
||||||
|
public void CommonCreateTable(String tableName,String geometryColumn,List<Map<String,Object>> columns);
|
||||||
|
}
|
||||||
29
src/main/java/com/gis3c/service/impl/PostGISServiceImpl.java
Normal file
29
src/main/java/com/gis3c/service/impl/PostGISServiceImpl.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.gis3c.service.impl;
|
||||||
|
|
||||||
|
import com.gis3c.dao.PostGISDao;
|
||||||
|
import com.gis3c.service.PostGISService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service("postGISService")
|
||||||
|
public class PostGISServiceImpl implements PostGISService {
|
||||||
|
@Resource private PostGISDao postGISDao;
|
||||||
|
|
||||||
|
public void CommonCreateTable(
|
||||||
|
String tableName,String geometryColumn,List<Map<String,Object>> columns){
|
||||||
|
Map<String,Object> tableStructure = new HashMap<>();
|
||||||
|
tableStructure.put("tableName",tableName);
|
||||||
|
tableStructure.put("columnList",columns);
|
||||||
|
|
||||||
|
Map<String,Object> SpatialIndexParam = new HashMap<>();
|
||||||
|
SpatialIndexParam.put("spatialIndexName","sidx_" + tableName + "_" + geometryColumn);
|
||||||
|
SpatialIndexParam.put("tableName",tableName);
|
||||||
|
SpatialIndexParam.put("geometryColumn",geometryColumn);
|
||||||
|
|
||||||
|
postGISDao.CommonCreateTable(tableStructure);
|
||||||
|
postGISDao.CreateSpatialIndex(SpatialIndexParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
131
src/main/java/com/gis3c/sqlmaps/PostGISMapper.xml
Normal file
131
src/main/java/com/gis3c/sqlmaps/PostGISMapper.xml
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
|
<mapper namespace="PostGISSql">
|
||||||
|
<resultMap id="GeoCityResultMap" type="java.util.HashMap">
|
||||||
|
<result property="geom" column="geom" javaType="Geometry"/>
|
||||||
|
</resultMap>
|
||||||
|
<!--创建空间表通用方法-->
|
||||||
|
<update id="commonCreateTable">
|
||||||
|
CREATE TABLE ${tableName}
|
||||||
|
<foreach item="item" index="index" collection="columnList" open="(" separator=",">
|
||||||
|
<choose>
|
||||||
|
<when test='item.typeCode == 1'>
|
||||||
|
${item.columnName} numeric
|
||||||
|
</when>
|
||||||
|
<when test='item.typeCode == 2'>
|
||||||
|
${item.columnName} NUMBER
|
||||||
|
</when>
|
||||||
|
<when test='item.typeCode == 3'>
|
||||||
|
${item.columnName} character varying(254)
|
||||||
|
</when>
|
||||||
|
<when test='item.typeCode == 91'>
|
||||||
|
geo geometry(POINT,4326)
|
||||||
|
</when>
|
||||||
|
<when test='item.typeCode == 911'>
|
||||||
|
geo geometry(MULTIPOINT,4326)
|
||||||
|
</when>
|
||||||
|
<when test='item.typeCode == 92'>
|
||||||
|
geo geometry(LINESTRING,4326)
|
||||||
|
</when>
|
||||||
|
<when test='item.typeCode == 922'>
|
||||||
|
geo geometry(MULTILINESTRING,4326)
|
||||||
|
</when>
|
||||||
|
<when test='item.typeCode == 93'>
|
||||||
|
geo geometry(POLYGON,4326)
|
||||||
|
</when>
|
||||||
|
<when test='item.typeCode == 933'>
|
||||||
|
geo geometry(MULTIPOLYGON,4326)
|
||||||
|
</when>
|
||||||
|
</choose>
|
||||||
|
</foreach>
|
||||||
|
,CONSTRAINT fid_pkey PRIMARY KEY (fid));
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<!--创建空间索引-->
|
||||||
|
<update id="createSpatialIndex">
|
||||||
|
CREATE INDEX ${spatialIndexName}
|
||||||
|
ON ${tableName}
|
||||||
|
USING gist
|
||||||
|
($(geometryColumn));
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<!--查询表是否存在,返回表个数-->
|
||||||
|
<select id="tableCount" parameterType="java.lang.String" resultType="java.lang.Integer">
|
||||||
|
select count(1) from pg_class where relname in (lower(#{tableName,jdbcType=VARCHAR}),upper(#{tableName,jdbcType=VARCHAR}));
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 删除空间表通用方法 -->
|
||||||
|
<delete id="commonTableRemove" parameterType="java.lang.String">
|
||||||
|
drop table ${_parameter};
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<!-- 插入空间信息通用方法 -->
|
||||||
|
<insert id="commonInsertBatch">
|
||||||
|
insert into ${tableName}
|
||||||
|
<foreach item="item" index="index" collection="keyList" open="(" separator="," close=")values">
|
||||||
|
${item}
|
||||||
|
</foreach>
|
||||||
|
<foreach collection="featuresList" item="featureValues" index="index" separator="," >
|
||||||
|
<foreach item="featureValue" index="featureIndex" collection="featureValues" open=" (" separator="," close=")">
|
||||||
|
<choose>
|
||||||
|
<when test='featureValue.key == "fid"'>
|
||||||
|
#{featureValue.value,jdbcType=INTEGER}
|
||||||
|
</when>
|
||||||
|
<when test='featureValue.key == "geo"'>
|
||||||
|
st_geomfromText(#{featureValue.value,jdbcType=VARCHAR},4326)
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
#{featureValue.value,jdbcType=VARCHAR}
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</foreach>
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<insert id="commonInsert">
|
||||||
|
insert into ${tableName}
|
||||||
|
<foreach item="item" index="index" collection="keyList" open="(" separator="," close=")">
|
||||||
|
${item}
|
||||||
|
</foreach>
|
||||||
|
<foreach item="featureValue" index="index" collection="valueList" open=" values(" separator="," close=")">
|
||||||
|
<choose>
|
||||||
|
<when test='featureValue.key == "fid"'>
|
||||||
|
#{featureValue.value,jdbcType=INTEGER}
|
||||||
|
</when>
|
||||||
|
<when test='featureValue.key == "geo"'>
|
||||||
|
st_geomfromText(#{featureValue.value,jdbcType=VARCHAR},4326)
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
#{featureValue.value,jdbcType=VARCHAR}
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!--查询表中字段信息-->
|
||||||
|
<select id="tableColumns" parameterType="java.lang.String" resultType="java.util.HashMap">
|
||||||
|
select column_name,data_type
|
||||||
|
from information_schema.columns where table_name = #{tableName,jdbcType=INTEGER} and table_schema='public';
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 清空表 -->
|
||||||
|
<delete id="clearSpatialTable" parameterType="java.lang.String">
|
||||||
|
delete from ${_parameter}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<select id="allCity" resultMap="GeoCityResultMap">
|
||||||
|
<!--
|
||||||
|
select t.name,t.code,t.geom as geom from geocity t
|
||||||
|
|
||||||
|
select t.name,t.code,ST_AsText(t.geom) as geom from geocountry t
|
||||||
|
where ST_Within(ST_GeometryFromText(#{geom,javaType=Geometry}),t.geom);
|
||||||
|
-->
|
||||||
|
select t.stationid,t.subtype,t.geom as geom from station t where ST_Intersects(
|
||||||
|
ST_Buffer(
|
||||||
|
Geography(#{geom,javaType=Geometry}),1000
|
||||||
|
),
|
||||||
|
t.geom
|
||||||
|
)
|
||||||
|
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
@ -1,4 +1,10 @@
|
|||||||
gis.driverClassName=oracle.jdbc.driver.OracleDriver
|
gis.driverClassName=oracle.jdbc.driver.OracleDriver
|
||||||
gis.url=jdbc:oracle:thin:@172.16.6.13:1521:orcl
|
gis.url=jdbc:oracle:thin:@172.16.6.13:1521:orcl
|
||||||
gis.username=spatial
|
gis.username=spatial
|
||||||
gis.password=spatial
|
gis.password=spatial
|
||||||
|
|
||||||
|
|
||||||
|
postgis.driverClassName=org.postgresql.Driver
|
||||||
|
postgis.url=jdbc:postgresql://localhost:5432/gisdb
|
||||||
|
postgis.username=postgres
|
||||||
|
postgis.password=postgres
|
||||||
@ -29,11 +29,10 @@
|
|||||||
<context:component-scan base-package="com.gis3c.*"/>
|
<context:component-scan base-package="com.gis3c.*"/>
|
||||||
|
|
||||||
<bean id="dataSource_GIS" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
|
<bean id="dataSource_GIS" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
|
||||||
<property name="driverClassName" value="${gis.driverClassName}"/>
|
<property name="driverClassName" value="${postgis.driverClassName}"/>
|
||||||
<property name="url" value="${gis.url}"/>
|
<property name="url" value="${postgis.url}"/>
|
||||||
<property name="username" value="${gis.username}"/>
|
<property name="username" value="${postgis.username}"/>
|
||||||
<property name="password" value="${gis.password}"/>
|
<property name="password" value="${postgis.password}"/>
|
||||||
<property name="accessToUnderlyingConnectionAllowed" value="true"/>
|
|
||||||
</bean>
|
</bean>
|
||||||
<bean id="sqlSessionFactory_GIS" class="org.mybatis.spring.SqlSessionFactoryBean">
|
<bean id="sqlSessionFactory_GIS" class="org.mybatis.spring.SqlSessionFactoryBean">
|
||||||
<property name="dataSource" ref="dataSource_GIS"/>
|
<property name="dataSource" ref="dataSource_GIS"/>
|
||||||
|
|||||||
@ -5,11 +5,10 @@
|
|||||||
<settings>
|
<settings>
|
||||||
<setting name="cacheEnabled" value="false"/>
|
<setting name="cacheEnabled" value="false"/>
|
||||||
</settings>
|
</settings>
|
||||||
<!--
|
|
||||||
<typeAliases>
|
<typeAliases>
|
||||||
<typeAlias type="com.vividsolutions.jts.geom.Geometry" alias="Geometry" />
|
<typeAlias type="com.vividsolutions.jts.geom.Geometry" alias="Geometry" />
|
||||||
</typeAliases>
|
</typeAliases>
|
||||||
<typeHandlers>
|
<typeHandlers>
|
||||||
<typeHandler handler="com.gis3c.common.OracleSpatialHandler" javaType="Geometry" />
|
<typeHandler handler="com.gis3c.postgis.PostGISHandler" javaType="Geometry" />
|
||||||
</typeHandlers>-->
|
</typeHandlers>
|
||||||
</configuration>
|
</configuration>
|
||||||
Loading…
Reference in New Issue
Block a user