Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. José Felgueiras nº 6179
  2.  
  3.  
  4. Exercicio 1
  5.  
  6.  
  7. CREATE DATABASE "Freq2_6179"
  8.   WITH OWNER = postgres
  9.        ENCODING = 'UTF8'
  10.        LC_COLLATE = 'Portuguese, Portugal'
  11.        LC_CTYPE = 'Portuguese, Portugal'
  12.        CONNECTION LIMIT = -1;
  13.  
  14.        
  15.        
  16.        
  17. Exercicio 2
  18.        
  19.        a)
  20.        
  21.        tabela fregpcpl
  22.             nº de registros 74
  23.             tipo de geometria ST_MultiPolygon
  24.            
  25.         tabela Meteo
  26.             nº de registros 37
  27.             tipo de geometria ST_Point
  28.            
  29.         tabela hidro
  30.             nº de registros 184
  31.             tipo de geometria ST_MultiLineString
  32.            
  33.         tabela ZPE
  34.             nº de registros 6
  35.             tipo de geometria ST_MultiPolygon
  36.            
  37.         b)
  38.        
  39.         create table turismo (id serial PRIMARY KEY, descricao text, codigo text);
  40.         select AddGeometryColumn('turismo', 'the_geom', 3763, 'GEOMETRY', 2 );
  41.        
  42.         INSERT INTO turismo VALUES ( 1, 'Norte','T1', ST_GeomFromText ('POLYGON ((-39880 247130, -338740 247500, -38930 246445, -39880 247130))', 3763 ) );
  43.         INSERT INTO turismo VALUES ( 2, 'Centro','T2', ST_GeomFromText ('POLYGON ((-34500 245520, -33250 245630, -34390 244490, -34500 245520))', 3763 ) );
  44.         INSERT INTO turismo VALUES ( 3, 'Sul','T3', ST_GeomFromText ('POLYGON ((-40520 237230, -39385 237590, -39570 236530, -40520 237230))', 3763 ) );
  45.        
  46.        
  47. Exercicio 3
  48.         a)
  49.         select descricao, st_area(the_geom) from turismo
  50.         "Norte";102183800
  51.         "Centro";649800
  52.         "Sul";568250
  53.        
  54.         b)
  55.         select concelho, sqrt(sum(ST_area2d(the_geom))) from fregpcpl where concelho like 'PAREDES DE COURA' or concelho like 'PONTE DE LIMA' GROUP BY concelho
  56.        
  57.         "PAREDES DE COURA";138185913.444047
  58.         "PONTE DE LIMA";320254616.706563
  59.  
  60.         c)
  61.         select count(*) from hidro where st_length(the_geom)<2000  
  62.         39
  63.        
  64.         d)
  65.         select count(m.*) from meteo m, zpe z where ST_within(m.the_geom, z.the_geom) and z.nome = 'Peneda-Gerês'  
  66.         14
  67.        
  68.         e)
  69.         select f.nome, count(m.*) from meteo m, fregpcpl f where f.concelho = 'PONTE DE LIMA' and ST_within(m.the_geom, f.the_geom) GROUP By f.nome    
  70.         "BOALHOSA";1
  71.         "MOREIRA DO LIMA";1
  72.         "LABRUJÓ";1
  73.         "ARCOZELO";1
  74.         "CALVELO";1
  75.         "ARCOS";1
  76.        
  77.        
  78.         f)
  79.         select designacao from hidro where ST_within( the_geom,( select st_buffer(the_geom, 5000) from meteo where nome = 'SOUTO') ) limit 1
  80.         "Rio Lima"
  81.         "Rio Lima"
  82.         "Rio Lima"
  83.         "Rio Lima"
  84.  
  85.        
  86.         g)
  87.         select m1.nome, m2.nome, st_distance(m1.the_geom, m2.the_geom) from meteo m1, meteo m2 where m1.nome != m2.nome order by st_distance(m1.the_geom, m2.the_geom) asc  limit 1
  88.         "LINDOSO 1";"LINDOSO 2";295.93763560723
  89.        
  90.         h)
  91.         select sum(st_length(intersection(h.the_geom, f.the_geom)))/1000
  92.         from hidro h, fregpcpl f
  93.         where st_intersects(h.the_geom,f.the_geom)  
  94.         and f.concelho = 'PAREDES DE COURA';
  95.        
  96.         61.3076312783985
  97.        
  98.         i)
  99.         select f.nome from fregpcpl f, meteo m where not st_intersects( st_buffer(m.the_geom,10000), f.the_geom )
  100.         "ROMARIGÃES"
  101.        
  102.        
  103. Exercicio 4
  104.  
  105.         a)
  106.         create view view4_a as
  107.             select gid, nome, the_geom from zpe where st_area(the_geom) > 50000000
  108.        
  109.         b)
  110.        
  111.         create view view4_b as
  112.             select m.gid, m.nome, m.the_geom from meteo m, fregpcpl f where ST_within(m.the_geom, f.the_geom) and f.concelho = 'PONTE DE LIMA'
  113.         c)
  114.         create view view4_c as
  115.             select t.id, t.the_geom
  116.             from turismo t, hidro h
  117.             where st_distance(t.the_geom, h.the_geom )<200
  118.        
  119. Exercicio 5
  120.        
  121.         a)
  122.        
  123.         select nome from zpe
  124.         where not st_intersects( the_geom, (select st_union(the_geom) from meteo))
  125.        
  126.         Retorna o nome de todas as zonas protegidas que nao tem estação meteriologica
  127.        
  128.         b)
  129.         select m.*
  130.         from meteo m, ( select st_union(the_geom) as the_geom from zpe) z,
  131.                         (select st_union(st_buffer(the_geom, 1000)) as the_geom from hidro) bh
  132.         where st_contains(st_difference(z.the_geom, bh.the_geom), m.the_geom);
  133.        
  134. Retorna todos os campos das estações meteorológica que ou estão numa zona protegida ou tem um rio a menos de 1 km
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement