Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. DROP TABLE IF EXISTS gtfs_ttc_agency;
  2. CREATE TABLE gtfs_ttc_agency(
  3. agency_id int,
  4. agency_name text,
  5. agency_url text,
  6. agency_timezone text,
  7. agency_lang text,
  8. agency_phone text,
  9. agency_fare_url text
  10. );
  11. COPY gtfs_ttc_agency FROM
  12. '/home/nate/gtfs/agency.txt' CSV HEADER;
  13.  
  14.  
  15. DROP TABLE IF EXISTS gtfs_ttc_calendar;
  16. CREATE TABLE gtfs_ttc_calendar(
  17. service_id smallint,
  18. monday boolean,
  19. tuesday boolean,
  20. wednesday boolean,
  21. thursday boolean,
  22. friday boolean,
  23. saturday boolean,
  24. sunday boolean,
  25. start_date text, -- todo
  26. end_date text -- todo
  27. );
  28. COPY gtfs_ttc_calendar FROM
  29. '/home/nate/gtfs/calendar.txt' CSV HEADER;
  30.  
  31.  
  32. DROP TABLE IF EXISTS gtfs_ttc_calendar_dates;
  33. CREATE TABLE gtfs_ttc_calendar_dates(
  34. service_id smallint,
  35. "date" text,
  36. exception_type smallint
  37. );
  38. COPY gtfs_ttc_calendar_dates FROM
  39. '/home/nate/gtfs/calendar_dates.txt' CSV HEADER;
  40.  
  41.  
  42. DROP TABLE IF EXISTS gtfs_ttc_routes;
  43. CREATE TABLE gtfs_ttc_routes (
  44. route_id int,
  45. agency_id int,
  46. route_short_name text,
  47. route_long_name text,
  48. route_desc text,
  49. route_type smallint,
  50. route_url text,
  51. route_color text,
  52. route_text_color text
  53. );
  54. COPY gtfs_ttc_routes FROM
  55. '/home/nate/gtfs/routes.txt' CSV HEADER;
  56.  
  57.  
  58. DROP TABLE IF EXISTS gtfs_ttc_shapes;
  59. CREATE TABLE gtfs_ttc_shapes (
  60. shape_id int,
  61. shape_pt_lat numeric,
  62. shape_pt_lon numeric,
  63. shape_pt_sequence smallint,
  64. shape_dist_traveled real
  65. );
  66. COPY gtfs_ttc_shapes FROM
  67. '/home/nate/gtfs/shapes.txt' CSV HEADER;
  68. -- add geometry field
  69. ALTER TABLE gtfs_ttc_shapes ADD COLUMN geom geography(POINT,4326);
  70. UPDATE gtfs_ttc_shapes SET geom = ST_MakePoint(shape_pt_lon,shape_pt_lat);
  71.  
  72.  
  73. DROP TABLE IF EXISTS gtfs_ttc_stops;
  74. CREATE TABLE gtfs_ttc_stops (
  75. stop_id integer,
  76. stop_code text,
  77. stop_name text,
  78. stop_desc text,
  79. stop_lat numeric,
  80. stop_lon numeric,
  81. zone_id smallint,
  82. stop_url text,
  83. location_type smallint,
  84. parent_station smallint,
  85. wheelchair_boarding smallint
  86. );
  87. COPY gtfs_ttc_stops FROM
  88. '/home/nate/gtfs/stops.txt' CSV HEADER;
  89. -- add geometry field
  90. ALTER TABLE gtfs_ttc_stops ADD COLUMN geom geography(POINT,4326);
  91. UPDATE gtfs_ttc_stops SET geom = ST_MakePoint(stop_lon,stop_lat);
  92.  
  93.  
  94. DROP TABLE IF EXISTS gtfs_ttc_stop_times;
  95. CREATE TABLE gtfs_ttc_stop_times (
  96. trip_id int,
  97. arrival_time interval,
  98. departure_time interval,
  99. stop_id int,
  100. stop_sequence smallint,
  101. stop_headsign text,
  102. pickup_type smallint,
  103. drop_off_type smallint,
  104. shape_dist_traveled real
  105. );
  106. COPY gtfs_ttc_stop_times FROM
  107. '/home/nate/gtfs/stop_times.txt' CSV HEADER;
  108.  
  109.  
  110. DROP TABLE IF EXISTS gtfs_ttc_trips;
  111. CREATE TABLE gtfs_ttc_trips (
  112. route_id int,
  113. service_id smallint,
  114. trip_id integer,
  115. trip_headsign text,
  116. trip_short_name text,
  117. direction_id text,
  118. block_id int,
  119. shape_id int,
  120. wheelchair_accessible smallint
  121. );
  122. COPY gtfs_ttc_trips FROM
  123. '/home/nate/gtfs/trips.txt' CSV HEADER;
  124. -- add geometry field
  125. ALTER TABLE gtfs_ttc_trips ADD COLUMN geom geometry(LINESTRING,4326);
  126. UPDATE gtfs_ttc_trips AS trip SET geom = shape
  127. FROM (
  128. SELECT
  129. shape_id,
  130. ST_MakeLine(geom::geometry ORDER BY shape_pt_sequence ASC) AS shape
  131. FROM gtfs_ttc_shapes
  132. GROUP BY shape_id
  133. ) AS sub
  134. WHERE sub.shape_id = trip.shape_id;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement