SELECT t1.*, T3.province_code, t3.province_name, st_asgeojson(t3.geom) geomJson,
st_x(t2.geom) lon, st_y(t2.geom) lat
FROM biz_urban_road_mileage_info t1,
biz_geographic_name t2,
biz_city t3
WHERE t1.parent_code ='430000'AND t1.city_code = t3.city_code
AND T1.city_name = t2.NAME
AND st_contains(t3.geom, t2.geom);
@TableField(exist = false, value = "province_code")
private
@TableField(exist = false, value = "province_name")
private
@TableField(exist = false)
private
private
private
2. Mapper 空间检索查询
在 Mapper 接口中直接定义 SQL 片段,支持按省份代码聚合统计各地市路网长度:
package com.yelang.project.extend.earthquake.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yelang.project.extend.earthquake.domain.UrbanRoadMileageInfo;
import com.yelang.project.extend.earthquake.domain.UrbanRoadMileageInfoVO;
publicinterfaceUrbanRoadMileageInfoMapperextendsBaseMapper<UrbanRoadMileageInfo> {
/**
* 查询省级以下地市路网长度 SQL
*/staticfinalStringLIST_BYPROVINCE_SQL="SELECT t1.city_code, MAX(t1.city_name) AS city_name," +
" SUM(CASE WHEN r.fclass IN ('motorway', 'motorway_link') THEN ST_Length(r.geom::geography) ELSE 0 END) AS highway_length, " +
" SUM(CASE WHEN r.fclass IN ('trunk', 'trunk_link') THEN ST_Length(r.geom::geography) ELSE 0 END) AS trunk_length, " +
" SUM(CASE WHEN r.fclass IN ('primary', 'primary_link') THEN ST_Length(r.geom::geography) ELSE 0 END) AS primary_length, " +
" SUM(CASE WHEN r.fclass IN ('secondary', 'secondary_link') THEN ST_Length(r.geom::geography) ELSE 0 END) AS secondary_length," +
" SUM(CASE WHEN r.fclass IN ('tertiary', 'tertiary_link') THEN ST_Length(r.geom::geography) ELSE 0 END) AS tertiary_length, " +
" SUM(CASE WHEN r.fclass IN ('residential', 'living_street') THEN ST_Length(r.geom::geography) ELSE 0 END) AS residential_length, " +
" SUM(CASE WHEN r.fclass IN ('service', 'unclassified') THEN ST_Length(r.geom::geography) ELSE 0 END) AS service_length, " +
" SUM(CASE WHEN r.fclass IN ('footway', 'pedestrian', 'path') THEN ST_Length(r.geom::geography) ELSE 0 END) AS pedestrian_length, " +
" SUM(CASE WHEN r.fclass = 'cycleway' THEN ST_Length(r.geom::geography) ELSE 0 END) AS cycleway_length, " +
" SUM(CASE WHEN r.fclass = 'track' THEN ST_Length(r.geom::geography) ELSE 0 END) AS track_length," +
" SUM(CASE WHEN r.fclass in ('steps', 'footway') THEN ST_Length(r.geom::geography) ELSE 0 END) AS steps_length," +
" SUM(ST_Length(r.geom::geography)) AS total_length " +
" FROM biz_road_network r JOIN biz_city t1 ON ST_Contains(t1.geom, r.geom) WHERE t1.province_code = #{province_code} " +
" GROUP BY t1.city_code ORDER BY total_length DESC ";
@Select(LIST_BYPROVINCE_SQL)
List<UrbanRoadMileageInfo> getListByProvinceCode(@Param("province_code") String provinceCode);
finalstaticStringGET_ROADMILEAGELIST_BY_PROVINCECODE="<script>" +
" SELECT t1.*,T3.province_code,t3.province_name,st_asgeojson(t3.geom) geomJson, " +
" st_x(t2.geom) lon,st_y(t2.geom) lat " +
" FROM biz_urban_road_mileage_info t1,biz_geographic_name t2,biz_city t3 " +
" WHERE t1.parent_code = #{provinceCode} AND t1.city_code = t3.city_code " +
" AND T1.city_name = t2.NAME AND st_contains(t3.geom, t2.geom) " +
"</script>";
@Select(GET_ROADMILEAGELIST_BY_PROVINCECODE)
List<UrbanRoadMileageInfoVO> getRoadMileageList(@Param("provinceCode") String provinceCode);
}