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/
export GISRC=/Users/usernamehere/.grassrc6
export LD_LIBRARY_PATH=/Applications/
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/Frameworks/GDAL.framework/Versions/1.7/Programs/:/Applications/

2. Scripting Python codes:
Open text editor and write scripts like followings, and then save as "".
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 "" 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("", 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/

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=
export ftp_proxy=

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

Acquire::http::proxy "";
Acquire::ftp::proxy "";
Acquire::https::proxy "";

* 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;

* 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.