使用Postgis使用SQL查询在Postgres中使用OSM给出(lat,long)时检索最近的道路

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

给定一个(lat,long)我试图使用“max_speed”和使用“highway”的街道类型找到最大速度。

我已经加载了我的数据库(Postgres和Postgis),如下所示:

$ osm2pgsql -c -d gis --slim -C 50000  /var/lib/postgresql/data/germany-latest.osm.pbf

我能找到的最相关的问题是How to query all shops around a certain longitude/latitude using osm-postgis?。我已经接受了查询,并插入了我在慕尼黑市中心的谷歌地图中找到的(lat,long)(因为帖子也与慕尼黑市中心有关,我有德国地图)。结果变空了。

gis=# SELECT name, shop FROM planet_osm_point WHERE ST_DWithin(way ,ST_SetSrid(ST_Point(48.137969, 11.573829), 900913), 100);
 name | shop 
------+------
(0 rows)

另外,当查看直接包含(lat,long)对的planet_osm_nodes时,我最终没有结果:

gis=# SELECT * FROM planet_osm_nodes WHERE ((lat BETWEEN 470000000 AND 490000000) AND (lon BETWEEN 100000000 AND 120000000)) LIMIT 10;
 id | lat | lon | tags 
----+-----+-----+------
(0 rows)

我验证了数据在我的数据库中:

gis=# SELECT COUNT(*) FROM planet_osm_point;
  count  
---------
 9924531
(1 row)

gis=# SELECT COUNT(*) FROM planet_osm_nodes;
   count   
-----------
 288597897
(1 row)

理想情况下,我的问题是 问:如何给出一组(lat,lon)的“最高速度”和“高速公路” 或者,我的问题是: 问:如何从其他堆栈溢出帖子中获取查询?

我最好的猜测是我需要以某种方式转换我的(lat,lon),或者出于某种原因我只是拥有错误的数据。

编辑:按要求添加样本数据:

gis=# SELECT * FROM planet_osm_point LIMIT 1;
  osm_id   | access | addr:housename | addr:housenumber | addr:interpolation | admin_level | aerialway | aeroway | amenity | area | barrier | bicycle | brand | bridge | boundary | building | capital | construction | covered | culvert |
 cutting | denomination | disused | ele | embankment | foot | generator:source | harbour | highway  | historic | horse | intermittent | junction | landuse | layer | leisure | lock | man_made | military | motorcar | name | natural | off
ice | oneway | operator | place | poi | population | power | power_source | public_transport | railway | ref | religion | route | service | shop | sport | surface | toll | tourism | tower:type | tunnel | water | waterway | wetland | wi
dth | wood | z_order |                        way                         
-----------+--------+----------------+------------------+--------------------+-------------+-----------+---------+---------+------+---------+---------+-------+--------+----------+----------+---------+--------------+---------+---------+
---------+--------------+---------+-----+------------+------+------------------+---------+----------+----------+-------+--------------+----------+---------+-------+---------+------+----------+----------+----------+------+---------+----
----+--------+----------+-------+-----+------------+-------+--------------+------------------+---------+-----+----------+-------+---------+------+-------+---------+------+---------+------------+--------+-------+----------+---------+---
----+------+---------+----------------------------------------------------
 304070863 |        |                |                  |                    |             |           |         |         |      |         |         |       |        |          |          |         |              |         |         |
         |              |         |     |            |      |                  |         | crossing |          |       |              |          |         |       |         |      |          |          |          |      |         |    
    |        |          |       |     |            |       |              |                  |         |     |          |       |         |      |       |         |      |         |            |        |       |          |         |   
|      |         | 010100002031BF0D0048E17A94F19F2941CDCCCCDCC60D5741
(1 row)

gis=# SELECT * FROM planet_osm_nodes LIMIT 1;
   id   |    lat    |   lon    | tags 
--------+-----------+----------+------
 234100 | 666501948 | 80442755 | 
(1 row)

编辑2:有关于“SRID”的提及,所以我从另一个表中添加了示例数据:

gis=# SELECT * FROM spatial_ref_sys LIMIT 1;
 srid | auth_name | auth_srid |                                                                                                                                                                    srtext                                  
                                                                                                                                  |                                           proj4text                                            
------+-----------+-----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------
 3819 | EPSG      |      3819 |  GEOGCS["HD1909",DATUM["Hungarian_Datum_1909",SPHEROID["Bessel 1841",6377397.155,299.1528128,AUTHORITY["EPSG","7004"]],TOWGS84[595.48,121.69,515.35,4.115,-2.9383,0.853,-3.408],AUTHORITY["EPSG","1024"]],PR
IMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","3819"]] | +proj=longlat +ellps=bessel +towgs84=595.48,121.69,515.35,4.115,-2.9383,0.853,-3.408 +no_defs 
(1 row)
sql postgresql gps openstreetmap postgis
1个回答
1
投票

PostGIS中的几何有一个不同的排序(lat long)首先是经度然后是纬度。此外,如果要将点从一个SRID转换为另一个SRID,请使用st_transfrom(),而不是ST_SetSrid。 ST_Transform将您的数据从一个坐标系统转换为另一个坐标系统。

select st_astext(st_transform(ST_SetSrid(ST_Point(11.573829,48.137969), 4326),900913))

ST_SetSrid - 只需更改对象的SRID。

select st_astext((ST_SetSrid(ST_Point(11.573829,48.137969),900913)

所以,你必须以这种方式改变你的SQL

SELECT name, shop 
  FROM planet_osm_point
 WHERE ST_DWithin(way,st_transform(ST_SetSrid(ST_Point(11.573829,48.137969), 4326),900913), 100);
© www.soinside.com 2019 - 2024. All rights reserved.