Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.