[Qgis-user] [QGIS-user] Convert r.report output from txt to csv/xls

Nicolas Cadieux njacadieux.gitlab at gmail.com
Wed Jan 19 05:45:14 PST 2022


Hi,

I am not in front of my computer so it’s difficult for me to test the r.report functions.  I see they have various flags 

-h
Suppress page headers
-f
Use formfeeds between pages
-e
Scientific format

I see you can suppress some information like the header and probably some information at the bottom of the page.  What is -e???  Could that be a easier csv output?

Are you using r.report for cross tabulation?  You may be able to get a less messy output with another QGIS algorithm.  What specific information do you need? Gdal info using the -stats flag probably has the same info you are looking for.  Make sure you do not use approximate statistics.   QGIS also has zonal statistics algorithms.  That would probably easier than adding a new python function in the model (but yes, I could be done).

Nicolas Cadieux
https://gitlab.com/njacadieux


> Le 18 janv. 2022 à 21:10, Igor Oliveira Ribeiro <igorgeoinformacao at gmail.com> a écrit :
> 
> 
> Hi Nicolas,
> thanks for your help. So, I don't know how to use python in QGIS. I know R and Matlab programming, but not about python. Please, see attached my model in QGIS. I would like to insert after each r.report box a conversion of the output file from txt to csv. Do you think it's possible?
> 
>> On Tue, Jan 18, 2022 at 10:05 PM Nicolas Cadieux <njacadieux.gitlab at gmail.com> wrote:
>> Hi,
>> 
>> Probably but this would be a Grass request.  
>> 
>> Nicolas Cadieux
>> https://gitlab.com/njacadieux
>> 
>>>> Le 18 janv. 2022 à 20:14, Ari Meyer <ari.meyer at gmail.com> a écrit :
>>>> 
>>> 
>>> Just a question, given the discussion here.  Shouldn't such a report be generated in a structured format like YAML/JSON/XML for easier parsing?  Would this merit an enhancement request?
>>> Ari
>>> 
>>>> On Tue, Jan 18, 2022 at 6:54 PM chris hermansen <clhermansen at gmail.com> wrote:
>>>> Nicolás, Igor and list,
>>>> 
>>>>> On Tue, Jan 18, 2022, 16:40 Nicolas Cadieux <njacadieux.gitlab at gmail.com> wrote:
>>>>> Hi,
>>>>> The r.report is a rather complicated text file that contains a lot of characters made for improving the look of the output.  On way could be to python your way thought it so that is can find your way to the proper information.  This would save time if you have lots of files. 
>>>> 
>>>> 
>>>> Or if you have to process the same file many times because your data is evolving.
>>>>> 
>>>>> The faster way, if you don’t program is to use a mixture of notepad++ along with excel or open office.  You can easily remove all useless characters like and replace them by no string or with a “,”.  Then you can import in open office.  I like OpenOffice Calc for this because you can they is to merge multiple separation characters into one.  This could help with the imports.  For example, if you have “line 1…….data,data,data”, you could use both the dot and the comma as separators and the multiple dots would be merged as one unique separator.  
>>>> 
>>>> 
>>>> Or not... If your decimal points are dots.
>>>>> 
>>>>> If you have multiple files, you could use concatenation to make one big .csv file.  For windows, use the example could here. https://superuser.com/questions/111825/a-command-line-or-batch-cmd-to-concatenate-multiple-files
>>>>> 
>>>>> Hope this helps.  This by the way is an excellent way to start learning Python programming.  Python has easy of way to read and write.txt file and multiple way to manipulate text strings.  Great project if you have the time to learn.
>>>> 
>>>> 
>>>> I have to transform data files like this quite often.
>>>> 
>>>> Generally whether using Python or another programming language, you want to use regular expressions to match and transform text patterns. The learning curve can be a bit steep but very worthwhile.
>>>> 
>>>> On Unix / Linux there is a specialized language for this type of transform called awk. It's probably available for Windows somewhere. The advantage of awk is there is no programming overhead for reading and writing lines; the awk programs are statements reacting to the input received from the file.
>>>>> 
>>>>> Nicolas Cadieux
>>>>> https://gitlab.com/njacadieux
>>>>> 
>>>>>>> Le 18 janv. 2022 à 19:18, Igor Oliveira Ribeiro <igorgeoinformacao at gmail.com> a écrit :
>>>>>>> 
>>>>>> 
>>>>>> Hi, 
>>>>>> I have been using qgis version 3.10 and 3.16. I've been using the r.report tool to extract some data from a raster. Currently, the report is generated from r.report in *.txt format. I would like to know if it is possible to convert this format to csv/xls, within QGIS?
>>>>>> 
>>>>>> -- 
>>>>>> 
>>>>>> See our last paper: 
>>>>>> Impact of biomass burning on a metropolitan area in the Amazon during the 2015 El Niño: The enhancement of carbon monoxide and levoglucosan concentrations.
>>>>>> 
>>>>>> Igor Oliveira Ribeiro
>>>>>> Post-Doc on Regional Climate Change, Vulnerability, Impacts and Adaptation - Cuomo Foundation/UEA
>>>>>> 
>>>>>> +55 92 98103 7136 | skype: igorflorestal
>>>>>> 
>>>>>> Universidade do Estado do Amazonas | Instituto Nacional de Pesquisas da Amazônia
>>>>>> 
>>>>>> Visite: www.geoescrita.com.br
>>>>>> 
>>>>>> 
>>>>>> Think globally, act locally!
>>>>>> _______________________________________________
>>>>>> Qgis-user mailing list
>>>>>> Qgis-user at lists.osgeo.org
>>>>>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
>>>>>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>>>>> _______________________________________________
>>>>> Qgis-user mailing list
>>>>> Qgis-user at lists.osgeo.org
>>>>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
>>>>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>>>> _______________________________________________
>>>> Qgis-user mailing list
>>>> Qgis-user at lists.osgeo.org
>>>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
>>>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>> _______________________________________________
>> Qgis-user mailing list
>> Qgis-user at lists.osgeo.org
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
> 
> 
> -- 
> 
> See our last paper: 
> Impact of biomass burning on a metropolitan area in the Amazon during the 2015 El Niño: The enhancement of carbon monoxide and levoglucosan concentrations.
> 
> Igor Oliveira Ribeiro
> Post-Doc on Regional Climate Change, Vulnerability, Impacts and Adaptation - Cuomo Foundation/UEA
> 
> +55 92 98103 7136 | skype: igorflorestal
> 
> Universidade do Estado do Amazonas | Instituto Nacional de Pesquisas da Amazônia
> 
> Visite: www.geoescrita.com.br
> 
> 
> Think globally, act locally!
> <model_r.report.pdf>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20220119/6387b019/attachment.html>


More information about the Qgis-user mailing list