Hi Jacky,

Yes of course. Please find attached my script.

Regards,

Mélanie

On 10/28/22 4:55 PM, Jacky Volpes via QGIS-Developer wrote:
Hi Mélanie,

Have you initialized your standalone script as shown in https://docs.qgis.org/3.22/en/docs/pyqgis_developer_cookbook/intro.html#using-pyqgis-in-standalone-scripts ?

Best regards,
Jacky


Le 28/10/2022 à 16:40, Mélanie Dol via QGIS-Developer a écrit :
Hi Andrea,

Thank you. I've updated with QGIS 3.26 Buenos Aires. The warning message have disappeared. Unfortunately, the script still generates a segmentation fault.

Best regards,

Mélanie Dol

On 10/28/22 11:47 AM, Andrea Giudiceandrea via QGIS-Developer wrote:
Il 27/10/2022 16:34, Mélanie Dol via QGIS-Developer ha scritto:
/usr/share/qgis/python/plugins/processing/algs/grass7/Grass7Utils.py:191: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if path is '':

Hi Mélanie,
while I don't know why that script generates a segmentation fault, It seems you are using QGIS 3.10 which is a three years old version. The QGIS repository for Ubuntu 20.04 currently offers the latest available QGIS LTR 3.22.12.

Best regards.

Andrea Giudiceandrea

_______________________________________________
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

--
Jacky Volpes

Ingénieur SIG - Oslandia

_______________________________________________
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

import sys
import qgis
from qgis.core import *
from osgeo import ogr
import PyQt5.QtCore
from PyQt5.QtGui import *
from qgis.analysis import QgsNativeAlgorithms

# Supply path to qgis install location
QgsApplication.setPrefixPath("/usr", True)

# Create a reference to the QgsApplication.  Setting the
# second argument to False disables the GUI.
qgs = QgsApplication([], False)

# Load providers
qgs.initQgis()

# Append the path where processing plugin can be found
sys.path.append('/usr/share/qgis/python/plugins')
import processing
from processing.core.Processing import Processing
Processing.initialize()
#QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())


Geopackage_Databasepath = "/home/Satoz/SATOCEAN_ANALYSIS_N202210190000_F202210190000.gpkg"

# __________________________________
# PRESSURE ISOBARS LAYER

print('1. Pressure Isobars Layer')

Layer_Pressure_Isobars =  QgsVectorLayer(Geopackage_Databasepath+ "|layername=SATOCEAN_PRESSURE_ISOBARS" , 'SATOCEAN_PRESSURE_ISOBARS', 'ogr')
#Layer_Pressure_Isobars =  iface.addVectorLayer(Geopackage_Databasepath+ "|layername=SATOCEAN_PRESSURE_ISOBARS" , 'SATOCEAN_PRESSURE_ISOBARS', 'ogr')

# Initialize the default symbol for this geometry type
symbol = QgsSymbol.defaultSymbol(Layer_Pressure_Isobars.geometryType())

# Get style
get_styles = QgsStyle.defaultStyle()
style_layer = get_styles.symbol('Pressure_Isobars')

# Apply Style
Layer_Pressure_Isobars.renderer().setSymbol(style_layer)
Layer_Pressure_Isobars.triggerRepaint()

# Label
layer_settings  = QgsPalLayerSettings()
text_format = QgsTextFormat()

myFont = QFont("Arial",20,QFont.Bold)
myFont.setUnderline(True)
text_format.setFont(myFont)
text_format.setSize(20)
text_format.setColor(QColor("#4c66ff"))

layer_settings.setFormat(text_format)

layer_settings.fieldName = "Pressure"
layer_settings.LabelPlacement = 4

layer_settings.enabled = True

layer_settings = QgsVectorLayerSimpleLabeling(layer_settings)
Layer_Pressure_Isobars.setLabelsEnabled(True)
Layer_Pressure_Isobars.setLabeling(layer_settings)
Layer_Pressure_Isobars.triggerRepaint()


# __________________________________
# FRONTS LAYER

print('2. Fronts Layer')

Layer_Fronts = QgsVectorLayer(Geopackage_Databasepath+ "|layername=SATOCEAN_FRONTS" , 'SATOCEAN_FRONTS', 'ogr')
#Layer_Fronts = iface.addVectorLayer(Geopackage_Databasepath+ "|layername=SATOCEAN_FRONTS" , 'SATOCEAN_FRONTS', 'ogr')
    
# Get unique values
I_FieldName = Layer_Fronts.fields().indexFromName('Front_Type')
Categories_Fronts = Layer_Fronts.uniqueValues(I_FieldName)
    
# Fill categories
categories = []
for Category in Categories_Fronts:
    # Initialize the default symbol for this geometry type
    symbol = QgsSymbol.defaultSymbol(Layer_Fronts.geometryType())
        
    # Get style
    get_styles = QgsStyle.defaultStyle()
        
    if "STATIONARY" in Category:
        style_layer = get_styles.symbol('Stationary_Front')
    elif "TROF" in Category:
        style_layer = get_styles.symbol('Trof_Front')
    elif "WARM" in Category:
        style_layer = get_styles.symbol('Warm_Front')
    elif 'COLD' in Category:
        style_layer = get_styles.symbol('Cold_Front')
    elif "OCCLUDED" in Category:
        style_layer = get_styles.symbol('Occluded_Front')
    elif "DOUBLE" in Category:
        style_layer = get_styles.symbol('Double_Line_Front')
    elif "ZZZ" in Category:
        style_layer = get_styles.symbol('ICTZ_Front')   
    else:
        style_layer = get_styles.symbol('Trof_Front')
           
    # Create renderer object
    Category_Defined = QgsRendererCategory(Category, style_layer, str(Category))
    	
    # Entry for the list of category items
    categories.append(Category_Defined)
    
# Create renderer object
renderer = QgsCategorizedSymbolRenderer('Front_Type', categories)

# Assign the created renderer to the layer
if renderer is not None:
    Layer_Fronts.setRenderer(renderer)
        
# Apply style   
Layer_Fronts.triggerRepaint()

# __________________________________
# PRESSURE CENTER LAYER

print('3. Pressure Center Layer')

Layer_Pressure_Center = QgsVectorLayer(Geopackage_Databasepath+ "|layername=SATOCEAN_PRESSURE_CENTER" , 'SATOCEAN_PRESSURE_CENTER', 'ogr')
#Layer_Pressure_Center = iface.addVectorLayer(Geopackage_Databasepath+ "|layername=SATOCEAN_PRESSURE_CENTER" , 'SATOCEAN_PRESSURE_CENTER', 'ogr')
    
# Get unique values
I_FieldName = Layer_Pressure_Center.fields().indexFromName('Pressure')
Categories_Pressure = Layer_Pressure_Center.uniqueValues(I_FieldName)
    
# Fill categories
categories = []
for Category in Categories_Pressure:
    # Initialize the default symbol for this geometry type
    symbol = QgsSymbol.defaultSymbol(Layer_Pressure_Center.geometryType())
        
    # Get style
    get_styles = QgsStyle.defaultStyle()
        
    if "L" in Category:
        style_layer = get_styles.symbol('Low_Pressure')
    elif "HURRICANE" in Category:
        style_layer = get_styles.symbol('Cyclone_SVG')    
    elif "H" in Category:
        style_layer = get_styles.symbol('High_Pressure')
        
    # Create renderer object
    Category_Defined = QgsRendererCategory(Category, style_layer, str(Category))
    	
    # Entry for the list of category items
    categories.append(Category_Defined)
    
# Create renderer object
renderer = QgsCategorizedSymbolRenderer('Pressure', categories)

# Assign the created renderer to the layer
if renderer is not None:
    Layer_Pressure_Center.setRenderer(renderer)
        
# Apply style   
Layer_Pressure_Center.triggerRepaint()

# Label
layer_settings  = QgsPalLayerSettings()
text_format = QgsTextFormat()

text_format.setFont(QFont("Arial",35,QFont.Bold))
text_format.setSize(35)

# Get color from attribute table
pc=QgsPropertyCollection('Text')
color_prop=QgsProperty()
color_prop.setField("Color")
pc.setProperty(QgsPalLayerSettings.Color,color_prop)
layer_settings.setDataDefinedProperties(pc)

layer_settings.setFormat(text_format)
layer_settings.fieldName = "Pressure"
layer_settings.LabelPlacement = 4
layer_settings.LabelQuadrantPosition = 3
layer_settings.xOffset = 2.4
layer_settings.yOffset = -0.5
layer_settings.enabled = True

#create and append a new rule (no label for hurricanes)
root = QgsRuleBasedLabeling.Rule(QgsPalLayerSettings())
rule = QgsRuleBasedLabeling.Rule(layer_settings)
rule.setDescription("Pressure")
rule.setFilterExpression('"Pressure"  NOT LIKE \'HURRICANE\'')
root.appendChild(rule)

#Apply label configuration
rules = QgsRuleBasedLabeling(root)
Layer_Pressure_Center.setLabelsEnabled(True)
Layer_Pressure_Center.setLabeling(rules)
Layer_Pressure_Center.triggerRepaint()

# Save geopackages
print('4. Save geopackages')
filename = '/home/Satoz/SATOCEAN_ANALYSIS_N202210190000_F202210190000_TEST.gpkg'
layers = [Layer_Pressure_Center,Layer_Fronts,Layer_Pressure_Isobars]
processing.run("native:package", {'LAYERS': layers, 'OUTPUT': filename, 'OVERWRITE': False, 'SAVE_STYLES': True})

# Finally, exitQgis() is called to remove the
# provider and layer registries from memory
qgs.exitQgis()

_______________________________________________
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

Reply via email to