Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10,409 changes: 5,897 additions & 4,512 deletions input/TABELAO_2019_12_11.csv

Large diffs are not rendered by default.

4,513 changes: 4,513 additions & 0 deletions input/TABELAO_2019_12_11_old.csv

Large diffs are not rendered by default.

4,773 changes: 4,773 additions & 0 deletions input/TABELAO_2025_01_24.csv

Large diffs are not rendered by default.

Binary file added input/TABELAO_2025_01_24.ods
Binary file not shown.
Binary file added input/Tabelao_Pinheiros.ods
Binary file not shown.
10,373 changes: 5,871 additions & 4,502 deletions output/clean_TABELAO_2019_12_11.csv

Large diffs are not rendered by default.

4,503 changes: 4,503 additions & 0 deletions output/clean_TABELAO_2019_12_11_old.csv

Large diffs are not rendered by default.

36 changes: 26 additions & 10 deletions output/error_TABELAO_2019_12_11.csv
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
id_street,id_point,metre,address,number,original_n,initial_date,final_date,source,author,date,coordinate,first_day,first_month,first_year,last_day,last_month,last_year,reason
296,296-474,474.9,Rua Jaguaribe,92.0,92,09/04/2029,12/06/1935,"Livro de Emplacamento - 30-6-1908 - L5, p.42; 15-12-1911 - L5, p.55; 4-3-1923 - L5, p.94; 4-9-1929 - L15, p.193; 7-12-1935 – L20, p.210 a 212 ",Orlando,16/10/2018,,9.0,4.0,2029.0,12.0,6.0,1935.0,Initial year is greater than final year.
296,296-780,780.3,Rua Jaguaribe,148.0,148,09/04/2029,12/06/1935,"Livro de Emplacamento - 30-6-1908 - L5, p.42; 15-12-1911 - L5, p.55; 4-3-1923 - L5, p.94; 4-9-1929 - L15, p.193; 7-12-1935 – L20, p.210 a 212 ",Orlando,16/10/2018,,9.0,4.0,2029.0,12.0,6.0,1935.0,Initial year is greater than final year.
175,175-29,29.0,rua pyrineus,24.0,24,01/01/1911,31/12/1910,"Livro de emplacamento 7, p. 128",Vitoria Martins,13/10/2018,,1.0,1.0,1911.0,31.0,12.0,1910.0,Initial year is greater than final year.
259,259-127,126.1,rua jurua,35.1,35A,26/07/1938,09/01/1925,"Livro de emplacamento 5, p. 96",Vitoria Martins,16/10/2018,,26.0,7.0,1938.0,9.0,1.0,1925.0,Initial year is greater than final year.
387,387-368,368.6,rua bella cintra,132.0,132,02/04/1933,20/03/1911,"Livro de emplacamento 2, p. 51; 2, p. 25",Vitoria Martins,18/10/2018,,2.0,4.0,1933.0,20.0,3.0,1911.0,Initial year is greater than final year.
411,411-966,965.0,avenida brigadeiro luis antonio,188.0,188,05/05/1934,16/10/1929,"Livro de emplacamento 16, p. 19; 2, p. 54",Vitoria Martins,18/10/2018,,5.0,5.0,1934.0,16.0,10.0,1929.0,Initial year is greater than final year.
45,45-1327,1326.8,avenida sao joao,453.0,453,10/01/1911,,"Livro de emplacamento 19, p. 43; 8, p. 164",Vitoria Martins,28/01/2019,,10.0,1.0,1911.0,,,,Invalid final_date.
690,690-24,25.4,Rua Barra do Tibagy,89.0,89,02/09/1915,28/09/1616,"Livro de Emplacamento L1; 99; L2;p.39 L2; p.44; L2; p.55; L13; p.55,56; L18; p.7,8; L21; p.386 a 389",Cintia,07/01/2019,,2.0,9.0,1915.0,28.0,9.0,1616.0,Initial year is greater than final year.
690,690-256,256.2,Rua Barra do Tibagy,41.0,41,25/07/1908,28/09/1616,"Livro de Emplacamento L1; 99; L2;p.39 L2; p.44; L2; p.55; L13; p.55,56; L18; p.7,8; L21; p.386 a 389",Cintia,07/01/2019,,25.0,7.0,1908.0,28.0,9.0,1616.0,Initial year is greater than final year.
690,690-592,591.3,Rua Barra do Tibagy,9.0,9,25/07/1908,28/09/1616,"Livro de Emplacamento L1; 99; L2;p.39 L2; p.44; L2; p.55; L13; p.55,56; L18; p.7,8; L21; p.386 a 389",Cintia,07/01/2019,,25.0,7.0,1908.0,28.0,9.0,1616.0,Initial year is greater than final year.
296,296-474,474.9,Rua Jaguaribe,92.0,92,09/04/2029,12/06/1935,"Livro de Emplacamento - 30-6-1908 - L5. p,42",Cintia,8/10/2018,,9.0,4.0,2029.0,12.0,6.0,1935.0,Initial year is greater than final year.
296,296-780,780.3,Rua Jaguaribe,148.0,148,09/04/2029,12/06/1935,"Livro de Emplacamento - 30-6-1908 - L5. p,42",Cintia,8/10/2018,,9.0,4.0,2029.0,12.0,6.0,1935.0,Initial year is greater than final year.
175,175-29,29.0,rua pyrineus,24.0,24,01/01/1911,31/12/1910,Livro de emplacamento 7. p. 128,Cintia,8/10/2018,,1.0,1.0,1911.0,31.0,12.0,1910.0,Initial year is greater than final year.
259,259-127,126.1,rua jurua,35.1,35A,26/07/1938,09/01/1925,Livro de emplacamento 5. p. 96,Cintia,8/10/2018,,26.0,7.0,1938.0,9.0,1.0,1925.0,Initial year is greater than final year.
387,387-368,368.6,rua bella cintra,132.0,132,02/04/1933,20/03/1911,Livro de emplacamento 2. p. 51,Cintia,8/10/2018,,2.0,4.0,1933.0,20.0,3.0,1911.0,Initial year is greater than final year.
411,411-966,965.0,avenida brigadeiro luis antonio,188.0,188,05/05/1934,16/10/1929,Livro de emplacamento 16. p. 19,Cintia,8/10/2018,,5.0,5.0,1934.0,16.0,10.0,1929.0,Initial year is greater than final year.
294,294-33,32.5,rua fortunato,33.0,33,26/10/1935,,Livro de emplacamento 20. p. 133,Cintia,8/10/2018,,26.0,10.0,1935.0,,,,Invalid final_date.
45,45-1327,1326.8,avenida sao joao,453.0,453,10/01/1911,,Livro de emplacamento 19. p. 43,Cintia,8/10/2018,,10.0,1.0,1911.0,,,,Invalid final_date.
690,690-24,25.4,Rua Barra do Tibagy,89.0,89,02/09/1915,28/09/1616,Livro de Emplacamento L1,Cintia,8/10/2018,,2.0,9.0,1915.0,28.0,9.0,1616.0,Initial year is greater than final year.
690,690-256,256.2,Rua Barra do Tibagy,41.0,41,25/07/1908,28/09/1616,Livro de Emplacamento L1,Cintia,8/10/2018,,25.0,7.0,1908.0,28.0,9.0,1616.0,Initial year is greater than final year.
690,690-592,591.3,Rua Barra do Tibagy,9.0,9,25/07/1908,28/09/1616,Livro de Emplacamento L1,Cintia,8/10/2018,,25.0,7.0,1908.0,28.0,9.0,1616.0,Initial year is greater than final year.
1744,1744-1157,1156.3,rua dos pinheiros,99.0,99,04/1921,09/27/1927,"Livro de emplacamento n,7. p. 186",Cintia,8/10/2018,,,,,,,,Invalid initial_date.
1744,1744-1157,1156.3,rua dos pinheiros,85.0,85,03/1921,03/1921,"Livro de emplacamento n,7. p. 186",Cintia,8/10/2018,,,,,,,,Invalid initial_date.
1744,1744-1427,1427.3,rua dos pinheiros,119.0,119,04/1921,09/27/1927,"Livro de emplacamento n,7. p. 186",Cintia,8/10/2018,,,,,,,,Invalid initial_date.
1744,1744-1427,1427.3,rua dos pinheiros,197.0,197,03/1921,03/1921,"Livro de emplacamento n,7. p. 186",Cintia,8/10/2018,,,,,,,,Invalid initial_date.
1744,1744-1559,1558.2,rua dos pinheiros,135.0,135,04/1921,09/27/1927,"Livro de emplacamento n,7. p. 186",Cintia,8/10/2018,,,,,,,,Invalid initial_date.
1744,1744-1559,1558.2,rua dos pinheiros,205.0,205,03/1921,03/1921,"Livro de emplacamento n,7. p. 186",Cintia,8/10/2018,,,,,,,,Invalid initial_date.
1744,1744-456,458.9,rua dos pinheiros,24.0,24,04/1921,09/27/1927,"Livro de emplacamento n,7. p. 186",Cintia,8/10/2018,,,,,,,,Invalid initial_date.
1744,1744-456,458.9,rua dos pinheiros,10.0,10,03/1921,03/1921,"Livro de emplacamento n,7. p. 186",Cintia,8/10/2018,,,,,,,,Invalid initial_date.
1744,1744-1022,1022.1,rua dos pinheiros,48.0,48,04/1921,09/27/1927,"Livro de emplacamento n,7. p. 186",Cintia,8/10/2018,,,,,,,,Invalid initial_date.
1744,1744-1022,1022.1,rua dos pinheiros,78.0,78,03/1921,03/1921,"Livro de emplacamento n,7. p. 186",Cintia,8/10/2018,,,,,,,,Invalid initial_date.
1744,1744-1574,1573.0,rua dos pinheiros,78.0,78,04/1921,09/27/1927,"Livro de emplacamento n,7. p. 186",Cintia,8/10/2018,,,,,,,,Invalid initial_date.
1744,1744-1574,1573.0,rua dos pinheiros,104.0,104,03/1921,03/1921,"Livro de emplacamento n,7. p. 186",Cintia,8/10/2018,,,,,,,,Invalid initial_date.
2010,2010-200,200.3,rua dos ingleses,31.0,31,20/101927,17/01/1938,,Cintia,8/10/2018,,,,,,,,Invalid initial_date.
2010,2010-95,95.6,rua dos ingleses,10.0,10,08/11/1929,17/02/1924,,Cintia,8/10/2018,,8.0,11.0,1929.0,17.0,2.0,1924.0,Initial year is greater than final year.
2010,2010-197,197.3,rua dos ingleses,50.0,50,20/101927,17/01/1938,,Cintia,8/10/2018,,,,,,,,Invalid initial_date.
11 changes: 11 additions & 0 deletions output/error_TABELAO_2019_12_11_old.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
id_street,id_point,metre,address,number,original_n,initial_date,final_date,source,author,date,coordinate,first_day,first_month,first_year,last_day,last_month,last_year,reason
296,296-474,474.9,Rua Jaguaribe,92.0,92,09/04/2029,12/06/1935,"Livro de Emplacamento - 30-6-1908 - L5, p.42; 15-12-1911 - L5, p.55; 4-3-1923 - L5, p.94; 4-9-1929 - L15, p.193; 7-12-1935 – L20, p.210 a 212 ",Orlando,16/10/2018,,9.0,4.0,2029.0,12.0,6.0,1935.0,Initial year is greater than final year.
296,296-780,780.3,Rua Jaguaribe,148.0,148,09/04/2029,12/06/1935,"Livro de Emplacamento - 30-6-1908 - L5, p.42; 15-12-1911 - L5, p.55; 4-3-1923 - L5, p.94; 4-9-1929 - L15, p.193; 7-12-1935 – L20, p.210 a 212 ",Orlando,16/10/2018,,9.0,4.0,2029.0,12.0,6.0,1935.0,Initial year is greater than final year.
175,175-29,29.0,rua pyrineus,24.0,24,01/01/1911,31/12/1910,"Livro de emplacamento 7, p. 128",Vitoria Martins,13/10/2018,,1.0,1.0,1911.0,31.0,12.0,1910.0,Initial year is greater than final year.
259,259-127,126.1,rua jurua,35.1,35A,26/07/1938,09/01/1925,"Livro de emplacamento 5, p. 96",Vitoria Martins,16/10/2018,,26.0,7.0,1938.0,9.0,1.0,1925.0,Initial year is greater than final year.
387,387-368,368.6,rua bella cintra,132.0,132,02/04/1933,20/03/1911,"Livro de emplacamento 2, p. 51; 2, p. 25",Vitoria Martins,18/10/2018,,2.0,4.0,1933.0,20.0,3.0,1911.0,Initial year is greater than final year.
411,411-966,965.0,avenida brigadeiro luis antonio,188.0,188,05/05/1934,16/10/1929,"Livro de emplacamento 16, p. 19; 2, p. 54",Vitoria Martins,18/10/2018,,5.0,5.0,1934.0,16.0,10.0,1929.0,Initial year is greater than final year.
45,45-1327,1326.8,avenida sao joao,453.0,453,10/01/1911,,"Livro de emplacamento 19, p. 43; 8, p. 164",Vitoria Martins,28/01/2019,,10.0,1.0,1911.0,,,,Invalid final_date.
690,690-24,25.4,Rua Barra do Tibagy,89.0,89,02/09/1915,28/09/1616,"Livro de Emplacamento L1; 99; L2;p.39 L2; p.44; L2; p.55; L13; p.55,56; L18; p.7,8; L21; p.386 a 389",Cintia,07/01/2019,,2.0,9.0,1915.0,28.0,9.0,1616.0,Initial year is greater than final year.
690,690-256,256.2,Rua Barra do Tibagy,41.0,41,25/07/1908,28/09/1616,"Livro de Emplacamento L1; 99; L2;p.39 L2; p.44; L2; p.55; L13; p.55,56; L18; p.7,8; L21; p.386 a 389",Cintia,07/01/2019,,25.0,7.0,1908.0,28.0,9.0,1616.0,Initial year is greater than final year.
690,690-592,591.3,Rua Barra do Tibagy,9.0,9,25/07/1908,28/09/1616,"Livro de Emplacamento L1; 99; L2;p.39 L2; p.44; L2; p.55; L13; p.55,56; L18; p.7,8; L21; p.386 a 389",Cintia,07/01/2019,,25.0,7.0,1908.0,28.0,9.0,1616.0,Initial year is greater than final year.
108 changes: 83 additions & 25 deletions sql/01_saboya_geometry_plsql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,93 @@
--------------------------------------------------

CREATE OR REPLACE FUNCTION saboya_geometry(streetId integer, numberPlace Float)
RETURNS text
RETURNS text
AS
$BODY$
DECLARE
zeroGeom text;
streetGeom text;
oldGeomPlace text;
streetSize Float;
startPoint text;
newGeom text;
newStreetGeom text;
equals boolean;
zeroGeom geometry;
streetGeom geometry;
oldGeomPlace text;
streetSize Float;
startPoint geometry;
newGeom geometry;
newStreetGeom geometry;
fraction Float;
equals boolean;
BEGIN
zeroGeom := (SELECT places.geom FROM places_pilot_area AS places INNER JOIN streets_pilot_area AS street ON places.id_street = street.id WHERE places.number = 0 AND street.id = streetId ORDER BY date DESC LIMIT 1);
streetGeom := (SELECT ST_LineMerge(geom) FROM streets_pilot_area WHERE id = streetId);
streetSize := (SELECT ST_Length(ST_Transform(geom, 29100)) FROM streets_pilot_area where id = streetId);
startPoint := (SELECT ST_StartPoint(ST_LineMerge(geom)) FROM streets_pilot_area WHERE id = streetId);
equals := (SELECT ST_Contains(startPt.geom,zeropt.geo) As ST_Contains FROM ( SELECT ST_Buffer(ST_StartPoint(ST_LineMerge(geom)), 0.0002) As geom FROM streets_pilot_area WHERE id = streetId ) As startPt, ( SELECT places.geom as geo FROM places_pilot_area AS places INNER JOIN streets_pilot_area AS street ON places.id_street = street.id WHERE places.number = 0 AND street.id = streetId ORDER BY date DESC LIMIT 1 ) As zeroPt);
IF equals = TRUE THEN
newGeom := (SELECT ST_LineInterpolatePoint(streetGeom, numberPlace/streetSize));
ELSE
newStreetGeom := (SELECT ST_Reverse(ST_GeometryN(ST_LineMerge(geom),1)) FROM streets_pilot_area WHERE id = streetId);
newGeom := (SELECT ST_LineInterpolatePoint(newStreetGeom, numberPlace/streetSize));
END IF;
IF newGeom IS NOT NULL THEN
RETURN st_astext(newGeom);
ELSE
RETURN NULL;
END IF;
RAISE NOTICE 'Processando streetId: %, numberPlace: %', streetId, numberPlace;

-- Busca a geometria do local com número 0 para referência
SELECT places.geom INTO zeroGeom
FROM places_pilot_area AS places
INNER JOIN streets_pilot_area AS street ON places.id_street = street.id
WHERE places.number = 0 AND street.id = streetId
ORDER BY date DESC
LIMIT 1;
RAISE NOTICE 'zeroGeom: %', ST_AsText(zeroGeom);

-- Busca e une as geometrias da rua, filtrando por tipos de linha
SELECT ST_LineMerge(geom) INTO streetGeom
FROM streets_pilot_area
WHERE id = streetId AND ST_GeometryType(geom) IN ('ST_LineString', 'ST_MultiLineString');
RAISE NOTICE 'streetGeom (após LineMerge e filtro): %', ST_AsText(streetGeom);
RAISE NOTICE 'Tipo de streetGeom: %', ST_GeometryType(streetGeom);

-- Calcula o comprimento da rua
SELECT ST_Length(ST_Transform(geom, 29100)) INTO streetSize
FROM streets_pilot_area
WHERE id = streetId;
RAISE NOTICE 'streetSize: %', streetSize;

-- Busca o ponto inicial da rua
SELECT ST_StartPoint(ST_LineMerge(geom)) INTO startPoint
FROM streets_pilot_area
WHERE id = streetId AND ST_GeometryType(geom) IN ('ST_LineString', 'ST_MultiLineString');
RAISE NOTICE 'startPoint: %', ST_AsText(startPoint);

-- Verifica se o ponto inicial está contido em um buffer ao redor da geometria do número 0
SELECT ST_Contains(
(SELECT ST_Buffer(ST_StartPoint(ST_LineMerge(geom)), 0.0002) FROM streets_pilot_area WHERE id = streetId AND ST_GeometryType(geom) IN ('ST_LineString', 'ST_MultiLineString')),
zeroGeom
) INTO equals;
RAISE NOTICE 'equals: %', equals;

-- Calcula o ponto interpolado com base na direção da rua
IF streetGeom IS NOT NULL AND ST_GeometryType(streetGeom) = 'ST_LineString' AND streetSize > 0 THEN
fraction := numberPlace / streetSize;
fraction := GREATEST(0, LEAST(1, fraction)); -- Garante que a fração esteja entre 0 e 1
SELECT ST_LineInterpolatePoint(streetGeom, fraction) INTO newGeom;
RAISE NOTICE 'newGeom (caso equals TRUE), fraction: %, newGeom: %', fraction, ST_AsText(newGeom); -- CORRIGIDO
ELSE
newGeom := NULL;
RAISE NOTICE 'newGeom definido como NULL (streetGeom não é LINESTRING ou é NULL ou streetSize <= 0)';
END IF;

IF newGeom IS NULL THEN
IF streetGeom IS NOT NULL AND ST_GeometryType(streetGeom) = 'ST_LineString' AND streetSize > 0 THEN
SELECT ST_Reverse(ST_GeometryN(ST_LineMerge(geom),1)) INTO newStreetGeom
FROM streets_pilot_area
WHERE id = streetId AND ST_GeometryType(geom) IN ('ST_LineString', 'ST_MultiLineString');
RAISE NOTICE 'newStreetGeom (após Reverse e GeometryN): %', ST_AsText(newStreetGeom);
RAISE NOTICE 'Tipo de newStreetGeom: %', ST_GeometryType(newStreetGeom);
IF newStreetGeom IS NOT NULL AND ST_GeometryType(newStreetGeom) = 'ST_LineString' THEN
fraction := numberPlace / streetSize;
fraction := GREATEST(0, LEAST(1, fraction)); -- Garante que a fração esteja entre 0 e 1
SELECT ST_LineInterpolatePoint(newStreetGeom, fraction) INTO newGeom;
RAISE NOTICE 'newGeom (caso equals FALSE), fraction: %, newGeom: %', fraction, ST_AsText(newGeom); -- CORRIGIDO
ELSE
newGeom := NULL;
RAISE NOTICE 'newGeom definido como NULL (newStreetGeom não é LINESTRING ou é NULL)';
END IF;
END IF;
END IF;

-- Retorna a geometria como texto, se não for nula
IF newGeom IS NOT NULL THEN
RETURN st_astext(newGeom);
ELSE
RETURN NULL;
END IF;
END;
$BODY$
LANGUAGE plpgsql;
Expand Down
29 changes: 27 additions & 2 deletions sql/02_post_processing.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
-- Consulta para identificar valores inválidos de id_street na sua tabela
SELECT DISTINCT t.id_street
FROM public.${table_name} t
LEFT JOIN public.streets_pilot_area s ON t.id_street = s.id
WHERE s.id IS NULL AND t.id_street IS NOT NULL;

-- *** IMPORTANTE: Execute a consulta acima para identificar os valores problemáticos. ***

-- Correção: Remover os registros da sua tabela que possuem valores de id_street inválidos
DELETE FROM public.${table_name}
WHERE id_street IN (
SELECT t.id_street
FROM public.${table_name} t
LEFT JOIN public.streets_pilot_area s ON t.id_street = s.id
WHERE s.id IS NULL AND t.id_street IS NOT NULL
);

-- *** Após executar a exclusão dos registros inválidos, prossiga com o restante do script. ***

ALTER TABLE public.${table_name} ADD COLUMN geom geometry(Point, 4326);

UPDATE public.${table_name} SET geom = ST_SetSRID(coordinate, 4326);
Expand Down Expand Up @@ -30,8 +49,14 @@ ALTER TABLE public.${table_name} ALTER COLUMN last_month TYPE integer USING last

ALTER TABLE public.${table_name} ALTER COLUMN last_year TYPE integer USING last_year::integer;

ALTER TABLE public.${table_name} ADD CONSTRAINT ${table_name}_constraint_fk_id_street FOREIGN KEY (id_street) REFERENCES public.streets_pilot_area (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE public.${table_name}
ADD CONSTRAINT ${table_name}_constraint_fk_id_street
FOREIGN KEY (id_street)
REFERENCES public.streets_pilot_area (id)
MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;

ALTER TABLE public.${table_name} RENAME index TO id;

ALTER TABLE public.${table_name} ADD CONSTRAINT ${table_name}_pk_id PRIMARY KEY (id);
ALTER TABLE public.${table_name} ADD CONSTRAINT ${table_name}_pk_id PRIMARY KEY (id);