Administrator 2 anni fa
parent
commit
e0c8235a1f

+ 37 - 0
src/main/java/com/sysu/admin/controller/city/CityController.java

@@ -1,5 +1,6 @@
 package com.sysu.admin.controller.city;
 
+import com.sysu.admin.controller.crop.CropLandService;
 import com.sysu.admin.controller.crop.range.LandRangeIndexService;
 import com.sysu.admin.controller.geo.qyz.QyzService;
 import com.sysu.admin.support.system.region.Region;
@@ -8,6 +9,7 @@ import com.sysu.admin.utils.shape.GeoCastUtil;
 import com.xiesx.fastboot.base.result.BaseResult;
 import com.xiesx.fastboot.base.result.R;
 import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.geom.Point;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
@@ -34,6 +36,8 @@ public class CityController {
     DistrictRepository districtRepository;
     @Autowired
     LandRangeIndexService mLandRangeIndexService;
+    @Autowired
+    CropLandService cropLandService;
 
     /**
      * 种植结构
@@ -76,6 +80,39 @@ public class CityController {
         return R.succ(res);
     }
 
+    @RequestMapping(value = "/findBuffer")
+    @ResponseBody
+    public BaseResult findBuffer(int code, int level){
+        Object res = null;
+        switch (level){
+            case 0:
+                Province province = provinceRepository.findByCode(code);
+                res = province;
+                if(province != null){
+                    Point point = cropLandService.getCenterPoint(province.getGeom());
+                    province.setWkt(cropLandService.getBuffer(new Double[]{point.getX(),point.getY()}, 5000));
+                }
+                break;
+            case 1:
+                City city = cityRepository.findByCode(code);
+                res = city;
+                if(city != null){
+                    Point point = cropLandService.getCenterPoint(city.getGeom());
+                    city.setWkt(cropLandService.getBuffer(new Double[]{point.getX(),point.getY()}, 5000));
+                }
+                break;
+            case 2:
+                District district = districtRepository.findByCode(code);
+                res = district;
+                if(district != null){
+                    Point point = cropLandService.getCenterPoint(district.getGeom());
+                    district.setWkt(cropLandService.getBuffer(new Double[]{point.getX(),point.getY()}, 5000));
+                }
+                break;
+        }
+        return R.succ(res);
+    }
+
 
 
 

+ 12 - 3
src/main/java/com/sysu/admin/controller/crop/CropLandController.java

@@ -12,6 +12,7 @@ import com.sysu.admin.controller.city.*;
 import com.sysu.admin.controller.crop.CropLand;
 import com.sysu.admin.controller.crop.CropLandService;
 import com.sysu.admin.controller.crop.CropLandVo;
+import com.sysu.admin.controller.crop.range.LandRangeIndexService;
 import com.sysu.admin.controller.geo.land.LandTaskStatus;
 import com.sysu.admin.support.base.BaseVo;
 import com.sysu.admin.support.base.ServiceContext;
@@ -31,9 +32,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.transaction.Transactional;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
 
@@ -49,6 +48,8 @@ public class CropLandController extends ServiceContext {
     @Autowired
     ShiroService shiroService;
     @Autowired
+    LandRangeIndexService mLandRangeIndexService;
+    @Autowired
     DistrictRepository districtRepository;
     @Autowired
     CityRepository cityRepository;
@@ -64,6 +65,14 @@ public class CropLandController extends ServiceContext {
         return R.succ(cityLand);
     }
 
+    @RequestMapping("/getGeoJson")
+    @ResponseBody
+    public BaseResult getGeojson(String tableNames, Double x1, Double y1,Double x2, Double y2){
+//        String[] tableNames = mLandRangeIndexService.getTableNames(x1,y1,x2,y2);
+        List<CropPoint> cropLandList = cityLandService.findCropLandNoGeomByTableNamesAndBBox(tableNames, x1,y1,x2,y2);
+        return R.succ(cropLandList);
+    }
+
     @RequestMapping("/getBuffer")
     @ResponseBody
     public BaseResult getBuffer(Double x, Double y, Integer m){

+ 20 - 0
src/main/java/com/sysu/admin/controller/crop/CropLandService.java

@@ -15,6 +15,7 @@ import com.sysu.admin.controller.geo.land.LandTaskStatus;
 import com.sysu.admin.support.base.BaseService;
 import com.sysu.admin.support.system.config.ConfigContext;
 import com.sysu.admin.support.system.user.User;
+import com.sysu.admin.utils.TextUtil;
 import com.sysu.admin.utils.file.FileUtil;
 import com.sysu.admin.utils.shape.GeoCastUtil;
 import com.sysu.admin.utils.shape.ShapeReader;
@@ -92,6 +93,25 @@ public class CropLandService extends BaseService<CropLand, Long> {
         return mCropPointRepository.getBuffer("Point("+point[0]+" "+point[1]+")", degree);
     }
 
+    public List<CropPoint> findCropLandNoGeomByTableNamesAndBBox(String tableNames, Double x1, Double y1, Double x2, Double y2){
+        String wkt = "POLYGON (("+x1+" "+y1+", "+x1+" "+y2+", "+x2+" "+y2+", "+x2+" "+y1+", "+x1+" "+y1+"))";
+        String sql = "";
+        String[]  tableNameArray = TextUtil.split(tableNames, ",");
+        int i=0;
+        for(String table : tableNameArray){
+            if(i > 0){
+                sql+="\n union all \n";
+            }
+            sql += " select id,gridcode,crop_type,st_asgeojson(center_point) as geojson,status,receiver,name,address,growing_period ";
+            sql += "from " + table;
+            sql += " where ST_Intersects(geom,st_geomfromtext('"+wkt+"',4326)) ";
+            i++;
+        }
+
+        List<CropPoint> cropLandList = mEntityManager.createNativeQuery(sql,CropPoint.class).getResultList();
+        return cropLandList;
+    }
+
     @Transactional
     public void updateStatus(Long id, Integer status, Long updateUserId){
         CropLand bean = mCropLandRepository.findOne(id);

+ 13 - 2
src/main/java/com/sysu/admin/controller/crop/CropPoint.java

@@ -34,13 +34,24 @@ public class CropPoint {
 //    @Column(columnDefinition = "center_point")
 //    private Point centerPoint;
 
+    @Column(name = "gridcode")
+    private Integer gridcode;
     @Column
-    private String geojson;
+    private String name;
+    @Column
+    private String address;
 
+    @Column
+    private String geojson;
+    /**
+     * 生长期
+     */
+    @Column
+    private Integer growingPeriod;
     /**
      * 领取人
      */
-    @Column(nullable = false)
+    @Column()
     private Long receiver;
     /**
      * 耕地类型

+ 2 - 1
src/main/java/com/sysu/admin/controller/crop/CropPointRepository.java

@@ -9,11 +9,12 @@ import java.util.List;
 public interface CropPointRepository extends JpaPlusRepository<CropPoint, Long> {
 
 
-    @Query(value = "SELECT id,crop_type,st_asgeojson(center_point) as geojson,status,receiver from \"p_crop\" where status in ?3 and St_within(center_point," +
+    @Query(value = "SELECT id,gridcode,crop_type,st_asgeojson(center_point) as geojson,status,receiver,name,address,growing_period from \"p_crop\" where status in ?3 and St_within(center_point," +
             " ST_Buffer(st_geomfromtext(?1,4326),?2, 'quad_segs=8')" +
             ");",nativeQuery = true)
     List<CropPoint> findByBufferAndStatus(String pointWKT, Double degree, Integer[] status);
 
+
     @Query(value = "select ST_AsText(ST_Buffer(st_geomfromtext(?1),?2, 'quad_segs=8'))", nativeQuery = true)
     String getBuffer(String pointWKT, Double degree);
 

+ 3 - 7
src/main/webapp/WEB-INF/jsp/comm/admin2.jsp

@@ -155,16 +155,12 @@
                 // 城市赋值
                 currentPicker = new city("#city-picker", {
                     getValListener: function(item){
+                        let landAction = geoServerContext.actions["1"]
                         let cityAction = geoServerContext.actions["3"]
                         if(cityAction){
-                            cityAction.fit(item.code, function(data){
-                                let landAction = geoServerContext.actions["1"]
+                            cityAction.fit(item.code,function(){
                                 if(landAction){
-                                    if(data.tableName){
-                                        landAction.changeMode(1, data.tableName)
-                                    }else{
-                                        landAction.changeMode(0)
-                                    }
+                                    landAction.obj.visibleWMTS([])
                                 }
                             })
                         }

+ 4 - 4
src/main/webapp/static/package/city.js

@@ -55,13 +55,13 @@ CityAction.prototype = {
         }
         return level
     },
-    find(code, success){
+    findBuffer(code, success){
         let level = this.getLevel(code);
         if(level == 0 || level == 1)
             return
         $.ajax({
             type : 'POST',
-            url : "/city/findJson",
+            url : "/city/findBuffer",
             data : {level: level, code: code},
             dataType : 'json',
             success : success
@@ -69,13 +69,13 @@ CityAction.prototype = {
     },
     fit(code, callback){
         let that = this
-        this.find(code, function(res){
+        this.findBuffer(code, function(res){
             if(res.code == 0){
                 if(res.data){
-                    that.context.currentView.fit(new ol.format.WKT().readGeometry(res.data.wkt).getExtent(),{duration: 1000})
                     if(callback){
                         callback(res.data)
                     }
+                    that.context.currentView.fit(new ol.format.WKT().readGeometry(res.data.wkt).getExtent(),{duration: 1000})
                 }
             }
         })

+ 71 - 39
src/main/webapp/static/package/cityland.js

@@ -15,7 +15,7 @@ CityLandAction.prototype = {
     createStatus : false,
     create(){
         let that = this
-        this.obj.getTileLayer()
+        this.obj.createTileLayer()
         this.tempVectorLayer = this.loadTempVectorLayer()
         this.drawMultiPolygon = new DrawMultiPolygon({vector: this.tempVectorLayer, map: this.context.currentMap,wkt: this.context.wkt})
 
@@ -46,10 +46,10 @@ CityLandAction.prototype = {
             return
         }
         // this.context.clicks[this.id] = this
+        this.obj.addTileLayer(this.context.currentMap)
         this.drawMultiPolygon.show()
-
         this.tempVectorLayer.setVisible(true)
-
+        this.context.landFilter()
         this.context.getSldStyleSign(this.obj.wmsData.params.STYLE)
         this.startStatus = true;
 
@@ -61,9 +61,7 @@ CityLandAction.prototype = {
             return
         }
         this.tempVectorLayer.setVisible(false)
-        for(let layer of this.obj.layerData.layer){
-            this.context.currentMap.removeLayer(layer)
-        }
+        this.obj.removeTileLayer(this.context.currentMap)
         console.log("drawMultiPolygon close")
         this.drawMultiPolygon.close()
         console.log("tempVectorLayer cleared")
@@ -144,18 +142,18 @@ CityLandAction.prototype = {
         let source = this.tempVectorLayer.getSource();
         source.addFeature(point)
     },
-    newFieldPoint(f){
-        let centerPoint = f.get("center_point")
+    newFieldPoint(data){
+        let geom = this.context.geojson.readGeometry(data["geojson"])
         let point = new ol.Feature({
-            geometry: new ol.geom.Point(centerPoint.coordinates)
+            geometry: geom
         });
-        for(let key of f.getKeys()){
-            if(key != "geometry"){
-                point.set(key,f.get(key))
+        for(let key in data){
+            if(key != "geojson"){
+                point.set(key,data[key])
             }
         }
         point.set("isPoint",1)
-        point.setId(f.get("id"))
+        point.setId(data["id"])
         return point;
     }
     ,loadTempVectorLayer(){
@@ -166,12 +164,16 @@ CityLandAction.prototype = {
             format: new ol.format.GeoJSON(),
             loader: function(extent, resolution, projection, success, failure) {
                 const proj = projection.getCode();
-                const url = baseUrl + '?service=WFS&' +
-                    'version=1.1.0&request=GetFeature&typename=wuhan:p_crop&' +
-                    'outputFormat=application/json&srsname=' + proj + '&' +
-                    'bbox=' + extent.join(',') + ',' + proj;
+                let typeNames = that.obj.getVisibleLayers()
+                console.log(typeNames)
+                let projCode = "3857"
+                if(typeNames == ""){
+                    typeNames = "p_crop"
+                    projCode = "4326"
+                }
+
                 const xhr = new XMLHttpRequest();
-                xhr.open('GET', url);
+                xhr.open('GET', "/crop/getGeoJson?tableNames="+typeNames + "&x1=" + extent[0] + "&y1=" + extent[1]+"&x2=" + extent[2] + "&y2="+extent[3]);
                 const onError = function() {
                     vectorSource.removeLoadedExtent(extent);
                     failure();
@@ -179,17 +181,17 @@ CityLandAction.prototype = {
                 xhr.onerror = onError;
                 xhr.onload = function() {
                     if (xhr.status == 200) {
-                        const features = vectorSource.getFormat().readFeatures(xhr.responseText);
-                        vectorSource.addFeatures(features);
-                        for(let feature of features){
-                            let id = feature.getId().substring(feature.getId().indexOf(".") + 1)
-                            feature.set("id",id)
-                            let area = feature.getGeometry().getArea()
-                            area = (area + area / 2) / 1000
-                            feature.set("area", area.toFixed(2));
-                            vectorSource.addFeature(that.newFieldPoint(feature))
+                        let res = JSON.parse(xhr.responseText);
+                        if(res.code == 0){
+                            let features = []
+                            let datas = res.data;
+                            for(let data of datas){
+                                let feature = that.newFieldPoint(data,projCode)
+                                vectorSource.addFeature(feature)
+                                features.push(feature)
+                            }
+                            success(features);
                         }
-                        success(features);
                     } else {
                         onError();
                     }
@@ -285,12 +287,36 @@ function CityLand(opt){
 }
 
 CityLand.prototype = {
+    visibleLayers:[],
+    getVisibleLayers(){
+        let names = "";
+        let i = 0;
+        for(let layerName of this.visibleLayers){
+            if(i > 0){
+                names += ","
+            }
+            names += layerName
+            i++;
+        }
+        return names;
+    },
     layerNames:['wuhan:p_land_banan','wuhan:p_land_beibei','wuhan:p_land_bishan','wuhan:p_land_changshou','wuhan:p_land_chengkou','wuhan:p_land_dadukou','wuhan:p_land_dazu','wuhan:p_land_dianjiang','wuhan:p_land_fengdu','wuhan:p_land_fengjie','wuhan:p_land_fuling','wuhan:p_land_hechuan','wuhan:p_land_jiangbei','wuhan:p_land_jiangjin','wuhan:p_land_jiulongpo','wuhan:p_land_kaizhou','wuhan:p_land_liangping','wuhan:p_land_nanan','wuhan:p_land_nanchuan','wuhan:p_land_pengshui','wuhan:p_land_qianjiang','wuhan:p_land_qijiang','wuhan:p_land_qiuyang','wuhan:p_land_rongchang','wuhan:p_land_shapingba','wuhan:p_land_shizhu','wuhan:p_land_tongliang','wuhan:p_land_tongnan','wuhan:p_land_wanzhou','wuhan:p_land_wulong','wuhan:p_land_wushan','wuhan:p_land_wuxi','wuhan:p_land_xiushan','wuhan:p_land_yongchuan','wuhan:p_land_yubei','wuhan:p_land_yunyang','wuhan:p_land_yuzhong','wuhan:p_land_zhong','wuhan:p_crop'],
-    getTileLayer(){
+    createTileLayer(){
         for(let layer of this.layerNames){
             this.getWMTS(layer)
         }
-    },getWMS(){
+    },
+    addTileLayer(map){
+        for(let layer of this.layerData.layer){
+            map.addLayer(layer)
+        }
+    },
+    removeTileLayer(map){
+        for(let layer of this.layerData.layer){
+            map.removeLayer(layer)
+        }
+    }
+    ,getWMS(){
         this.layerData.source = new ol.source.ImageWMS({
             ratio: 1,
             url: 'http://change.zylfsm.com/geoserver/wuhan/wms',
@@ -334,20 +360,26 @@ CityLand.prototype = {
             wrapX: true
         })
         this.layerData.source.push(source);
-
-        this.layerData.layer.push(new ol.layer.Tile({
+        let tile = new ol.layer.Tile({
             source: source,
             zIndex: 2,
             minZoom: 7,
-            maxZoom: 30
-        }));
+            maxZoom: 30,
+            visible: false,
+            properties:{"name":typeName.substring(typeName.indexOf(":") + 1)}
+        })
+        this.layerData.layer.push(tile);
+        return tile;
     },
-    loadWMTS(tableNames){
-        for(let layer of this.obj.layerData.layer){
-            for(let tableName of tableNames){
-                asd12312" "
+    visibleWMTS(tableNames){
+        console.log(tableNames)
+        this.visibleLayers = tableNames
+        for(let layer of this.layerData.layer){
+            if(tableNames.includes(layer.get("name"))){
+                layer.setVisible(true)
+            }else{
+                layer.setVisible(false)
             }
-            this.context.currentMap.addLayer(layer)
         }
     }
 }

+ 17 - 25
src/main/webapp/static/package/geo_server_context.js

@@ -8,6 +8,7 @@ function GeoServerContext(opt,geoserver_path){
     this.currentView = opt.currentView || window.view
     this.projection = opt.projection || window.projection
     this.wkt = new ol.format.WKT()
+    this.geojson = new ol.format.GeoJSON()
     let that = this
     this.currentMap.on("click", function(event){
         for(let id in that.clicks){
@@ -19,24 +20,7 @@ function GeoServerContext(opt,geoserver_path){
     })
 
     this.currentMap.on("moveend", function(){
-        let bbox = that.currentView.calculateExtent(that.currentMap.getSize());
-        $.ajax({
-            type : 'POST',
-            url : "/range_index/getTableNames",
-            data : {x1:bbox[0],y1:bbox[1],x2:bbox[2],y2:bbox[3]},
-            dataType : 'json',
-            success : function(res){
-                for(let action of that.actions){
-                    if(action && action.loadWMTS){
-                        let tableNames = res.data;
-                        if(tableNames.length == 0){
-                            tableNames.push("wuhan:p_crop");
-                        }
-                        action.action.loadWMTS(tableNames)
-                    }
-                }
-            }
-        });
+        that.landFilter()
     })
 
 
@@ -126,17 +110,25 @@ GeoServerContext.prototype = {
             }
         });
     },
-    getLoadTypeNames(bbox, callback){
+    landFilter(){
+        let that = this
+        let bbox = that.currentView.calculateExtent(that.currentMap.getSize());
         $.ajax({
             type : 'POST',
-            url : "/crop/getBuffer",
-            data : { x : coordinate[0], y : coordinate[1], m:m},
+            url : "/range_index/getTableNames",
+            data : {x1:bbox[0],y1:bbox[1],x2:bbox[2],y2:bbox[3]},
             dataType : 'json',
             success : function(res){
-                callback(res)
-            },error: function(req){
-                if(error)
-                    error(req)
+                for(let key in that.actions){
+                    let action = that.actions[key]
+                    if(action && action.obj && action.obj.visibleWMTS){
+                        let tableNames = res.data;
+                        if(tableNames.length == 0){
+                            tableNames.push("p_crop");
+                        }
+                        action.obj.visibleWMTS(tableNames)
+                    }
+                }
             }
         });
     }

+ 3 - 1
src/test/java/com/sysu/admin/utils/shape/postgis/Main.java

@@ -9,7 +9,9 @@ public class Main {
 //            e.printStackTrace();
 //        }
 
-        PostGisUtilTest.layers();
+//        PostGisUtilTest.layers();
+//        PostGisUtilTest.updateCenterPoint();
+        PostGisUtilTest.updateSrid();
 
     }
 }

+ 12 - 0
src/test/java/com/sysu/admin/utils/shape/postgis/PostGisUtilTest.java

@@ -112,6 +112,18 @@ public class PostGisUtilTest extends BaseTest {
         }
     }
 
+    public static void updateCenterPoint(){
+        for(String tableName : getTableNames()){
+            System.out.println("update "+ tableName + " t1 set  center_point = st_centroid(geom);");
+        }
+    }
+
+    public static void updateSrid(){
+        for(String tableName : getTableNames()){
+            System.out.println("update "+ tableName + " t1 set  geom = ST_Transform(geom,'EPSG:3857',4326);");
+        }
+    }
+
     public static void insertLandRangeIndex(){
         for(String tableName : getTableNames()){
             System.out.println("insert into p_land_range_index(\"start\",\"end\",\"table_name\") ");