[postgis-users] Topology: error creating aggregated topogeom (at city level) from a neighborhoods topogeom

Lucas Ferreira Mation lucasmation at gmail.com
Mon Feb 1 05:03:14 PST 2016


strk, thank you once again! I works now. I comment on your comments in line
bellow and add the full code in the end, for future reference  (I couldn't
find a working example in google)

*--2) Creating the more aggregated cities table and adding a topogeometry*

> You're not defining a hierarchical layer here, but a primitive one. For a hierarchical one you'll want to pass an additional parameter specifying the cchild layer identifier.

OK, agreed. This I created a new topogeom ('tg_cities2') with this syntax

SELECT topology.addtopogeometrycolumn('topo_AC',
'public','cities','tg_cities2','POLYGON',1);

Now contents of topology.layer table looks like this:

-- 
topology_id;layer_id;shcema_name;table_name;feature_column;feature_type;level;child_id
-- 15;1;"public";"temp_geom_ac";"tg_geom_dump_utm";3;0;NULL
-- 15;2;"public";"cities";"tg_cities";3;0;NULL
-- 15;3;"public";"cities";"tg_cities2";3;1;1

Thus the layer_id for "tg_cities2" is 3 (


-- 3) adding content to "tg_cities"

Just by correcting the layed_id the previous code worked.

a) on your suggestion
>>* TopoElementArray_Agg(ARRAY[(tg_geom_dump_utm).id,(tg_geom_dump_utm).layer_id])
*
>Here you're trying to pass a "layer_id" as the "type" of component for a non-hierarchical layer, thus the error

If I understood your suggestion correctly, I should have:

*TopoElementArray_Agg(ARRAY[(tg_geom_dump_utm).id,3])
*

where "3" indicates the topogem type (area). This makes the code err, while
keeping

*TopoElementArray_Agg(ARRAY[(tg_geom_dump_utm).id,(tg_geom_dump_utm).layer_id])*

works. What is not very clear from the syntax is if the syntax of
*TopoElementArray_Agg
*

should follow the child or the parent topogeom "class" (hierarquical or not)


b) I also added a WHERE clause to the subquery that creates the
*TopoElementArray*
excluding the rows where the child topogeom is missing. Theese were
polygons of the original setcors shapefile that could not be loaed to the
child toogem, i.e., gave an error in the toTopoGeom function.



To recap, this is the code that works:


--1) creating the underlying topology elements, (sectors)

CREATE TABLE cities AS
SELECT     substring(cod_set,1,7) AS cod_mun
FROM temp_geom_ac
GROUP BY substring(cod_set,1,7)
SELECT topology.addtopogeometrycolumn('topo_AC',
'public','cities','tg_cities2','POLYGON',1);


--2) Creating the more aggregated cities table and adding a topogeometry

CREATE TABLE cities AS
SELECT 	substring(cod_set,1,7) AS cod_mun
FROM temp_geom_ac
GROUP BY substring(cod_set,1,7)
SELECT topology.addtopogeometrycolumn('topo_AC',
'public','cities','tg_cities2','POLYGON',1);


-- 3) adding content to "tg_cities"

UPDATE cities
SET tg_cities2 = CreateTopogeom(
	'topo_AC', -- topology name
	3, -- indicates topogeom type is area
	3, -- indicates the layer id, as created by "addtopogeometrycolumn"
above. Check topology.layer table if you don't know
	foo.city_faces)
FROM(	SELECT 	substring(cod_set,1,7) AS cod_mun,
		TopoElementArray_Agg(ARRAY[(tg_geom_dump_utm).id,(tg_geom_dump_utm).layer_id])
AS city_faces
	FROM temp_geom_ac
	WHERE (tg_geom_dump_utm).id IS NOT NULL -- igonres sectors that could
not be loaded to the sectors topogem (tg_geom_dump_utm)
	GROUP BY substring(cod_set,1,7)
     ) as foo
WHERE  cities.cod_mun=foo.cod_mun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20160201/e0b13843/attachment.html>


More information about the postgis-users mailing list