[GRASS-user] Uploading NumPy array as a new column to a vector map

César Augusto Ramírez Franco caesarivs at gmail.com
Sat Feb 16 09:39:00 PST 2019


On Fri, Feb 15, 2019, 09:17 Markus Neteler <neteler at osgeo.org wrote:

> Hi,
>
> Am Do., 14. Feb. 2019, 15:50 hat César Augusto Ramírez Franco <
> caesarivs at gmail.com> geschrieben:
>
>> Greetings,
>>
>> I have a municipality polygon layer with a poverty index (percent) and a
>> population count, I'm multiplying them to visualize the vulnerability for
>> each municipality, due to the distribution of that new variable I want to
>> compute the logarithm, which is not possible in sqlite,
>>
>
> Yes but there is an extension for this.
>
> See
> https://grasswiki.osgeo.org/wiki/Build_SQLite_extension_on_Linux
>
> It may solve the issue.
>
> Best
> Markus
>
>
Thanks!

That's actually pretty neat! I'll test this in the lab's computers this
week.

so I tried reading the column with numpy and issuing a np.log10(). I'm
>> happy with the result, but how can I get this new numpy array to a new
>> column in the vector map in a simple way?
>>
>> This is what I already have:
>>
>> #!/usr/bin/env python
>>
>> import grass.script as gs
>> import numpy as np
>> import matplotlib.pyplot as plt
>>
>> nbi_pob = np.array(gs.vector_db_select("muniant", columns =
>> "nbi_pob")["values"].values()).astype(float).squeeze()
>>
>> plt.hist(nbi_pob)
>> plt.show()
>>
>> log_nbi_pob = np.log10(nbi_pob)
>>
>> plt.hist(log_nbi_pob)
>> plt.show()
>>
>> I'm trying to introduce this kind of analysis to students who are not
>> familiar nor proficient with programming (this is an GIS introductory
>> course) so the numpy bit is already complex enough to them, and I'd like to
>> avoid using for loops with cursors to achieve this.
>>
>> Is there a simple solution to this?
>>
>> --
>> *César Augusto Ramírez Franco*
>> _______________________________________________
>> grass-user mailing list
>> grass-user at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/grass-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20190216/32c90f54/attachment.html>


More information about the grass-user mailing list