to_wkt_
Quickly and easily convert arrays to Well-Known Text (WKT) format. Which are commonly used in GIS Databases such as PostGIS.
Installation
Add this line to your application's Gemfile:
gem 'to_wkt_'
And then execute:
$ bundle
Or install it yourself as:
$ gem install to_wkt_
Usage
ToWkt automatically exposes the following methods on any instance of Array
:
-
#to_wkt_point
-
converts an array to a WKT POINT
-
e.g.
```ruby [0,0].to_wkt_point # "POINT(0 0)" ```
-
-
#to_wkt_line_string
-
converts an array to a WKT LINESTRING
-
e.g.
```ruby [ [0,0], [1,1], [1,2] ].to_wkt_line_string # "LINESTRING(0 0,1 1,1 2)" ```
-
-
#to_wkt_polygon
-
converts an array to a WKT POLYGON
-
e.g.
```ruby polygon_array = [ [ [0,0], [4,0], [4,4], [0,4], [0,0] ], [ [1,1], [2,1], [2,2], [1,2], [1,1] ] ] polygon_array.to_wkt_polygon # "POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1))" ```
-
-
#to_wkt_multi_point
-
converts an array to a WKT MULTIPOINT
-
e.g.
```ruby [ [0,0], [1,2] ].to_wkt_multi_point # "MULTIPOINT(0 0,1 2)" ```
-
-
#to_wkt_multi_line_string
-
converts an array to a WKT MULTILINESTRING
-
e.g.
```ruby multi_line_array = [ [ [0,0], [1,1], [1,2] ], [ [2,3], [3,2], [5,4] ] ] multi_line_array.to_wkt_multi_line_string # "MULTILINESTRING((0 0,1 1,1 2),(2 3,3 2,5 4))" ```
-
-
#to_wkt_multi_polygon
-
converts an array to a WKT MULTIPOLYGON
-
e.g.
```ruby multi_polygon_array = [ [ [[0,0], [4,0], [4,4], [0,4], [0,0]], [[1,1], [2,1], [2,2], [1,2], [1,1]] ], [ [[-1,-1], [-1,-2], [-2,-2], [-2,-1], [-1,-1]] ] ] multi_polygon_array.to_wkt_multi_polygon= "MULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)),((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)))" ```
-
Contributing
ToDos
WKT specs contain 18 different geometries; right now only 6 are implemented in to_wkt_.
- Implemented
- Point
- LineString
- Polygon
- MultiPoint
- MultiLineString
- MultiPolygon
-
Not Implemented
- Geometry
- Triangle
- CircularString
- Curve
- MultiCurve
- CompoundCurve
- CurvePolygon
- Surface
- MultiSurface
- PolyhedralSurface
- TIN
- GeometryCollection
Some of these will be easier to implement than others.
How to Contribute
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request