Commit efc17c39 authored by 周健威's avatar 周健威

修改代码

parent b2aa04ee
......@@ -29,6 +29,10 @@
<snapshots><enabled>true</enabled></snapshots>
<releases><enabled>false</enabled></releases>
</repository>
<repository>
<id>GeoSolutions</id>
<url>https://maven.geo-solutions.it</url>
</repository>
</repositories>
<properties>
......@@ -36,6 +40,20 @@
</properties>
<dependencies>
<dependency>
<groupId>it.geosolutions</groupId>
<artifactId>geoserver-manager</artifactId>
<version>1.7.0</version>
</dependency>
<!--style 生成-->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.19</version>
</dependency>
<dependency>
<groupId>com.github.wxiaoqi</groupId>
<artifactId>ace-admin-api</artifactId>
......
package com.upyuns.platform.rs.datacenter.rest;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.github.pagehelper.PageInfo;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
......@@ -11,11 +15,10 @@ import com.upyuns.platform.rs.datacenter.entity.RscpImageDataNewest;
import com.upyuns.platform.rs.datacenter.entity.RscpMonitorimage;
import com.upyuns.platform.rs.datacenter.entity.RscpMosaicimage;
import com.upyuns.platform.rs.datacenter.pojo.RscpImageDataNewestDTO;
import com.upyuns.platform.rs.datacenter.utils.GeoServerUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import tk.mybatis.mapper.entity.Example;
import java.util.List;
......@@ -24,6 +27,46 @@ import java.util.List;
@RequestMapping("/web/rscpMonitorimage")
public class RscpMonitorimageController extends BaseController<RscpMonitorimageBiz, RscpMonitorimage> {
@RequestMapping(value = "/app/unauth/publishMap",method={RequestMethod.POST})
@ResponseBody
public ObjectRestResponse<String> publishMap(@RequestBody PublishMapDTO dto){
if(StrUtil.isBlank(dto.getWorkSpace())) {
dto.setWorkSpace("gdxm");
}
// ResultBean<String> resultBean = new ResultBean<String>();
dto.setStyle("raster");
GeoServerUtil.publishGeoTIFF(dto.getWorkSpace(), dto.getLayerName(), dto.getFilePath(), dto.getLayerName(), dto.getStyle());
// HttpClientUtils httpClientApi = new HttpClientUtils("https://zzrsmgmt.upyuns.com/api/website/lmyxmonitorimage/web/app/unauth/baseAdd");
// httpClientApi.execute()
RscpMonitorimage rscpMonitorimage = new RscpMonitorimage();
rscpMonitorimage.setStatus(2);
// rscpMonitorimage.setType(dto.getType());
if(dto.getType() == 2213) {
rscpMonitorimage.setLegendurl("https://hstandfarm.upyuns.com/legend/植被覆盖度图例.png");
}
if(dto.getType() == 2216) {
rscpMonitorimage.setLegendurl("https://hstandfarm.upyuns.com/legend/火灾风险等级图例.png");
}
rscpMonitorimage.setUrl("https://hstandfarm.upyuns.com/geoserver/"+dto.getWorkSpace()+"/wms");
rscpMonitorimage.setTitle(dto.getTitle());
rscpMonitorimage.setResourcename(dto.getLayerName());
rscpMonitorimage.setStartTime(DateUtil.offsetDay(DateUtil.date(), -1));
rscpMonitorimage.setEndTime(DateUtil.date());
baseBiz.insertSelective(rscpMonitorimage);
return ObjectRestResponse.succ();
}
@Data
public static class PublishMapDTO {
String workSpace;
String title;
String filePath;
String layerName;
String style;
Integer type;
}
@ApiModelProperty("检测图斑最新时间分页")
@IgnoreUserToken
@RequestMapping(value = "/app/unauth/mapAll",method = RequestMethod.GET)
......
package com.upyuns.platform.rs.datacenter.utils;
import it.geosolutions.geoserver.rest.GeoServerRESTManager;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
public class GeoServerUtil {
/**
* geoServer配置
*/
private static String url = "http://10.5.52.4:18080/geoserver";
private static String geoUsername = "admin";
private static String geoPassword = "upyuns";
public static GeoServerRESTManager getManager() throws MalformedURLException {
URL u = new URL(url);
//获取管理对象
GeoServerRESTManager geoServerRESTManager = new GeoServerRESTManager(u, geoUsername, geoPassword);
return geoServerRESTManager;
}
/**
* 判断工作区(workspace)是否存在,不存在则创建
*/
public static boolean judgeWorkSpace(String workspace) throws MalformedURLException {
boolean flag = false;
GeoServerRESTManager manager = getManager();
GeoServerRESTPublisher publisher = manager.getPublisher();
List<String> workspaces = manager.getReader().getWorkspaceNames();
if (!workspaces.contains(workspace)) {
boolean createWorkspace = publisher.createWorkspace(workspace);
flag = true;
System.out.println("create workspace : " + createWorkspace);
} else {
flag = false;
System.out.println("workspace已经存在了,workspace :" + workspace);
}
return flag;
}
/**
* 当发布图层时会自动创建数据储存,于是我把创建数据储存的方法删除了
*
* @param store 存储名
* @param workSpace 工作空间名
* @param filePath 要发布的图层的硬盘的目录地址
* @param layerName 要发布的图层的名字
* @param style 发布图层使用的样式,因为我的几个样式已经提前传到工作空间了,所以就没有用代码
* @return boolean
*/
public static boolean shpJudgeDatabase(String workSpace, String store, String filePath, String layerName, String style) {
GeoServerRESTManager manager = null;
RESTCoverageStore restStore = null;
try {
manager = getManager();
GeoServerRESTPublisher publisher = manager.getPublisher();
//
boolean publish = publisher.publishGeoTIFF(workSpace, store, layerName, new File(filePath), "EPSG:4326",
GSResourceEncoder.ProjectionPolicy.FORCE_DECLARED, style, null);
System.out.println("publish (TIFF文件发布状态) : " + publish);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* 当发布图层时会自动创建数据储存,于是我把创建数据储存的方法删除了
*
* @param store 存储名
* @param workSpace 工作空间名
* @param filePath 要发布的图层的硬盘的目录地址
* @param layerName 要发布的图层的名字
* @param style 发布图层使用的样式,因为我的几个样式已经提前传到工作空间了,所以就没有用代码
* @return boolean
*/
public static boolean publishGeoTIFF(String workSpace, String store, String filePath, String layerName, String style) {
GeoServerRESTManager manager = null;
// RESTCoverageStore restStore = null;
try {
// URL urlShapefilePath = new URL("file://"+ filePath);
manager = getManager();
GeoServerRESTPublisher publisher = manager.getPublisher();
// boolean result = false;
// GSGeoTIFFDatastoreEncoder storeEncoder = new GSGeoTIFFDatastoreEncoder(store, urlShapefilePath);
// result = manager.getStoreManager().create(workSpace, storeEncoder);
// if(result) {
boolean publish = publisher.publishGeoTIFF(workSpace, store, layerName, new File(filePath), "EPSG:4326",
GSResourceEncoder.ProjectionPolicy.FORCE_DECLARED, style, null);
System.out.println("publish (TIFF文件发布状态) : " + publish);
// }
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static void main(String[] args) throws MalformedURLException, FileNotFoundException, URISyntaxException {
GeoServerRESTManager manager = GeoServerUtil.getManager();
Boolean flag = manager.getReader().existsDatastore("test", "mt-VC-202312-yangxi-a-2public");
Boolean flag2 = manager.getReader().existsCoveragestore("test", "mt-VC-202312-yangxi-a-2public");
Boolean flag3 = manager.getReader().existsDatastore("rsinsure2", "mt-rsinsure2farmblock-2024-231224206201-a-0public");
GeoServerRESTPublisher publisher = manager.getPublisher();
// try {
// // 数据存储需要的文件
//// String shpFilePath = String.format("file://%s", "/sdbdata/geoserver/data_insure2/block/230781/mt-farmblock-2023-230781202-a-0public/mt-farmblock-2023-230781202-a-0public.shp");
// String shpFilePath = String.format("file://%s", "/sdbdata/geoserver/data_insure2/block/230781/mt-farmblock-2023-230781202-a-0public/mt-farmblock-2023-230781202-a-0public.shp");
// URL urlShapeFile = new URL(shpFilePath);
// // 创建数据集
// GSShapefileDatastoreEncoder datastoreEncoder = new GSShapefileDatastoreEncoder("mt-rsinsure3farmblock6", urlShapeFile);
// datastoreEncoder.setCharset(Charset.forName("UTF-8"));
// datastoreEncoder.setType("shapefile");
// datastoreEncoder.setE
// manager.getStoreManager().create("rsinsure3", datastoreEncoder);
// } catch (MalformedURLException e) {
// e.printStackTrace();
// }
///Users/zhoujianwei/Downloads/农险平安202410/mt-rsinsure3farmblock/mt-rsinsure3farmblock.shp
// boolean publish = publisher.publishShp("rsinsure3", "mt-rsinsure3farmblock", (NameValuePair[])null, "mt-rsinsure3farmblock", GeoServerRESTPublisher.UploadMethod.EXTERNAL, new URI("file:///sdbdata/geoserver/data_insure3/mt-rsinsure3farmblock/mt-rsinsure3farmblock.shp"), "EPSG:4326",(String)null,
// GSResourceEncoder.ProjectionPolicy.FORCE_DECLARED, "polygon");
// try {
// // 数据存储需要的文件
// String shpFilePath = String.format("file://%s", "/sdbdata/geoserver/data_insure3/mt-rsinsure3farmblock/mt-rsinsure3farmblock.shp");
// URL urlShapeFile = new URL(shpFilePath);
// // 创建数据集
// GSShapefileDatastoreEncoder datastoreEncoder = new GSShapefileDatastoreEncoder("mt-rsinsure3farmblock2", urlShapeFile);
// datastoreEncoder.setCharset(Charset.forName("UTF-8"));
// manager.getStoreManager().create("rsinsure3", datastoreEncoder);
// } catch (MalformedURLException e) {
// e.printStackTrace();
// }
// if (!restReader.existsLayer(workSpace, layerName)) {
// try {
// GSFeatureTypeEncoder gsFeatureTypeEncoder = new GSFeatureTypeEncoder();
// gsFeatureTypeEncoder.setTitle("mt-rsinsure3farmblock2");
// gsFeatureTypeEncoder.setName("mt-rsinsure3farmblock2");
// gsFeatureTypeEncoder.setSRS(GeoServerRESTPublisher.DEFAULT_CRS);
//
// GSLayerEncoder gsLayerEncoder = new GSLayerEncoder();
// gsLayerEncoder.addStyle("polygon");
//
// boolean layer = publisher.publishDBLayer("rsinsure3", "mt-rsinsure3farmblock2", gsFeatureTypeEncoder, gsLayerEncoder);
// System.out.println("publish layer : " + layer);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// GSFeatureTypeEncoder featureTypeEncoder = new GSFeatureTypeEncoder();
// featureTypeEncoder.setName("mt-rsinsure3farmblock2");
// featureTypeEncoder.setTitle("mt-rsinsure3farmblock2");
// featureTypeEncoder.setSRS(GeoServerRESTPublisher.DEFAULT_CRS);
//
// featureTypeEncoder.setProjectionPolicy(GSResourceEncoder.ProjectionPolicy.FORCE_DECLARED);
// if (!publisher.createResource("rsinsure3", GeoServerRESTPublisher.StoreType.DATASTORES, "mt-rsinsure3farmblock2", featureTypeEncoder)) {
//
// } else {
// GSLayerEncoder layerEncoder = publisher.configureDefaultStyle("polygon");
// publisher.configureLayer("rsinsure3", "mt-rsinsure3farmblock2", layerEncoder);
// }
// }
// String layerName = "mt-rsinsure3farmblock2";
// if (!manager.getReader().existsLayer("rsinsure3", layerName)) {
// try {
// GSFeatureTypeEncoder gsFeatureTypeEncoder = new GSFeatureTypeEncoder();
// gsFeatureTypeEncoder.setTitle(layerName);
// gsFeatureTypeEncoder.setName(layerName);
// gsFeatureTypeEncoder.setSRS(GeoServerRESTPublisher.DEFAULT_CRS);
//
// GSLayerEncoder gsLayerEncoder = new GSLayerEncoder();
// gsLayerEncoder.addStyle("polygon");
//
//// boolean layer = publisher.configureLayer("rsinsure3", "mt-rsinsure3farmblock3", gsLayerEncoder);
// boolean layer = publisher.publishDBLayer("rsinsure3", "mt-rsinsure3farmblock2", gsFeatureTypeEncoder, gsLayerEncoder);
// System.out.println("publish layer : " + layer);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// GSFeatureTypeEncoder featureTypeEncoder = new GSFeatureTypeEncoder();
// featureTypeEncoder.setName("mt-rsinsure3farmblock2");
// featureTypeEncoder.setTitle("mt-rsinsure3farmblock2");
// featureTypeEncoder.setSRS(GeoServerRESTPublisher.DEFAULT_CRS);
// featureTypeEncoder.setNativeCRS(GeoServerRESTPublisher.DEFAULT_CRS);
//
// featureTypeEncoder.setProjectionPolicy(GSResourceEncoder.ProjectionPolicy.FORCE_DECLARED);
// if (!publisher.createResource("rsinsure3", GeoServerRESTPublisher.StoreType.DATASTORES, "mt-rsinsure3farmblock2", featureTypeEncoder)) {
//
// } else {
// GSLayerEncoder layerEncoder = publisher.configureDefaultStyle("polygon");
// publisher.configureLayer("rsinsure3", "mt-rsinsure3farmblock2", layerEncoder);
// }
//publishShp(String workspace, String storename, String layername, File zipFile, String srs)
//
// boolean publish = publisher.publishShp("rsinsure3", "mt-rsinsure3farmblock", "mt-rsinsure3farmblock", new File("/Users/zhoujianwei/Downloads/农险平安202410/mt-rsinsure3farmblock.zip"), GeoServerRESTPublisher.DEFAULT_CRS);
// .publishShp("rsinsure3", "mt-rsinsure3farmblock", (NameValuePair[])null, "mt-rsinsure3farmblock", GeoServerRESTPublisher.UploadMethod.FILE, new File("/sdbdata/geoserver/data_insure3/block/mt-rsinsure3farmblock.zip"), "EPSG:4326",(String)null,
// GSResourceEncoder.ProjectionPolicy.FORCE_DECLARED, "polygon");
//
// File file = new File("/Users/zhoujianwei/Downloads/农险平安202410/mt-rsinsure3farmblock.zip");
////File file = new File("/Users/zhoujianwei/Downloads/农险平安202410/mt-rsinsure3farmblock/mt-rsinsure3farmblock.shp");
// flag = publisher.publishShp("rsinsure3", "mt-rsinsure3farmblock",
// new NameValuePair[]{new NameValuePair("charset", "UTF-8")},
// "mt-rsinsure3farmblock",
// GeoServerRESTPublisher.UploadMethod.FILE,
// file.toURI(),
// GeoServerRESTPublisher.DEFAULT_CRS,
// "polygon");
System.out.println(flag);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment