RGeo::Shapefile

RGeo::Shapefile is an optional module for RGeo for reading geospatial data from ESRI shapefiles.

Summary

RGeo is a key component for writing location-aware applications in the Ruby programming language. At its core is an implementation of the industry standard OGC Simple Features Specification, which provides data representations of geometric objects such as points, lines, and polygons, along with a set of geometric analysis operations. See the README for the “rgeo” gem for more information.

RGeo::Shapefile is an optional RGeo add-on module for reading geospatial data from ESRI shapefiles. The shapefile format is a common file format for geospatial data sets. It is specified in this ESRI whitepaper.

Example:

require 'rgeo/shapefile'

RGeo::Shapefile::Reader.open('myshpfil.shp') do |file|
  puts "File contains #{file.num_records} records."
  file.each do |record|
    puts "Record number #{record.index}:"
    puts "  Geometry: #{record.geometry.as_text}"
    puts "  Attributes: #{record.attributes.inspect}"
  end
  file.rewind
  record = file.next
  puts "First record geometry was: #{record.geometry.as_text}"
end

Installation

RGeo::Shapefile has the following requirements:

Install RGeo::Shapefile as a gem:

gem install rgeo
gem install rgeo-shapefile

See the README for the “rgeo” gem, a required dependency, for further installation information.

To-do list

Development and support

Documentation is available at virtuoso.rubyforge.org/rgeo-shapefile/README_rdoc.html

Source code is hosted on Github at github.com/dazuma/rgeo-shapefile

Contributions are welcome. Fork the project on Github.

Report bugs on Github issues at github.org/dazuma/rgeo-shapefile/issues

Contact the author at dazuma at gmail dot com.

Acknowledgments

RGeo is written by Daniel Azuma (www.daniel-azuma.com).

Development of RGeo is sponsored by GeoPage, Inc. (www.geopage.com).

Although we don’t use shapelib (shapelib.maptools.org) to read ESRI shapefiles, we did borrow a bunch of their test cases.

License

Copyright 2010-2012 Daniel Azuma

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.