[GRASS-dev] How to check if a vector map is multi-layer?

Hi,

it would be nice to have in v.info or v.category the possibility to
check if a vector map comes with multiple layers.
I didn't figure out how to add that in these or one of these modules.
Perhaps I am missing something.

This test is needed e.g. in g.gui.rlisetup.

thanks
Markus

Hi,

2014-10-28 15:49 GMT+01:00 Markus Neteler <neteler@osgeo.org>:

it would be nice to have in v.info or v.category the possibility to
check if a vector map comes with multiple layers.

v.category op=report

is not enough? Martin

--
Martin Landa * http://geo.fsv.cvut.cz/gwiki/Landa *
http://www.gismentors.eu/mentors/landa

On Tue, Oct 28, 2014 at 4:01 PM, Martin Landa <landa.martin@gmail.com> wrote:

Hi,

2014-10-28 15:49 GMT+01:00 Markus Neteler <neteler@osgeo.org>:

it would be nice to have in v.info or v.category the possibility to
check if a vector map comes with multiple layers.

v.category op=report

Well, it outputs a lot of information like
...
25/28/29/26/27/138/137/136/139/23/133/135
28/26/27/138/137/136
...

Needed is a way to parse it and turn into a yes/no multilayer information.
Or, better, an additional line in
v.info -e myvector
?

Markus

Hi,

2014-10-28 16:08 GMT+01:00 Markus Neteler <neteler@osgeo.org>:

v.category op=report

Well, it outputs a lot of information like
...
25/28/29/26/27/138/137/136/139/23/133/135
28/26/27/138/137/136
...

this `op=print` no?

Needed is a way to parse it and turn into a yes/no multilayer information.
Or, better, an additional line in
v.info -e myvector

Probably yes, Martin

--
Martin Landa * http://geo.fsv.cvut.cz/gwiki/Landa *
http://www.gismentors.eu/mentors/landa

On Tue, Oct 28, 2014 at 3:49 PM, Markus Neteler <neteler@osgeo.org> wrote:

Hi,

it would be nice to have in v.info or v.category the possibility to
check if a vector map comes with multiple layers.
I didn't figure out how to add that in these or one of these modules.
Perhaps I am missing something.

Does

v.category option=layers

not help?

Markus M

On Tue, Oct 28, 2014 at 4:25 PM, Markus Metz
<markus.metz.giswork@gmail.com> wrote:

On Tue, Oct 28, 2014 at 3:49 PM, Markus Neteler <neteler@osgeo.org> wrote:

Hi,

it would be nice to have in v.info or v.category the possibility to
check if a vector map comes with multiple layers.
I didn't figure out how to add that in these or one of these modules.
Perhaps I am missing something.

Does

v.category option=layers

not help?

v.category k_buffer1000m option=layers
1

Right that works but at this point I have to rephrase my question :slight_smile:

We have the issue of overlapping polygons (v.buffer done on points)
which are a separate issue in itself, hence the resulting print report
for the categories is as such:

25/30/28/29/26/27/138/137/136/139/135/140
56/182
55/181/56/182
58/59/62/61/184/185/187/188/55/181/56/57/182/183
58/59/62/61/184/185/187/188/55/181/57/183
55/181/56/60/182/186

That's a set of categories g.gui.rlisetup cannot handle. In order to
avoid that it dies with ugly messages we want to catch such situations
and exit with a proper error message...

Markus

On Tue, Oct 28, 2014 at 4:49 PM, Markus Neteler <neteler@osgeo.org> wrote:

On Tue, Oct 28, 2014 at 4:25 PM, Markus Metz
<markus.metz.giswork@gmail.com> wrote:

On Tue, Oct 28, 2014 at 3:49 PM, Markus Neteler <neteler@osgeo.org> wrote:

Hi,

it would be nice to have in v.info or v.category the possibility to
check if a vector map comes with multiple layers.
I didn't figure out how to add that in these or one of these modules.
Perhaps I am missing something.

Does

v.category option=layers

not help?

v.category k_buffer1000m option=layers
1

Right that works but at this point I have to rephrase my question :slight_smile:

We have the issue of overlapping polygons (v.buffer done on points)
which are a separate issue in itself, hence the resulting print report
for the categories is as such:

25/30/28/29/26/27/138/137/136/139/135/140
56/182
55/181/56/182
58/59/62/61/184/185/187/188/55/181/56/57/182/183
58/59/62/61/184/185/187/188/55/181/57/183
55/181/56/60/182/186

That's a set of categories g.gui.rlisetup cannot handle.

So the question is how to handle multiple categories per feature and
layer instead of multiple layers per vector?

Would it be so difficult to enable g.gui.rlisetup to handle these cases?

In order to
avoid that it dies with ugly messages we want to catch such situations
and exit with a proper error message...

Alternatively, g.gui.rlisetup and the r.li.* logic could be changed to
accept such situations.

Markus M

On 28 October 2014 20:40, Markus Metz <markus.metz.giswork@gmail.com> wrote:

So the question is how to handle multiple categories per feature and
layer instead of multiple layers per vector?

yes

Would it be so difficult to enable g.gui.rlisetup to handle these cases?

Yes, it should but we was looking for a generic method

In order to
avoid that it dies with ugly messages we want to catch such situations
and exit with a proper error message...

Alternatively, g.gui.rlisetup and the r.li.* logic could be changed to
accept such situations.

I think that r.li.* should work, the problem right now is in
g.gui.rlisetup because "/" is a character not allowed for the name of
new vectors.
g.gui.rlisetup creates a new vector for any selected features and it
add the cat as suffix for the name of the new vectors

Markus M

--
ciao
Luca

http://gis.cri.fmach.it/delucchi/
www.lucadelu.org

On Wed, Oct 29, 2014 at 8:44 AM, Luca Delucchi <lucadeluge@gmail.com> wrote:

On 28 October 2014 20:40, Markus Metz <markus.metz.giswork@gmail.com> wrote:

So the question is how to handle multiple categories per feature and
layer instead of multiple layers per vector?

yes

Would it be so difficult to enable g.gui.rlisetup to handle these cases?

Yes, it should but we was looking for a generic method

The generic method is v.category option=print

In order to
avoid that it dies with ugly messages we want to catch such situations
and exit with a proper error message...

Alternatively, g.gui.rlisetup and the r.li.* logic could be changed to
accept such situations.

I think that r.li.* should work, the problem right now is in
g.gui.rlisetup because "/" is a character not allowed for the name of
new vectors.
g.gui.rlisetup creates a new vector for any selected features and it
add the cat as suffix for the name of the new vectors

Please try the attached patch for gui/wxpython/rlisetup.

Markus M

(attachments)

rlisetup.patch (2.77 KB)

Hi Markus,

On 29 October 2014 09:15, Markus Metz <markus.metz.giswork@gmail.com> wrote:

Please try the attached patch for gui/wxpython/rlisetup.

I test your patch and it works. I improved a little bit it (attached
the new patch).
Do you apply it?

Markus M

--
ciao
Luca

http://gis.cri.fmach.it/delucchi/
www.lucadelu.org

(attachments)

gguirlisetup.patch (5.39 KB)

On Thu, Oct 30, 2014 at 2:31 PM, Luca Delucchi <lucadeluge@gmail.com> wrote:

Hi Markus,

On 29 October 2014 09:15, Markus Metz <markus.metz.giswork@gmail.com> wrote:

Please try the attached patch for gui/wxpython/rlisetup.

I test your patch and it works. I improved a little bit it (attached
the new patch).

Why did you remove the part that removes duplicates? This is needed in
order to avoid that the same raster is created twice, independent of
whether a feature has multiple categories or not (different features
can have the same category).

The description of the new function obtainCategories() is wrong. The
function does not check whether a vector is multilayer. The function
does not even check whether a feature has multiple categories in a
given layer. The function returns a list of all categories in layer X
for type=centroid which is what you want for g.gui.rlisetup. Actually,
g.gui.lisetup does not care about the vector layer, which is another
bug. And it does not care about the vector type. You should add the
options layer= and type= wherever appropriate.

Do you apply it?

Not in this form.

Markus M

On 30 October 2014 15:08, Markus Metz <markus.metz.giswork@gmail.com> wrote:

On Thu, Oct 30, 2014 at 2:31 PM, Luca Delucchi <lucadeluge@gmail.com> wrote:

Hi Markus,

On 29 October 2014 09:15, Markus Metz <markus.metz.giswork@gmail.com> wrote:

Please try the attached patch for gui/wxpython/rlisetup.

I test your patch and it works. I improved a little bit it (attached
the new patch).

Why did you remove the part that removes duplicates? This is needed in
order to avoid that the same raster is created twice, independent of
whether a feature has multiple categories or not (different features
can have the same category).

I only move it to a function because it is used more than one, and
change the for loop with a single line code [ sorted(set(list)) this
is what I usually use in Python to remove duplicate from list ]

The description of the new function obtainCategories() is wrong. The
function does not check whether a vector is multilayer. The function
does not even check whether a feature has multiple categories in a
given layer. The function returns a list of all categories in layer X
for type=centroid which is what you want for g.gui.rlisetup.

ok, could you fix the description with the right sentence?

Actually,
g.gui.lisetup does not care about the vector layer, which is another
bug. And it does not care about the vector type. You should add the
options layer= and type= wherever appropriate.

You are right, for the type we could add a check when the user select
the vector, only vector with areas should be accepted.

For the layer I don't know what could be the right solution, maybe
another combobox to select the layer to use?

Markus M

--
ciao
Luca

http://gis.cri.fmach.it/delucchi/
www.lucadelu.org

On Thu, Oct 30, 2014 at 3:23 PM, Luca Delucchi <lucadeluge@gmail.com> wrote:

On 30 October 2014 15:08, Markus Metz <markus.metz.giswork@gmail.com> wrote:

On Thu, Oct 30, 2014 at 2:31 PM, Luca Delucchi <lucadeluge@gmail.com> wrote:

Hi Markus,

On 29 October 2014 09:15, Markus Metz <markus.metz.giswork@gmail.com> wrote:

Please try the attached patch for gui/wxpython/rlisetup.

I test your patch and it works. I improved a little bit it (attached
the new patch).

Why did you remove the part that removes duplicates? This is needed in
order to avoid that the same raster is created twice, independent of
whether a feature has multiple categories or not (different features
can have the same category).

I only move it to a function because it is used more than one, and
change the for loop with a single line code [ sorted(set(list)) this
is what I usually use in Python to remove duplicate from list ]

Oops, I did not notice the set(), sorry!

The description of the new function obtainCategories() is wrong. The
function does not check whether a vector is multilayer. The function
does not even check whether a feature has multiple categories in a
given layer. The function returns a list of all categories in layer X
for type=centroid which is what you want for g.gui.rlisetup.

ok, could you fix the description with the right sentence?

See attached patch.

Actually,
g.gui.lisetup does not care about the vector layer, which is another
bug. And it does not care about the vector type. You should add the
options layer= and type= wherever appropriate.

You are right, for the type we could add a check when the user select
the vector, only vector with areas should be accepted.

I have added type= where it was missing.

For the layer I don't know what could be the right solution, maybe
another combobox to select the layer to use?

Yes, or fix it to layer 1. I have added a layer option to the relevant
functions in functions.py, right now fixed to 1.

You can submit the attached patch if it works for you.

Markus M

Markus M

--
ciao
Luca

http://gis.cri.fmach.it/delucchi/
www.lucadelu.org

(attachments)

gguirlisetup.patch2 (6.24 KB)

On Fri, Oct 31, 2014 at 9:34 AM, Markus Metz
<markus.metz.giswork@gmail.com> wrote:

On Thu, Oct 30, 2014 at 3:23 PM, Luca Delucchi <lucadeluge@gmail.com> wrote:

On 30 October 2014 15:08, Markus Metz <markus.metz.giswork@gmail.com> wrote:

On Thu, Oct 30, 2014 at 2:31 PM, Luca Delucchi <lucadeluge@gmail.com> wrote:

Hi Markus,

On 29 October 2014 09:15, Markus Metz <markus.metz.giswork@gmail.com> wrote:

Please try the attached patch for gui/wxpython/rlisetup.

I test your patch and it works. I improved a little bit it (attached
the new patch).

Why did you remove the part that removes duplicates? This is needed in
order to avoid that the same raster is created twice, independent of
whether a feature has multiple categories or not (different features
can have the same category).

I only move it to a function because it is used more than one, and
change the for loop with a single line code [ sorted(set(list)) this
is what I usually use in Python to remove duplicate from list ]

Oops, I did not notice the set(), sorry!

The description of the new function obtainCategories() is wrong. The
function does not check whether a vector is multilayer. The function
does not even check whether a feature has multiple categories in a
given layer. The function returns a list of all categories in layer X
for type=centroid which is what you want for g.gui.rlisetup.

ok, could you fix the description with the right sentence?

See attached patch.

Actually,
g.gui.lisetup does not care about the vector layer, which is another
bug. And it does not care about the vector type. You should add the
options layer= and type= wherever appropriate.

You are right, for the type we could add a check when the user select
the vector, only vector with areas should be accepted.

I have added type= where it was missing.

For the layer I don't know what could be the right solution, maybe
another combobox to select the layer to use?

Yes, or fix it to layer 1. I have added a layer option to the relevant
functions in functions.py, right now fixed to 1.

You can submit the attached patch if it works for you.

My previous patch did not work for me, but the attached patch
gguirlisetup.patch3 works for me now. Please test.

Markus M

(attachments)

gguirlisetup.patch3 (7.58 KB)

Hi,

On 1 November 2014 23:34, Markus Metz <markus.metz.giswork@gmail.com> wrote:

My previous patch did not work for me, but the attached patch
gguirlisetup.patch3 works for me now. Please test.

I improved you patch adding a new combobox to choose the layer number.
I have some problems with wxpython:
- I added two GError (if the vector has no areas or if the vector has
no dblinks), but when they appear they are back to the layertree, I
tried to close the layertree before using Dismiss() but it return me
and error
- I'm not able to cleanup the layer number combox if the vector is
without dblinks o without areas

some wxpython expert could check the new patch?

thanks

Markus M

--
ciao
Luca

http://gis.cri.fmach.it/delucchi/
www.lucadelu.org

(attachments)

gguirlisetup.patch4 (11.4 KB)

On Wed, Nov 12, 2014 at 4:31 AM, Luca Delucchi <lucadeluge@gmail.com> wrote:

Hi,

On 1 November 2014 23:34, Markus Metz <markus.metz.giswork@gmail.com>
wrote:

>
> My previous patch did not work for me, but the attached patch
> gguirlisetup.patch3 works for me now. Please test.
>

Hi Luca,

I improved you patch adding a new combobox to choose the layer number.
I have some problems with wxpython:
- I added two GError (if the vector has no areas or if the vector has
no dblinks), but when they appear they are back to the layertree, I
tried to close the layertree before using Dismiss() but it return me
and error

- I'm not able to cleanup the layer number combox if the vector is

without dblinks o without areas

can you try this new version? I also did some changes for wxPython 3

compatibility

Anna

some wxpython expert could check the new patch?

thanks

> Markus M

--
ciao
Luca

http://gis.cri.fmach.it/delucchi/
www.lucadelu.org

_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

(attachments)

rlisetup_patch_anna.diff (14.6 KB)

On 13 November 2014 02:47, Anna Petrášová <kratochanna@gmail.com> wrote:

Hi Luca,

Hi Anna,

I improved you patch adding a new combobox to choose the layer number.
I have some problems with wxpython:
- I added two GError (if the vector has no areas or if the vector has
no dblinks), but when they appear they are back to the layertree, I
tried to close the layertree before using Dismiss() but it return me
and error

- I'm not able to cleanup the layer number combox if the vector is
without dblinks o without areas

can you try this new version? I also did some changes for wxPython 3
compatibility

thanks a lot I committed it (with some small changes).
Your was a workaround, not a fix of my problem, but I like the idea,
it is simpler and it works :wink:

Just a question, my implementation was wrong or is a limit of wxpython?

Anna

--
ciao
Luca

http://gis.cri.fmach.it/delucchi/
www.lucadelu.org

On Thu, Nov 13, 2014 at 5:23 AM, Luca Delucchi <lucadeluge@gmail.com> wrote:

On 13 November 2014 02:47, Anna Petrášová <kratochanna@gmail.com> wrote:

>
> Hi Luca,
>

Hi Anna,

>>
>>
>> I improved you patch adding a new combobox to choose the layer number.
>> I have some problems with wxpython:
>> - I added two GError (if the vector has no areas or if the vector has
>> no dblinks), but when they appear they are back to the layertree, I
>> tried to close the layertree before using Dismiss() but it return me
>> and error
>>
>> - I'm not able to cleanup the layer number combox if the vector is
>> without dblinks o without areas
>>
> can you try this new version? I also did some changes for wxPython 3
> compatibility
>

thanks a lot I committed it (with some small changes).
Your was a workaround, not a fix of my problem, but I like the idea,
it is simpler and it works :wink:

For workaround, you could have used wx.CallAfter like this:
self.vectselect.Bind(wx.EVT_TEXT, lambda evt: wx.CallAfter(self.OnVector,
evt))

which would solve the problem with the hanging combo tree. The info label
is in my opinion better solution anyway and it should be used more often in
wxGUI instead of poping up error dialogs.

Just a question, my implementation was wrong or is a limit of wxpython?

If you are talking about the combo layertree behavior, I think it's a bug,
this widget has a lot of other issues.

> Anna
>

--
ciao
Luca

http://gis.cri.fmach.it/delucchi/
www.lucadelu.org