Thursday 9 June 2011

GRASS GIS programming with Python on Mac OS X

Geographic Resources Analysis Support System (GRASS) is the one of free GIS software.
Because this software supports multiplatform environments, it works on Windows, Mac and Linux.
In my case, I installed GRASS on my iMac and Ubuntu laptop. GRASS is my primary GIS software, now.

Although many popular GIS softwares provide integrated graphical interfaces, GRASS provides "libraries" for geographical analysis,
and users need to combine these libraries for own purposes.
Therefore, programming skills are essential to fully enjoy the benefit of this software.

Bash scripts are the most popular way to implement any procedures.
However, bash scrips aren't supported on Windows platform,
and it's not efficient to implement complicated process.

Because of these reasons, I tried Python scripts for GRASS programming,
and here I draw up memos of setting up and of sample codes on Mac OS X.

1. Setting up Python environment:
Open terminal and set up system environment.

export GISBASE=/Applications/GRASS-6.4.app/Contents/MacOS
export GISRC=/Users/usernamehere/.grassrc6
export LD_LIBRARY_PATH=/Applications/GRASS-6.4.app/Contents/MacOS/lib
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

2. Scripting Python codes:
Open text editor and write scripts like followings, and then save as "sample.py".
In this example, vector information is acquired by using Python script.

# -*- coding: utf-8 -*-
import os
import grass.script as grass

# Get vector map information of "sites" by using "v.info" with "-t" flag.
# You can use multiple flags at the same time by connecting flags characters with +.
# A single flag, "t", is used in this example.
info = grass.parse_command("v.info", flags="t", map="sites")

# The result is retured as dict type.
print info

# Get specific key as integer.
print int(info['points'])

3. Run Python script on GRASS shell.
Type like following on GRASS shell.

GRASS 6.4.0 (miyagi):~ > python path/to/the/python/sample.py

Sunday 6 March 2011

Proxy setting on Ubuntu 10.10 at Doshisha University.

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.
Because there is a fatal bug in Ubunbu 10.10, network proxy would be invalid after the first update.
In that case, proxy should be configured by yourself.

1. edit /etc/bash.bashrc. Add to following lines at the end of file :
export http_proxy=http://username:password@proxy.doshisha.ac.jp:8080/
export ftp_proxy=http://username:password@proxy.doshisha.ac.jp:8080/


2. edit, or create new file /etc/apt/apt.conf :

Acquire::http::proxy "http://username:password@proxy.doshisha.ac.jp:8080/";
Acquire::ftp::proxy "ftp://username:password@proxy.doshisha.ac.jp:8080/";
Acquire::https::proxy "https://username:password@proxy.doshisha.ac.jp:8080/";


* To set up above configuration on text editor(gedit), type following command on terminal screen;
sudo gedit /etc/apt/apt.conf
sudo gedit ~/.bashrc

3. Access "Network Proxy" tool and configure your proxy settings.
System -> Preferences -> Network Proxy


Following article would be helpful;
http://ubuntuforums.org/archive/index.php/t-83401

* Note that login do-net is always required when you start new session,
or you can't connect to Internet service includes Ubuntu Software Center and Update Manager.

Monday 28 February 2011

Which is the best text editor??

Yesterday, I discussed with my fellows about proper text editors for scripting.
Because everyone would have interest about this topic,
I'm going to write about "adequate text editor for scripting", as my first blog.

We use a text editor for writing R, Bash , HTML and Javascript,
and sometimes use it for reading unknown files.
To do such things, following requirements are needed;
1. having style templates for R, Bash, HTML and Javascript.
2. having functions for check/changing text-encoding.

In my case, multi-platform software is important as well
because I work on my various projects with Win, Mac and Ubuntu,
3. multi-platform(supports Win, Mac and Ubuntu) is preferred.

As a result we concluded that "Komodo Editor" may be better than anything else.
By applying a plugin, "Sciviews-K ", to Komodo Edit, these requirements fulfilled.


Installing Komodo Editor & Sciviews-K on Ubuntu is a little bit tricky
for such people who are a beginner of Ubuntu. Following HP will be helpful;

I could install Komodo Editor & Sciviews-K on Ubuntu without any problems.
I confirmed that Komodo Editor 6.1.1 is working on Ubuntu 10.10.