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(

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





