473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Could someone check my Postgresql spatial queries

1
Could someone check my Postgresql queries? I wrote the explanation first and then the query.

# 1 list all sushi bars within borders of Cracow city
Expand|Select|Wrap|Line Numbers
  1. select name from planet_osm_point where amenity='restaurant' and name ilike '%sushi%' and ST_Within(way, (select multipolygon from krakow limit 1));
# 2 calculate the total length of aphalt roads in Cracow
Expand|Select|Wrap|Line Numbers
  1. select sum(st_length(way)) from planet_osm_roads where surface='asphalt' and ST_Within(way, (select multipolygon from krakow limit 1));
#3 count all carpet beaters in Cracow
Expand|Select|Wrap|Line Numbers
  1. select count(*) from planet_osm_point  where amenity='beater' and ST_Within(way, (select multipolygon from krakow limit 1));
#4 find distance between Wydział Matematyki i Informatyki UJ and the restaurant Miód i Malina
Expand|Select|Wrap|Line Numbers
  1. select ST_distance((select way from planet_osm_point where amenity = 'university' and name ilike '%Wydział Matematyki i Informatyki%'), (select way from planet_osm_point where amenity = 'restaurant' and name ilike '%malina%'));
# find how many amenities are in the radius of 10 km from the restaurant "miód i malina"
Expand|Select|Wrap|Line Numbers
  1. select amenity, count(*) from planet_osm_point where ST_distance((select way from planet_osm_point where name ilike '%malina%' and amenity = 'restaurant'), way) <= 10000 group by amenity order by 2 desc;
#find longest primary roads in Kraków
Expand|Select|Wrap|Line Numbers
  1. select name, sum(ST_length(way)) from planet_osm_roads where highway = 'primary' and name is not null and name not ilike '%powiat%' and name not ilike '%województwo%' and name not ilike '%subregion%' and name not ilike '%Kraków%' and ST_within(way, (select multipolygon from krakow limit 1))  group by name order by 2 desc limit 10;
#find longest only pedestrian road in Kraków
Expand|Select|Wrap|Line Numbers
  1. select name, sum(ST_length(way)) from planet_osm_roads where highway = 'pedestrian' and name is not null and name not ilike '%powiat%' and name not ilike '%województwo%' and name not ilike '%subregion%' and name not ilike '%Kraków%' and ST_within(way, (select multipolygon from krakow limit 1))  group by name order by 2 desc limit 1;
#select amenities which are at most 10 km from restaurant Miód i Malina and at most 5 km from "Szara Ges", group them by their type and count them
Expand|Select|Wrap|Line Numbers
  1. select amenity, count(*) from planet_osm_point where (ST_distance((select way from planet_osm_point where name ilike '%malina%' and amenity = 'restaurant'), way) <= 10000 and st_distance((select way from planet_osm_point where name ilike '%szara ges%' and amenity = 'restaurant'), way) <= 5000) group by amenity order by 2 desc;
#select theatres which are not further than 50 km from Sukiennice (Rynek Główny) but they lie outside Krakow and give distance
Expand|Select|Wrap|Line Numbers
  1. select name, ST_distance(way, (select way from planet_osm_point where name ilike '%muzeum sukiennice%')) from planet_osm_point where amenity = 'theatre' and st_distance(way, (select way from planet_osm_point where name ilike '%muzeum sukiennice%')) <500000 and not ST_Within(way, (select multipolygon from krakow limit 1));
#find all the castles from the map and their distance from the Krakow city center
Expand|Select|Wrap|Line Numbers
  1. select a.name, ST_distance(ST_setSRID(a.way, 4326), ST_GeomFromText('POINT(19.938333 50.061389)', 4326)) from planet_osm_polygon as a where historic ilike '%castle%'order by 1;
#calculate areas of different lakes that can be found in the map
Expand|Select|Wrap|Line Numbers
  1. select name, sum(st_area(way)) from planet_osm_polygon where water = 'lake'and name is not null group by name  order by 1;
#calculate the area of different lakes within Cracow boundaries.
Expand|Select|Wrap|Line Numbers
  1. select name, sum(st_area(way)) from planet_osm_polygon where water = 'lake'and name is not null and ST_Within(way, (select multipolygon from krakow limit 1))  group by name  order by 1;
#calculate total area of forests within Cracow boundaries
Expand|Select|Wrap|Line Numbers
  1. select sum(st_area(way)) from planet_osm_polygon where (wood ilike '%coniferous%') or (wood ilike 'mixed') or (wood ilike '%evergreen%') or (wood ilike '%deciduous%')  and ST_Within(way, (select multipolygon from krakow limit 1));
# Number of intersections between asphalt roads which are shorter than 100m.
Expand|Select|Wrap|Line Numbers
  1. select count(*) from planet_osm_roads as a, planet_osm_roads as b where a.surface = 'asphalt' and b.surface='asphalt' and a.osm_id != b.osm_id and st_length(b.way) < 100 and st_length(a.way) < 100 and st_crosses(a.way,b.way);
Aug 2 '18 #1
1 2426
zmbd
5,501 Expert Mod 4TB
Picia,
These read like homework questions and as such will not receive a lot of response - no one here will typically re-write a homework answer.

If you have a particular problem with one of these, given that you have shown your work, you may receive some direction if you can tell us what the issue is; however, we will not do your work for you - it's not fair to you and it's not fair to your fellow students.

Finally, ALL sql, script, VBA, Code, etc... must be formatted using either the [CODE/] format tool or manually enclosed between [code] [/code] tags.
Aug 6 '18 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: mike | last post by:
regards: Could someone good to see the programming archtecture? http://www.wretch.cc/album/show.php?i=otp&b=1&f=1107098054&p=0 Is the programming archtecture reasonable? ?.? thank you wish...
5
by: shang | last post by:
Hi! I am trying to find a function that converts a string into a double or a long double number. I found atod() but I don't know which library I have to include to use it. Could someone help me? ...
0
by: Shapper | last post by:
Hello, I have this code in Global.asax: Sub Session_Start(Sender As Object, E As EventArgs) Dim cookie As HttpCookie = Request.Cookies("MyCookie") If Not cookie Is Nothing Then...
3
by: Amy | last post by:
Hi, I have 6 If Then Else statements I was supposed to write. I did so but I know that they have to be wrong because they all look the same. Could someone take a look at them and point me in the...
8
by: Bart | last post by:
Could someone explain me what is wrong with this code ? I gives me a compile error: Error 1 Use of unassigned local variable 'fileStreamObject' C:\Documents and Settings\Bart\Local...
1
by: henryJack85 | last post by:
Hi, everyone I want to compare Oracle and PostgreSQL. I need some information.... Do you know, how PostgreSQL searching Queries? You can give me some guide to do this comparison. I glad to...
5
by: patelxxx | last post by:
I have a FORM with allows user to input their name and then user clicks submit which this goes to my .cgi script. Can someone check this .cgi script as the results are not being displayed as...
3
by: shapper | last post by:
Hello, I have two tables: Polls and Options: Poll PollID, Question Options OptionID, PollID, Answer I want to select a Poll given its ID and all Options associated to it. Options should...
1
by: Beef Bowl | last post by:
Please check my code why it isn't producing result that has decimal places that i want? int main () { double a,b,fa,fb,fc,c,f,x,t,g,y,temp; int max=500; int i,z; cout<<"Enter tolerance: ";...
2
by: ErraticFox | last post by:
Hello, for some reason everytime I register on my website, I get "Could not check username" no matter what I use. I'm sure it might be a spelling mistake(?) but I've looked through everywhere and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.