Geography Reference
In-Depth Information
will use the postgres-pr library, and for working with geometries, we will
use GeoRuby. We can install these using gem. To install RubyGems,
download the distribution file for your platform, and unpack it. Make
sure you have rdoc installed first. Then install Rubygems by changing
to the distribution directory and running the setup.rb file:
$ ruby setup.rb
Install the remaining dependencies using gem:
# gem install postgres-pr
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed postgres-pr-0.4.0
# gem install GeoRuby
Successfully installed GeoRuby-1.2.1
Installing ri documentation for GeoRuby-1.2.1...
Installing RDoc documentation for GeoRuby-1.2.1...
Now we have the tools installed and are ready to give it a go. We already
have a PostgreSQL database with some layers loaded. First let's just
run a simple script to check the connectivity and make sure everything
is working correctly. We can test this with the following code:
require 'rubygems'
require 'postgres-pr/connection'
c = PostgresPR::Connection.new('gis_data', 'gsherman', '', 'tcp://madison:5432')
res =c.query('select * from geometry_columns')
res.rows.each{|r|
puts r
puts "-------------"
}
The first couple of records from the script are shown next, just to prove
it worked. We have connectivity to our database and were able to print
out all the records in the geometry_columns table.
public
country
shape
2
4326
MULTIPOLYGON
-------------
public
edit_test
shape
2
4326
POINT
-------------
 
Search WWH ::




Custom Search