Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Processing] GRASS fix all ext scripts #5968

Merged
merged 16 commits into from Jan 9, 2018
Merged

[Processing] GRASS fix all ext scripts #5968

merged 16 commits into from Jan 9, 2018

Conversation

ghost
Copy link

@ghost ghost commented Dec 31, 2017

Description

This PR fixes all the Python scripts in the ext/ directory of the GRASS Processing provider.

The scripts are provided in order to properly handle the internal logic of some algorithms (well a lot of algorithms actually). For example, if you want to use v.net.iso you have to build an internal GRASS vector with two layers (one for the network and the other for the center points). There is no mechanism in QGIS to build this special vector so you have to build it before really using v.net.iso. The ext script just do it for you so you only have to provide one line vector layer for the network and one point layer for the center points, directly from QGIS.

I have also improved Grass7Algorithm.py (the main algorithm handling code for the provider) by adding support for some specific cases. Some description files where also broken and I have updated them.

When this PR will be merged in master, the GRASS Processing provider will be at (about) the same level than in QGIS 2.x.

However, I have discarded some (or specific options for) algorithms:

  • for v.net, I have deleted all turn tables options because I haven't found yet a way to properly handle them from QGIS (actually it is because I can't export them from GRASS).
  • i.rectify: I can't find a way to make it work (I need more time to find a way to properly incorporate GCP points).
  • v.lrs.* : I don't understand the logic behind this, so I can't build data to test those algorithms.

Checklist

Reviewing is a process done by project maintainers, mostly on a volunteer basis. We try to keep the overhead as small as possible and appreciate if you help us to do so by completing the following items. Feel free to ask in a comment if you have troubles with any of them.

  • Commit messages are descriptive and explain the rationale for changes
  • Commits which fix bugs include fixes #11111 in the commit message next to the description
  • Commits which add new features are tagged with [FEATURE] in the commit message
  • Commits which change the UI or existing user workflows are tagged with [needs-docs] in the commit message and containt sufficient information in the commit message to be documented
  • I have read the QGIS Coding Standards and this PR complies with them
  • This PR passes all existing unit tests (test results will be reported by travis-ci after opening this PR)
  • New unit tests have been added for core changes
  • I have run the scripts/prepare-commit.sh script before each commit

@timlinux
Copy link
Member

timlinux commented Jan 1, 2018

@medspx Thanks for this. Do you have any ability to test on MacOS? I still (as of about a week ago when I last tested) can't get any GRASS algs to run on Mac.

@nirvn
Copy link
Contributor

nirvn commented Jan 2, 2018

@timlinux , maybe not entirely a mac-only issue, I've also not been able to run most GRASS algorithms on my Ubuntu machine, including simple ones like v.clean. I'll paste the log output here later today.

@nirvn
Copy link
Contributor

nirvn commented Jan 2, 2018

Try this:

  • Download the attached project and open it ( grass.zip )
  • Try to execute the v.clean algorithm on the project's "Simple" layer (keep outputs as temporary)

Over here, both the errors and the cleaned layers are empty. The algorithm log output is as follow:

Processing algorithm...
Algorithm 'v.clean - Toolset for cleaning topology of vector map.' starting...
Input parameters:
{ 'input' : '/home/webmaster/Desktop/grass/simple.shp', 'type' : [0,1,2,3,4,5,6], 'tool' : [0], 'threshold' : '', '-b' : False, '-c' : False, 'output' : '/tmp/processing_171788030d40465b93b88dab4baa6cb2/ecd720aaa419426298568db11e9cb80a/output.shp', 'error' : '/tmp/processing_171788030d40465b93b88dab4baa6cb2/ffd66b191a3a405bbfd3a950d3ef3adf/error.shp', 'GRASS_REGION_PARAMETER' : '', 'GRASS_SNAP_TOLERANCE_PARAMETER' : -1, 'GRASS_MIN_AREA_PARAMETER' : 0.0001, 'GRASS_OUTPUT_TYPE_PARAMETER' : 0 }

g.proj -c proj4="+proj=utm +zone=48 +a=6377276.345 +b=6356075.41314024 +towgs84=198,881,317,0,0,0,0 +units=m +no_defs"
v.external input="/home/webmaster/Desktop/grass/simple.shp" output="a5a4b066781d323" --overwrite -o
g.region n=1541456.0 s=1524973.0 e=736925.0 w=726973.0
v.clean input=a5a4b066781d323 type="point" tool="break" output=outputc9e7d32f3fce4fc9a5a15fb3c5f7aed5 error=errorc9e7d32f3fce4fc9a5a15fb3c5f7aed5 --overwrite
v.out.ogr -c type=auto input="outputc9e7d32f3fce4fc9a5a15fb3c5f7aed5" output="/tmp/processing_171788030d40465b93b88dab4baa6cb2/ecd720aaa419426298568db11e9cb80a/output.shp" format=ESRI_Shapefile --overwrite
v.out.ogr -c type=auto input="errorc9e7d32f3fce4fc9a5a15fb3c5f7aed5" output="/tmp/processing_171788030d40465b93b88dab4baa6cb2/ffd66b191a3a405bbfd3a950d3ef3adf/error.shp" format=ESRI_Shapefile --overwrite
Cleaning up temporary files... 
access: No such file or directory 
ERROR: LOCATION  not available 
Starting GRASS GIS... 
Executing  ... 
Default region was updated to the new projection, but if you have multiple mapsets `g.region -d` should be run in each to update the region from the default 
Projection information updated 
Building topology for vector map ... 
Using external data format 'ESRI Shapefile' (feature type 'polygon') 
Registering primitives... 

6 primitives registered 
154 vertices registered 
Number of nodes: 5 
Number of primitives: 6 
Number of points: 0 
Number of lines: 0 
Number of boundaries: 5 
Number of centroids: 1 
Number of areas: 5 
Number of isles: 5 
v.external complete. Link to vector map  created. 
-------------------------------------------------- 
Tool: Threshold 
Break: 0 
-------------------------------------------------- 
Copying features... 
16..33..50..66..83..100 
DBMI-SQLite driver error: 
Unable to create index: 
create unique index if not exists outputc9e7d32f3fce4fc9a5a15fb3c5f7aed5_ on outputc9e7d32f3fce4fc9a5a15fb3c5f7aed5 ( ) 
near ")": syntax error 

DBMI-SQLite driver error: 
Unable to create index: 
create unique index if not exists outputc9e7d32f3fce4fc9a5a15fb3c5f7aed5_ on outputc9e7d32f3fce4fc9a5a15fb3c5f7aed5 ( ) 
near ")": syntax error 

WARNING: Unable to create index 
WARNING: Unable to copy table  for layer 1 from  to  
WARNING: Failed to copy attribute table to output vector map 
Rebuilding parts of topology... 
Building topology for vector map ... 
Registering primitives... 

6 primitives registered 
155 vertices registered 
Number of nodes: 5 
Number of primitives: 6 
Number of points: 0 
Number of lines: 0 
Number of boundaries: 5 
Number of centroids: 1 
Number of areas: - 
Number of isles: - 
-------------------------------------------------- 
Tool: Break lines at intersections 
-------------------------------------------------- 
Rebuilding topology for output vector map... 
Building topology for vector map ... 
Registering primitives... 

6 primitives registered 
155 vertices registered 
Building areas... 
0..16..33..50..66..83..100 
5 areas built 
5 isles built 
Attaching islands... 
20..40..60..80..100 
Attaching centroids... 
16..33..50..66..83..100 
Number of nodes: 5 
Number of primitives: 6 
Number of points: 0 
Number of lines: 0 
Number of boundaries: 5 
Number of centroids: 1 
Number of areas: 5 
Number of isles: 5 
-------------------------------------------------- 
Building topology for error vector map... 
Building topology for vector map ... 
Registering primitives... 

0 primitives registered 
0 vertices registered 
Building areas... 
100 
0 areas built 
0 isles built 
Attaching islands... 
Attaching centroids... 
Number of nodes: 0 
Number of primitives: 0 
Number of points: 0 
Number of lines: 0 
Number of boundaries: 0 
Number of centroids: 0 
Number of areas: 0 
Number of isles: 0 
WARNING: The map contains islands. With the -c flag, islands will appear as filled areas, not holes in the output map. 
ERROR: Key column <> not found 
WARNING: Unable to determine input map's vector feature type(s). 
WARNING: No attribute table found -> using only category numbers as attributes 
WARNING: Output layer is empty, no features written 
v.out.ogr complete. 0 features (Unknown (any) type) written to  (ESRI_Shapefile format). 
Execution of  finished. 
Cleaning up temporary files... 
Execution completed in 0.26 seconds
Results:
{'error': , 'output': }

Loading resulting layers
Algorithm 'v.clean - Toolset for cleaning topology of vector map.' finished

@ghost
Copy link
Author

ghost commented Jan 7, 2018

Hello,

@nirvn It was just a problem with v.external which doesn't work properly for v.clean. You just have to modify the configuration settings to disable v.external in Settings -> Options -> Processing -> Providers -> GRASS -> use v.external.
v_external

I have also disabled v.external by default with the latest commit, just in case (actually it is already disabled by default in #5726 which is not merged for the moment).

When it is disabled, I have (some) results with v.clean on your data (note the use of v.in.ogr instead of v.external in the logs):

Processing algorithm...
Algorithm 'v.clean - Toolset for cleaning topology of vector map.' starting...
Input parameters:
{ 'GRASS_OUTPUT_TYPE_PARAMETER' : 0, 'error' : '/tmp/processing_ed853c54f7cc426fada7c23410117afc/6d863d6f9a5c4bfc95a71d32be062a76/error.shp', 'tool' : [0], 'threshold' : '', 'type' : [0,1,2,3,4,5,6], 'GRASS_REGION_PARAMETER' : '', 'output' : '/tmp/processing_ed853c54f7cc426fada7c23410117afc/a71e726f7fdb4656ba57251b091c8a5a/output.shp', 'GRASS_SNAP_TOLERANCE_PARAMETER' : -1, '-b' : False, '-c' : False, 'GRASS_MIN_AREA_PARAMETER' : 0.0001, 'input' : '/home/medspx/tmp/simple.shp' }

g.proj -c proj4="+proj=utm +zone=48 +a=6377276.345 +b=6356075.41314024 +towgs84=198,881,317,0,0,0,0 +units=m +no_defs"
v.in.ogr min_area=0.0001 snap=-1.0 input="/home/medspx/tmp/simple.shp" output="vector_5a51f1aa5676d2" --overwrite -o
g.region n=1541456.0 s=1524973.0 e=736925.0 w=726973.0
v.clean input=vector_5a51f1aa5676d2 type="point,line,boundary,centroid,area,face,kernel" tool="break" output=output206b9e5261af4774b0175fde58aeca6c error=error206b9e5261af4774b0175fde58aeca6c --overwrite
v.out.ogr type=auto input="output206b9e5261af4774b0175fde58aeca6c" output="/tmp/processing_ed853c54f7cc426fada7c23410117afc/a71e726f7fdb4656ba57251b091c8a5a/output.shp" format=ESRI_Shapefile --overwrite
v.out.ogr type=auto input="error206b9e5261af4774b0175fde58aeca6c" output="/tmp/processing_ed853c54f7cc426fada7c23410117afc/6d863d6f9a5c4bfc95a71d32be062a76/error.shp" format=ESRI_Shapefile --overwrite
Démarrage du SIG GRASS ... 
Exécution de </tmp/processing_ed853c54f7cc426fada7c23410117afc/grassdata/grass_batch_job.sh> ... 
Default region was updated to the new projection, but if you have multiple mapsets `g.region -d` should be run in each to update the region from the default 
Projection information updated 
ATTENTION: Datum <Indian_1960> non reconnu par GRASS et aucuns paramètres trouvés 
Over-riding projection check 
Check if OGR layer <simple> contains polygons... 
0..100 
Importing 1 features (OGR layer <simple>)... 
0..100 
----------------------------------------------------- 
Enregistrement des primitives ... 

5 primitives registered 
154 vertices registered 
Nombre de nœuds: 5 
Nombre de primitives: 5 
Nombre de points: 0 
Nombre de lignes :0 
Nombre de contours: 5 
Nombre de centroïdes: 0 
Nombre de surfaces: - 
Nombre d'îles: - 
----------------------------------------------------- 
Cleaning polygons 
----------------------------------------------------- 
Breaking polygons... 
Breaking polygons (pass 1: select break points)... 
20..40..60..80..100 
Breaking polygons (pass 2: break at selected points)... 
20..40..60..80..100 
----------------------------------------------------- 
Removing duplicates... 
20..40..60..80..100 
----------------------------------------------------- 
Breaking boundaries... 
0..20..40..60..80..100 
----------------------------------------------------- 
Removing duplicates... 
20..40..60..80..100 
----------------------------------------------------- 
Cleaning boundaries at nodes... 
20..40..60..80..100 
----------------------------------------------------- 
Merging boundaries... 
20..40..60..80..100 
----------------------------------------------------- 
Removing dangles... 
20..40..60..80..100 
----------------------------------------------------- 
Construction des surfaces ... 
0..20..40..60..80..100 
5 areas built 
5 isles built 
Nombre de nœuds: 5 
Nombre de primitives: 5 
Nombre de points: 0 
Nombre de lignes :0 
Nombre de contours: 5 
Nombre de centroïdes: 0 
Nombre de surfaces: 5 
Nombre d'îles: 5 
----------------------------------------------------- 
Removing bridges... 
20..40..60..80..100 
----------------------------------------------------- 
Enregistrement des primitives ... 

5 primitives registered 
154 vertices registered 
Construction des surfaces ... 
0..20..40..60..80..100 
5 areas built 
5 isles built 
Attachement des îles ... 
20..40..60..80..100 
Nombre de nœuds: 5 
Nombre de primitives: 5 
Nombre de points: 0 
Nombre de lignes :0 
Nombre de contours: 5 
Nombre de centroïdes: 0 
Nombre de surfaces: 5 
Nombre d'îles: 5 
----------------------------------------------------- 
Finding centroids for OGR layer <simple>... 
0..100 
----------------------------------------------------- 
Writing centroids... 
20..40..60..80..100 
----------------------------------------------------- 
1 input polygons 
Total area: 1.24236E+08 (5 areas) 
Area without category: 4.36948E+06 (4 areas) 
----------------------------------------------------- 
Copie des objets ... 
16..33..50..66..83..100 
Construction de la topologie pour la carte vectorielle <vector_5a51f1aa5676d2@PERMANENT>... 
Enregistrement des primitives ... 

6 primitives registered 
155 vertices registered 
Construction des surfaces ... 
0..16..33..50..66..83..100 
5 areas built 
5 isles built 
Attachement des îles ... 
20..40..60..80..100 
Attachement des centroïdes ... 
16..33..50..66..83..100 
Nombre de nœuds: 5 
Nombre de primitives: 6 
Nombre de points: 0 
Nombre de lignes :0 
Nombre de contours: 5 
Nombre de centroïdes: 1 
Nombre de surfaces: 5 
Nombre d'îles: 5 
-------------------------------------------------- 
Tool: Threshold 
Break: 0 
-------------------------------------------------- 
Copie des objets ... 
16..33..50..66..83..100 
Rebuilding parts of topology... 
Construction de la topologie pour la carte vectorielle <output206b9e5261af4774b0175fde58aeca6c@PERMANENT>... 
Enregistrement des primitives ... 

6 primitives registered 
155 vertices registered 
Nombre de nœuds: 5 
Nombre de primitives: 6 
Nombre de points: 0 
Nombre de lignes :0 
Nombre de contours: 5 
Nombre de centroïdes: 1 
Nombre de surfaces: - 
Nombre d'îles: - 
-------------------------------------------------- 
Tool: Break lines at intersections 
0..16..33..50..66..83..100 
-------------------------------------------------- 
Rebuilding topology for output vector map... 
Construction de la topologie pour la carte vectorielle <output206b9e5261af4774b0175fde58aeca6c@PERMANENT>... 
Enregistrement des primitives ... 

6 primitives registered 
155 vertices registered 
Construction des surfaces ... 
0..16..33..50..66..83..100 
5 areas built 
5 isles built 
Attachement des îles ... 
20..40..60..80..100 
Attachement des centroïdes ... 
16..33..50..66..83..100 
Nombre de nœuds: 5 
Nombre de primitives: 6 
Nombre de points: 0 
Nombre de lignes :0 
Nombre de contours: 5 
Nombre de centroïdes: 1 
Nombre de surfaces: 5 
Nombre d'îles: 5 
-------------------------------------------------- 
Building topology for error vector map... 
Construction de la topologie pour la carte vectorielle <error206b9e5261af4774b0175fde58aeca6c@PERMANENT>... 
Enregistrement des primitives ... 

0 primitives registered 
0 vertices registered 
Construction des surfaces ... 
100 
0 areas built 
0 isles built 
Attachement des îles ... 
Attachement des centroïdes ... 
Nombre de nœuds: 0 
Nombre de primitives: 0 
Nombre de points: 0 
Nombre de lignes :0 
Nombre de contours: 0 
Nombre de centroïdes: 0 
Nombre de surfaces: 0 
Nombre d'îles: 0 
Exporting 5 areas (may take some time)... 
20..40..60..80..100 
ATTENTION: 4 features without category were skipped. Features without category are written only when -c flag is given. 
v.out.ogr terminé. 1 feature (Polygon type) written to <output206b9e5261af4774b0175fde58aeca6c> (ESRI_Shapefile format). 
ATTENTION: Unable to determine input map's vector feature type(s). 
ATTENTION: Aucune table attributaire trouvée -> on utilise les identifiants de catégories comme attributs 
ATTENTION: Output layer is empty, no features written 
v.out.ogr terminé. 0 features (Unknown (any) type) written to <error206b9e5261af4774b0175fde58aeca6c> (ESRI_Shapefile format). 
Exécution de </tmp/processing_ed853c54f7cc426fada7c23410117afc/grassdata/grass_batch_job.sh> terminée. 
Nettoyage des fichiers temporaires ... 
Execution completed in 0.36 seconds
Results:
{'error': <QgsProcessingOutputLayerDefinition {'sink':/tmp/processing_ed853c54f7cc426fada7c23410117afc/6d863d6f9a5c4bfc95a71d32be062a76/error.shp, 'createOptions': {'fileEncoding': 'System'}}>, 'output': <QgsProcessingOutputLayerDefinition {'sink':/tmp/processing_ed853c54f7cc426fada7c23410117afc/a71e726f7fdb4656ba57251b091c8a5a/output.shp, 'createOptions': {'fileEncoding': 'System'}}>}

Loading resulting layers
Algorithm 'v.clean - Toolset for cleaning topology of vector map.' finished

@ghost
Copy link
Author

ghost commented Jan 7, 2018

@timlinux Hello, I am really sorry, I don't have a Mac for the tests (and debugging). I assumed that it was a POSIX OS and that I could use the same code and options than for GNU/Linux distributions. But it seems that it is not the case.

Can someone else help with this issue?

@nirvn
Copy link
Contributor

nirvn commented Jan 9, 2018

@medspx , I've tested this PR, working nicely, and v.clean (as well as a bunch of other operations) are now working with the new default settings.

@nyalldawson , we should probably merge this fix ASAP.

@nyalldawson
Copy link
Collaborator

I'll let @alexbruy do that

@alexbruy alexbruy merged commit 566704a into qgis:master Jan 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants