-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jeff Stern - Assignment #2 Submission #1
base: main
Are you sure you want to change the base?
Conversation
from bus_stop_geom as b | ||
join census_block_groups as bg | ||
on ST_Intersects( | ||
ST_Buffer(ST_Transform(b.geometry, 32129),800), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of this line, the query completes in a reasonable time for me only if I add an index such as:
drop index if exists septa_bus_stops__geom_32129__buffer;
create index septa_bus_stops__geom_32129__buffer
on septa_bus_stops
using GiST (ST_Buffer(ST_Transform(ST_SetSRID(ST_Point(stop_lon, stop_lat), 4326), 32129), 800));
Instead of using ST_Intersects(ST_Buffer(...
, you could use ST_DWithin(...
, and then could at least get rid of the ST_Buffer
in the above index and still complete in a reasonable time.
from bus_stop_block_group as b | ||
join census_population_adj as cp using(geoid) | ||
group by b.stop_name | ||
order by estimated_pop_800m desc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be ordered asc
, but I see you got the right answer (as entered in the README), so I assume this was changed and just not checked in.
bg.stop_name AS stop_name, | ||
ST_Distance(ST_Transform(bg.geometry,32129), ST_Transform(pwd.geometry,32129)) as distance_m | ||
from bus_stop_geom as bg | ||
order by distance_m desc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would want this to be ascending, since we want the closest (i.e., smallest distance) bus stops
cross join lateral ( | ||
select | ||
bg.stop_name AS stop_name, | ||
ST_Distance(ST_Transform(bg.geometry,32129), ST_Transform(pwd.geometry,32129)) as distance_m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'd want to use the nearest neighbor operator (<->
) here, since it is a way of measuring distance that can use a spatial index, whereas the ST_Distance
function [frustratingly] cannot
No description provided.