digital-guard / preserv

Digital Preservation Project
http://git.digital-guard.org/preserv
Apache License 2.0
0 stars 0 forks source link

ERROR: lwcollection_construct: mixed dimension geometries: 2/0 #102

Closed 0e1 closed 2 years ago

0e1 commented 2 years ago

A aplicação da função ingest.feature_asis_assign_volume retorna

ERROR: lwcollection_construct: mixed dimension geometries: 2/0

no processo de ingestão do layer nsvia de BR/PR/Araucaria/_pk0061.01:

ERROR:  lwcollection_construct: mixed dimension geometries: 2/0
CONTEXT:  SQL statement "WITH get_layer_type AS (SELECT (ingest.donated_PackComponent_geomtype(p_file_id))[1] AS gtype)
    SELECT to_jsonb(t3)            FROM (
        SELECT n, CASE gtype
            WHEN 'poly'  THEN 'polygons'
            WHEN 'line'  THEN 'segments'
            WHEN 'point'  THEN 'points'
            END n_unit,
        size, CASE gtype
            WHEN 'poly'  THEN 'km2'
            WHEN 'line'  THEN 'km'
            ELSE  ''
            END size_unit,
            bbox_km2,
            size_mdn
        FROM (
            SELECT gtype, n, CASE gtype
                WHEN 'poly'  THEN round( ST_Area(geom,true)/1000000.0)::int
                WHEN 'line'  THEN round( ST_Length(geom,true)/1000.0)::int
                ELSE  null::int
            END size,
            round( (ST_Area(ST_OrientedEnvelope(geom),true)/1000000)::numeric, 1)::int AS bbox_km2,
            round(size_mdn::numeric,3) AS size_mdn
            FROM (
                SELECT count(*) n, st_collect(geom) as geom, CASE gtype --(gtype||iif(p_usemedian,'','_no'::text))
                    WHEN 'poly'  THEN percentile_disc (0.5) WITHIN GROUP(ORDER BY ST_Area(geom,true)) /1000000.0
                    WHEN 'line'  THEN percentile_disc (0.5) WITHIN GROUP(ORDER BY ST_Length(geom,true)) /1000.0
                    ELSE  null::float
                    END size_mdn
                FROM ingest.feature_asis, get_layer_type
                WHERE file_id=p_file_id
                GROUP BY gtype
            ) t1a, get_layer_type
        ) t2
    ) t3"
PL/pgSQL function ingest.feature_asis_assign_volume(bigint,boolean,boolean) line 46 at SQL statement
SQL statement "UPDATE ingest.donated_PackComponent
    SET proc_step=2,   -- if insert process occurs after q_query.
        lineage = lineage || ingest.feature_asis_assign(q_file_id)
    WHERE id=q_file_id"
PL/pgSQL function ingest.any_load_assign(text,text,bigint) line 8 at SQL statement
make: *** [makefile:68: nsvia] Error 1

Saída completa da ingestão do layer nsvia:

make nsvia pg_db=ingest99 nointeraction=y

------------------------------------------
------ BR-PR-Araucaria  ------
------ Layer tipo nsvia_full  ------
-- Incluindo dados do arquivo-1 do package-7600006101102 na base ingest99 --
 Nome-hash do arquivo-1: 52302cd28b0d4e36ba923a7f1fc82ff4d16f544a92b667933f8b46e036213b88.zip
 Tabela do layer: pk7600006101102_p1_nsvia
 Sub-arquivos do arquivo-1 com o conteúdo alvo: '*Bairros*' '*Localidades Rurais*'
 Tema dos sub-arquivos: Todos os shapefiles
Run with tmux and sudo! (DANGER: seems not idempotent on psql)
claiton
Above user is root? If not, you have permissions for all paths?
psql postgres://postgres@localhost/ingest99 -c "DROP TABLE IF EXISTS pk7600006101102_p1_nsvia CASCADE"
NOTICE:  table "pk7600006101102_p1_nsvia" does not exist, skipping
DROP TABLE
Extracting ....
cd /tmp/sandbox/_pkBR611_002; 7z  x -y /var/www/preserv.addressforall.org/download/52302cd28b0d4e36ba923a7f1fc82ff4d16f544a92b667933f8b46e036213b88.zip '*Bairros*' '*Localidades Rurais*' ; chmod -R a+rwx . > /dev/null

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=C.UTF-8,Utf16=on,HugeFiles=on,64 bits,4 CPUs DO-Regular (306F2),ASM,AES-NI)

Scanning the drive for archives:
1 file, 850728 bytes (831 KiB)                        

Extracting archive: /var/www/preserv.addressforall.org/download/52302cd28b0d4e36ba923a7f1fc82ff4d16f544a92b667933f8b46e036213b88.zip
--
Path = /var/www/preserv.addressforall.org/download/52302cd28b0d4e36ba923a7f1fc82ff4d16f544a92b667933f8b46e036213b88.zip
Type = zip
Physical Size = 850728

Everything is Ok

Files: 10
Size:       771882
Compressed: 850728
Conferindo se SRID 29192 está configurado:
 srid  |                                            proj4text                                            
-------+-------------------------------------------------------------------------------------------------
 29192 | +proj=utm +zone=22 +south +ellps=aust_SA +towgs84=-66.87,4.37,-38.52,0,0,0,0 +units=m +no_defs 
(1 row)

Executando shp2pgsql ...
cd /tmp/sandbox/_pkBR611_002; find /tmp/sandbox/_pkBR611_002 -path "*Bairros*.shp" -exec sh -c "psql postgres://postgres@localhost/ingest99 -c 'DROP TABLE IF EXISTS pk7600006101102_p1_nsvia'; shp2pgsql -D   -s 29192 '{}' pk7600006101102_p1_nsvia | psql -q postgres://postgres@localhost/ingest99; psql postgres://postgres@localhost/ingest99 -c \"SELECT ingest.any_load('shp2sql','$(find /tmp/sandbox/_pkBR611_002 -path "*Bairros*.shp" | head -n 1)','nsvia_full','pk7600006101102_p1_nsvia','7600006101102','52302cd28b0d4e36ba923a7f1fc82ff4d16f544a92b667933f8b46e036213b88.zip',array['gid', 'nome AS ns_name', 'geom'],5,1,True)\"; chmod -R a+rx . 2> /dev/null" \;
NOTICE:  table "pk7600006101102_p1_nsvia" does not exist, skipping
DROP TABLE
Field id is an FTDouble with width 10 and precision 0
Field fid_ is an FTDouble with width 10 and precision 0
Field level is an FTDouble with width 10 and precision 0
Field color is an FTDouble with width 10 and precision 0
Field area is an FTDouble with width 24 and precision 15
Field area_1 is an FTDouble with width 24 and precision 15
Shapefile type: PolygonZ
Postgis type: MULTIPOLYGON[4]
                             addgeometrycolumn                             
---------------------------------------------------------------------------
 public.pk7600006101102_p1_nsvia.geom SRID:29192 TYPE:MULTIPOLYGON DIMS:4 
(1 row)

NOTICE:  Self-intersection at or near point -49.418645924556891 -25.557199318401143 0
NOTICE:  Self-intersection at or near point -49.418645924556891 -25.557199318401143 0
NOTICE:  feature_asis_assign_volume : f
                              any_load                              
--------------------------------------------------------------------
 From file_id=2 inserted type=nsvia_full.                          +
                                                                   +
         Statistics:                                               +
 .                                                                 +
         Before deduplication:                                     +
                                                                   +
         Originals: 19 items.                                      +
                                                                   +
         Not Intersecs: 0 items.                                   +
                                                                   +
         Invalid: 1 items.                                         +
                                                                   +
         Not simple: 0 items.                                      +
                                                                   +
         Empty: 0 items.                                           +
                                                                   +
         Small: 0 items.                                           +
                                                                   +
         Null: 0 items.                                            +
                                                                   +
         Invalid geometry type: 0 items.                           +
                                                                   +
         Not closed: 0 items.                                      +
                                                                   +
         Large: 0 items.                                           +
                                                                   +
         Inserted in feature_asis: 18 items.                       +
                                                                   +
         Inserted in feature_asis_discarded: 1 items.              +
                                                                   +
                                                                   +
         After deduplication:                                      +
                                                                   +
         Removed duplicates from feature_asis: 0 items.            +
                                                                   +
         Inserted in feature_asis_discarded (duplicates): 0 items. +
                                                                   +
         Inserted in feature_asis (aggregated duplicates): 0 items.+
                                                                   +
         Resulting in feature_asis: 18                             +

(1 row)

cd /tmp/sandbox/_pkBR611_002; find /tmp/sandbox/_pkBR611_002 -path "*Localidades Rurais*.shp" -exec sh -c "psql postgres://postgres@localhost/ingest99 -c 'DROP TABLE IF EXISTS pk7600006101102_p1_nsvia'; shp2pgsql -D   -s 29192 '{}' pk7600006101102_p1_nsvia | psql -q postgres://postgres@localhost/ingest99; psql postgres://postgres@localhost/ingest99 -c \"SELECT ingest.any_load('shp2sql','$(find /tmp/sandbox/_pkBR611_002 -path "*Bairros*.shp" | head -n 1)','nsvia_full','pk7600006101102_p1_nsvia','7600006101102','52302cd28b0d4e36ba923a7f1fc82ff4d16f544a92b667933f8b46e036213b88.zip',array['gid', 'nomes AS ns_name', 'geom'],5,1,False)\"; chmod -R a+rx . 2> /dev/null" \;
DROP TABLE
Field id is an FTDouble with width 10 and precision 0
Field area_km2 is an FTDouble with width 10 and precision 0
Field area_m2 is an FTDouble with width 24 and precision 15
Shapefile type: Polygon
Postgis type: MULTIPOLYGON[2]
                             addgeometrycolumn                             
---------------------------------------------------------------------------
 public.pk7600006101102_p1_nsvia.geom SRID:29192 TYPE:MULTIPOLYGON DIMS:2 
(1 row)

NOTICE:  Ring Self-intersection at or near point -49.499055304110669 -25.505735569026864
NOTICE:  Ring Self-intersection at or near point -49.393720759992696 -25.683581696329217
NOTICE:  Ring Self-intersection at or near point -49.499055304110669 -25.505735569026864
NOTICE:  Ring Self-intersection at or near point -49.393720759992696 -25.683581696329217
                              any_load                              
--------------------------------------------------------------------
 From file_id=2 inserted type=nsvia_full.                          +
                                                                   +
         Statistics:                                               +
 .                                                                 +
         Before deduplication:                                     +
                                                                   +
         Originals: 41 items.                                      +
                                                                   +
         Not Intersecs: 0 items.                                   +
                                                                   +
         Invalid: 2 items.                                         +
                                                                   +
         Not simple: 0 items.                                      +
                                                                   +
         Empty: 0 items.                                           +
                                                                   +
         Small: 0 items.                                           +
                                                                   +
         Null: 0 items.                                            +
                                                                   +
         Invalid geometry type: 0 items.                           +
                                                                   +
         Not closed: 0 items.                                      +
                                                                   +
         Large: 0 items.                                           +
                                                                   +
         Inserted in feature_asis: 39 items.                       +
                                                                   +
         Inserted in feature_asis_discarded: 2 items.              +
                                                                   +
                                                                   +
         After deduplication:                                      +
                                                                   +
         Removed duplicates from feature_asis: 2 items.            +
                                                                   +
         Inserted in feature_asis_discarded (duplicates): 2 items. +
                                                                   +
         Inserted in feature_asis (aggregated duplicates): 1 items.+
                                                                   +
         Resulting in feature_asis: 38                             +

(1 row)

psql postgres://postgres@localhost/ingest99 -c "SELECT ingest.any_load_assign( '$(find /tmp/sandbox/_pkBR611_002 -path "*Bairros*.shp" | head -n 1)','nsvia_full','7600006101102' )"
NOTICE:  feature_asis_assign_volume : f
ERROR:  lwcollection_construct: mixed dimension geometries: 2/0
CONTEXT:  SQL statement "WITH get_layer_type AS (SELECT (ingest.donated_PackComponent_geomtype(p_file_id))[1] AS gtype)
    SELECT to_jsonb(t3)            FROM (
        SELECT n, CASE gtype
            WHEN 'poly'  THEN 'polygons'
            WHEN 'line'  THEN 'segments'
            WHEN 'point'  THEN 'points'
            END n_unit,
        size, CASE gtype
            WHEN 'poly'  THEN 'km2'
            WHEN 'line'  THEN 'km'
            ELSE  ''
            END size_unit,
            bbox_km2,
            size_mdn
        FROM (
            SELECT gtype, n, CASE gtype
                WHEN 'poly'  THEN round( ST_Area(geom,true)/1000000.0)::int
                WHEN 'line'  THEN round( ST_Length(geom,true)/1000.0)::int
                ELSE  null::int
            END size,
            round( (ST_Area(ST_OrientedEnvelope(geom),true)/1000000)::numeric, 1)::int AS bbox_km2,
            round(size_mdn::numeric,3) AS size_mdn
            FROM (
                SELECT count(*) n, st_collect(geom) as geom, CASE gtype --(gtype||iif(p_usemedian,'','_no'::text))
                    WHEN 'poly'  THEN percentile_disc (0.5) WITHIN GROUP(ORDER BY ST_Area(geom,true)) /1000000.0
                    WHEN 'line'  THEN percentile_disc (0.5) WITHIN GROUP(ORDER BY ST_Length(geom,true)) /1000.0
                    ELSE  null::float
                    END size_mdn
                FROM ingest.feature_asis, get_layer_type
                WHERE file_id=p_file_id
                GROUP BY gtype
            ) t1a, get_layer_type
        ) t2
    ) t3"
PL/pgSQL function ingest.feature_asis_assign_volume(bigint,boolean,boolean) line 46 at SQL statement
SQL statement "UPDATE ingest.donated_PackComponent
    SET proc_step=2,   -- if insert process occurs after q_query.
        lineage = lineage || ingest.feature_asis_assign(q_file_id)
    WHERE id=q_file_id"
PL/pgSQL function ingest.any_load_assign(text,text,bigint) line 8 at SQL statement
make: *** [makefile:68: nsvia] Error 1
0e1 commented 2 years ago

O problema acontece em decorrência da aplicação de ST_Collect em dados com coordenadas XY e XYZ , no trecho da função _ingest.feature_asis_assignvolume:

SELECT count(*) n, st_collect(geom) as geom, CASE gtype --(gtype||iif(p_usemedian,'','_no'::text))
    WHEN 'poly'  THEN percentile_disc (0.5) WITHIN GROUP(ORDER BY ST_Area(geom,true)) /1000000.0
    WHEN 'line'  THEN percentile_disc (0.5) WITHIN GROUP(ORDER BY ST_Length(geom,true)) /1000.0
    ELSE  null::float
    END size_mdn

nsvia possui dois arquivos shapefile:

A solução utilizada foi aplicar ST_Force2D para forçar as geometrias XYZ em XY.

@crebollobr Você pode testar a ingestão e geração dos arquivos publicáveis para BR/PR/Araucaria/_pk0061.01. Usar uma base nova.

0e1 commented 2 years ago

Caso encontrar problemas, reabrir a issue.