32.基于java+postgis的wms服务

本文介绍了如何在SpringBoot应用中,通过SQL查询处理GeoJSON数据并将其转换为地图图像,包括点、线、多边形的绘制以及文本标注。使用了WMS服务接口和ImageUtil类进行图形处理和输出PNG格式的图像。

sql查询

参数
textfiled,属性字段
layername,表名
geo,wkt格式范围

     <select id="selectGeoList" parameterType="java.lang.String" resultType="java.lang.String">
    	select 
    	  <choose>
            <when test = "textfiled!=null and textfiled!=''">
              concat(st_astext(geom),' ',${textfiled})
            </when>
            <otherwise>
                 st_astext(geom)
            </otherwise>
        </choose>
         from ${layername}
    	  where geom is not null and st_intersects(ST_GeomFromText('${geo}',4326), geom)
    </select>

数据写入地图


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hx.service.CommonService;
import com.hx.util.image.ImageUtil;

import java.awt.Graphics2D;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;

import java.util.List;


import javax.annotation.Resource;
import javax.imageio.ImageIO;

import javax.servlet.http.HttpServletResponse;

/**
 * @author jdy
 *
 * @date 2023-02-16
 */
@RequestMapping("wms")
@RestController()
public class WmsController {
   
   
	
	@Autowired
    private CommonService commonService;
	  
	 @RequestMapping(value = "/wmslayer", method = RequestMethod.GET)
	 public void getLayer(@RequestParam(value = "LAYER") String LAYER,
			 @RequestParam(value = "WIDTH")Integer WIDTH,
			 @RequestParam(value = "HEIGHT")Integer HEIGHT,
			 @RequestParam(value = "BBOX")String BBOX,
			 @RequestParam(value = "type")String type,
			 @RequestParam(value = "textfiled")String textfiled,HttpServletResponse response ) {
   
   


	     BufferedImage image = new BufferedImage(WIDTH, HEIGHT,BufferedImage.TYPE_INT_RGB);  
	         Graphics2D g2d = image.createGraphics();  
	         image = g2d.getDeviceConfiguration().createCompatibleImage(WIDTH, HEIGHT,  
	            Transparency.TRANSLUCENT);  
	         g2d.dispose();  
	         g2d = image.createGraphics();  
	      
	         
	        	 String layername=LAYER;
	        	 String type= type;
	        	 List<String>  geoData =null;
	        	 if(type.equals("text")) {
   
   
	        		 geoData =  commonService.selectGeoList(layername,textfiled,BBOX);
	        	 }else {
   
   
	        		 geoData =  commonService.selectGeoList(layername,null,BBOX);
	        	 }
	        	 
		         if(type.equals("point")) {
   
   
		             String fileurl= "D:\\a.png";
			         ImageUtil.drawPointByImage(g2d,fileurl,geoData, WIDTH, HEIGHT,BBOX);
		         }else if(type.equals(
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

紫雪giser

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值