Created
February 13, 2014 02:58
-
-
Save jenningsanderson/8968949 to your computer and use it in GitHub Desktop.
Sample geo-processing basics (Reading shapefiles) with Ruby.
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
## This first one can only read shapefiles | |
require 'rgeo-shapefile' | |
puts "This is a test of reading a shapefile" | |
shape = RGeo::Shapefile::Reader.open('../lab3/data/interestAreas.shp') | |
shape.each do |record| | |
puts record.geometry.area | |
end | |
puts shape.open? | |
shape.close | |
puts shape.open? | |
## This one can read and write... but none of it is very straightforward.: | |
require 'geo_ruby' | |
require 'geo_ruby/shp' # Shapefile | |
GeoRuby::Shp4r::ShpFile.open('../lab3/data/interestAreas.shp') do |shp| | |
shp.each do |shape| | |
geom = shape.geometry #a GeoRuby SimpleFeature | |
puts "BOUNDING BOX: #{geom.bounding_box.inspect }\n"#I can get bounding box, but I can't calculate area? | |
att_data = shape.data #a Hash | |
puts "Attribute data: #{att_data.inspect}" | |
shp.fields.each do |field| | |
puts "Field: #{field.inspect}" | |
puts att_data[field.name] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment