Sunday, 26 July 2015

pyqgis - Why does QGIS 3.2 "native:extractvertices" algorithm not work properly in standalone script?



I execute standalone python code (almost identical to the code in the accepted answer):


The output file does not contain data, and I get this error message:


Warning 6: Normalized/laundered field name: 'vertex_index' to 'vertex_ind'
Warning 6: Normalized/laundered field name: 'vertex_part' to 'vertex_par'
Warning 6: Normalized/laundered field name: 'vertex_part_index' to 'vertex_p_1'

Process finished with exit code -1073741819 (0xC0000005)

Field name limitation is known shapefile issue, but why output file is empty and why I get exit code -1073741819 (0xC0000005)?


Here is input and output shapefiles:



enter image description here________enter image description here


What can cause this problem?


Here is the code:


import sys

from qgis.core import (
QgsApplication,
QgsProcessingFeedback,
QgsVectorLayer
)

from qgis.analysis import QgsNativeAlgorithms

QgsApplication.setPrefixPath(r'C:\OSGeo4W64\apps\qgis', True)
qgs = QgsApplication([], False)
qgs.initQgis()

sys.path.append(r'C:\OSGeo4W64\apps\qgis\python\plugins')

import processing
from processing.core.Processing import Processing

Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())

layer = QgsVectorLayer(r"G:\test\input.shp", 'my layer', 'ogr')
output = r"G:\test\output.shp"
params = {
'INPUT': layer,
'OUTPUT': output,
}
feedback = QgsProcessingFeedback()

res = processing.run("native:extractvertices", params, feedback=feedback)
print(res)

Answer



Based on my comments.


This is my py3-env.bat


@ECHO OFF 

set OSGEO4W_ROOT=C:\OSGeo4W64

@echo off

call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
call "%OSGEO4W_ROOT%\bin\qt5_env.bat"
call "%OSGEO4W_ROOT%\bin\py3_env.bat"

@echo off
path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
set GDAL_FILENAME_IS_UTF8=YES

set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000

set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins

SET PYCHARM="C:\Program Files\JetBrains\PyCharm 2018.1.4\bin\pycharm64.exe"

set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python
set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python36
set PYTHONPATH=%OSGEO4W_ROOT%\apps\Python36\lib\site-packages;%PYTHONPATH%

set QT_QPA_PLATFORM_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\Qt5\plugins\platforms
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis



cd /d %~dp0
::python3 extractvertices_standalone.py
::pause
start "PyCharm aware of QGIS" /B %PYCHARM% %*

if execute the file directly from .bat work,and if open pycharm.This is my project using the osge4w python interpreter


enter image description here


Run and pycharm console show :




{'OUTPUT': 'C:\datos\output\output.shp'}



Open the file to see the result in QGIS.


enter image description here


Finally the standalone script,it's just like his worst simply by using my shapefiles


#native:extractvertices
import sys

from qgis.core import (

QgsApplication,
QgsProcessingFeedback,
QgsVectorLayer
)
from qgis.analysis import QgsNativeAlgorithms

QgsApplication.setPrefixPath(r'C:\OSGeo4W64\apps\qgis', True)
qgs = QgsApplication([], False)
qgs.initQgis()


sys.path.append(r'C:\OSGeo4W64\apps\qgis\python\plugins')

import processing
from processing.core.Processing import Processing
Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())

layer = QgsVectorLayer(r"C:\datos\shapefiles\regions.shp", 'my layer', 'ogr')
output = r"C:\datos\output\output.shp"
params = {

'INPUT': layer,
'OUTPUT': output,
}
feedback = QgsProcessingFeedback()
res = processing.run("native:extractvertices", params, feedback=feedback)
print(res)

Tested using Windows 10 and QGIS 3.2


I hope this helps you


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...