Progress - colindancias de un terreno

 
Vista:
Imágen de perfil de bit

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
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de bit

colindancias de un terreno

Publicado por bit (2 intervenciones) el 13/11/2013 19:43:39
HE ESTADO MEJORANDO YA FUNCIONA PERO NO ES EXACTO EN EL CALCULO.. AHORA TENGO EL UN ERROR DE CONVERSIÓN DE TIPOS.. RECORD A INTEGER COMO LO HAGO?

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
98
99
100
101
102
103
104
105
106
CREATE OR REPLACE FUNCTION mapa.b_colindancias2(p_codigo_catastral character varying)
  RETURNS SETOF text[] AS
$BODY$
DECLARE
 
  xminA RECORD;
  yminA RECORD;
  xmaxA RECORD;
  ymaxA RECORD;
 
  regC RECORD;
 
  xminB RECORD;
  yminB RECORD;
  xmaxB RECORD;
  ymaxB RECORD;
 
  --voy a sacar un vertice.. para mejorar la exactitud del algoritmo:
  xmedA numeric;
  ymedA numeric;
  xmedB numeric;
  ymedB numeric;
 
  vresultado TEXT[]:='{}';
  j int:=0;
  --mi_arreglo: = mi_arreglo | | ARRAY [[rec.dato1 :: texto, rec.dato2 :: text]];
BEGIN
   --RAISE NOTICE 'mostrando registro:...';
--devuelve los 4 puntos del poligono objetivo:
   SELECT ST_XMin(i.the_geom)::numeric INTO xminA from mapa.inmueble as i where i.codigo_catastral=p_codigo_catastral;
   SELECT ST_YMin(i.the_geom)::numeric INTO yminA from mapa.inmueble as i where i.codigo_catastral=p_codigo_catastral;
   SELECT ST_XMax(i.the_geom)::numeric INTO xmaxA from mapa.inmueble as i where i.codigo_catastral=p_codigo_catastral;
   SELECT ST_YMax(i.the_geom)::numeric INTO ymaxA from mapa.inmueble as i where i.codigo_catastral=p_codigo_catastral;
   --RAISE NOTICE 'el yminA: %',yminA;
--devuelve los lotes conlindantes:
   FOR regC 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
	ORDER BY i.codigo_catastral
   LOOP
	--si es diferente al codigo catastral pivote trabajar con los otros codigos catastrales
	--IF regC.codigo_catastral<>p_codigo_catastral THEN
		--RAISE NOTICE 'regC.[numero_lote]: %', regC.numero_lote;
 
 
		--sacar 4 puntos del poligono colindante:
		SELECT ST_XMin(i.the_geom)::numeric INTO xminB from mapa.inmueble as i where i.codigo_catastral=regC.codigo_catastral;
		SELECT ST_YMin(i.the_geom)::numeric INTO yminB from mapa.inmueble as i where i.codigo_catastral=regC.codigo_catastral;
		SELECT ST_XMax(i.the_geom)::numeric INTO xmaxB from mapa.inmueble as i where i.codigo_catastral=regC.codigo_catastral;
		SELECT ST_YMax(i.the_geom)::numeric INTO ymaxB from mapa.inmueble as i where i.codigo_catastral=regC.codigo_catastral;
		--RAISE NOTICE 'yminB: %', yminB;
 
		--hacer las comparaciones para introduccir al vector_resultado EL ERROR DE TIPOS ESTA AQUI EN ESTAS OPERACIONES:
		xmedA:=(xmaxA::integer-xminA::integer)-xminA::integer;
		ymedA:=(ymaxA-yminA)-yminA;
		xmedB:=(xmaxB-xminB)-xminB;
		ymedB:=(ymaxB-yminB)-yminB;
 
		IF(ymaxB>ymaxA)AND(yminB>yminA)AND((xminB<xminA)or(xmaxB<xminA))AND(ymedB>ymedA)THEN
			RAISE NOTICE 'Norte: %', quote_ident(regC.numero_lote);
			j:=j+1;
			vresultado[j]:='Norte';
			--RAISE NOTICE 'vresultado: %', vresultado[j];
			j:=j+1;
			vresultado[j]:=regC.numero_lote;
			--RAISE NOTICE 'vresultado: %', vresultado[j];
 
			--asignar al vector la orientacion y el numero_lote
		 ELSE
			IF(ymaxB<ymaxA)AND(yminB<yminA)AND((xminB>xminA)OR(xmaxB>xminA))AND(ymedB<ymedA)THEN
				RAISE NOTICE 'Sur: %',quote_ident(regC.numero_lote);
				j:=j+1;
				vresultado[j]:='Sur';
				j:=j+1;
				vresultado[j]:=regC.numero_lote;
			ELSE
				IF((xmaxB<=xminA)OR(xminB<xminA))THEN
					RAISE NOTICE 'Oeste: %',quote_ident(regC.numero_lote);
					j:=j+1;
					vresultado[j]:='Oeste';
					j:=j+1;
					vresultado[j]:=regC.numero_lote;
				ELSE
					IF((xminB>=xmaxA)OR(xmaxB>xmaxA))THEN
						RAISE NOTICE 'Este: %',quote_ident(regC.numero_lote);
						j:=j+1;
						vresultado[j]:='Este';
						j:=j+1;
						vresultado[j]:=regC.numero_lote;
 
					END IF;
				END IF;
			END IF;
		END IF;
 
    END LOOP;
 
    RETURN NEXT vresultado;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100
  ROWS 1000;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar