Proj4はここからダウンロード
$ wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz
$ wget http://download.osgeo.org/proj/proj-datumgrid-1.5.zip
$ tar xzvf proj-4.8.0.tar.gz
$ cd proj-4.8.0/nad
$ unzip ../../proj-datumgrid-1.5.zip
$ cd ..
$ ./configure
$ make
$ sudo make install
GEOSはここからダウンロード
(geos-3.4.1)
$ wget http://download.osgeo.org/geos/geos-3.4.1.tar.bz2
$ tar -xjvf geos-3.4.1.tar.bz2
$ ./configure
$ make
$ make install
GDAL
$ wget http://download.osgeo.org/gdal/gdal-1.9.2.tar.gz
$ tar xzvf gdal-1.9.2.tar.gz
$ cd gdal-1.9.2
$ ./configure --with-static-proj4=/usr/local/lib
$ make # Go get some coffee, this takes a while.
$ sudo make install
$ cd ..
libxml2(ここ)
$ wget http://xmlsoft.org/sources/libxml2-2.9.1.tar.gz
$ tar xzvf libxml2-2.9.1.tar.gz
※ sudo apt-get install libxml2-dev でもいいかも。
PostGIS
$ wget http://download.osgeo.org/postgis/source/postgis-2.1.0.tar.gz
$ tar xzvf postgis-2.1.0.tar.gz
$ cd postgis-2.1.0
$ ./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config
$ make
$ sudo make install
Ubuntuでapt-get installでpostgresqlをインストールした場合
$ sudo apt-get install postgresql-server-dev-9.2
$ ./configure --with-pgconfig=/usr/lib/postgresql/9.2/bin/pg_config
Macの場合
./configure --with-static-proj4=/usr/local/lib --with-postgres-includes=/usr/local/pgsql/include
上記がめんどくさいときは以下のパッケージをインストールする。
(Ubuntu)
$ sudo apt-get install libxml2-dev
$ sudo apt-get install libproj-dev
$ sudo apt-get install libgeos-dev
$ sudo apt-get install libgdal1-dev
$ ./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config
$ make
$ sudo make install
(CentOS)
$ sudo yum install geos-python.x86_64
$ sudo yum install proj-devel.x86_64
GISテンプレート作成
$ createdb -E UTF8 template_postgis # Creating the template spatial database.
$ createlang -d template_postgis plpgsql # Adding PLPGSQL language support.
$ psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';"
$ psql -d template_postgis -f /usr/share/postgresql/9.2/contrib/postgis-2.1/postgis.sql
$ psql -d template_postgis -f /usr/share/postgresql/9.2/contrib/postgis-2.1/spatial_ref_sys.sql
$ psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;" # Enabling users to alter spatial tables.
$ psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"
Python Image Library
$ http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz
$ tar xzvf Imaging-1.1.7.tar.gz
$ cd Imaging-1.1.7
$ sudo python setup.py install
データベース作成
$ createdb -T template_postgis -U postgres -O username hogedb
$ (CREATE DATABASE hogedb OWNER username TEMPLATE template_postgis;)
hogedb=# \d
List of relations
Schema | Name | Type | Owner
--------+-------------------+-------+----------
public | geography_columns | view | postgres
public | geometry_columns | table | postgres
public | spatial_ref_sys | table | postgres
(3 rows)
Create GIS Index
CREATE INDEX xxxx_xxxxx_id ON tablename USING gist (pt);
settings.py設定
INSTALLED_APPS = (
# 'django.contrib.auth',
# 'django.contrib.contenttypes',
# 'django.contrib.sessions',
# 'django.contrib.sites',
'django.contrib.gis',
'hogehogeapp',
)
http://chris-lamb.co.uk/2009/09/30/geodjango-and-uk-postcode-database/
http://code.google.com/p/geodjango-basic-apps/wiki/FOSS4GWorkshop
参 考:
Error発生
DjangoUnicodeDecodeError: 'ascii' codec can't decode byte
原因はここ。(とりあえず、Debug ModeをFalseにして回避)
Distanceと他のフィルターとの組み合わせ
ここによると遅延フィルターにより何回
SRID(Spatial Reference Identifier)
目的:PostGISでDistance関数を使う
キーワード:
GeomFromEWKT POINT
SRID は 4326 です。SRID 4326 は、geography インスタンスのメソッドを使用する際に WGS 84 空間参照系にマップされます。WGS 84 (SRID 4326)
参考