初始化
This commit is contained in:
parent
7670fd8d4f
commit
8a450864b8
@ -6,6 +6,8 @@ package com.gis3c.common.exception;
|
||||
public class BusinessException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer exceptionCode;
|
||||
|
||||
public BusinessException(){
|
||||
super();
|
||||
}
|
||||
@ -21,4 +23,24 @@ public class BusinessException extends RuntimeException {
|
||||
public BusinessException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public BusinessException(Integer exceptionCode){
|
||||
super();
|
||||
this.exceptionCode = exceptionCode;
|
||||
}
|
||||
|
||||
public BusinessException(String message,Integer exceptionCode) {
|
||||
super(message);
|
||||
this.exceptionCode = exceptionCode;
|
||||
}
|
||||
|
||||
public BusinessException(Throwable cause,Integer exceptionCode) {
|
||||
super(cause);
|
||||
this.exceptionCode = exceptionCode;
|
||||
}
|
||||
|
||||
public BusinessException(String message, Throwable cause,Integer exceptionCode) {
|
||||
super(message, cause);
|
||||
this.exceptionCode = exceptionCode;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.gis3c.spatial.common;
|
||||
|
||||
|
||||
import com.gis3c.spatial.entity.BaseFeature;
|
||||
import com.gis3c.spatial.entity.Region;
|
||||
import org.geotools.data.DataUtilities;
|
||||
import org.geotools.data.simple.SimpleFeatureCollection;
|
||||
import org.geotools.geojson.feature.FeatureJSON;
|
||||
@ -18,6 +19,34 @@ import java.util.List;
|
||||
* Created by hukekuan on 2018/1/16.
|
||||
*/
|
||||
public class FeatureUtilities {
|
||||
/**
|
||||
* SimpleFeature转GeoJSON字符串
|
||||
* @param simpleFeature
|
||||
* @return
|
||||
*/
|
||||
public static String Feature2Json(SimpleFeature simpleFeature) throws IOException {
|
||||
String result = null;
|
||||
FeatureJSON fjson = new FeatureJSON();
|
||||
StringWriter writer = new StringWriter();
|
||||
fjson.writeFeature(simpleFeature,writer);
|
||||
result = writer.toString();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param t 继承于BaseFeature的实体类转换成GeoJSON字符串
|
||||
* @param featureIndex
|
||||
* @param <T>
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static <T extends BaseFeature> String JavaBean2Json(T t,String featureIndex)
|
||||
throws IOException {
|
||||
SimpleFeature simpleFeature =t.javaBean2SimpleFeature("featureIndex");
|
||||
return Feature2Json(simpleFeature);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: 将java bean转换为Simple Feature
|
||||
* @param beansList
|
||||
@ -30,9 +59,8 @@ public class FeatureUtilities {
|
||||
throw new NullPointerException("参数无效");
|
||||
}
|
||||
List<SimpleFeature> simpleFeatureList = new ArrayList<>();
|
||||
SimpleFeatureType featureType = beansList.get(0).createFeatureType();
|
||||
for(int i = 0,len = beansList.size();i < len;i++){
|
||||
simpleFeatureList.add(beansList.get(i).javaBean2SimpleFeature(featureType,Integer.toString(i)));
|
||||
simpleFeatureList.add(beansList.get(i).javaBean2SimpleFeature(Integer.toString(i)));
|
||||
}
|
||||
|
||||
return simpleFeatureList;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.gis3c.spatial.entity;
|
||||
|
||||
import com.gis3c.common.exception.BusinessException;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import org.geotools.feature.simple.SimpleFeatureBuilder;
|
||||
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
|
||||
@ -55,11 +56,11 @@ public class BaseFeature {
|
||||
* @throws NullPointerException
|
||||
* @date 2017-07-10 下午6:39
|
||||
*/
|
||||
public SimpleFeatureType createFeatureType() throws NullPointerException{
|
||||
public SimpleFeatureType createFeatureType() {
|
||||
SimpleFeatureTypeBuilder build = new SimpleFeatureTypeBuilder();
|
||||
SimpleFeatureType featureType=null;
|
||||
if(!geometryChecked()){
|
||||
throw new NullPointerException("空间字段为空");
|
||||
throw new BusinessException("空间字段为空");
|
||||
}
|
||||
|
||||
CoordinateReferenceSystem crs = null;
|
||||
@ -77,28 +78,28 @@ public class BaseFeature {
|
||||
/**
|
||||
* @author hukekuan
|
||||
* @Description 生成SimpleFeature对象
|
||||
* @param featureType,转换类对应的featureType
|
||||
* @param featureIndex,feature序列号
|
||||
* @return 对象转SimpleFeature
|
||||
* @throws IllegalArgumentException
|
||||
* @throws IllegalAccessException
|
||||
* @date 2017-07-10 下午7:10
|
||||
*/
|
||||
public SimpleFeature javaBean2SimpleFeature(SimpleFeatureType featureType, String featureIndex)
|
||||
throws IllegalArgumentException, IllegalAccessException {
|
||||
SimpleFeature simpleFeature = null;
|
||||
if(featureType == null){
|
||||
throw new IllegalArgumentException("featureType参数为空");
|
||||
}
|
||||
public SimpleFeature javaBean2SimpleFeature(String featureIndex) {
|
||||
SimpleFeatureType featureType = this.createFeatureType();
|
||||
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
|
||||
|
||||
List<Field> fields = this.AllFieldes();
|
||||
List<Object> objList = new ArrayList<>();
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
objList.add(field.get(this));
|
||||
try {
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
objList.add(field.get(this));
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new BusinessException("无访问权限");
|
||||
}
|
||||
simpleFeature = featureBuilder.buildFeature(featureIndex, objList.toArray());
|
||||
return simpleFeature;
|
||||
|
||||
return featureBuilder.buildFeature(featureIndex, objList.toArray());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ public interface RegionService {
|
||||
* 获取区域实体
|
||||
* @param reginCode
|
||||
*/
|
||||
public Region findRegionByCode(String reginCode);
|
||||
public String findRegionByCode(String reginCode);
|
||||
|
||||
/**
|
||||
* 获取区域中心点
|
||||
@ -28,14 +28,14 @@ public interface RegionService {
|
||||
* @param reginCode
|
||||
* @return
|
||||
*/
|
||||
public List<Region> findAroundRegions(String reginCode);
|
||||
public String findAroundRegions(String reginCode);
|
||||
|
||||
/**
|
||||
* 获取区域内部的所有子区域
|
||||
* @param parentCode
|
||||
* @return
|
||||
*/
|
||||
public List<Region> findRegionsByParentCode(String parentCode);
|
||||
public String findRegionsByParentCode(String parentCode);
|
||||
|
||||
/**
|
||||
* 获取子区域内部的所有子区域的中心点
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
package com.gis3c.spatial.service.impl;
|
||||
|
||||
import com.gis3c.common.exception.BusinessException;
|
||||
import com.gis3c.spatial.common.FeatureUtilities;
|
||||
import com.gis3c.spatial.dao.RegionDao;
|
||||
import com.gis3c.spatial.entity.Region;
|
||||
import com.gis3c.spatial.entity.RegionCenter;
|
||||
import com.gis3c.spatial.entity.RegionType;
|
||||
import com.gis3c.spatial.service.RegionService;
|
||||
import org.opengis.feature.simple.SimpleFeature;
|
||||
import org.opengis.feature.simple.SimpleFeatureType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -20,11 +25,18 @@ public class RegionServiceImpl implements RegionService {
|
||||
private RegionDao regionDao;
|
||||
|
||||
@Override
|
||||
public Region findRegionByCode(String reginCode) {
|
||||
return regionDao.findRegionByCode(
|
||||
public String findRegionByCode(String reginCode) {
|
||||
String regionJson = null;
|
||||
Region queryRegion = regionDao.findRegionByCode(
|
||||
regionTableByCode(reginCode).getName(),
|
||||
reginCode
|
||||
);
|
||||
try {
|
||||
regionJson = FeatureUtilities.JavaBean2Json(queryRegion,"1");
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException("Region实体转GeoJSON出错");
|
||||
}
|
||||
return regionJson;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -36,25 +48,41 @@ public class RegionServiceImpl implements RegionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Region> findAroundRegions(String reginCode) {
|
||||
return regionDao.findAroundRegions(
|
||||
public String findAroundRegions(String reginCode) {
|
||||
String result = null;
|
||||
List<Region> regionLsit = regionDao.findAroundRegions(
|
||||
regionTableByCode(reginCode).getName(),
|
||||
reginCode
|
||||
);
|
||||
try {
|
||||
result = FeatureUtilities.JavaBeans2Json(regionLsit);
|
||||
} catch (IllegalAccessException | IOException e) {
|
||||
throw new BusinessException("Region实体转GeoJSON出错");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Region> findRegionsByParentCode(String parentCode) {
|
||||
public String findRegionsByParentCode(String parentCode) {
|
||||
String result = null;
|
||||
|
||||
RegionType parentType = regionTableByCode(parentCode);
|
||||
RegionType regionType = parentType.ChildType();
|
||||
if (regionType == null) {
|
||||
throw new IllegalArgumentException("新政区编号输入错误");
|
||||
throw new BusinessException("新政区编号输入错误");
|
||||
}
|
||||
|
||||
return regionDao.findRegionsByParentCode(
|
||||
List<Region> regionLsit = regionDao.findRegionsByParentCode(
|
||||
regionType.getName(),
|
||||
getlikeCode(parentCode)
|
||||
);
|
||||
|
||||
try {
|
||||
result = FeatureUtilities.JavaBeans2Json(regionLsit);
|
||||
} catch (IllegalAccessException | IOException e) {
|
||||
throw new BusinessException("Region实体转GeoJSON出错");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user