|
@@ -25,8 +25,9 @@ import java.util.List;
|
|
|
public class AreaService {
|
|
|
|
|
|
private static AreaService instance;
|
|
|
- public static AreaService getInstance(){
|
|
|
- if(instance == null){
|
|
|
+
|
|
|
+ public static AreaService getInstance() {
|
|
|
+ if (instance == null) {
|
|
|
return new AreaService();
|
|
|
}
|
|
|
return instance;
|
|
@@ -47,23 +48,25 @@ public class AreaService {
|
|
|
public List<GeoJsonBean> gridPolygonList = new ArrayList<>();
|
|
|
|
|
|
@PostConstruct
|
|
|
- public void initGeoData(){
|
|
|
+ public void initGeoData() {
|
|
|
System.out.println("<<<<<<<<------AreaService>initGeoData------>>>>>>>>>");
|
|
|
instance = this;
|
|
|
- new Thread(()->runGeoData()).start();
|
|
|
- new Thread(()->runZEWLData()).start();
|
|
|
- new Thread(()->initPolygons()).start();
|
|
|
+ new Thread(() -> runGeoData()).start();
|
|
|
+ new Thread(() -> runZEWLData()).start();
|
|
|
+ new Thread(() -> initPolygons()).start();
|
|
|
}
|
|
|
|
|
|
- public void initPolygons(){
|
|
|
+ public void initPolygons() {
|
|
|
List<List<GeoJsonBean>> lis = new ArrayList<>();
|
|
|
lis.add(cjPolygonList);
|
|
|
lis.add(wGridPolygonList);
|
|
|
lis.add(gridPolygonList);
|
|
|
String[] path = new String[]{"classpath:geojson/qp_cunju.geojson", "classpath:geojson/青浦区微网格-wgs84.geojson",
|
|
|
"classpath:geojson/责任网格-wgs84.geojson"};
|
|
|
+// String[] path = new String[]{"D:/geojson/qp_cunju.geojson", "D:/geojson/青浦区微网格-wgs84.geojson",
|
|
|
+// "D:/geojson/责任网格-wgs84.geojson"};
|
|
|
|
|
|
- for(int j = 0; j < path.length; j ++){
|
|
|
+ for (int j = 0; j < path.length; j++) {
|
|
|
BufferedReader br = null;
|
|
|
try {
|
|
|
File file = ResourceUtils.getFile(path[j]);
|
|
@@ -78,7 +81,7 @@ public class AreaService {
|
|
|
|
|
|
JSONArray featrues = json.getJSONArray("features");
|
|
|
|
|
|
- for(int i = 0; i < featrues.size(); i ++){
|
|
|
+ for (int i = 0; i < featrues.size(); i++) {
|
|
|
JSONObject properties = featrues.getJSONObject(i).getJSONObject("properties");
|
|
|
JSONObject geoJson = new JSONObject();
|
|
|
geoJson.put("type", "MultiPolygon");
|
|
@@ -88,7 +91,7 @@ public class AreaService {
|
|
|
GeometryJSON geometryJSON = new GeometryJSON();
|
|
|
MultiPolygon multiPolygon = geometryJSON.readMultiPolygon(geoJson.toJSONString());
|
|
|
GeoJsonBean geoJsonBean = new GeoJsonBean();
|
|
|
- if(file.getName().contains("cunju")){
|
|
|
+ if (file.getName().contains("cunju")) {
|
|
|
JSONObject resultProp = new JSONObject();
|
|
|
resultProp.put("网格名称", properties.getString("__10"));
|
|
|
resultProp.put("shape_leng", properties.getString("shape__length"));
|
|
@@ -103,7 +106,7 @@ public class AreaService {
|
|
|
resultProp.put("面积", properties.getString("__1"));
|
|
|
resultProp.put("objectid", properties.getString("objectid"));
|
|
|
geoJsonBean.setProperties(resultProp);
|
|
|
- } else if(file.getName().contains("微网格")){
|
|
|
+ } else if (file.getName().contains("微网格")) {
|
|
|
JSONObject resultProp = new JSONObject();
|
|
|
resultProp.put("objectid", properties.getString("OBJECTID"));
|
|
|
resultProp.put("所属街道", properties.getString("æ\u0089\u0080å±\u009Eè¡\u0097"));
|
|
@@ -113,7 +116,7 @@ public class AreaService {
|
|
|
resultProp.put("Shape_Area", properties.getString("Shape_Area"));
|
|
|
resultProp.put("微格网名称", properties.getString("å¾®ç½\u0091_1"));
|
|
|
geoJsonBean.setProperties(resultProp);
|
|
|
- } else if(file.getName().contains("责任网格")){
|
|
|
+ } else if (file.getName().contains("责任网格")) {
|
|
|
geoJsonBean.setProperties(properties);
|
|
|
}
|
|
|
geoJsonBean.setMultiPolygon(multiPolygon);
|
|
@@ -129,7 +132,7 @@ public class AreaService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public GeoJsonBean isInGridPolygon(double lon, double lat){
|
|
|
+ public GeoJsonBean isInGridPolygon(double lon, double lat) {
|
|
|
Geometry point = null;
|
|
|
try {
|
|
|
point = reader.read("POINT (" + lon + " " + lat + ")");
|
|
@@ -137,19 +140,19 @@ public class AreaService {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
|
|
|
- for(GeoJsonBean bean : gridPolygonList){
|
|
|
- try{
|
|
|
- if(bean.getMultiPolygon().contains(point)){
|
|
|
+ for (GeoJsonBean bean : gridPolygonList) {
|
|
|
+ try {
|
|
|
+ if (bean.getMultiPolygon().contains(point)) {
|
|
|
return bean;
|
|
|
}
|
|
|
- } catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public GeoJsonBean isInWGridPolygon(double lon, double lat){
|
|
|
+ public GeoJsonBean isInWGridPolygon(double lon, double lat) {
|
|
|
Geometry point = null;
|
|
|
try {
|
|
|
point = reader.read("POINT (" + lon + " " + lat + ")");
|
|
@@ -157,15 +160,15 @@ public class AreaService {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
|
|
|
- for(GeoJsonBean bean : wGridPolygonList){
|
|
|
- if(bean.getMultiPolygon().contains(point)){
|
|
|
+ for (GeoJsonBean bean : wGridPolygonList) {
|
|
|
+ if (bean.getMultiPolygon().contains(point)) {
|
|
|
return bean;
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public GeoJsonBean isInCJPolygon(double lon, double lat){
|
|
|
+ public GeoJsonBean isInCJPolygon(double lon, double lat) {
|
|
|
Geometry point = null;
|
|
|
try {
|
|
|
point = reader.read("POINT (" + lon + " " + lat + ")");
|
|
@@ -173,8 +176,8 @@ public class AreaService {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
|
|
|
- for(GeoJsonBean bean : cjPolygonList){
|
|
|
- if(bean.getMultiPolygon().contains(point)){
|
|
|
+ for (GeoJsonBean bean : cjPolygonList) {
|
|
|
+ if (bean.getMultiPolygon().contains(point)) {
|
|
|
return bean;
|
|
|
}
|
|
|
}
|
|
@@ -182,8 +185,10 @@ public class AreaService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- /** 初始化责任网络数据 **/
|
|
|
- public void runZEWLData(){
|
|
|
+ /**
|
|
|
+ * 初始化责任网络数据
|
|
|
+ **/
|
|
|
+ public void runZEWLData() {
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
BufferedReader br = null;
|
|
|
try {
|
|
@@ -197,7 +202,7 @@ public class AreaService {
|
|
|
}
|
|
|
zrwl = JSONObject.parseObject(sb.toString(), Zerenwangluo.class);
|
|
|
zrwlFeatures = zrwl.getFeatures();
|
|
|
- for(int i = 0; i < zrwlFeatures.size(); i ++) {
|
|
|
+ for (int i = 0; i < zrwlFeatures.size(); i++) {
|
|
|
|
|
|
Zerenwangluo.FeaturesDTO.AttributesDTO attributes = zrwlFeatures.get(i).getAttributes();
|
|
|
zrwlProperties.add(attributes);
|
|
@@ -206,9 +211,9 @@ public class AreaService {
|
|
|
JSONArray coordinates = new JSONArray();
|
|
|
JSONArray coordinates1 = new JSONArray();
|
|
|
|
|
|
- for(List<List<Double>> rings : geometry.getRings()){
|
|
|
+ for (List<List<Double>> rings : geometry.getRings()) {
|
|
|
JSONArray coordinates2 = new JSONArray();
|
|
|
- for(List<Double> ring : rings){
|
|
|
+ for (List<Double> ring : rings) {
|
|
|
JSONArray coordinates3 = new JSONArray();
|
|
|
double x = ring.get(0);
|
|
|
double y = ring.get(1);
|
|
@@ -242,26 +247,25 @@ public class AreaService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- public JSONObject getLiabilityGridByLatlon(double lat, double lon){
|
|
|
+ public JSONObject getLiabilityGridByLatlon(double lat, double lon) {
|
|
|
Zerenwangluo.FeaturesDTO.AttributesDTO attribute = null;
|
|
|
try {
|
|
|
Geometry point = reader.read("POINT (" + lon + " " + lat + ")");
|
|
|
boolean done = false;
|
|
|
- for(int i = 0; i < zrwlMulPolygonList.size(); i ++){
|
|
|
- if(done){
|
|
|
+ for (int i = 0; i < zrwlMulPolygonList.size(); i++) {
|
|
|
+ if (done) {
|
|
|
break;
|
|
|
}
|
|
|
MultiPolygon multiPolygon = zrwlMulPolygonList.get(i);
|
|
|
String wktStr = multiPolygon.toString();
|
|
|
- if(wktStr.contains("), (")){// 如果是多面,则拆分成单面再重新比对
|
|
|
+ if (wktStr.contains("), (")) {// 如果是多面,则拆分成单面再重新比对
|
|
|
String[] wktStrs = wktStr.split("\\), \\(");
|
|
|
List<MultiPolygon> polygons = new ArrayList<>();
|
|
|
- for(int j = 0; j < wktStrs.length; j ++){
|
|
|
- if(j == 0){
|
|
|
+ for (int j = 0; j < wktStrs.length; j++) {
|
|
|
+ if (j == 0) {
|
|
|
MultiPolygon polygon1 = (MultiPolygon) reader.read(wktStrs[0] + ")))");
|
|
|
polygons.add(polygon1);
|
|
|
- } else if(j == wktStrs.length - 1){
|
|
|
+ } else if (j == wktStrs.length - 1) {
|
|
|
MultiPolygon polygon2 = (MultiPolygon) reader.read("MULTIPOLYGON (((" + wktStrs[j]);
|
|
|
polygons.add(polygon2);
|
|
|
} else {
|
|
@@ -269,15 +273,15 @@ public class AreaService {
|
|
|
polygons.add(polygon3);
|
|
|
}
|
|
|
}
|
|
|
- for(MultiPolygon polygon : polygons){
|
|
|
- if(polygon.contains(point)){
|
|
|
+ for (MultiPolygon polygon : polygons) {
|
|
|
+ if (polygon.contains(point)) {
|
|
|
attribute = zrwlProperties.get(i);
|
|
|
done = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
} else {// 如果是单面,则直接比对
|
|
|
- if(multiPolygon.contains(point)){
|
|
|
+ if (multiPolygon.contains(point)) {
|
|
|
attribute = zrwlProperties.get(i);
|
|
|
break;
|
|
|
}
|
|
@@ -292,8 +296,10 @@ public class AreaService {
|
|
|
return JSONObject.parseObject(JSON.toJSONString(attribute));
|
|
|
}
|
|
|
|
|
|
- /** 初始化村居数据 **/
|
|
|
- public void runGeoData(){
|
|
|
+ /**
|
|
|
+ * 初始化村居数据
|
|
|
+ **/
|
|
|
+ public void runGeoData() {
|
|
|
BufferedReader br = null;
|
|
|
try {
|
|
|
File file = ResourceUtils.getFile("classpath:geojson/qp_cunju.geojson");
|
|
@@ -307,7 +313,7 @@ public class AreaService {
|
|
|
|
|
|
JSONObject json = JSONObject.parseObject(sb.toString());
|
|
|
JSONArray features = json.getJSONArray("features");
|
|
|
- for(int i = 0; i < features.size(); i ++) {
|
|
|
+ for (int i = 0; i < features.size(); i++) {
|
|
|
|
|
|
JSONObject feature = features.getJSONObject(i);
|
|
|
JSONObject geometry = feature.getJSONObject("geometry");
|
|
@@ -327,19 +333,19 @@ public class AreaService {
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
System.out.println("<<<<<<<<------run geo data error------>>>>>>>>>");
|
|
|
- } catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
System.out.println("<<<<<<<<------run geo data error------>>>>>>>>>");
|
|
|
}
|
|
|
System.out.println("<<<<<<<<------run geo data complete------>>>>>>>>>");
|
|
|
}
|
|
|
|
|
|
- public Village getAreaCodeByLatlon(double lat, double lon){
|
|
|
+ public Village getAreaCodeByLatlon(double lat, double lon) {
|
|
|
Village geoAC = null;
|
|
|
try {
|
|
|
Geometry point = reader.read("POINT (" + lon + " " + lat + ")");
|
|
|
- for(int i = 0; i < mulPolygonList.size(); i ++){
|
|
|
- if(mulPolygonList.get(i).contains(point)){
|
|
|
+ for (int i = 0; i < mulPolygonList.size(); i++) {
|
|
|
+ if (mulPolygonList.get(i).contains(point)) {
|
|
|
geoAC = propertiList.get(i);
|
|
|
break;
|
|
|
}
|
|
@@ -351,19 +357,19 @@ public class AreaService {
|
|
|
return geoAC;
|
|
|
}
|
|
|
|
|
|
- public List<Village> getAreaCodeByLatlons(JSONArray locations){
|
|
|
- if(locations == null || locations.size() < 1){
|
|
|
+ public List<Village> getAreaCodeByLatlons(JSONArray locations) {
|
|
|
+ if (locations == null || locations.size() < 1) {
|
|
|
return null;
|
|
|
} else {
|
|
|
List<Village> result = new ArrayList<>();
|
|
|
try {
|
|
|
- for(int i = 0; i < locations.size(); i ++){
|
|
|
+ for (int i = 0; i < locations.size(); i++) {
|
|
|
JSONObject jsonObject = locations.getJSONObject(i);
|
|
|
Village geoAreaCode = getAreaCodeByLatlon(jsonObject.getDouble("lat"), jsonObject.getDouble("lon"));
|
|
|
result.add(geoAreaCode);
|
|
|
}
|
|
|
return result;
|
|
|
- } catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
return null;
|
|
|
}
|
|
|
}
|