[QGIS-Developer] QgsProcessingParameterProviderConnection using cached database connections

2023-11-30 Thread Bo Victor Thomsen via QGIS-Developer

Ok, I'm developing a processing plugin with two algorithms:

 * The first algorithm: The user provides a number of informations
   about a /new/ database. The algorithm creates the new database using
   the information - and creates postgis extension, schemas and some
   tables in the new database.
   And lastly: it creates a database connection for the new database in
   QGIS.

 * The second algorithm: The user chooses a database connection from a
   combobox created using the
   /QgsProcessingParameterProviderConnection/ class. Finally the
   algorithm creates and populates a number of tables using the chosen
   connection

However: If you use the first algorithm to create the database and 
immediately uses the second algorithm trying to populate the new 
database, the connection is /not/ listed in the combobox.


I suspect it's because the /QgsProcessingParameterProviderConnection /is 
using the cached list of  connections when populating the dropdown list/

/

Somewhat like this (in Python):

metadata = QgsProviderRegistry.instance().providerMetadata('postgres')
pg_connections = metadata.connections(cached=True) # Read the cached 
settings


I've had a similar problem in the past that was solved by changing the 
"cached=True" to "cached=False" thereby forcing a reread of the 
connection list.


If you restart QGIS after running algorithm no 1 and /then/ runs 
algorithm no 2 it works like a charm.


My question: Is it possible to force 
/QgsProcessingParameterProviderConnection /to re-read the list of 
connections ? And, if possible, how ??



--

Med venlig hilsen / Best regards

Bo Victor Thomsen
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


[QGIS-Developer] Questions regarding the QgsProcessingAlgorithm class

2023-11-23 Thread Bo Victor Thomsen via QGIS-Developer

Hi list -

I apologize for the cross-posting to this mailing list from qgis-user. 
But I hope, that somebody has the answers to the questions...


I have a couple of (probably dumb) questions on how to use the 
"QgsProcessingAlgorithm" class.


 * A have a lot parameter inputs placed in the "advanced" section af
   the processing input dialog. It's parameters that seldom has to be
   changed.
   How do I present the "Avanced" section /not/ unfolded? The default
   is to unfold this section and thus possibly confuse users by showing
   a lot of seldom changed parameters.

 * One of my input parameters is a "QgsProcessingParameterString"
   parameter that will contain a password.
   Can I obfuscate the parameter input, i.e showing '***' instead
   of the password ?

 * the "QgsProcessingParameterFeatureSource" method creates a drop-down
   with names of layers in the map /and/ a checkbox with the label
   "Selected features only". Is it possible to set the checkmark
   automatically when showing the processing userdialog ? And how ??

--
Med venlig hilsen / Best regards

Bo Victor Thomsen
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


[QGIS-Developer] Embedded styling in some datatypes

2023-11-23 Thread Bo Victor Thomsen via QGIS-Developer

Hi list -

I'm wondering about how to use embedded styling in certain types of file 
formats (like MapInfo Tab). I know its possible to read the embedded 
styling from a Tab fil and then convert it to a styling object in QGIS.


However, what about the other direction ? Take a specific QGIS style 
from the layer styling of a tab file, and and write the specific style 
into the feature, so it will be present if you later open the tab file 
in (gasp!) MapIno ?


The use case would be organisations that have a mixed environment of 
QGIS and MapInfo installations. It would allow QGIS users to create and 
update object in a .tab file and save the file. Later this file - if 
opened in MapInfo (or QGIS) - would be shown with the correct embedded 
styling.


--
Med venlig hilsen / Best regards

Bo Victor Thomsen

___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


[QGIS-Developer] Lazy question about using views in GeoPackages

2023-05-26 Thread Bo Victor Thomsen via QGIS-Developer

Hi list -

Recently, I've begun experimenting with creating spatial view's of 
base-tables inside GeoPackages. A Geopackage is basically a SQLite file 
containing  spatial data- and meta-tables with specific structures of 
information about the spatial tables.


So it's possible to create a permanent view of a table (or tables) in 
the GeoPackage by making a functioning SQL select statement and 
prefixing it with "CREATE VIEW /view_name/ AS .. /the select statement/ 
.. (This is database 101 knowledge)


However, if you want to expose those views as "read-only" tables/layers 
for "non-sql-using" QGIS users  you have to update several meta-tables 
in the GeoPackage: /gpkg_contents/, /gpkg_geometry_columns/ and maybe 
/gpkg_ogr_contents/.


I'm brainstorming with myself about making some kind of automated 
updating of the meta-tables with information about the views created. 
Maybe some python code and maybe creating triggers for the base table to 
handle data changes regarding the extend of the data.


And now (at last !!) my question: I haven't been able to find very much 
information about this subject using Google or StackExchange. So.. Is 
there some existing code / plugin / information so I don't have to 
"reinvent the wheel" ?



--
Med venlig hilsen / Best regards

Bo Victor Thomsen
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


[QGIS-Developer] Strange behaviour of geometryChanged event on object QgsVectorLayer

2022-12-10 Thread Bo Victor Thomsen via QGIS-Developer

Hi list ..

If I define an event listener for event  geometryChanged event on object 
QgsVectorLayer in the Python console like this:


*=
*

*# event listener...
def feedback(fid, geom):
    # print id and geometry wkt in the console
    print ('id: {}, geometry: {}'.format(fid, geom.asWkt()))

# find layer
layer = iface.activeLayer()
*

*#  connect listener to event on layer
layer.geometryChanged.connect(feedback)*

*==
*


It works nicely, printing the id and  the WKT of the object changed. 
However, the event fires *3* times, thus printing the same message 3 times.


Why does it do that ? (And no, I haven't connected it 3 times to the 
same event. If I connect it twice, I'll get *6* lines in the the 
console. And I did the experiment with a new user profile).


Windows 10, QGIS 3.26.3


--
Med venlig hilsen / Best regards

Bo Victor Thomsen
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


[QGIS-Developer] Work on QgsAbstractDatabaseProviderConnection for MS SQL Server

2022-09-02 Thread Bo Victor Thomsen via QGIS-Developer

Hi List -

I am working on a plugin that's is using for connections 
(QgsAbstractDatabaseProviderConnection) to several types of databases, 
including Postgres, GeoPackage and MS SQLServer.


I was hoping to use the method "createSqlVectorLayer 
" 
for converting some fairly complex SQL queries into QGIS vector layers. 
This works super nice for Postgres and GeoPackage. However the current 
version (QGIS 3.26) doesn't support this method for MS SQLServer. As 
illustrated in this piece of code:


conns = 
QgsProviderRegistry.instance().providerMetadata('mssql').connections(False)

conn = conns['geodata @ localhost'] # SQL server connection
capabilities = conn.capabilities()
print(bool(capabilities & QgsAbstractDatabaseProviderConnection.SqlLayers))

The last statement shows "False" for MS SqlServer connections, 
indicating the missing functionality. (QGIS ver. 3.26 or older)



My first question is: Has there been done any work on this for MS SQL 
Server connections in QGIS master (next version) ?


The second question: Is it possible for someone in the group of Core 
developers to provide me with a ballpark figure for implementing the 
missing functionality for the mssql driver ??


To be specific: get method "createSqlVectorLayer 
" 
to work for MS SQL Server connections.


If somebody steps up to the challenge I will send the information to my 
customers so they can consider making QGIS better instead of paying me 
for an ugly workaround.



Med venlig hilsen / Kind regards

Bo Victor Thomsen
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


[QGIS-Developer] Event to register adding layers in QGIS

2022-08-26 Thread Bo Victor Thomsen via QGIS-Developer

Hi list -

I have a small "startup.py" project - The goal is to register every time 
a user opens af layer in QGIS in a organization with lots of QGIS users. 
The end goal is to find data sources that are maintained but actually 
not used.


To that purpose I created the following script as a "proof of concept":

*from qgis.core import QgsProject, QgsMessageLog, Qgis, QgsLayerTreeLayer
from datetime import datetime
import os


def onAddedChildren(node, indexFrom, indexTo):

    for i in range(indexFrom, indexTo+1):
    child = node.children()[i]
    if isinstance(child, QgsLayerTreeLayer):
    layer = child.layer()
    name = ''
    uri = ''
    if (layer):
    name = layer.name()
    datap = layer.dataProvider()
    if datap:
    uri = datap.dataSourceUri()
    strx = 
'"{}";"{}";"{}";"{}";"{}"'.format(datetime.today().strftime('%Y-%m-%d 
%H:%M:%S'),os.getlogin(),child.name(),name,uri)

    with open("d:/tmp/loglag.csv", "a") as g:
    g.write(strx+'\n')

root = QgsProject.instance().layerTreeRoot()
root.addedChildren.connect(onAddedChildren)
*

(I know - I might into trouble with users appending data to the same 
file at the same time, but that is solveable)


The above script works like a charm, when a user add a single layer 
using the data source manager. But it partially fails when opening a 
project. The layers are registred, but it doesn't register the uri for 
the individual layers. I assume the event "addedChildren" is fired 
before the layers is fully loaded.


So is there some other event I can use to get my full layer info ?

--

Med venlig hilsen / Kind regards

Bo Victor Thomsen
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [QGIS-Developer] Is it possible to make QGIS show the fired queries to databases in Debugging Tools?

2022-07-29 Thread Bo Victor Thomsen via QGIS-Developer

Nice to know  -

What about GeoPackage ? Is it technically difficult or was is not 
requested ??


I'm just wondering. GeoPackage is - after all - a major data format for 
QGIS..


And both Spatialite and GeoPackage is based on the same db-technology: 
SQLite


Med venlig hilsen / Kind regards

Bo Victor Thomsen

Den 29-07-2022 kl. 11:12 skrev Alessandro Pasotti via QGIS-Developer:

It is currently implemented for PG, Oracle, MSSQL and spatialite.

___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [QGIS-Developer] Fwd: [Qgis-user] Editing a multipolygon object changes type from Multipolygon to Polygon

2022-04-02 Thread Bo Victor Thomsen via QGIS-Developer
I'll just add that  I have observed the same behaviour using a 
GeoPackage based layer. It was during a teaching session with 10-15 
students, so I can't remember exactly how and which editing tool that 
was the cause of the error.


Windows 10 / QGIS 3.22.3


Med venlig hilsen / Kind regards

Bo Victor Thomsen

Den 01-04-2022 kl. 17:38 skrev Jörg Höttges via QGIS-Developer:

Hi everyone,

I'm using QGIS 3.16 to 3.22. I created a table with multipolygon 
objects in a SpatiaLite database. When editing one of the polygons 
there appears a warning "Die Operation würden Geometrietyp ändern" 
("The operation would change geometry type") and saving of the 
changings failes.


Following are the objects before and after the modification:

before editing:
wkt_geom: MultiPolygon (((379698.836953434 
5709466.3700011175871, 379705.347671694 
5709460.9349959021807, 379703.797000204891 
5709459.0760035017729, 379697.347813735 
5709464.7740020861626, 379698.836953434 
5709466.3700011175871)))


after adding the point (379701.027186265 
5709464.5429959766865):
wkt_geom: Polygon ((379701.027186265 
5709464.5429959766865, 379705.347671694 
5709460.9349959021807, 379703.797000204891 
5709459.0760035017729, 379697.347813735 
5709464.7740020861626, 379698.836953434 
5709466.3700011175871, 379701.027186265 
5709464.5429959766865))


how can I make sure that the type does not change due to editing? The 
only idea i have is to remove or modify the geometry constraint in the 
Spatialite database table for the geometry column. The warning still 
appears but saving is successful.


Interesting fact: The problem didn't appear with QGIS 3.16.

Many thanks for your help!

Jörg Höttges

---
FH Aachen
University of Applied Sciences
Bayernallee 9
52066 Aachen | Germany
www.fh-aachen.de/menschen/hoettges



___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info:https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-developer___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer