GithubHelp home page GithubHelp logo

seuros / rgeo-activerecord Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rgeo/rgeo-activerecord

0.0 1.0 0.0 288 KB

RGeo ActiveRecord extensions and tools for spatial connection adapters

License: Other

Ruby 100.00%

rgeo-activerecord's Introduction

RGeo::ActiveRecord

Gem version GitHub Workflow Status Code Climate

RGeo::ActiveRecord is an optional RGeo module providing spatial extensions for ActiveRecord, as well as a set of helpers for writing spatial ActiveRecord adapters based on RGeo.

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::ActiveRecord is an optional RGeo add-on module providing spatial extensions for ActiveRecord, as well as a set of helpers for writing spatial ActiveRecord adapters based on RGeo.

Installation

Gemfile:

gem 'rgeo-activerecord'

Version 7.1+ supports ActiveRecord 6.1, and 7.x with rgeo 3.0+

Version 7.0+ supports ActiveRecord 5.x, 6.x, and 7.x with rgeo 1.0+

Version 6.2+ supports ActiveRecord 5.x and 6.x with rgeo 1.0+

Version 6.1 supports ActiveRecord 5.x and 6.0 with rgeo 1.0+.

Version 6.0 supports ActiveRecord 5.x with rgeo 1.x.

Version 5.0 supports ActiveRecord 5.0 and 5.1, with rgeo 0.6.

Version 4.0 supports ActiveRecord 4.2.

Version 1.1.0 supports ActiveRecord 4.0 and 4.1

Version 0.6.0 supports earlier versions of ruby and ActiveRecord:

  • Ruby 1.8.7 or later
  • ActiveRecord 3.0.3 - 3.2.x
  • rgeo 0.3.20 or later
  • arel 2.0.6 or later

Spatial Factories for Columns

This is an introduction. More details are available in the wiki entry.

Register spatial factories in the SpatialFactoryStore singleton class to parse spatial data. Each spatial column in your models will use the SpatialFactoryStore to parse the stored WKB into an RGeo Feature. The factory from the SpatialFactoryStore is chosen based on metadata from the spatial column and the attributes with which the factory was registered to the store. For example, you can set a factory for point types, for types matching a specific SRID, having a Z coordinate, or any combination of attributes.

The supported keys when registering a spatial type are listed here with their expected values:

geo_type: string  # geometry, point, polygon, line_string, geometry_collection,
                  # multi_line_string, multi_point, multi_polygon
has_m:    boolean # true, false
has_z:    boolean # true, false
sql_type: string  # geometry, geography
srid:     int     # (any valid SRID)

The default factories are RGeo::Geographic.spherical_factory for geographic types, and RGeo::Cartesian.preferred_factory for geometric types.

Here is an example setup:

RGeo::ActiveRecord::SpatialFactoryStore.instance.tap do |config|
  # By default, use the GEOS implementation for spatial columns.
  config.default = RGeo::Geos.factory

  # But use a geographic implementation for point columns.
  config.register(RGeo::Geographic.spherical_factory(srid: 4326), geo_type: "point")
end

NOTE: rgeo_factory_generator and related methods were removed in version 4.0, since column types are no longer tied to their database column in ActiveRecord 4.2.

Spatial Queries

RGeo-ActiveRecord provides an Arel interface to use functions commonly found in spatial databases. The interface also allows for the creation of your own spatial functions if they are not defined.

Here is an example using st_contains:

point = RGeo::Geos.factory(srid: 0).point(1,1)

buildings = Building.arel_table
containing_buildings = Building.where(buildings[:geom].st_contains(point))

or using the Arel.spatial node:

point = "SRID=0;POINT(1,1)"

buildings = Building.arel_table
containing_buildings = Building.where(buildings[:geom].st_contains(Arel.spatial(point)))

Note: If you pass a WKT representation into an st_function, you should prepend the string with SRID=your_srid, otherwise the database will assume SRID=0 which may cause errors on certain operations.

RGeo Dependency

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

Development and support

This README is the official documentation.

RDoc documentation is available at http://rdoc.info/gems/rgeo-activerecord

Source code is hosted on Github at http://github.com/rgeo/rgeo-activerecord

Contributions are welcome. Fork the project on Github.

Report bugs on Github issues at http://github.com/rgeo/rgeo-activerecord/issues

Support available on the rgeo-users google group at http://groups.google.com/group/rgeo-users

Acknowledgments

Daniel Azuma created RGeo. Tee Parham is a former maintainer. Keith Doggett is a current maintainer. Ulysse Buonomo is a current maintainer.

Development is supported by:

License

Copyright 2020 Daniel Azuma, Tee Parham

https://github.com/rgeo/rgeo-activerecord/blob/master/LICENSE.txt

rgeo-activerecord's People

Contributors

teeparham avatar dazuma avatar keithdoggett avatar gui avatar seuros avatar andreasknoepfle avatar gravitystorm avatar corneverbruggen avatar jayvarner avatar marinosb avatar matthewrudy avatar petergoldstein avatar ugisozols avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.