2009-09-24 51 views
1

這是我發送到PostGIS的郵件列表繪製在PostGIS的線路使用近鄰法

到目前爲止,在我的努力創造一個點,其預期 位置之間的線電子郵件中的交叉傳遞在一條線上已經很長,但我幾乎在那裏。截至昨日,以及 包括任何近鄰分析之前,我得到了 顯示此圖像的結果:

QGis screenshot

正如你所看到的,在粉紅色的每個點連接到所有的投影點,而,我只想將每個粉紅色x連接到它的相應投影。

在IRC上,建議使用BostonGIS's nearest neighbor method。我向PostgreSQL輸入函數並嘗試失敗,如下所述。我假設我的錯誤是由於錯誤的參數類型。我玩過這個,把一些列的類型改成了varchar,但是我仍然無法使它工作。

任何想法我做錯了什麼?有關如何解決它的任何建議?

代碼:

-- this sql script creates a line table that connects points 

-- convert multi lines into lines 

CREATE TABLE exploded_roads AS 
SELECT the_geom 
FROM (
    SELECT ST_GeometryN(
    the_geom, 
    generate_series(1, ST_NumGeometries(the_geom))) 
    AS the_geom 
    FROM "StreetCenterLines" 
) 
AS foo; 


-- Create line table that'll connect the centroids to the projected points on exploded lines 
CREATE TABLE lines_from_centroids_to_roads (
    the_geom geometry, 
    edge_id SERIAL 
); 

-- Populate Table 
INSERT INTO lines_from_centroids_to_roads (the_geom) 
SELECT 
    ST_MakeLine(
     centroids.the_geom, 
     (pgis_fn_nn(centroids.the_geom, 1000000, 1,1000, 'exploded_roads' ,'true', 'gid', 
      ST_Line_Interpolate_Point(
       exploded_roads.the_geom, 
       ST_Line_Locate_Point(
        exploded_roads.the_geom, 
        centroids.the_geom 
       ) 
      ) 
     )).* 
    ) 
FROM exploded_roads, fred_city_o6_da_centroids centroids; 

DROP TABLE exploded_roads; 

錯誤

NOTICE: CREATE TABLE will create implicit sequence "lines_from_centroids_to_roads_edge_id_seq" for serial column "lines_from_centroids_to_roads.edge_id" 

ERROR: function pgis_fn_nn(geometry, integer, integer, integer, unknown, unknown, unknown, geometry) does not exist 
LINE 28: (pgis_fn_nn(centroids.the_geom, 1000000, 1,1000, 'exploded... 
      ^
HINT: No function matches the given name and argument types. You might need to add explicit type casts. 


********** Error ********** 

ERROR: function pgis_fn_nn(geometry, integer, integer, integer, unknown, unknown, unknown, geometry) does not exist 
SQL state: 42883 
Hint: No function matches the given name and argument types. You might need to add explicit type casts. 
Character: 584 

回答

1

事實證明,我不需要使用最近的鄰居。我分配了一個與我連接線的質心相同的ID

-- this sql script creates a line table that connects points 

-- delete existing tables if they exist 
DROP TABLE exploded_roads; 
DROP TABLE projected_points; 
DROP TABLE lines_from_centroids_to_roads; 


-- convert multi lines into lines 
CREATE TABLE exploded_roads (
    the_geom geometry, 
    edge_id  serial 
); 

-- insert the linestring that don't need to be converted 
INSERT INTO exploded_roads 
SELECT the_geom 
FROM "StreetCenterLines" 
WHERE st_geometrytype(the_geom) = 'ST_LineString'; 


INSERT INTO exploded_roads 
SELECT the_geom 
FROM (
    SELECT ST_GeometryN(
    the_geom, 
    generate_series(1, ST_NumGeometries(the_geom))) 
    AS the_geom 
    FROM "StreetCenterLines" 
) 
AS foo; 





-- create projected points table with ids matching centroid table 
CREATE TABLE projected_points (
    the_geom geometry, 
    pid  serial, 
    dauid  int 
); 


-- Populate Table 
INSERT INTO projected_points(the_geom, dauid) 
SELECT DISTINCT ON ("DAUID") 
    ( 
     ST_Line_Interpolate_Point(
      exploded_roads.the_geom, 
      ST_Line_Locate_Point(
       exploded_roads.the_geom, 
       centroids.the_geom 
      ) 
     ) 
    ), 
    (centroids."DAUID"::int) 

FROM exploded_roads, fred_city_o6_da_centroids centroids; 


-- Create Line tables 
CREATE TABLE lines_from_centroids_to_roads (
    the_geom geometry, 
    edge_id SERIAL 
); 


-- Populate Line Table 
INSERT INTO lines_from_centroids_to_roads(
SELECT 
    ST_MakeLine(centroids.the_geom, projected_points.the_geom) 
FROM projected_points, fred_city_o6_da_centroids centroids 
WHERE projected_points.dauid = centroids."DAUID"::int 
); 

-- Delete temp tables 
--DROP TABLE exploded_roads; 
--DROP TABLE projected_points; 
+0

你爲什麼要使用'ST_Line_Interpolate_Point'? 'ST_Line_Locate_Point'應該清楚點上的位置嗎? – Stophface 2016-12-02 16:52:27

1

的一個問題是,我認爲功能預計second argument (distguess) to be a double precision而不是整數。嘗試1000000.0或嘗試強制浮動...

+0

我試過了兩個,但沒有解決它,但在通知上的讚譽。 – dassouki 2009-09-24 20:35:31

+0

一個猜測,但我會嘗試寫'exploded_roads','true','gid' - part'as''exploded_roads'','''''',''gid''或者「exploded_roads」,「true」 ,「gid」...你是否在使用像pgadmin這樣的工具來運行這個查詢? – ChristopheD 2009-09-24 20:52:25

+0

我正在使用PgAdmin來運行查詢。 「真」會返回錯誤: 錯誤:語法錯誤處於或接近「真」 線28:... the_geom,1000000.0,110000,「exploded_roads」,「true」,「g。 .. – dassouki 2009-09-24 23:02:18