PostGIS SQL从一组点生成单独的线段,具有不同的ID

时间:2012-04-05 15:23:52

标签: postgresql geospatial postgis

所有

我可能试图将SQL角度推得太远,但我需要从一组GPS跟踪点生成简单的两个顶点线段作为来自许多车辆(veh_id)的馈送。生成的线段也按ID分组输入。

我可以使用现有的POSTGIS工具生成多段线,甚至可以在制作多段线之后将它们分成单独的段,但是保持线段分离会让我脑子冻结。

业务需求是,我需要将时间/距离公式应用于每个细分,因为它是基于每个用于达到每个细分速度的点的计算得出的。输入是混合车辆ID的事实似乎可能是一个问题。

我知道这是某种加入方式,但我还没能让它成功。我想如果我能找到一种方法,至少将每个分段的点数配对以构建单独的线段,我可以让其余部分工作。 “cmdrecid”是时间顺序的,但对于所有车辆,每辆车基础上会有间隙

我的sql远离原始点看起来像任何人的任何想法或指针,谢谢! :

     select a.cmdrecid,
               a.esn,
               a.time_idx,
               a.the_geom,
               a.speed,
               a.veh_id
          from stmaint_plots a, (select veh_id, count(*) 
                                   from stmaint_plots 
                                  where time_idx >= (NOW() - INTERVAL '1 minutes') 
                               group by veh_id having count(*) > 1
                                 ) as b
         where a.time_idx >= (NOW() - INTERVAL '1 minutes') 
           and a.veh_id = b.veh_id
      order by b.veh_id, a.time_idx desc;

     cmdrecid |   esn    |        time_idx        |                      the_geom                      | speed | veh_id 
    ----------+----------+------------------------+----------------------------------------------------+-------+--------
       562233 | 10202001 | 2012-04-05 10:05:54-05 | 0101000020840D030031FB5FADF10221418696195E70770341 |  16.0 | 2042
       562226 | 10202001 | 2012-04-05 10:05:46-05 | 0101000020840D030031FB5FADF10221418696195E70770341 |  16.0 | 2042
       562246 | 10202010 | 2012-04-05 10:06:16-05 | 0101000020840D0300DC583A10C74921419B78BD2F3C440441 |  29.6 | 2075
       562232 | 10202010 | 2012-04-05 10:05:53-05 | 0101000020840D0300BAD35538334A2141F97506A3732D0441 |   1.0 | 2075
       562216 | 10202010 | 2012-04-05 10:05:33-05 | 0101000020840D0300BAD35538334A2141F97506A3732D0441 |   0.0 | 2075
       562239 | 11031319 | 2012-04-05 10:06:08-05 | 0101000020840D030090D4FFEB8DFD214168556D2F88770341 |   0.0 | 2202
       562227 | 11031319 | 2012-04-05 10:05:46-05 | 0101000020840D030090D4FFEB8DFD214168556D2F88770341 |   0.0 | 2202
       562245 | 10202004 | 2012-04-05 10:06:14-05 | 0101000020840D03000EE2342EC8382141C3A07B7223420241 |   3.8 | 2234
       562231 | 10202004 | 2012-04-05 10:05:53-05 | 0101000020840D0300645F4BBDF837214194A58D9944430241 |   1.5 | 2234
       562219 | 10202004 | 2012-04-05 10:05:35-05 | 0101000020840D0300645F4BBDF837214194A58D9944430241 |   0.0 | 2234
       562242 | 11030817 | 2012-04-05 10:06:10-05 | 0101000020840D0300F07C6C31085B2141DAE94B086BF20341 |   6.7 | 2350
       562213 | 11030817 | 2012-04-05 10:05:31-05 | 0101000020840D03009BF21B7B0C5C2141D4D6754598EB0341 |   0.1 | 2350
       562229 | 11072928 | 2012-04-05 10:05:51-05 | 0101000020840D0300A05299973C66214137D638BF22820441 |   0.0 | 2369
       562217 | 11072928 | 2012-04-05 10:05:34-05 | 0101000020840D0300A05299973C66214137D638BF22820441 |   0.1 | 2369
       562244 | 11072930 | 2012-04-05 10:06:12-05 | 0101000020840D0300526B108976CE2041538A57D001C40241 |   0.0 | 2372
       562234 | 11072930 | 2012-04-05 10:05:55-05 | 0101000020840D0300526B108976CE2041538A57D001C40241 |   0.1 | 2372
       562211 | 11072930 | 2012-04-05 10:05:31-05 | 0101000020840D0300526B108976CE2041538A57D001C40241 |   0.1 | 2372
       562243 | 11031308 | 2012-04-05 10:06:11-05 | 0101000020840D0300A3888CBB4D0C224131ACAA5F99860341 |   0.0 | 2482
       562230 | 11031308 | 2012-04-05 10:05:51-05 | 0101000020840D0300A3888CBB4D0C224131ACAA5F99860341 |   0.0 | 2482
       562214 | 11031308 | 2012-04-05 10:05:32-05 | 0101000020840D0300A3888CBB4D0C224131ACAA5F99860341 |   0.0 | 2482
       562240 | 11072901 | 2012-04-05 10:06:08-05 | 0101000020840D0300D5C9EF09F7FD214181016B7FD7710341 |   4.4 | 2522
       562220 | 11072901 | 2012-04-05 10:05:36-05 | 0101000020840D03007FE8CC1AF6FD214104C0399242750341 |   2.4 | 2522
       562241 | 11072910 | 2012-04-05 10:06:08-05 | 0101000020840D0300BE72D47D5A0D2241C53399774B630341 |   0.0 | 2532
       562225 | 11072910 | 2012-04-05 10:05:45-05 | 0101000020840D0300BE72D47D5A0D2241C53399774B630341 |   0.0 | 2532
       562249 | 11030821 | 2012-04-05 10:06:25-05 | 0101000020840D0300E15572FD4E042141D491539CA1E80441 |   0.0 | 2538
       562236 | 11030821 | 2012-04-05 10:06:04-05 | 0101000020840D0300E15572FD4E042141D491539CA1E80441 |   0.0 | 2538
       562223 | 11030821 | 2012-04-05 10:05:44-05 | 0101000020840D03008EA28CFC7F032141E6E959569FE80441 |  12.2 | 2538
       562235 | 11031332 | 2012-04-05 10:05:55-05 | 0101000020840D030064B179212BFE2141F351ECB0B4700341 |   3.9 | 2809
       562215 | 11031332 | 2012-04-05 10:05:33-05 | 0101000020840D0300B033836AF6FD214143DE49E11E740341 |   2.8 | 2809
       562248 | 11031326 | 2012-04-05 10:06:20-05 | 0101000020840D030046D5FF39849421418F854A13E9DA0241 |   0.0 | 2811
       562221 | 11031326 | 2012-04-05 10:05:39-05 | 0101000020840D030046D5FF39849421418F854A13E9DA0241 |   0.2 | 2811
    (31 rows)

1 个答案:

答案 0 :(得分:0)

看看这个问题:

https://gis.stackexchange.com/questions/34687/how-to-split-osm-roads-into-individual-segments-at-intersections

总的共识是,这不是一个好主意,因为你可以创建不存在的交叉点(天桥等,成为交叉点)。更好的方法是使用osm2pgrouting或osm2po之类的工具。