Created
March 20, 2015 07:43
-
-
Save komasaru/8dd4bbc39b7af7c57102 to your computer and use it in GitHub Desktop.
Ruby script to read geometric datas from shapefile.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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