Skip to content

Instantly share code, notes, and snippets.

@komasaru
Created March 20, 2015 07:43
Show Gist options
  • Save komasaru/8dd4bbc39b7af7c57102 to your computer and use it in GitHub Desktop.
Save komasaru/8dd4bbc39b7af7c57102 to your computer and use it in GitHub Desktop.
Ruby script to read geometric datas from shapefile.
#! /usr/local/bin/ruby
# coding: utf-8
#*********************************************
# Ruby script to read geometric datas from shapefile.
#*********************************************
#
require 'georuby'
require 'geo_ruby/shp'
include GeoRuby::Shp4r
class Shp
def initialize
@shpfile = "/path/to/shapefile.shp"
end
def exec
begin
ShpFile.open(@shpfile) do |shp|
shp.each { |s| p s.geometry.as_json }
end
rescue => e
$stderr.puts "[ERROR][#{self.class.name}.#{__method__}] #{e}"
e.backtrace.each{ |trace| $stderr.puts "\t#{trace}" }
exit 1
end
end
end
Shp.new.exec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment