Re: [Qgis-user] Using aggregates functions to count intersected features from another layer

2016-10-27 Thread DelazJ
Thanks to you and for the ongoing work!

2016-10-20 8:14 GMT+02:00 Matthias Kuhn :

> On 10/20/2016 12:33 AM, Nyall Dawson wrote:
> > On 19 October 2016 at 22:22, Neumann, Andreas 
> wrote:
> > - attributes from the parent feature are automatically available
> > within the filter, UNLESS there's a duplicate field name from the
> > child feature
>
> I like this, e.g. PostgreSQL handles it the same way for joined fields.
> But it warns in case of duplication and requires an explicit source
> table statement in case of duplication. In the case where the child
> feature suddenly gets a new field with the same name, the semantic of
> the expression should not silently change but a warning be issued.
>
> > - expose the parent feature via the variable @parent. This could be
> > used with the functions geometry(@parent), attribute(@parent,
> > "some_dup_field_name")
>
> Based on above statement, there should also be a @child variable.
> Or attributes could be exposed as parent.attr / child.attr.
>
> >
> > Then you'd be able to write:
> >
> > aggregate ('mypoint', 'count', "id", intersects ($geometry,
> geometry(@parent)))
>
> aggregate('mypoint', 'count', "id", mypoint.fk = @parent.id))
>
> or
>
> aggregate('mypoint', 'count', "id", attribute(@child, "id") =
> attribute(@parent, "id"))
>
> # Error in case both have a field "id"
> aggregate('mypoint', 'count', "id", mypoint.fk = "id"))
>
> >
> > The trickiest part in implementing this would be making sure the
> > current aggregate value cache correctly handles use of parent feature
> > attributes/geometry.
> >
> > Re virtual layers: I've always seen these as a "heavier" (+ more
> > powerful!) approach, which is OK for some use cases but for others (Eg
> > data defined controls, composer labels, etc) it's preferable to have
> > these calculations available directly within the expression engine.
>
> I also think this needs to be fixed in expressions. I have a use-case
> for it with default values at the moment.
>
> Matthias
> ___
> Qgis-user mailing list
> Qgis-user@lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
>
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user

Re: [Qgis-user] Using aggregates functions to count intersected features from another layer

2016-10-27 Thread DelazJ
Hi,


2016-10-19 21:53 GMT+02:00 Matthias Kuhn :

> Hi,
> The Expressions Plus plugin is there for sharing expressions that are of
> broader interest but for whatever reason did not make it (yet) to core [1]
>
> Though I have it installed, I wasn't aware of this objective. And I think
there are developers that may be in the same case.
Need some advertisement?


> Would be great to push there whatever is interesting so we don't have to
> install a bazillion different plugins.
>
> While it can be used as a repository for developers, I think for the end
user, a "Download function" button in the Function Editor dialog where he
can pick the functions he needs would be easier to use.
Am I repeating Akbar GSOC on another feature?

Regards,
Harrissou


> Matthias
>
> [1] https://plugins.qgis.org/plugins/qgsexpressionsplus/
>
>
> On 19/10/16 21:42, DelazJ wrote:
>
> Hi all,
> Thank you all for your answers. This is really a great community! I
> already knew that but let me say it loudly. It also shows all the
> capabilities of QGIS to solve a problem.
>
> Nicolas, as Andreas said, I'm looking for something dynamic, live.
>
> The virtual layer can indeed be an option despite the creation of an
> intermediate but somehow live layer. Would be nice to have Andreas
> questions documented in the user manual so that users are fully aware of
> any potential limitations of the feature or its great power.
>
> Another powerful feature I often neglect is the function editor. Maybe
> because there are so many functions in the list that I end up thinking that
> their combination would be enough. I think it's the way I will go as no
> intermediate layer is involved and despite your remarks (which are not far
> from Andreas questions about virtual layers). Thank you Germán for
> reminding me.
> That makes me wonder: we have in QGIS, ways to share processing scripts
> and models, to share symbols, styles... What about something to share
> custom expression functions? Plugins somehow already do that but I think
> there are many people that have an operational code (that fills some small
> and common needs like mine) but don't have time/skills to create the Gui
> around. Does it sound reasonable/feasible? Maybe should I open a discussion
> in dev list (or a ticket)?
>
> Back to the approach I was following to solve the issue (combining default
> functions in expression) may I understand that it was endless? No way to
> group by when using aggregate function...?
>
> Greetings,
> Harrissou
>
> Envoyé depuis mon HTC
>
> - Reply message -
> De : "Germán Carrillo" 
> Pour : "Neumann, Andreas" , "Harrissou 'DelazJ'" <
> del...@gmail.com>
> Cc : "Nathan Woodrow" , "qgis-user" <
> qgis-user@lists.osgeo.org>, "Nicolas Cadieux" <
> nicolas.cadi...@archeotec.ca>
> Objet : [Qgis-user] Using aggregates functions to count intersected
> features from another layer
> Date : mer., oct. 19, 2016 18:04
>
> Hi All,
>
>
> Harrissou, have a look at [1] for a very similar question and one possible
> solution using the Function Editor (of course, instead of sum you would use
> count).
>
> Do you other devs find that approach useful? Any hint for keeping the
> index up-to-date?
>
> Is there any interest in having this kind of functions available for QGIS
> expressions? I could help with that.
>
>
> Regards,
>
> Germán
> --
> [1] http://gis.stackexchange.com/a/212762/4972
>
>
> 2016-10-19 7:42 GMT-05:00 Neumann, Andreas :
>
>> Good idea to use a virtual layer for that! It is probably also more
>> efficient than a QGIS expression.
>>
>> Just to understand the virtual layers correctly:
>>
>> when is the query behind the virtual layer executed?
>>
>> - at every redraw?
>>
>> - once at creation?
>>
>> - at project reload?
>>
>> Aren't the virtual layers automatically updated, at least when the
>> project reloads?
>>
>> Are the results cached or not?
>>
>> Would also make sense to add a "update" option for a virtual layer, if
>> that doesn't exist yet.
>>
>> Greetings,
>>
>> Andreas
>>
>>
>>
>> On 2016-10-19 14:32, Nathan Woodrow wrote:
>>
>> Maybe using a virtual layer query via DB Manager will work.  You have
>> full SQL join support. Speed isn't always the best but gives you the full
>> power of SQL which is the correct way to do this IMO.
>>
>> E.g SELECT LayerA.id, COUNT(*) FROM layerA
>> JOIN layerB ON ST_WithIn(layerA.geometry, layerB.geometry)
>> GROUP BY layerA.type
>>
>> Although you can't do an update but you can make a new layer with the new
>> counts.
>>
>> - Nathan
>>
>> On Wed, Oct 19, 2016 at 10:22 PM, Neumann, Andreas 
>> wrote:
>>
>>> Well yes - but that is not a "live" point in polygon. It create separate
>>> layers which need to be kept up-to-date.
>>>
>>> Harrissou was after a "live" point in polygon, which is automatically
>>> kept up-to-date through a QGIS expression.
>>>
>>> Maybe Nyall knows how to write the correct aggregate expression for that?
>>>
>>> Greetings,
>>>
>>> Andreas
>>>
>>> On 2016-10-19 14:11, Nicolas Cadieux wrote:

Re: [Qgis-user] Using aggregates functions to count intersected features from another layer

2016-10-19 Thread Matthias Kuhn
On 10/20/2016 12:33 AM, Nyall Dawson wrote:
> On 19 October 2016 at 22:22, Neumann, Andreas  wrote:
> - attributes from the parent feature are automatically available
> within the filter, UNLESS there's a duplicate field name from the
> child feature

I like this, e.g. PostgreSQL handles it the same way for joined fields.
But it warns in case of duplication and requires an explicit source
table statement in case of duplication. In the case where the child
feature suddenly gets a new field with the same name, the semantic of
the expression should not silently change but a warning be issued.

> - expose the parent feature via the variable @parent. This could be
> used with the functions geometry(@parent), attribute(@parent,
> "some_dup_field_name")

Based on above statement, there should also be a @child variable.
Or attributes could be exposed as parent.attr / child.attr.

> 
> Then you'd be able to write:
> 
> aggregate ('mypoint', 'count', "id", intersects ($geometry, 
> geometry(@parent)))

aggregate('mypoint', 'count', "id", mypoint.fk = @parent.id))

or

aggregate('mypoint', 'count', "id", attribute(@child, "id") =
attribute(@parent, "id"))

# Error in case both have a field "id"
aggregate('mypoint', 'count', "id", mypoint.fk = "id"))

> 
> The trickiest part in implementing this would be making sure the
> current aggregate value cache correctly handles use of parent feature
> attributes/geometry.
> 
> Re virtual layers: I've always seen these as a "heavier" (+ more
> powerful!) approach, which is OK for some use cases but for others (Eg
> data defined controls, composer labels, etc) it's preferable to have
> these calculations available directly within the expression engine.

I also think this needs to be fixed in expressions. I have a use-case
for it with default values at the moment.

Matthias
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user

Re: [Qgis-user] Using aggregates functions to count intersected features from another layer

2016-10-19 Thread Nyall Dawson
On 19 October 2016 at 22:22, Neumann, Andreas  wrote:
> Well yes - but that is not a "live" point in polygon. It create separate
> layers which need to be kept up-to-date.
>
> Harrissou was after a "live" point in polygon, which is automatically kept
> up-to-date through a QGIS expression.
>
> Maybe Nyall knows how to write the correct aggregate expression for that?

It's not possible using aggregate expressions at the moment - the
aggregate filters only have access to the child feature's attributes +
geometry, not the parent's.

I've been thinking about how to address this, and I'm leaning toward:

- attributes from the parent feature are automatically available
within the filter, UNLESS there's a duplicate field name from the
child feature
- expose the parent feature via the variable @parent. This could be
used with the functions geometry(@parent), attribute(@parent,
"some_dup_field_name")

Then you'd be able to write:

aggregate ('mypoint', 'count', "id", intersects ($geometry, geometry(@parent)))

The trickiest part in implementing this would be making sure the
current aggregate value cache correctly handles use of parent feature
attributes/geometry.

Re virtual layers: I've always seen these as a "heavier" (+ more
powerful!) approach, which is OK for some use cases but for others (Eg
data defined controls, composer labels, etc) it's preferable to have
these calculations available directly within the expression engine.


Nyall



>
> Greetings,
>
> Andreas
>
> On 2016-10-19 14:11, Nicolas Cadieux wrote:
>
>
> Try this.
>
> http://www.qgistutorials.com/fr/docs/points_in_polygon.html
>
> Nicolas
>
> Le 19 oct. 2016 à 06:37, DelazJ [via OSGeo.org] <[hidden email]> a écrit :
>
> Hi,
>
> I have a polygon layer and a point one.
> I'd like to calculate for each polygon feature, the number of points that it
> covers. I thought the aggregates functions could help me find an easier and
> straight expression to perform this (without creating intermediate layers)
> but I fail to find any correct syntax.
>
> I tried aggregate ('mypoint', 'count', "id", intersects ($geometry,
> geometry($currentfeature)))
>
>  And many variants of the fourth option but It always return the total of
> points or an error. Actually this option is a filter and I wonder if i'm not
> missing a "group by" option in the aggregate function (which seems to be the
> appropriate one in my case). Is it possible?
> The work around I found is to populate an ad'hoc field in the point layer
> with overlapping polygon id, thanks to the SpatialJoin plugin, then I create
> a one-to-many relation in the project between the two layers in other to use
> relation_aggregate function.
> But I expected something more direct.
>
> Any hint, please?
>
> Thanks,
> Harrissou
>
> ___
> Qgis-user mailing list
> [hidden email]
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
>
> 
> If you reply to this email, your message will be added to the discussion
> below:
> http://osgeo-org.1560.x6.nabble.com/Using-aggregates-functions-to-count-intersected-features-from-another-layer-tp5291420.html
> To start a new topic under Quantum GIS - User, email [hidden email]
> To unsubscribe from Quantum GIS - User, click here.
> NAML
>
>
> 
> View this message in context: Re: Using aggregates functions to count
> intersected features from another layer
> Sent from the Quantum GIS - User mailing list archive at Nabble.com.
>
> ___
> Qgis-user mailing list
> Qgis-user@lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
>
>
>
>
>
> ___
> Qgis-user mailing list
> Qgis-user@lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user

Re: [Qgis-user] Using aggregates functions to count intersected features from another layer

2016-10-19 Thread Matthias Kuhn
Hi,

The Expressions Plus plugin is there for sharing expressions that are of
broader interest but for whatever reason did not make it (yet) to core [1]

Would be great to push there whatever is interesting so we don't have to
install a bazillion different plugins.

Matthias

[1] https://plugins.qgis.org/plugins/qgsexpressionsplus/

On 19/10/16 21:42, DelazJ wrote:
> Hi all,
> Thank you all for your answers. This is really a great community! I
> already knew that but let me say it loudly. It also shows all the
> capabilities of QGIS to solve a problem.
>
> Nicolas, as Andreas said, I'm looking for something dynamic, live. 
>
> The virtual layer can indeed be an option despite the creation of an
> intermediate but somehow live layer. Would be nice to have Andreas
> questions documented in the user manual so that users are fully aware
> of any potential limitations of the feature or its great power.
>
> Another powerful feature I often neglect is the function editor. Maybe
> because there are so many functions in the list that I end up thinking
> that their combination would be enough. I think it's the way I will go
> as no intermediate layer is involved and despite your remarks (which
> are not far from Andreas questions about virtual layers). Thank you
> Germán for reminding me. 
> That makes me wonder: we have in QGIS, ways to share processing
> scripts and models, to share symbols, styles... What about something
> to share custom expression functions? Plugins somehow already do that
> but I think there are many people that have an operational code (that
> fills some small and common needs like mine) but don't have
> time/skills to create the Gui around. Does it sound
> reasonable/feasible? Maybe should I open a discussion in dev list (or
> a ticket)?
>
> Back to the approach I was following to solve the issue (combining
> default functions in expression) may I understand that it was endless?
> No way to group by when using aggregate function...?
>
> Greetings,
> Harrissou
>
> Envoyé depuis mon HTC
>
> - Reply message -
> De : "Germán Carrillo"  >
> Pour : "Neumann, Andreas"  >, "Harrissou 'DelazJ'"  >
> Cc : "Nathan Woodrow"  >, "qgis-user"  >, "Nicolas Cadieux"
> mailto:nicolas.cadi...@archeotec.ca>>
> Objet : [Qgis-user] Using aggregates functions to count intersected
> features from another layer
> Date : mer., oct. 19, 2016 18:04
>
> Hi All, 
>
>
> Harrissou, have a look at [1] for a very similar question and one
> possible solution using the Function Editor (of course, instead of sum
> you would use count).
>
> Do you other devs find that approach useful? Any hint for keeping the
> index up-to-date?
>
> Is there any interest in having this kind of functions available for
> QGIS expressions? I could help with that.
>
>
> Regards, 
>
> Germán
> --
> [1] http://gis.stackexchange.com/a/212762/4972
> 
>
>
> 2016-10-19 7:42 GMT-05:00 Neumann, Andreas  >:
>
> Good idea to use a virtual layer for that! It is probably also
> more efficient than a QGIS expression.
>
> Just to understand the virtual layers correctly:
>
> when is the query behind the virtual layer executed?
>
> - at every redraw?
>
> - once at creation?
>
> - at project reload?
>
> Aren't the virtual layers automatically updated, at least when the
> project reloads?
>
> Are the results cached or not?
>
> Would also make sense to add a "update" option for a virtual
> layer, if that doesn't exist yet.
>
> Greetings,
>
> Andreas
>
>  
>
> On 2016-10-19 14:32, Nathan Woodrow wrote:
>
>> Maybe using a virtual layer query via DB Manager will work.  You
>> have full SQL join support. Speed isn't always the best but gives
>> you the full power of SQL which is the correct way to do this IMO.
>>  
>> E.g SELECT LayerA.id, COUNT(*) FROM layerA 
>> JOIN layerB ON ST_WithIn(layerA.geometry, layerB.geometry)
>> GROUP BY layerA.type
>>  
>> Although you can't do an update but you can make a new layer with
>> the new counts.
>>  
>> - Nathan
>>
>> On Wed, Oct 19, 2016 at 10:22 PM, Neumann, Andreas
>> mailto:a.neum...@carto.net>> wrote:
>>
>> Well yes - but that is not a "live" point in polygon. It
>> create separate layers which need to be kept up-to-date.
>>
>> Harrissou was after a "live" point in polygon, which is
>> automatically kept up-to-date through a QGIS expression.
>>
>> Maybe Nyall knows how to write the correct aggregate
>> expression for that?
>>
>> Greetings,
>>
>> Andreas
>>
>> On 2016-10-19 14:11, Nicolas Cadieux wrote:
>>
>>  
>> Try this.
>>  
>> http://www.qgistutorials.com/fr/doc

Re: [Qgis-user] Using aggregates functions to count intersected features from another layer

2016-10-19 Thread DelazJ
 Hi all,
Thank you all for your answers. This is really a great community! I already
knew that but let me say it loudly. It also shows all the capabilities of
QGIS to solve a problem.

Nicolas, as Andreas said, I'm looking for something dynamic, live.

The virtual layer can indeed be an option despite the creation of an
intermediate but somehow live layer. Would be nice to have Andreas
questions documented in the user manual so that users are fully aware of
any potential limitations of the feature or its great power.

Another powerful feature I often neglect is the function editor. Maybe
because there are so many functions in the list that I end up thinking that
their combination would be enough. I think it's the way I will go as no
intermediate layer is involved and despite your remarks (which are not far
from Andreas questions about virtual layers). Thank you Germán for
reminding me.
That makes me wonder: we have in QGIS, ways to share processing scripts and
models, to share symbols, styles... What about something to share custom
expression functions? Plugins somehow already do that but I think there are
many people that have an operational code (that fills some small and common
needs like mine) but don't have time/skills to create the Gui around. Does
it sound reasonable/feasible? Maybe should I open a discussion in dev list
(or a ticket)?

Back to the approach I was following to solve the issue (combining default
functions in expression) may I understand that it was endless? No way to
group by when using aggregate function...?

Greetings,
Harrissou

Envoyé depuis mon HTC

- Reply message -
De : "Germán Carrillo" 
Pour : "Neumann, Andreas" , "Harrissou 'DelazJ'" <
del...@gmail.com>
Cc : "Nathan Woodrow" , "qgis-user" <
qgis-user@lists.osgeo.org>, "Nicolas Cadieux" 
Objet : [Qgis-user] Using aggregates functions to count intersected
features from another layer
Date : mer., oct. 19, 2016 18:04

Hi All,


Harrissou, have a look at [1] for a very similar question and one possible
solution using the Function Editor (of course, instead of sum you would use
count).

Do you other devs find that approach useful? Any hint for keeping the index
up-to-date?

Is there any interest in having this kind of functions available for QGIS
expressions? I could help with that.


Regards,

Germán
--
[1] http://gis.stackexchange.com/a/212762/4972


2016-10-19 7:42 GMT-05:00 Neumann, Andreas :

> Good idea to use a virtual layer for that! It is probably also more
> efficient than a QGIS expression.
>
> Just to understand the virtual layers correctly:
>
> when is the query behind the virtual layer executed?
>
> - at every redraw?
>
> - once at creation?
>
> - at project reload?
>
> Aren't the virtual layers automatically updated, at least when the project
> reloads?
>
> Are the results cached or not?
>
> Would also make sense to add a "update" option for a virtual layer, if
> that doesn't exist yet.
>
> Greetings,
>
> Andreas
>
>
>
> On 2016-10-19 14:32, Nathan Woodrow wrote:
>
> Maybe using a virtual layer query via DB Manager will work.  You have full
> SQL join support. Speed isn't always the best but gives you the full power
> of SQL which is the correct way to do this IMO.
>
> E.g SELECT LayerA.id, COUNT(*) FROM layerA
> JOIN layerB ON ST_WithIn(layerA.geometry, layerB.geometry)
> GROUP BY layerA.type
>
> Although you can't do an update but you can make a new layer with the new
> counts.
>
> - Nathan
>
> On Wed, Oct 19, 2016 at 10:22 PM, Neumann, Andreas 
> wrote:
>
>> Well yes - but that is not a "live" point in polygon. It create separate
>> layers which need to be kept up-to-date.
>>
>> Harrissou was after a "live" point in polygon, which is automatically
>> kept up-to-date through a QGIS expression.
>>
>> Maybe Nyall knows how to write the correct aggregate expression for that?
>>
>> Greetings,
>>
>> Andreas
>>
>> On 2016-10-19 14:11, Nicolas Cadieux wrote:
>>
>>
>> Try this.
>>
>> http://www.qgistutorials.com/fr/docs/points_in_polygon.html
>>
>> Nicolas
>>
>> Le 19 oct. 2016 à 06:37, DelazJ [via OSGeo.org] <[hidden email]> a
>> écrit :
>>
>> Hi,
>>
>> I have a polygon layer and a point one.
>> I'd like to calculate for each polygon feature, the number of points that
>> it covers. I thought the aggregates functions could help me find an easier
>> and straight expression to perform this (without creating intermediate
>> layers) but I fail to find any correct syntax.
>>
>> I tried aggregate ('mypoint', 'count', "id", intersects ($geometry,
>> geometry($currentfeature)))
>>
>>  And many variants of the fourth option but It always return the total of
>> points or an error. Actually this option is a filter and I wonder if i'm
>> not missing a "group by" option in the aggregate function (which seems to
>> be the appropriate one in my case). Is it possible?
>> The work around I found is to populate an ad'hoc field in the point layer
>> with overlapping polygon id, thanks to the SpatialJoin plugin, then I
>> create a on

Re: [Qgis-user] Using aggregates functions to count intersected features from another layer

2016-10-19 Thread Germán Carrillo
Hi All,


Harrissou, have a look at [1] for a very similar question and one possible
solution using the Function Editor (of course, instead of sum you would use
count).

Do you other devs find that approach useful? Any hint for keeping the index
up-to-date?

Is there any interest in having this kind of functions available for QGIS
expressions? I could help with that.


Regards,

Germán
--
[1] http://gis.stackexchange.com/a/212762/4972


2016-10-19 7:42 GMT-05:00 Neumann, Andreas :

> Good idea to use a virtual layer for that! It is probably also more
> efficient than a QGIS expression.
>
> Just to understand the virtual layers correctly:
>
> when is the query behind the virtual layer executed?
>
> - at every redraw?
>
> - once at creation?
>
> - at project reload?
>
> Aren't the virtual layers automatically updated, at least when the project
> reloads?
>
> Are the results cached or not?
>
> Would also make sense to add a "update" option for a virtual layer, if
> that doesn't exist yet.
>
> Greetings,
>
> Andreas
>
>
>
> On 2016-10-19 14:32, Nathan Woodrow wrote:
>
> Maybe using a virtual layer query via DB Manager will work.  You have full
> SQL join support. Speed isn't always the best but gives you the full power
> of SQL which is the correct way to do this IMO.
>
> E.g SELECT LayerA.id, COUNT(*) FROM layerA
> JOIN layerB ON ST_WithIn(layerA.geometry, layerB.geometry)
> GROUP BY layerA.type
>
> Although you can't do an update but you can make a new layer with the new
> counts.
>
> - Nathan
>
> On Wed, Oct 19, 2016 at 10:22 PM, Neumann, Andreas 
> wrote:
>
>> Well yes - but that is not a "live" point in polygon. It create separate
>> layers which need to be kept up-to-date.
>>
>> Harrissou was after a "live" point in polygon, which is automatically
>> kept up-to-date through a QGIS expression.
>>
>> Maybe Nyall knows how to write the correct aggregate expression for that?
>>
>> Greetings,
>>
>> Andreas
>>
>> On 2016-10-19 14:11, Nicolas Cadieux wrote:
>>
>>
>> Try this.
>>
>> http://www.qgistutorials.com/fr/docs/points_in_polygon.html
>>
>> Nicolas
>>
>> Le 19 oct. 2016 à 06:37, DelazJ [via OSGeo.org] <[hidden email]> a
>> écrit :
>>
>> Hi,
>>
>> I have a polygon layer and a point one.
>> I'd like to calculate for each polygon feature, the number of points that
>> it covers. I thought the aggregates functions could help me find an easier
>> and straight expression to perform this (without creating intermediate
>> layers) but I fail to find any correct syntax.
>>
>> I tried aggregate ('mypoint', 'count', "id", intersects ($geometry,
>> geometry($currentfeature)))
>>
>>  And many variants of the fourth option but It always return the total of
>> points or an error. Actually this option is a filter and I wonder if i'm
>> not missing a "group by" option in the aggregate function (which seems to
>> be the appropriate one in my case). Is it possible?
>> The work around I found is to populate an ad'hoc field in the point layer
>> with overlapping polygon id, thanks to the SpatialJoin plugin, then I
>> create a one-to-many relation in the project between the two layers in
>> other to use relation_aggregate function.
>> But I expected something more direct.
>>
>> Any hint, please?
>>
>> Thanks,
>> Harrissou
>>
>> ___
>> Qgis-user mailing list
>> [hidden email]
>> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
>> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
>>
>> --
>> If you reply to this email, your message will be added to the discussion
>> below:
>> http://osgeo-org.1560.x6.nabble.com/Using-aggregates-functio
>> ns-to-count-intersected-features-from-another-layer-tp5291420.html
>> To start a new topic under Quantum GIS - User, email [hidden email]
>> To unsubscribe from Quantum GIS - User, click here.
>> NAML
>> 
>>
>>
>> --
>> View this message in context: Re: Using aggregates functions to count
>> intersected features from another layer
>> 
>> Sent from the Quantum GIS - User mailing list archive
>>  at
>> Nabble.com.
>>
>> ___
>> Qgis-user mailing list
>> Qgis-user@lists.osgeo.org
>> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
>> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
>>
>>
>>
>>
>> ___

Re: [Qgis-user] Using aggregates functions to count intersected features from another layer

2016-10-19 Thread Neumann, Andreas
Good idea to use a virtual layer for that! It is probably also more
efficient than a QGIS expression. 

Just to understand the virtual layers correctly: 

when is the query behind the virtual layer executed? 

- at every redraw? 

- once at creation? 

- at project reload? 

Aren't the virtual layers automatically updated, at least when the
project reloads? 

Are the results cached or not? 

Would also make sense to add a "update" option for a virtual layer, if
that doesn't exist yet. 

Greetings, 

Andreas 

On 2016-10-19 14:32, Nathan Woodrow wrote:

> Maybe using a virtual layer query via DB Manager will work.  You have full 
> SQL join support. Speed isn't always the best but gives you the full power of 
> SQL which is the correct way to do this IMO. 
> 
> E.g SELECT LayerA.id, COUNT(*) FROM layerA  
> JOIN layerB ON ST_WithIn(layerA.geometry, layerB.geometry) 
> GROUP BY layerA.type 
> 
> Although you can't do an update but you can make a new layer with the new 
> counts.
> 
> - Nathan 
> 
> On Wed, Oct 19, 2016 at 10:22 PM, Neumann, Andreas  
> wrote:
> 
> Well yes - but that is not a "live" point in polygon. It create separate 
> layers which need to be kept up-to-date. 
> 
> Harrissou was after a "live" point in polygon, which is automatically kept 
> up-to-date through a QGIS expression. 
> 
> Maybe Nyall knows how to write the correct aggregate expression for that? 
> 
> Greetings, 
> 
> Andreas
> 
> On 2016-10-19 14:11, Nicolas Cadieux wrote: 
> 
> Try this. 
> 
> http://www.qgistutorials.com/fr/docs/points_in_polygon.html [1] 
> 
> Nicolas 
> 
> Le 19 oct. 2016 à 06:37, DelazJ [via OSGeo.org [2]] <[hidden email]> a écrit :
> 
> Hi,
> 
> I have a polygon layer and a point one. I'd like to calculate for each 
> polygon feature, the number of points that it covers. I thought the 
> aggregates functions could help me find an easier and straight expression to 
> perform this (without creating intermediate layers) but I fail to find any 
> correct syntax. 
> 
> I tried aggregate ('mypoint', 'count', "id", intersects ($geometry, 
> geometry($currentfeature)))
> 
> And many variants of the fourth option but It always return the total of 
> points or an error. Actually this option is a filter and I wonder if i'm not 
> missing a "group by" option in the aggregate function (which seems to be the 
> appropriate one in my case). Is it possible? 
> The work around I found is to populate an ad'hoc field in the point layer 
> with overlapping polygon id, thanks to the SpatialJoin plugin, then I create 
> a one-to-many relation in the project between the two layers in other to use 
> relation_aggregate function. 
> But I expected something more direct. 
> 
> Any hint, please?
> 
> Thanks, Harrissou 
> ___ 
> Qgis-user mailing list 
> [hidden email] 
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user [3]
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user [3] 
> 
> -
> 
> If you reply to this email, your message will be added to the discussion 
> below: 
> http://osgeo-org.1560.x6.nabble.com/Using-aggregates-functions-to-count-intersected-features-from-another-layer-tp5291420.html
>  [4] 
> To start a new topic under Quantum GIS - User, email [hidden email] 
> To unsubscribe from Quantum GIS - User, click here.
> NAML [5] 
> 
> -
> View this message in context: Re: Using aggregates functions to count 
> intersected features from another layer [6]
> Sent from the Quantum GIS - User mailing list archive [7] at Nabble.com.
> 
> ___
> Qgis-user mailing list
> Qgis-user@lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user [3]
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user [3]

___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-user [3]
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user [3] 

  

Links:
--
[1] http://www.qgistutorials.com/fr/docs/points_in_polygon.html
[2] http://OSGeo.org
[3] http://lists.osgeo.org/mailman/listinfo/qgis-user
[4]
http://osgeo-org.1560.x6.nabble.com/Using-aggregates-functions-to-count-intersected-features-from-another-layer-tp5291420.html
[5]
http://osgeo-org.1560.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml
[6]
http://osgeo-org.1560.x6.nabble.com/Using-aggregates-functions-to-count-intersected-features-from-another-layer-tp5291420p5291443.html
[7] http://osgeo-org.1560.x6.nabble.com/Quantum-GIS-User-f4125267.html
___
Qgis-us

Re: [Qgis-user] Using aggregates functions to count intersected features from another layer

2016-10-19 Thread Nathan Woodrow
Maybe using a virtual layer query via DB Manager will work.  You have full
SQL join support. Speed isn't always the best but gives you the full power
of SQL which is the correct way to do this IMO.

E.g SELECT LayerA.id, COUNT(*) FROM layerA
JOIN layerB ON ST_WithIn(layerA.geometry, layerB.geometry)
GROUP BY layerA.type

Although you can't do an update but you can make a new layer with the new
counts.

- Nathan

On Wed, Oct 19, 2016 at 10:22 PM, Neumann, Andreas 
wrote:

> Well yes - but that is not a "live" point in polygon. It create separate
> layers which need to be kept up-to-date.
>
> Harrissou was after a "live" point in polygon, which is automatically kept
> up-to-date through a QGIS expression.
>
> Maybe Nyall knows how to write the correct aggregate expression for that?
>
> Greetings,
>
> Andreas
>
> On 2016-10-19 14:11, Nicolas Cadieux wrote:
>
>
> Try this.
>
> http://www.qgistutorials.com/fr/docs/points_in_polygon.html
>
> Nicolas
>
> Le 19 oct. 2016 à 06:37, DelazJ [via OSGeo.org] <[hidden email]> a écrit :
>
> Hi,
>
> I have a polygon layer and a point one.
> I'd like to calculate for each polygon feature, the number of points that
> it covers. I thought the aggregates functions could help me find an easier
> and straight expression to perform this (without creating intermediate
> layers) but I fail to find any correct syntax.
>
> I tried aggregate ('mypoint', 'count', "id", intersects ($geometry,
> geometry($currentfeature)))
>
>  And many variants of the fourth option but It always return the total of
> points or an error. Actually this option is a filter and I wonder if i'm
> not missing a "group by" option in the aggregate function (which seems to
> be the appropriate one in my case). Is it possible?
> The work around I found is to populate an ad'hoc field in the point layer
> with overlapping polygon id, thanks to the SpatialJoin plugin, then I
> create a one-to-many relation in the project between the two layers in
> other to use relation_aggregate function.
> But I expected something more direct.
>
> Any hint, please?
>
> Thanks,
> Harrissou
>
> ___
> Qgis-user mailing list
> [hidden email]
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
>
> --
> If you reply to this email, your message will be added to the discussion
> below:
> http://osgeo-org.1560.x6.nabble.com/Using-aggregates-functions-to-count-
> intersected-features-from-another-layer-tp5291420.html
> To start a new topic under Quantum GIS - User, email [hidden email]
> To unsubscribe from Quantum GIS - User, click here.
> NAML
> 
>
>
> --
> View this message in context: Re: Using aggregates functions to count
> intersected features from another layer
> 
> Sent from the Quantum GIS - User mailing list archive
>  at
> Nabble.com.
>
> ___
> Qgis-user mailing list
> Qgis-user@lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
>
>
>
>
> ___
> Qgis-user mailing list
> Qgis-user@lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
>
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user

Re: [Qgis-user] Using aggregates functions to count intersected features from another layer

2016-10-19 Thread Neumann, Andreas
Well yes - but that is not a "live" point in polygon. It create separate
layers which need to be kept up-to-date. 

Harrissou was after a "live" point in polygon, which is automatically
kept up-to-date through a QGIS expression. 

Maybe Nyall knows how to write the correct aggregate expression for
that? 

Greetings, 

Andreas 

On 2016-10-19 14:11, Nicolas Cadieux wrote:

> Try this. 
> 
> http://www.qgistutorials.com/fr/docs/points_in_polygon.html 
> 
> Nicolas 
> 
> Le 19 oct. 2016 à 06:37, DelazJ [via OSGeo.org [2]] <[hidden email]> a écrit :
> 
>> Hi,
>> 
>> I have a polygon layer and a point one. I'd like to calculate for each 
>> polygon feature, the number of points that it covers. I thought the 
>> aggregates functions could help me find an easier and straight expression to 
>> perform this (without creating intermediate layers) but I fail to find any 
>> correct syntax. 
>> 
>> I tried aggregate ('mypoint', 'count', "id", intersects ($geometry, 
>> geometry($currentfeature)))
>> 
>> And many variants of the fourth option but It always return the total of 
>> points or an error. Actually this option is a filter and I wonder if i'm not 
>> missing a "group by" option in the aggregate function (which seems to be the 
>> appropriate one in my case). Is it possible? 
>> The work around I found is to populate an ad'hoc field in the point layer 
>> with overlapping polygon id, thanks to the SpatialJoin plugin, then I create 
>> a one-to-many relation in the project between the two layers in other to use 
>> relation_aggregate function. 
>> But I expected something more direct. 
>> 
>> Any hint, please?
>> 
>> Thanks, Harrissou 
>> ___ 
>> Qgis-user mailing list 
>> [hidden email] 
>> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
>> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user 
>> 
>> -
>> 
>> If you reply to this email, your message will be added to the discussion 
>> below: 
>> http://osgeo-org.1560.x6.nabble.com/Using-aggregates-functions-to-count-intersected-features-from-another-layer-tp5291420.html
>>  
>> To start a new topic under Quantum GIS - User, email [hidden email] 
>> To unsubscribe from Quantum GIS - User, click here.
>> NAML [1]
> 
> -
> View this message in context: Re: Using aggregates functions to count 
> intersected features from another layer [3]
> Sent from the Quantum GIS - User mailing list archive [4] at Nabble.com.
> 
> ___
> Qgis-user mailing list
> Qgis-user@lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user

  

Links:
--
[1]
http://osgeo-org.1560.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml
[2] http://OSGeo.org
[3]
http://osgeo-org.1560.x6.nabble.com/Using-aggregates-functions-to-count-intersected-features-from-another-layer-tp5291420p5291443.html
[4] http://osgeo-org.1560.x6.nabble.com/Quantum-GIS-User-f4125267.html
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user

Re: [Qgis-user] Using aggregates functions to count intersected features from another layer

2016-10-19 Thread Nicolas Cadieux
Try this.

http://www.qgistutorials.com/fr/docs/points_in_polygon.html

Nicolas

> Le 19 oct. 2016 à 06:37, DelazJ [via OSGeo.org] 
>  a écrit :
> 
> Hi,
> 
> I have a polygon layer and a point one.
> I'd like to calculate for each polygon feature, the number of points that it 
> covers. I thought the aggregates functions could help me find an easier and 
> straight expression to perform this (without creating intermediate layers) 
> but I fail to find any correct syntax. 
> 
> I tried aggregate ('mypoint', 'count', "id", intersects ($geometry, 
> geometry($currentfeature)))
> 
>  And many variants of the fourth option but It always return the total of 
> points or an error. Actually this option is a filter and I wonder if i'm not 
> missing a "group by" option in the aggregate function (which seems to be the 
> appropriate one in my case). Is it possible?
> 
> The work around I found is to populate an ad'hoc field in the point layer 
> with overlapping polygon id, thanks to the SpatialJoin plugin, then I create 
> a one-to-many relation in the project between the two layers in other to use 
> relation_aggregate function.
> But I expected something more direct.
> 
> Any hint, please?
> 
> Thanks,
> Harrissou
> 
> ___ 
> Qgis-user mailing list 
> [hidden email] 
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user 
> 
> If you reply to this email, your message will be added to the discussion 
> below:
> http://osgeo-org.1560.x6.nabble.com/Using-aggregates-functions-to-count-intersected-features-from-another-layer-tp5291420.html
> To start a new topic under Quantum GIS - User, email 
> ml-node+s1560n4125267...@n6.nabble.com 
> To unsubscribe from Quantum GIS - User, click here.
> NAML




--
View this message in context: 
http://osgeo-org.1560.x6.nabble.com/Using-aggregates-functions-to-count-intersected-features-from-another-layer-tp5291420p5291443.html
Sent from the Quantum GIS - User mailing list archive at Nabble.com.___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user