
colindancias de un terreno
Publicado por bit (2 intervenciones) el 11/11/2013 15:31:21
AYUDA PARA ENCONTRAR LAS COLINDANCIAS.. DE UN TERRENO (CORRIJAN ME LOS TIPOS DE DATOS SOY NOVATO EN POSTGRES):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
-- Function: mapa.b_colindancias(character varying, character varying)
-- DROP FUNCTION mapa.b_colindancias(character varying, character varying);
CREATE OR REPLACE FUNCTION mapa.b_colindancias(p_codigo_catastral character varying)
RETURNS TEXT[] AS
$BODY$
DECLARE
--devuelve los numero_lote colindante:
/*sql varchar='
SELECT i.numero_lote
FROM mapa.inmueble AS i,mapa.inmueble AS i2
WHERE ST_DWithin(i2.the_geom,i.the_geom,8)
AND i2.codigo_catastral='||quote_literal(p_codigo_catastral);
sql2 varchar='select st_xmin(i.the_geom) from mapa.inmueble as i where i.codigo_catastral='||quote_literal(p_codigo_catastral);
*/
xmin integer;
xmax integer;
ymin integer;
ymax integer;
reg1 RECORD;
reg2 RECORD;
vresultado TEXT[]:='{}';
j int:=1;
--mi_arreglo: = mi_arreglo | | ARRAY [[rec.dato1 :: texto, rec.dato2 :: text]];
BEGIN
RAISE NOTICE 'mostrando registro:...';
j=1;
--devuelve los 4 puntos del poligono objetivo:
SELECT st_xmin(i.the_geom)::numeric as xmin INTO reg1 from mapa.inmueble as i where i.codigo_catastral=quote_literal(p_codigo_catastral);
SELECT st_xmax(i.the_geom)::numeric as xmax INTO reg1 from mapa.inmueble as i where i.codigo_catastral=quote_literal(p_codigo_catastral);
SELECT st_ymin(i.the_geom)::numeric as ymin INTO reg1 from mapa.inmueble as i where i.codigo_catastral=quote_literal(p_codigo_catastral);
SELECT st_xmax(i.the_geom)::numeric as xmax INTO reg1 from mapa.inmueble as i where i.codigo_catastral=quote_literal(p_codigo_catastral);
RAISE NOTICE 'el xmin: %s..', (reg1.xmin);
--devuelve los lotes conlindantes:
FOR reg2 IN
SELECT i.codigo_catastral,i.numero_lote
FROM mapa.inmueble AS i
JOIN mapa.inmueble AS i2
ON ST_DWithin(i2.the_geom,i.the_geom,8)
WHERE i2.codigo_catastral=p_codigo_catastral
LOOP
--si es diferente al codigo catastral pivote trabajar con los otros codigos catastrales
IF reg2.codigo_catastral<>p_codigo_catastral THEN
RAISE NOTICE 'codigo_catastral: %s..', quote_ident(reg2.numero_lote);
--sacar 4 puntos del poligono colindante:
SELECT st_xmin(i.the_geom)::numeric as xmin INTO reg2 from mapa.inmueble as i where i.codigo_catastral=quote_literal(reg2.codigo_catastral);
SELECT st_ymin(i.the_geom)::numeric as ymin INTO reg2 from mapa.inmueble as i where i.codigo_catastral=quote_literal(reg2.codigo_catastral);
SELECT st_xmax(i.the_geom)::numeric as xmax INTO reg2 from mapa.inmueble as i where i.codigo_catastral=quote_literal(reg2.codigo_catastral);
SELECT st_ymax(i.the_geom)::numeric as ymax INTO reg2 from mapa.inmueble as i where i.codigo_catastral=quote_literal(reg2.codigo_catastral);
--hacer las comparaciones para introduccir al vector_resultado
IF(reg2.ymax>=reg1.ymin)THEN
RAISE NOTICE 'Norte:', quote_ident(reg2.numero_lote);
vresultado[i]='Norte';
vresultado[i+1]=quote_indent(reg2.numero_lote);
--asignar al vector la orientacion y el numero_lote
END IF;
IF(reg2.ymin<=reg1.ymax)THEN
RAISE NOTICE 'Sur:',quote_ident(reg2.numero_lote);
vresultado[i]='Sur';
vresultado[i+1]=quote_indent(reg2.numero_lote);
END IF;
IF(reg2.xmax<=reg1.xmin)THEN
RAISE NOTICE 'Oeste:',quote_ident(reg2.numero_lote);
vresultado[i]='Oeste';
vresultado[i+1]=quote_indent(reg2.numero_lote);
END IF;
IF(reg2.xmin>=reg1.xmax)THEN
RAISE NOTICE 'Este:',quote_ident(reg2.numero_lote);
vresultado[i]='Este';
vresultado[i+1]=quote_indent(reg2.numero_lote);
END IF;
END IF;
j=j+2;
-- Now "registro" has one record from cs_materialized_views
--EXECUTE 'TRUNCATE TABLE ' || quote_ident(registro.codigo_catastral);
--EXECUTE 'INSERT INTO '
-- || quote_ident(registro.codigo_catastral) || ' '
-- || registro.mv_query;
END LOOP;
RAISE NOTICE 'fuera reg2.xmin: %s...', quote_ident((reg2.xmin)::varchar);
--RETURN; -- FINALIZA O INDICA QUE usado si se ha definido variables de entrada y salida
--RETURN QUERY EXECUTE sql; -- cuando tenemos que devolver REGISTROS DE LA VARIABLE: sql
--RETURN NEXT registro;--RETORNA EL VALOR DE LA VARIABLE "reg1"
--RETURN NEXT reg2;
RETURN vresultado;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
Valora esta pregunta


0