tag:blogger.com,1999:blog-36480913069773800142024-02-19T23:59:18.579-08:00Something about Culture and Information ScienceYu Fujimotohttp://www.blogger.com/profile/00522356224690770821noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-3648091306977380014.post-78229125892010929072011-06-09T02:22:00.000-07:002011-06-09T02:31:18.345-07:00GRASS GIS programming with Python on Mac OS XGeographic Resources Analysis Support System (GRASS) is the one of free GIS software.<br />
Because this software supports multiplatform environments, it works on Windows, Mac and Linux.<br />
In my case, I installed GRASS on my iMac and Ubuntu laptop. GRASS is my primary GIS software, now.<br />
<br />
Although many popular GIS softwares provide integrated graphical interfaces, GRASS provides "libraries" for geographical analysis,<br />
and users need to combine these libraries for own purposes.<br />
Therefore, programming skills are essential to fully enjoy the benefit of this software.<br />
<br />
Bash scripts are the most popular way to implement any procedures.<br />
However, bash scrips aren't supported on Windows platform,<br />
and it's not efficient to implement complicated process.<br />
<br />
Because of these reasons, I tried Python scripts for GRASS programming,<br />
and here I draw up memos of setting up and of sample codes on Mac OS X.<br />
<br />
1. Setting up Python environment:<br />
Open terminal and set up system environment.<br />
<br />
<span class="Apple-style-span" style="color: red;">export GISBASE=/Applications/GRASS-6.4.app/Contents/MacOS</span><br />
<span class="Apple-style-span" style="color: red;">export GISRC=/Users/usernamehere/.grassrc6</span><br />
<span class="Apple-style-span" style="color: red;">export LD_LIBRARY_PATH=/Applications/GRASS-6.4.app/Contents/MacOS/lib</span><br />
<span class="Apple-style-span" style="color: red;">export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/Frameworks/GDAL.framework/Versions/1.7/Programs/:/Applications/GRASS-6.4.app/Contents/MacOS:/Library/Frameworks/PROJ.framework/Versions/4/Programs/:/Applications/GRASS-6.4.app/Contents/MacOS/lib:/Applications/GRASS-6.4.app/Contents/MacOS/scripts:/Applications/GRASS-6.4.app/Contents/MacOS/etc:/Applications/GRASS-6.4.app/Contents/MacOS/bin:/Applications/GRASS-6.4.app/Contents/MacOS/etc/python:/usr/X11/bin</span><br />
<br />
2. Scripting Python codes:<br />
Open text editor and write scripts like followings, and then save as "sample.py".<br />
In this example, vector information is acquired by using Python script.<br />
<br />
<span class="Apple-style-span" style="color: lime;"><i># -*- coding: utf-8 -*-</i></span><br />
<span class="Apple-style-span" style="color: magenta;">import</span> os<br />
<span class="Apple-style-span" style="color: magenta;">import</span> grass.script as grass<br />
<br />
<i><span class="Apple-style-span" style="color: lime;"># Get vector map information of "sites" by using "v.info" with "-t" flag.</span></i><br />
<i><span class="Apple-style-span" style="color: lime;"># You can use multiple flags at the same time by connecting flags characters with +.</span></i><br />
<i><span class="Apple-style-span" style="color: lime;"># A single flag, "t", is used in this example.</span></i><br />
info = <span class="Apple-style-span" style="color: magenta;">grass.parse_command(</span>"v.info", flags="t", map="sites"<span class="Apple-style-span" style="color: magenta;">)</span><br />
<br />
<span class="Apple-style-span" style="color: lime;"><i># The result is retured as dict type.</i></span><br />
<span class="Apple-style-span" style="color: magenta;">print</span> info<br />
<br />
<span class="Apple-style-span" style="color: lime;"><i># Get specific key as integer.</i></span><br />
<span class="Apple-style-span" style="color: magenta;">print</span> <span class="Apple-style-span" style="color: magenta;">int(</span>info['points']<span class="Apple-style-span" style="color: magenta;">)</span><br />
<br />
3. Run Python script on GRASS shell.<br />
Type like following on GRASS shell.<br />
<br />
<span class="Apple-style-span" style="color: red;">GRASS 6.4.0 (miyagi):~ > python path/to/the/python/sample.py</span><br />
<div><br />
</div>Yu Fujimotohttp://www.blogger.com/profile/00522356224690770821noreply@blogger.com0tag:blogger.com,1999:blog-3648091306977380014.post-5729653386676518232011-03-06T01:33:00.000-08:002011-03-19T10:05:17.455-07:00Proxy setting on Ubuntu 10.10 at Doshisha University.<span style="color: white;"><span style="font-size: 85%;"></span></span>This is a reminder for proxy setting on Ubuntu 10.10 at Doshisha University.This is a reminder for proxy setting on Ubuntu 10.10 at Doshisha University.<br />
Because there is a fatal bug in Ubunbu 10.10, network proxy would be invalid after the first update.<br />
In that case, proxy should be configured by yourself.<br />
<br />
1. edit /etc/bash.bashrc. Add to following lines at the end of file :<br />
<span class="Apple-style-span" style="color: red;"> export http_proxy=http://username:password@proxy.doshisha.ac.jp:8080/<br />
export ftp_proxy=http://username:password@proxy.doshisha.ac.jp:8080/</span><br />
<br />
2. edit, or create new file /etc/apt/apt.conf :<br />
<br />
<span class="Apple-style-span" style="color: red;"> Acquire::http::proxy "http://username:password@proxy.doshisha.ac.jp:8080/";<br />
Acquire::ftp::proxy "ftp://username:password@proxy.doshisha.ac.jp:8080/";<br />
Acquire::https::proxy "https://username:password@proxy.doshisha.ac.jp:8080/";</span><br />
<br />
* To set up above configuration on text editor(gedit), type following command on terminal screen;<br />
<span class="Apple-style-span" style="color: red;"> sudo gedit /etc/apt/apt.conf<br />
sudo gedit ~/.bashrc</span> <br />
3. Access "Network Proxy" tool and configure your proxy settings.<br />
<span class="Apple-style-span" style="color: red;"> System -> Preferences -> Network Proxy</span><br />
<br />
<br />
Following article would be helpful;<br />
<a href="http://ubuntuforums.org/archive/index.php/t-83401"><span class="Apple-style-span" style="color: blue;">http://ubuntuforums.org/archive/index.php/t-83401</span></a><br />
<br />
* Note that login do-net is always required when you start new session,<br />
or you can't connect to Internet service includes Ubuntu Software Center and Update Manager.<span style="font-size: 85%;"><br />
</span>Yu Fujimotohttp://www.blogger.com/profile/00522356224690770821noreply@blogger.com0tag:blogger.com,1999:blog-3648091306977380014.post-74107336824993532011-02-28T01:31:00.000-08:002011-03-06T01:40:09.715-08:00Which is the best text editor??<div>Yesterday, I discussed with my fellows about proper text editors for scripting.</div><div>Because everyone would have interest about this topic, </div><div>I'm going to write about "adequate text editor for scripting", as my first blog.</div><div><br /></div><div>We use a text editor for writing R, Bash , HTML and Javascript, </div><div>and sometimes use it for reading unknown files.</div><div>To do such things, following requirements are needed;</div><div>1. having style templates for R, Bash, HTML and Javascript.</div><div>2. having functions for check/changing text-encoding.</div><div><br /></div><div>In my case, multi-platform software is important as well </div><div>because I work on my various projects with Win, Mac and Ubuntu,</div><div>3. multi-platform(supports Win, Mac and Ubuntu) is preferred.</div><div><br /></div><div>As a result we concluded that "Komodo Editor" may be better than anything else.</div><div>By applying a plugin, "Sciviews-K ", to Komodo Edit, these requirements fulfilled.</div><div><br /></div><div><a href="http://www.activestate.com/komodo-edit"><span style="color:#3366ff;">Komodo Editor: http://www.activestate.com/komodo-edit</span></a></div><div><a href="http://sciviews.org/SciViews-K/"><span style="color:#3366ff;">Sciviews: http://sciviews.org/SciViews-K/</span></a></div><div><br /></div><div>Installing Komodo Editor & Sciviews-K on Ubuntu is a little bit tricky</div><div>for such people who are a beginner of Ubuntu. Following HP will be helpful; </div><div><a href="http://usefulubuntu.blogspot.com/2009/03/installing-komodo-edit-5.html"><span style="color:#3366ff;">http://usefulubuntu.blogspot.com/2009/03/installing-komodo-edit-5.html</span></a></div><div><br /></div><div>I could install Komodo Editor & Sciviews-K on Ubuntu without any problems.</div><div>I confirmed that Komodo Editor 6.1.1 is working on Ubuntu 10.10.</div>Yu Fujimotohttp://www.blogger.com/profile/00522356224690770821noreply@blogger.com2