如何按国家/地区查询来自PostGIS的数据?

问题描述 投票:2回答:1

我已经从TM_WORLD_BORDERS_SIMPL-0.3.zip下载了一个世界地图shapefile>

世界地图表的列如下:

gid integer NOT NULL DEFAULT nextval('table_world_gid_seq'::regclass),
fips character varying(2) COLLATE pg_catalog."default",
iso2 character varying(2) COLLATE pg_catalog."default",
iso3 character varying(3) COLLATE pg_catalog."default",
un smallint,
name character varying(50) COLLATE pg_catalog."default",
area integer,
pop2005 bigint,
region smallint,
subregion smallint,
lon double precision,
lat double precision,
geom geometry(MultiPolygon,4326)

现在我想通过geom列查询我的数据,例如,查询中国的数据。

//function in controller
@GetMapping("china")
fun getInChina(): Result<List<WalkItem>> {
    val ce = countryRepo.findById(30).get()
    val wes = walkRepo.findInCountry(ce.geom!!)
    return Result.success(wes)
}
//function in repository
@Query("SELECT new tech.return0er.donkeygo.model.WalkItem(w) FROM ${WalkEntity.TABLE_NAME} w WHERE ST_Intersects(ST_PointOnSurface(:area), w.start_point) = true")
fun findInCountry(area: Geometry): List<WalkItem>

但始终返回空数据列表。我在中国地区确实有数据。

PS:通过获取地图的左上角位置和右下角位置,我还有另一个查询。

@Query("SELECT new tech.return0er.donkeygo.model.WalkItem(w, u) FROM ${WalkEntity.TABLE_NAME} w, ${UserEntity.TABLE_NAME} u WHERE INTERSECTS(w.start_point, :area) = true" +
            " AND w.visibility=${WalkEntity.VISIBLE_TO_ALL} AND w.state=${WalkEntity.STATE_VISIBLE}" +
            " AND w.uid=u.uid" +
            " ORDER BY w.start_time DESC")
fun findWithin(area: Geometry, pageable: Pageable): List<WalkItem>
@GetMapping("within")
fun findWithin(@RequestParam("lat_north") latNorth: Double,
               @RequestParam("lon_west") lonWest: Double,
               @RequestParam("lat_south") latSouth: Double,
               @RequestParam("lon_east") lonEast: Double,
               page: Int, size: Int): Result<List<WalkItem>> {
    val rectangle = GeometryFactory().createPolygon(arrayOf(
            Coordinate(latNorth, lonWest),
            Coordinate(latNorth, lonEast),
            Coordinate(latSouth, lonEast),
            Coordinate(latSouth, lonWest),
            Coordinate(latNorth, lonWest)
    ))
    val wes = walkRepo.findWithin(rectangle, PageRequest.of(page, size))
    return Result.success(wes)
}

此作品找到。我试图将中国的gemo传递给findWithin的area参数,但也没有进行查询。

我的一些数据:

{
    "altitude": 1391.2064208984375,
    "latitude": 39.99987095,
    "longitude": 115.43765119
}
{
    "altitude": 45.00225830078125,
    "latitude": 40.00929495,
    "longitude": 116.38653411
}
{
    "altitude": 1075.603759765625,
    "latitude": 39.86346926,
    "longitude": 115.59797164
}

这些是我想在中国查询的一些要点。

屏幕快照图片显示了我通过地图的角位置查询出的数据。Query by map's corner positions

我已经从TM_WORLD_BORDERS_SIMPL-0.3.zip下载了世界地图图形文件。世界地图表的列如下:gid整数NOT NULL默认DEFAULT nextval('table_world_gid_seq':: regclass),fips ...

sql postgresql spring-boot postgis shapefile
1个回答
3
投票
我相信您要查询的是latitude longitude而不是longitude latitude-后一种组合是所有SRS中最常见的组合。您的坐标看起来很好,并且确实与数据集中的中国多边形重叠。

查询-导入shapefile和您提供的坐标

© www.soinside.com 2019 - 2024. All rights reserved.