1
我按照這個question來計算最近的道路(線串)的POI。我能夠計算線串中的最近點,但是我無法找到從POI到線串上最近點(頂點)的距離。如何計算最近點到PostGIS中的線串?
這是我尋找最近POI的代碼。
CREATE TABLE road(id serial PRIMARY KEY, the_geog geography(LINESTRING,4326));
CREATE TABLE poi(gid serial PRIMARY KEY, name varchar, city varchar, the_geog geography(POINT,4326))
值是:
INSERT INTO road (id, the_geog) VALUES (123, ST_GeographyFromText('SRID=4326;LINESTRING(85.280194 23.296728,85.281572 23.297479)'));
要計算最近點:
SELECT poi.name,poi.city,ST_AsTEXT(poi.the_geog), ST_Distance(road.the_geog, poi.the_geog)/1000.0 AS distance_km,ST_AsTEXT(road.the_geog::geometry) FROM road, poi WHERE road.id = 123 AND ST_DWithin(road.the_geog, poi.the_geog, 10000.0) ORDER BY ST_LineLocatePoint(road.the_geog::geometry, poi.the_geog::geometry), ST_Distance(road.the_geog, poi.the_geog);
如果線串是由這代表:[85.280194 23.296728,85.281572 23.297479]
,我要像結果:
poi vertex distance_km
85.280194 23.296728 85.280001 23.299876 3
85.289673 23.291987 85.281572 23.297479 5