Administrator 2 tahun lalu
induk
melakukan
908bef7576

+ 6 - 1
src/main/java/com/sysu/admin/controller/aland/Land.java

@@ -8,6 +8,7 @@ import lombok.experimental.Accessors;
 import lombok.experimental.FieldNameConstants;
 import org.hibernate.annotations.DynamicInsert;
 import org.hibernate.annotations.DynamicUpdate;
+import org.locationtech.jts.geom.Geometry;
 import org.locationtech.jts.geom.MultiPolygon;
 import org.locationtech.jts.geom.Point;
 
@@ -27,7 +28,6 @@ public class Land {
     /*
 字段信息:value——潜在产值(元)
 area_ha——地块面积(公顷)
-MAJORITY——三调地块(0其他 1水田 2水浇地 )
 crop_type——作物类别
 id_card——身份证
 name——姓名
@@ -43,6 +43,9 @@ Area——面积(平方米)
 
     public Land(){
     }
+    public Land(Geometry geometry){
+        this.geom = (MultiPolygon)geometry;
+    }
 
 
     /**
@@ -89,6 +92,8 @@ Area——面积(平方米)
     private Double value;
     @Column
     private Integer majority;
+    @Column
+    private Integer parcelType;
 
     @JSONField(serialize = false)
     @Column(columnDefinition = "geom")

+ 5 - 2
src/main/java/com/sysu/admin/controller/aland/LandAreaStat.java

@@ -9,8 +9,11 @@ public class LandAreaStat {
     private Double area;
     private String color;
 
-    static  String[] name2s = {"其他","水田","水浇地"};
-    static  String[] colors = {"#6E7F85","#0D53AF","#7B9CFB"};
+    /**
+     * 0其它 1水田  2水浇地  3旱地  4果园
+     */
+    static  String[] name2s = {"其他","水田","水浇地","旱地","果园"};
+    static  String[] colors = {"#6E7F85","#0D53AF","#7B9CFB","#D4B48F","#E99209"};
 
     public static String castName(Integer id){
         if(id != null){

+ 7 - 4
src/main/java/com/sysu/admin/controller/aland/LandRepository.java

@@ -13,11 +13,11 @@ public interface LandRepository extends JpaPlusRepository<Land, Long> {
     @Query(value = "select crop_type,sum(area) from  leizhou_land where St_within(geom,st_geomfromtext(?1,4326)) group by crop_type",nativeQuery = true)
     List<Object[]> statCropType(String wkt);
 
-    @Query(value = "select majority,sum(area) from  leizhou_land  group by majority",nativeQuery = true)
-    List<Object[]> statMajorityAll();
+    @Query(value = "select parcel_type,sum(area) from  leizhou_land  group by parcel_type",nativeQuery = true)
+    List<Object[]> statParcelTypeAll();
 
-    @Query(value = "select majority,sum(area) from  leizhou_land where St_within(geom,st_geomfromtext(?1,4326)) group by majority",nativeQuery = true)
-    List<Object[]> statMajority(String wkt);
+    @Query(value = "select parcel_type,sum(area) from  leizhou_land where St_within(geom,st_geomfromtext(?1,4326)) group by parcel_type",nativeQuery = true)
+    List<Object[]> statParcelType(String wkt);
 
     @Query(value = "select * from  leizhou_land where St_within(geom,st_geomfromtext(?1,4326)) limit ?2",nativeQuery = true)
     List<Land> findListByWkt(String wkt,Integer limit);
@@ -25,4 +25,7 @@ public interface LandRepository extends JpaPlusRepository<Land, Long> {
     @Query(value = "select * from  leizhou_land where  St_within(geom,st_geomfromtext(?1,4326)) and crop_type = ?2 limit ?3",nativeQuery = true)
     List<Land> findListByWktAndCropType(String wkt, String cropType, Integer limit);
 
+    @Query(value = "select new Land(geom) from Land")
+    List<Land> findAllGeom();
+
 }

+ 3 - 4
src/main/java/com/sysu/admin/controller/aland/LandService.java

@@ -5,7 +5,6 @@ import com.sysu.admin.controller.city.CityRepository;
 import com.sysu.admin.controller.city.DistrictRepository;
 import com.sysu.admin.controller.city.TownRepository;
 import com.sysu.admin.support.base.BaseService;
-import com.sysu.admin.support.system.user.User;
 import com.sysu.admin.utils.MySimpleDateFormat;
 import com.sysu.admin.utils.TextUtil;
 import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
@@ -38,12 +37,12 @@ public class LandService extends BaseService<Land,Long> {
         List<Object[]> res = null;
         if(townId != null) {
             String wkt = townRepository.findWktById(townId);
-            res = landRepository.statMajority(wkt);
+            res = landRepository.statParcelType(wkt);
         }else if(StringUtils.isNotBlank(district)) {
             String wkt = districtRepository.findWktByCode(district);
-            res = landRepository.statMajority(wkt);
+            res = landRepository.statParcelType(wkt);
         }else{
-            res = landRepository.statMajorityAll();
+            res = landRepository.statParcelTypeAll();
         }
         res.stream().forEach(o -> {
             Double area = (Double)o[1];

+ 8 - 8
src/main/java/com/sysu/admin/utils/shape/ShapeReader.java

@@ -103,9 +103,9 @@ public class ShapeReader {
             SimpleFeature feature = itertor.next();
 
             Map<String, Object> map = new HashMap<>();
-            addValue(map, feature, "InPoly_F_1");
+            addValue(map, feature, "InPoly_FID");
             System.out.println();
-            System.out.println(map.get("inpoly_f_1"));
+            System.out.println(map.get("inpoly_fid"));
             addValue(map, feature, "Area");
             addValue(map, feature, "SimPgnFlag");
             addValue(map, feature, "TOC");
@@ -120,12 +120,15 @@ public class ShapeReader {
             addValue(map, feature, "crop_type");
             addValue(map, feature, "area_ha");
             addValue(map, feature, "value");
+            addValue(map, feature, "intensity");
             addValue(map, feature, "MAJORITY");
             addValue(map, feature, "ParcelType");
             Geometry geometry = (Geometry)feature.getDefaultGeometry();
-//            for(Coordinate[] coordinate : geometry.getCoordinates()){
-//                GeoCastUtil.mactorToLonlat()
-//            }
+            for(Coordinate coordinate : geometry.getCoordinates()){
+                Double[] res = GeoCastUtil.mactorToLonlat(new Double[]{coordinate.getX(), coordinate.getY()});
+                coordinate.setX(res[0]);
+                coordinate.setY(res[1]);
+            }
             map.put("geom",GeoCastUtil.geomToWkt(geometry));
             list.add(map);
         }
@@ -134,9 +137,6 @@ public class ShapeReader {
 
     public static void addValue(Map<String,Object> map, SimpleFeature feature, String key){
         Object val = feature.getAttribute(key);
-        if(val == null){
-            val = feature.getProperty(key);
-        }
         map.put(key.toLowerCase(), val);
     }
 

+ 3 - 2
src/test/java/com/sysu/admin/utils/shape/postgis/PostGisUtilTest.java

@@ -151,10 +151,10 @@ public class PostGisUtilTest {
         int c = 100;
         while(i < list.size()) {
             if(i % c == 0) {
-                fileWriter.append("insert into " + typeName + "(id,area,simpgnflag,toc,quxian,shengdao,hupo,gdp_pop,slope,aspect,name,id_card,crop_type,area_ha,value,majority,parceltype,geom) values");
+                fileWriter.append("insert into leizhou_land (id,area,simpgnflag,toc,quxian,shengdao,hupo,gdp_pop,slope,aspect,name,id_card,crop_type,area_ha,value,intensity,majority,parcel_type,geom) values");
             }
             Map<String, Object> map = list.get(i);
-            fileWriter.append(" ('"+map.get("inpoly_f_1")+"',");
+            fileWriter.append(" ('"+((Double)map.get("inpoly_fid")).intValue()+"',");
             fileWriter.append("'"+map.get("area")+"',");
             fileWriter.append("'"+map.get("simpgnflag")+"',");
             fileWriter.append("'"+map.get("toc")+"',");
@@ -169,6 +169,7 @@ public class PostGisUtilTest {
             fileWriter.append("'"+map.get("crop_type")+"',");
             fileWriter.append("'"+map.get("area_ha")+"',");
             fileWriter.append("'"+map.get("value")+"',");
+            fileWriter.append("'"+((Double)map.get("intensity")).intValue()+"',");
             fileWriter.append("'"+map.get("majority")+"',");
             fileWriter.append("'"+map.get("parceltype")+"',");
             fileWriter.append("st_geomfromtext('");

+ 34 - 0
src/test/java/com/sysu/admin/utils/shape/postgis/UpdateTownId.java

@@ -0,0 +1,34 @@
+package com.sysu.admin.utils.shape.postgis;
+
+import com.sysu.admin.MarkApplication;
+import com.sysu.admin.api.base.BaseTest;
+import com.sysu.admin.controller.aland.Land;
+import com.sysu.admin.controller.aland.LandRepository;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.locationtech.jts.geom.MultiPolygon;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.List;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = MarkApplication.class)
+public class UpdateTownId extends BaseTest {
+
+    @Autowired
+    LandRepository landRepository;
+
+    @Test
+    public void updateTownIdSql(){
+        List<Land> landList = landRepository.findAllGeom();
+        landList.stream().forEach(land -> {
+            MultiPolygon multiPolygon = land.getGeom();
+
+        });
+
+
+    }
+
+}