Re: [Qgis-developer] Using the QgsBrowserModel in Python

2015-07-30 Thread Ludovic Delauné
Le 30/07/2015 13:47, Hugo Mercier a écrit :
 Hi,
 
 On 29/07/2015 17:50, Ludovic Delauné wrote:
 Hi devs,

 i'm trying to use the QgsBrowserModel in a Python plugin.
 I need to get the URI from a selected Item in the QTreeView, i expected to 
 have a QgsLayerItem returned by the dataItem() in order to get the uri() 
 member but a QgsDataItem
 is returned instead.
 Given a QgsDataItem, is it possible to get the uri of my data source ?

 Is this a bug due to the binding 
 (https://github.com/qgis/QGIS/blob/feb3bee85837d707b1b10c14064fcb55364e282d/python/core/qgsbrowsermodel.sip)
  or i'm not in the right way ?

 Here are the few steps to reproduce the problem in a console:

 ---
 from PyQt4.QtGui import QTreeView
 tv = QTreeView(None)
 m = QgsBrowserModel()
 tv.setModel(m)
 tv.show()
 m.dataItem(tv.currentIndex())
 
 output is :
 qgis._core.QgsDataItem object at 0x7f6cb8bcca68
 
 Apparently, this is because QgsDataItem has nothing to convert to its
 derived types in the Python bindings. I'll add a %ConvertToSubClassCode.
 
 Thanks for the report

Thanks for that clarification.

My current workaround is to use the mimeData method and deserialize the item to 
obtain the URI :

Add to the steps above :

from qgis.core import QgsMimeDataUtils
uri_list = QgsMimeDataUtils.decodeUriList(m.mimeData([tv.currentIndex()]))
uri_list[0].uri

--
Ludovic



___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Using the QgsBrowserModel in Python

2015-07-30 Thread Hugo Mercier
Hi,

On 29/07/2015 17:50, Ludovic Delauné wrote:
 Hi devs,
 
 i'm trying to use the QgsBrowserModel in a Python plugin.
 I need to get the URI from a selected Item in the QTreeView, i expected to 
 have a QgsLayerItem returned by the dataItem() in order to get the uri() 
 member but a QgsDataItem
 is returned instead.
 Given a QgsDataItem, is it possible to get the uri of my data source ?
 
 Is this a bug due to the binding 
 (https://github.com/qgis/QGIS/blob/feb3bee85837d707b1b10c14064fcb55364e282d/python/core/qgsbrowsermodel.sip)
  or i'm not in the right way ?
 
 Here are the few steps to reproduce the problem in a console:
 
 ---
 from PyQt4.QtGui import QTreeView
 tv = QTreeView(None)
 m = QgsBrowserModel()
 tv.setModel(m)
 tv.show()
 m.dataItem(tv.currentIndex())
 
 output is :
 qgis._core.QgsDataItem object at 0x7f6cb8bcca68

Apparently, this is because QgsDataItem has nothing to convert to its
derived types in the Python bindings. I'll add a %ConvertToSubClassCode.

Thanks for the report

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] function similar to Excel VLOOKUP - SOLVED

2015-07-30 Thread Zoltan Szecsei

Awesome. Thank you.

I added the extra column to the shapefile attributes, joined the 
shapefile to the CSV file, and then updated the new column in my 
shapefile using:
attribute($currentfeature,'joinedcolumn')  (NOTE: single quotes for 
field name)


I'm sure I could have skipped the Join step and just used getfeature as 
suggested below, but I went the Join route anyway.


Big thanks,
Zoltan


On 2015/07/30 14:34, DelazJ wrote:

Hi,
I think combining getFeature and attribute functions should help u do 
that in the field calculator, though I haven't used them on csv files.
Assuming col1 in your csv contains also the code you are looking for, 
applying this expression on shapefile col 6 in QGIS field calculator 
may do the job:

attribute (getFeature ('mycsvfile', 'mycsv_col1', myshape_col1), 'col2')

Regards,
DelazJ

2015-07-30 13:06 GMT+02:00 Zoltan Szecsei zolt...@geograph.co.za 
mailto:zolt...@geograph.co.za:


Hi,
How could I implement something like vlookup in QGIS?

I have a shapefile with 2000 polygons and column 1 of its
attribute table has a code value.

Using the code in this column 1, I need to look up which row of a
CSV file has that code, and return column 2 of the CSV file.
This returned value must then be placed into a new column (say
column 6) on the shapefile attribute table.
I could pre-add the new column to this shapefile, and then run the
vlookup equivalent too, of course.

I tried this by opening the DBF file in Libreoffice calc, sorting
the columns, adding the extra two columns of my lookup data, then
ran vlookup and saved/closed the DBF file.

Once back in QGIS the attributes ended up being linked to the
wrong polygons (probably because I sorted the DBF file outside of
QGIS).

Thanks in advance,
Zoltan


-- 


===
Zoltan Szecsei PrGISc [PGP0031]
Geograph (Pty) Ltd.
GIS and Photogrammetric Services

P.O. Box 7, Muizenberg 7950, South Africa.

Mobile: +27-83-6004028 tel:%2B27-83-6004028
Fax: +27-86-6115323 tel:%2B27-86-6115323 www.geograph.co.za
http://www.geograph.co.za
===

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org mailto:Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer




___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


--

===
Zoltan Szecsei PrGISc [PGP0031]
Geograph (Pty) Ltd.
GIS and Photogrammetric Services

P.O. Box 7, Muizenberg 7950, South Africa.

Mobile: +27-83-6004028
Fax:+27-86-6115323 www.geograph.co.za
===

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [Qgis-developer] function similar to Excel VLOOKUP

2015-07-30 Thread Roy

How about a  Join 

 QGIS join

Il 30/07/2015 13.06, Zoltan Szecsei ha scritto:

Hi,
How could I implement something like vlookup in QGIS?

I have a shapefile with 2000 polygons and column 1 of its attribute 
table has a code value.


Using the code in this column 1, I need to look up which row of a CSV 
file has that code, and return column 2 of the CSV file.
This returned value must then be placed into a new column (say column 
6) on the shapefile attribute table.
I could pre-add the new column to this shapefile, and then run the 
vlookup equivalent too, of course.


I tried this by opening the DBF file in Libreoffice calc, sorting the 
columns, adding the extra two columns of my lookup data, then ran 
vlookup and saved/closed the DBF file.


Once back in QGIS the attributes ended up being linked to the wrong 
polygons (probably because I sorted the DBF file outside of QGIS).


Thanks in advance,
Zoltan




___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] function similar to Excel VLOOKUP

2015-07-30 Thread DelazJ
Hi,
I think combining getFeature and attribute functions should help u do that
in the field calculator, though I haven't used them on csv files.
Assuming col1 in your csv contains also the code you are looking for,
applying this expression on shapefile col 6 in QGIS field calculator may
do the job:
attribute (getFeature ('mycsvfile', 'mycsv_col1', myshape_col1), 'col2')

Regards,
DelazJ

2015-07-30 13:06 GMT+02:00 Zoltan Szecsei zolt...@geograph.co.za:

 Hi,
 How could I implement something like vlookup in QGIS?

 I have a shapefile with 2000 polygons and column 1 of its attribute table
 has a code value.

 Using the code in this column 1, I need to look up which row of a CSV file
 has that code, and return column 2 of the CSV file.
 This returned value must then be placed into a new column (say column 6)
 on the shapefile attribute table.
 I could pre-add the new column to this shapefile, and then run the vlookup
 equivalent too, of course.

 I tried this by opening the DBF file in Libreoffice calc, sorting the
 columns, adding the extra two columns of my lookup data, then ran vlookup
 and saved/closed the DBF file.

 Once back in QGIS the attributes ended up being linked to the wrong
 polygons (probably because I sorted the DBF file outside of QGIS).

 Thanks in advance,
 Zoltan


 --

 ===
 Zoltan Szecsei PrGISc [PGP0031]
 Geograph (Pty) Ltd.
 GIS and Photogrammetric Services

 P.O. Box 7, Muizenberg 7950, South Africa.

 Mobile: +27-83-6004028
 Fax:+27-86-6115323 www.geograph.co.za
 ===

 ___
 Qgis-developer mailing list
 Qgis-developer@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/qgis-developer

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [Qgis-developer] memory layer performance while adding many features?

2015-07-30 Thread Raymond Nijssen

Merci Denis,

I will try both options later today.

Raymond


On 30-07-15 09:34, Denis Rouzaud wrote:

 From your code [0] , I would see 2 options:

* add features all at once on the provider using
QgsVectorDataProvider::addFeatures (the method you currently use)

* work on the layer level rather than the provider, which I believe is
the recommended way for plugins. Make the layer editable, and add
features to the edit buffer and commit at once. Or maybe commit 1000 by
1000.

I hope this helps.




[0]
https://github.com/opengeogroep/AERIUS-QGIS-plugins/blob/master/ImaerReader/imaer_reader.py#L228


On 07/30/2015 09:20 AM, Raymond Nijssen wrote:

Hi Denis,

The code is in the ImaerReader plugin in the qgis repo and in github:

https://github.com/opengeogroep/AERIUS-QGIS-plugins

I'm adding the features one by one.

Regards,
Raymond

On 30-07-15 08:46, Denis Rouzaud wrote:

Hi Raymond,

Can you show us the code doing this?
Do you commit features one by one ar all at once?

Best wishes,
Denis

On 07/29/2015 09:04 AM, Raymond Nijssen wrote:

Dear developers, ;)

A plugin of mine imports data from a gml file into a memory layer.
Works fine for tiny gml files, but takes forever on huge ones. Sounds
plausible maybe, but the relation is not linear.

So I did did some tests and found out that reading and parsing the gml
and creating the features always goes at the same speed of about 400
features a second (fps). But when adding these to my memory layer, the
process slows down tremendously.

I output the fps for every 1000 features and it gave me this graph:

http://terglobo.nl/downloads/memory-layer-performance.png

At the end of the importing process I'm processing just 3 features per
second.

Is this expected behaviour? Is a memory layer not meant for something
like this? Or is this a bug?

In the source code I found that for every feature I add to a memory
layer the index is updated. Could that be inefficient?

Hoping anyone can explain!

Regards,
Raymond












--
Terglobo
Ampèrestraat 110
5223 CT 's-Hertogenbosch
06-25314983
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer

[Qgis-developer] Dissolve/Intersection/Clip in 2.10 doesn´t work (Regression)

2015-07-30 Thread Lene Fischer
Hi,
I have installed QGIS 2.10.1 on Windows 7 (64 bit).

When I use the Geoprocessing tool - Dissolve, Clip and Intersection

Dissolve and add Unique ID field – All polygons that are unique are stored and 
all the rest are not are not created.

The problem is both in the vector menu and in the Processing toolbox.

Can anyone confirm ?

Regards
Lene Fischer

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [Qgis-developer] Freeze on release-2_8 branch

2015-07-30 Thread Jürgen E . Fischer
Hi,

On Thu, 30. Jul 2015 at 09:05:11 +1000, Nyall Dawson wrote:
 They were both backported to 2.8.3 (thanks Jürgen!). I assume the release
 announcement is waiting on the packages being built and available for the
 major platforms.

We need to be noisy about point releases, too?  It's all on github anyway.
Can't sales or marketing take care of that? ;)


Jürgen

-- 
Jürgen E. Fischer   norBIT GmbH Tel. +49-4931-918175-31
Dipl.-Inf. (FH) Rheinstraße 13  Fax. +49-4931-918175-50
Software Engineer   D-26506 Norden http://www.norbit.de
QGIS release manager (PSC)  GermanyIRC: jef on FreeNode 



signature.asc
Description: Digital signature
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [Qgis-developer] Definition of Perimeter for polygons with holes

2015-07-30 Thread Hugo Mercier
Hi Marco,

On 28/07/2015 10:38, Marco Hugentobler wrote:
 Hi
 
 While working on QgsDistanceArea, I noticed the definition of perimeter
 in QGIS is not the same as in PostGIS. PostGIS returns the length of
 outer and inner rings, while QGIS expects the length of the outer ring
 only:
 
 test_distancearea.py:
 
 polygon = QgsGeometry.fromPolygon(
 [
 [ QgsPoint(0,0), QgsPoint(3,0), QgsPoint(3,3),
 QgsPoint(0,3), QgsPoint(0,0) ],
 [ QgsPoint(1,1), QgsPoint(2,1), QgsPoint(2,2),
 QgsPoint(1,2), QgsPoint(1,1) ],
 ]
 )
 
 perimeter = da.measurePerimeter(polygon)
 assert perimeter == 12, Expected:\n%f\nGot:\n%f\n % (12, perimeter)
 
 
 Using the following in PostGis returns 16 (length of inner and outer
 rings):
 
 SELECT ST_Perimeter( ST_GeomFromText( 'POLYGON(( 0 0, 3 0, 3 3, 0 3, 0
 0),(1 1, 2 1, 2 2, 1 2, 1 1))', -1 ) );
 
 What is your opinion? Is it okay to change it in QGIS to also consider
 the length of inner rings or are there any strong arguments against that?

Good question ! :)
I don't know if there is one ideal definition of the perimeter of inner
rings. After all, we may decide to see the inner perimeter as a negative
one ... as it is for the area.
So, just a proposition: let the user decide what to do with the two
perimeters (outer and inner), adding an option to retrieve separately
the inner perimeter ?

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] memory layer performance while adding many features?

2015-07-30 Thread Denis Rouzaud

Hi Raymond,

Can you show us the code doing this?
Do you commit features one by one ar all at once?

Best wishes,
Denis

On 07/29/2015 09:04 AM, Raymond Nijssen wrote:

Dear developers, ;)

A plugin of mine imports data from a gml file into a memory layer. 
Works fine for tiny gml files, but takes forever on huge ones. Sounds 
plausible maybe, but the relation is not linear.


So I did did some tests and found out that reading and parsing the gml 
and creating the features always goes at the same speed of about 400 
features a second (fps). But when adding these to my memory layer, the 
process slows down tremendously.


I output the fps for every 1000 features and it gave me this graph:

http://terglobo.nl/downloads/memory-layer-performance.png

At the end of the importing process I'm processing just 3 features per 
second.


Is this expected behaviour? Is a memory layer not meant for something 
like this? Or is this a bug?


In the source code I found that for every feature I add to a memory 
layer the index is updated. Could that be inefficient?


Hoping anyone can explain!

Regards,
Raymond




___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] memory layer performance while adding many features?

2015-07-30 Thread Hugo Mercier
Hi Raymond,

On 29/07/2015 09:04, Raymond Nijssen wrote:
 Dear developers, ;)
 
 A plugin of mine imports data from a gml file into a memory layer. Works
 fine for tiny gml files, but takes forever on huge ones. Sounds
 plausible maybe, but the relation is not linear.
 
 So I did did some tests and found out that reading and parsing the gml
 and creating the features always goes at the same speed of about 400
 features a second (fps). But when adding these to my memory layer, the
 process slows down tremendously.
 
 I output the fps for every 1000 features and it gave me this graph:
 
 http://terglobo.nl/downloads/memory-layer-performance.png
 
 At the end of the importing process I'm processing just 3 features per
 second.
 
 Is this expected behaviour? Is a memory layer not meant for something
 like this? Or is this a bug?
 
 In the source code I found that for every feature I add to a memory
 layer the index is updated. Could that be inefficient?

If I am correct the spatial index is created only if you ask so (by
passing index=yes). Do you have the same results without spatial index ?

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] memory layer performance while adding many features?

2015-07-30 Thread Raymond Nijssen

Hi Hugo,

I'm not specifically adding an index. So if you are right, I'm not using 
that.


Regards,
Raymond


On 30-07-15 09:10, Hugo Mercier wrote:

Hi Raymond,

On 29/07/2015 09:04, Raymond Nijssen wrote:

Dear developers, ;)

A plugin of mine imports data from a gml file into a memory layer. Works
fine for tiny gml files, but takes forever on huge ones. Sounds
plausible maybe, but the relation is not linear.

So I did did some tests and found out that reading and parsing the gml
and creating the features always goes at the same speed of about 400
features a second (fps). But when adding these to my memory layer, the
process slows down tremendously.

I output the fps for every 1000 features and it gave me this graph:

http://terglobo.nl/downloads/memory-layer-performance.png

At the end of the importing process I'm processing just 3 features per
second.

Is this expected behaviour? Is a memory layer not meant for something
like this? Or is this a bug?

In the source code I found that for every feature I add to a memory
layer the index is updated. Could that be inefficient?


If I am correct the spatial index is created only if you ask so (by
passing index=yes). Do you have the same results without spatial index ?

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer



--
Terglobo
Ampèrestraat 110
5223 CT 's-Hertogenbosch
06-25314983
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] memory layer performance while adding many features?

2015-07-30 Thread Denis Rouzaud

From your code [0] , I would see 2 options:

* add features all at once on the provider using 
QgsVectorDataProvider::addFeatures (the method you currently use)


* work on the layer level rather than the provider, which I believe is 
the recommended way for plugins. Make the layer editable, and add 
features to the edit buffer and commit at once. Or maybe commit 1000 by 
1000.


I hope this helps.




[0] 
https://github.com/opengeogroep/AERIUS-QGIS-plugins/blob/master/ImaerReader/imaer_reader.py#L228


On 07/30/2015 09:20 AM, Raymond Nijssen wrote:

Hi Denis,

The code is in the ImaerReader plugin in the qgis repo and in github:

https://github.com/opengeogroep/AERIUS-QGIS-plugins

I'm adding the features one by one.

Regards,
Raymond

On 30-07-15 08:46, Denis Rouzaud wrote:

Hi Raymond,

Can you show us the code doing this?
Do you commit features one by one ar all at once?

Best wishes,
Denis

On 07/29/2015 09:04 AM, Raymond Nijssen wrote:

Dear developers, ;)

A plugin of mine imports data from a gml file into a memory layer.
Works fine for tiny gml files, but takes forever on huge ones. Sounds
plausible maybe, but the relation is not linear.

So I did did some tests and found out that reading and parsing the gml
and creating the features always goes at the same speed of about 400
features a second (fps). But when adding these to my memory layer, the
process slows down tremendously.

I output the fps for every 1000 features and it gave me this graph:

http://terglobo.nl/downloads/memory-layer-performance.png

At the end of the importing process I'm processing just 3 features per
second.

Is this expected behaviour? Is a memory layer not meant for something
like this? Or is this a bug?

In the source code I found that for every feature I add to a memory
layer the index is updated. Could that be inefficient?

Hoping anyone can explain!

Regards,
Raymond









___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer