初始化
This commit is contained in:
parent
cb65181306
commit
3d5342f5cb
@ -1,6 +1,7 @@
|
|||||||
package com.gis3c.spatial.common;
|
package com.gis3c.spatial.common;
|
||||||
|
|
||||||
import com.gis3c.spatial.entity.feature.BaseFeature;
|
|
||||||
|
import com.gis3c.spatial.entity.BaseFeature;
|
||||||
import org.geotools.data.DataUtilities;
|
import org.geotools.data.DataUtilities;
|
||||||
import org.geotools.data.simple.SimpleFeatureCollection;
|
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||||
import org.geotools.geojson.feature.FeatureJSON;
|
import org.geotools.geojson.feature.FeatureJSON;
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.gis3c.spatial.dao;
|
package com.gis3c.spatial.dao;
|
||||||
|
|
||||||
|
import com.gis3c.common.persistence.annotation.C3SpatialDao;
|
||||||
import com.gis3c.spatial.entity.Region;
|
import com.gis3c.spatial.entity.Region;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -8,10 +9,11 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* Created by hukekuan on 2018/3/9.
|
* Created by hukekuan on 2018/3/9.
|
||||||
*/
|
*/
|
||||||
|
@C3SpatialDao
|
||||||
public interface RegionDao {
|
public interface RegionDao {
|
||||||
public Region findRegionByCode(String reginType, String reginCode);
|
public Region findRegionByCode(String reginTable, String reginCode);
|
||||||
public String findRgionCenterByCode(String reginType, String reginCode);
|
public String findRgionCenterByCode(String reginTable, String reginCode);
|
||||||
public List<Region> findAroundRegions(String reginType, String reginCode);
|
public List<Region> findAroundRegions(String reginTable, String reginCode);
|
||||||
public List<Region> findRegionsByParentCode(String parentCode);
|
public List<Region> findRegionsByParentCode(String reginTable, String parentCode);
|
||||||
public List<Map<String,String>> findRegionCentersByParentCode(String parentCode);
|
public List<Map<String,String>> findRegionCentersByParentCode(String reginTable, String parentCode);
|
||||||
}
|
}
|
||||||
|
|||||||
38
src/main/java/com/gis3c/spatial/entity/RegionType.java
Normal file
38
src/main/java/com/gis3c/spatial/entity/RegionType.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package com.gis3c.spatial.entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by hukekuan on 2018/3/9.
|
||||||
|
*/
|
||||||
|
public enum RegionType {
|
||||||
|
PROVINCE("geoprovince"), CITY("geocity"), COUNTRY("geocountry"), TOWN("geotown");
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private RegionType(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegionType ChildType() {
|
||||||
|
RegionType childType = null;
|
||||||
|
switch (this) {
|
||||||
|
case PROVINCE:
|
||||||
|
childType = RegionType.CITY;
|
||||||
|
break;
|
||||||
|
case CITY:
|
||||||
|
childType = RegionType.COUNTRY;
|
||||||
|
break;
|
||||||
|
case COUNTRY:
|
||||||
|
childType = RegionType.TOWN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return childType;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,26 +11,23 @@ import java.util.Map;
|
|||||||
public interface RegionService {
|
public interface RegionService {
|
||||||
/**
|
/**
|
||||||
* 获取区域实体
|
* 获取区域实体
|
||||||
* @param reginType
|
|
||||||
* @param reginCode
|
* @param reginCode
|
||||||
*/
|
*/
|
||||||
public Region findRegionByCode(String reginType, String reginCode);
|
public Region findRegionByCode(String reginCode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取区域中心点
|
* 获取区域中心点
|
||||||
* @param reginType
|
|
||||||
* @param reginCode
|
* @param reginCode
|
||||||
* @return 中心点wkt字符串
|
* @return 中心点wkt字符串
|
||||||
*/
|
*/
|
||||||
public String findRgionCenterByCode(String reginType, String reginCode);
|
public String findRgionCenterByCode(String reginCode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取区域周边区域
|
* 获取区域周边区域
|
||||||
* @param reginType
|
|
||||||
* @param reginCode
|
* @param reginCode
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<Region> findAroundRegions(String reginType, String reginCode);
|
public List<Region> findAroundRegions(String reginCode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取区域内部的所有子区域
|
* 获取区域内部的所有子区域
|
||||||
|
|||||||
@ -1,7 +1,11 @@
|
|||||||
package com.gis3c.spatial.service.impl;
|
package com.gis3c.spatial.service.impl;
|
||||||
|
|
||||||
|
import com.gis3c.spatial.dao.RegionDao;
|
||||||
import com.gis3c.spatial.entity.Region;
|
import com.gis3c.spatial.entity.Region;
|
||||||
|
import com.gis3c.spatial.entity.RegionType;
|
||||||
import com.gis3c.spatial.service.RegionService;
|
import com.gis3c.spatial.service.RegionService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -9,29 +13,101 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* Created by hukekuan on 2018/3/9.
|
* Created by hukekuan on 2018/3/9.
|
||||||
*/
|
*/
|
||||||
|
@Service
|
||||||
public class RegionServiceImpl implements RegionService {
|
public class RegionServiceImpl implements RegionService {
|
||||||
|
@Autowired
|
||||||
|
private RegionDao regionDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Region findRegionByCode(String reginType, String reginCode) {
|
public Region findRegionByCode(String reginCode) {
|
||||||
return null;
|
return regionDao.findRegionByCode(
|
||||||
|
regionTableByCode(reginCode).getName(),
|
||||||
|
reginCode
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String findRgionCenterByCode(String reginType, String reginCode) {
|
public String findRgionCenterByCode(String reginCode) {
|
||||||
return null;
|
return regionDao.findRgionCenterByCode(
|
||||||
|
regionTableByCode(reginCode).getName(),
|
||||||
|
reginCode
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Region> findAroundRegions(String reginType, String reginCode) {
|
public List<Region> findAroundRegions(String reginCode) {
|
||||||
return null;
|
return regionDao.findAroundRegions(
|
||||||
|
regionTableByCode(reginCode).getName(),
|
||||||
|
reginCode
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Region> findRegionsByParentCode(String parentCode) {
|
public List<Region> findRegionsByParentCode(String parentCode) {
|
||||||
return null;
|
RegionType parentType = regionTableByCode(parentCode);
|
||||||
|
RegionType regionType = parentType.ChildType();
|
||||||
|
if (regionType == null) {
|
||||||
|
throw new IllegalArgumentException("新政区编号输入错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
return regionDao.findRegionsByParentCode(
|
||||||
|
regionType.getName(),
|
||||||
|
getlikeCode(parentCode)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, String>> findRegionCentersByParentCode(String parentCode) {
|
public List<Map<String, String>> findRegionCentersByParentCode(String parentCode) {
|
||||||
return null;
|
RegionType parentType = regionTableByCode(parentCode);
|
||||||
|
RegionType regionType = parentType.ChildType();
|
||||||
|
if (regionType == null) {
|
||||||
|
throw new IllegalArgumentException("新政区编号输入错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
return regionDao.findRegionCentersByParentCode(
|
||||||
|
regionType.getName(),
|
||||||
|
getlikeCode(parentCode)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据行政区编号信息获取对应的新政区类型
|
||||||
|
*
|
||||||
|
* @param regionCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private RegionType regionTableByCode(String regionCode) {
|
||||||
|
if (regionCode == null || (regionCode.length() != 6 && regionCode.length() != 12)) {
|
||||||
|
throw new IllegalArgumentException("行政区编号格式错误");
|
||||||
|
}
|
||||||
|
RegionType regionTable = null;
|
||||||
|
int codeLength = regionCode.length();
|
||||||
|
String checkedCode = regionCode.substring(codeLength - 3, codeLength);
|
||||||
|
if ("000".equals(checkedCode)) {
|
||||||
|
regionTable = codeLength == 6 ? RegionType.PROVINCE : RegionType.TOWN;
|
||||||
|
} else if (checkedCode.endsWith("00")) {
|
||||||
|
regionTable = RegionType.CITY;
|
||||||
|
} else {
|
||||||
|
regionTable = RegionType.COUNTRY;
|
||||||
|
}
|
||||||
|
return regionTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用于查询子行政区的行政区编号
|
||||||
|
*
|
||||||
|
* @param regionCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String getlikeCode(String regionCode) {
|
||||||
|
String liekCode = null;
|
||||||
|
if (regionCode.endsWith("0000")) {
|
||||||
|
liekCode = regionCode.substring(0, 2);
|
||||||
|
} else if (regionCode.endsWith("00")) {
|
||||||
|
liekCode = regionCode.substring(0, 4);
|
||||||
|
} else {
|
||||||
|
liekCode = regionCode;
|
||||||
|
}
|
||||||
|
return liekCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import com.gis3c.ol.entity.Map;
|
|||||||
import com.gis3c.ol.service.LayerService;
|
import com.gis3c.ol.service.LayerService;
|
||||||
import com.gis3c.ol.service.MapService;
|
import com.gis3c.ol.service.MapService;
|
||||||
import com.gis3c.ol.service.SourceService;
|
import com.gis3c.ol.service.SourceService;
|
||||||
|
import com.gis3c.spatial.entity.RegionType;
|
||||||
import com.gis3c.spatial.service.TestService;
|
import com.gis3c.spatial.service.TestService;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
@ -25,15 +26,19 @@ public class App {
|
|||||||
public static void main(String[] args) throws IllegalAccessException, IOException {
|
public static void main(String[] args) throws IllegalAccessException, IOException {
|
||||||
ApplicationContext context = ApplicationInit();
|
ApplicationContext context = ApplicationInit();
|
||||||
|
|
||||||
SourceService sourceService = context.getBean(SourceService.class);
|
// SourceService sourceService = context.getBean(SourceService.class);
|
||||||
LayerService layerService = context.getBean(LayerService.class);
|
// LayerService layerService = context.getBean(LayerService.class);
|
||||||
MapService mapService = context.getBean(MapService.class);
|
// MapService mapService = context.getBean(MapService.class);
|
||||||
TestService testService = context.getBean(TestService.class);
|
// TestService testService = context.getBean(TestService.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
String code = "370300";
|
||||||
|
System.out.println(code.substring(0,4));
|
||||||
|
|
||||||
|
// RegionType r1 = RegionType.CITY;
|
||||||
|
// RegionType r2 = RegionType.CITY;
|
||||||
|
//
|
||||||
|
// System.out.println(r1.ChildType().getName());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
package com.gis3c.spatial.entity;
|
package com.gis3c.spatial.entity;
|
||||||
|
|
||||||
import com.gis3c.spatial.entity.feature.BaseFeature;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hukekuan on 2018/1/16.
|
* Created by hukekuan on 2018/1/16.
|
||||||
*/
|
*/
|
||||||
|
|||||||
29
src/test/resources/mappings/spatial/RegionDao.xml
Normal file
29
src/test/resources/mappings/spatial/RegionDao.xml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?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="com.gis3c.spatial.dao.RegionDao">
|
||||||
|
<resultMap id="regionResult" type="com.gis3c.spatial.entity.Region">
|
||||||
|
<result property="reginCode" column="code" />
|
||||||
|
<result property="regionName" column="name" />
|
||||||
|
<result property="geometry" column="geom" javaType="Geometry"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<select id="findRegionByCode" resultMap="regionResult">
|
||||||
|
SELECT t.code, t.name, t.geom
|
||||||
|
FROM ${reginTable} t
|
||||||
|
where t.code = #{reginCode, javaType=java.lang.String};
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="findRgionCenterByCode" resultType="java.util.HashMap">
|
||||||
|
SELECT t.code, st_astext(st_centroid(t.geom)) as center
|
||||||
|
FROM ${reginTable} t
|
||||||
|
where t.code = #{reginCode, javaType=java.lang.String};
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="findAroundRegions" resultMap="regionResult">
|
||||||
|
select t1.code, t1.name
|
||||||
|
from ${reginTable} t1,(
|
||||||
|
select geom from ${reginTable} where code = #{reginCode, javaType=java.lang.String}
|
||||||
|
) t2
|
||||||
|
where ST_Disjoint(t2.geom,t1.geom) = false;
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
@ -1,15 +0,0 @@
|
|||||||
<?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="com.gis3c.spatial.dao.TestDao">
|
|
||||||
<resultMap id="mapResult" type="com.gis3c.spatial.entity.Test">
|
|
||||||
<result property="id" column="id" />
|
|
||||||
<result property="name" column="name" />
|
|
||||||
<result property="direction" column="direction" />
|
|
||||||
<result property="geometry" column="geom" javaType="Geometry"/>
|
|
||||||
</resultMap>
|
|
||||||
|
|
||||||
<select id="allList" resultMap="mapResult">
|
|
||||||
SELECT id,name,direction,geom
|
|
||||||
FROM roadpoint;
|
|
||||||
</select>
|
|
||||||
</mapper>
|
|
||||||
@ -5,6 +5,6 @@ sys.username=gis
|
|||||||
sys.password=gis
|
sys.password=gis
|
||||||
|
|
||||||
spatial.driverClassName=org.postgresql.Driver
|
spatial.driverClassName=org.postgresql.Driver
|
||||||
spatial.url=jdbc:postgresql:postgis
|
spatial.url=jdbc:postgresql://172.16.6.13:5432/gisdb
|
||||||
spatial.username=postgres
|
spatial.username=postgres
|
||||||
spatial.password=postgres
|
spatial.password=postgres
|
||||||
Loading…
Reference in New Issue
Block a user