[postgis-users] Select polygons within polygon with PostGIS 2.0

Sandro Santilli strk at keybit.net
Thu Oct 11 10:10:33 PDT 2012


On Thu, Oct 11, 2012 at 01:21:25PM +0200, Michal Zimmermann wrote:
> Yep, I have TopoGeometry fields.
> -- counties
> "Topology topo_kraje (12), SRID 4326, precision 0
> 36 nodes, 48 edges, 14 faces, 14 topogeoms in 1 layers
> Layer 1, type Polygonal (3), 14 topogeoms
>  Deploy: edpp.kraje.topo
> "
> -- districts
> "Topology topo_orp (13), SRID 4326, precision 0
> 962 nodes, 1611 edges, 651 faces, 206 topogeoms in 1 layers
> Layer 1, type Polygonal (3), 206 topogeoms
>  Deploy: edpp.orp.topo
> "

Those are 2 distinct topologies.

What I meant was a single topology with 2 layers.
First layer (simple) would be the districts and
second layer (hierarchical) would be the counties,
defined by the districts that make them up.

Building the TopoGeometry in the second layer won't
be possible with the toTopoGeom function, but you'll
have to use the CreateTopogeom function, using the first
layer id as the "element_type" and the TopoGeometry.id as
the "element_id" of the topoelementarray.

Note that you will still need ST_Covers to find which
TopoGeometry objects of the first layer will define
those of the second layer. But only the first time.

Mind you: all of this is very new and experimental, so
only move further if you're ready to get your hands dirty
and try something new. Beside, I just realized that the
documentation for CreateTopoGeom (the function you would
use to construct the hierarchical TopoGeometry objects)
doesn't contain any example about building hierarchical
TopoGeometries. It would be something like this:

 UPDATE countytable SET topogeom =
    CreateTopoGeom('topo_orp', 3, -- areal type
                               2, -- hierarchical layer id
                               TopoElementArray_agg(ARRAY[id(d.topogeom), 1])
    FROM edpp.orp.topo d;

The above code is untested

--strk;

 http://www.cartodb.com - Map, analyze and build applications with your data

                                       ~~ http://strk.keybit.net 



> 
> On 10/11/12, Sandro Santilli <strk at keybit.net> wrote:
> > On Thu, Oct 11, 2012 at 12:10:34PM +0200, Michal Zimmermann wrote:
> >> Sandro,
> >> earlier you said
> >> >One benefit is making the spatial relationships explicit, so that
> >> > you could encode your counties as being composed by the districts,
> >> > and the districts would be composed by faces, which would be defined
> >> > by (shared) edges.
> >> > At that point querying for "all districts in a county" would just be
> >> > a matter of listing the components of a "county" TopoGeometry.
> >>
> >> Does this mean it is better approach to have only one topology enabled
> >> layer (in my case districts) with features having some id of which
> >> county they belong to? In the end, I need to have county > districts >
> >> cadastral areas chain (all of them being represented as polygons).
> >> Right now I have both counties and districts layer with topology, but
> >> I can't see a way to join them (e. g. to "select all districts from
> >> counties where county.id = 1").
> >
> > You mean you have TopoGeometry fields ?
> > Show the output of TopologySummary(<your_topology_name>)
> >
> > --strk;
> >
> >  http://www.cartodb.com - Map, analyze and build applications with your
> > data
> >
> >                                        ~~ http://strk.keybit.net
> >
> > _______________________________________________
> > postgis-users mailing list
> > postgis-users at postgis.refractions.net
> > http://postgis.refractions.net/mailman/listinfo/postgis-users
> >
> 
> 
> -- 
> Michal Zimmermann (zimmi)
> WWW: http://www.zimmi.cz
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users



More information about the postgis-users mailing list