-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bdad5e1
Showing
14 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*.cr] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/docs/ | ||
/lib/ | ||
/bin/ | ||
/.shards/ | ||
*.dwarf | ||
|
||
# Libraries don't need dependency lock | ||
# Dependencies will be locked in applications that use them | ||
/shard.lock |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
language: crystal | ||
|
||
script: | ||
- crystal spec | ||
- crystal tool format --check |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020 Anton Maminov | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# GeoJSON | ||
|
||
The [GeoJSON](https://tools.ietf.org/html/rfc7946) Format for Crystal | ||
|
||
[![Build Status](https://travis-ci.org/geocrystal/geo_json.svg?branch=master)](https://travis-ci.org/geocrystal/geo_json) | ||
|
||
## GeoJSON types | ||
|
||
- [ ] Point | ||
- [ ] MultiPoint | ||
- [ ] LineString | ||
- [ ] MultiLineString | ||
- [ ] Polygon | ||
- [ ] MultiPolygon | ||
- [ ] GeometryCollection | ||
- [ ] Feature | ||
- [ ] FeatureCollection | ||
|
||
## Installation | ||
|
||
1. Add the dependency to your `shard.yml`: | ||
|
||
```yaml | ||
dependencies: | ||
geo_json: | ||
github: geocrystal/geo_json | ||
``` | ||
2. Run `shards install` | ||
|
||
## Usage | ||
|
||
```crystal | ||
require "geo_json" | ||
``` | ||
|
||
TODO: Write usage instructions here | ||
|
||
## Development | ||
|
||
TODO: Write development instructions here | ||
|
||
## Contributing | ||
|
||
1. Fork it (<https://github.com/geocrystal/geo_json/fork>) | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Add some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create a new Pull Request | ||
|
||
## Contributors | ||
|
||
- [Anton Maminov](https://github.com/mamantoha) - creator and maintainer |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: geo_json | ||
version: 0.0.1 | ||
|
||
authors: | ||
- Anton Maminov <[email protected]> | ||
|
||
crystal: 0.33.0 | ||
|
||
license: MIT |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "./spec_helper" | ||
|
||
describe GeoJSON::Coordinates do | ||
it "raises an exception if coordinates are invalid" do | ||
expect_raises Exception, "GeoJSON::Coordinates must have two coordinates" do | ||
GeoJSON::Coordinates.new([1.0, 1.0, 0.0]) | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "./spec_helper" | ||
|
||
describe GeoJSON do | ||
it "should have version" do | ||
GeoJSON::VERSION.should_not be_nil | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require "./spec_helper" | ||
|
||
describe GeoJSON::Point do | ||
longitude = -80.1347334 | ||
latitude = 25.7663562 | ||
position = [longitude, latitude] | ||
|
||
point_json = { | ||
"type" => "Point", | ||
"coordinates" => position, | ||
}.to_json | ||
|
||
it "parses json" do | ||
point = GeoJSON::Point.from_json(point_json) | ||
|
||
point.should be_a(GeoJSON::Point) | ||
point.type.should eq("Point") | ||
point.coordinates.should be_a(GeoJSON::Coordinates) | ||
point.longitude.should eq(longitude) | ||
point.latitude.should eq(latitude) | ||
end | ||
|
||
it "creates object" do | ||
point = GeoJSON::Point.new(longitude: longitude, latitude: latitude) | ||
|
||
point.should be_a(GeoJSON::Point) | ||
point.type.should eq("Point") | ||
point.coordinates.should be_a(GeoJSON::Coordinates) | ||
point.longitude.should eq(longitude) | ||
point.latitude.should eq(latitude) | ||
|
||
point.to_json.should eq(point_json) | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require "spec" | ||
require "../src/geo_json" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require "json" | ||
require "./geo_json/**" | ||
|
||
module GeoJSON | ||
VERSION = "0.0.1" | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module GeoJSON | ||
class Coordinates | ||
getter coordinates : Array(Float64) | ||
|
||
def initialize(@coordinates : Array(Float64)) | ||
raise_if_invalid | ||
end | ||
|
||
def initialize(parser : JSON::PullParser) | ||
@coordinates = Array(Float64).new(parser) | ||
|
||
raise_if_invalid | ||
end | ||
|
||
def longitude | ||
coordinates[0] | ||
end | ||
|
||
def latitude | ||
coordinates[1] | ||
end | ||
|
||
private def raise_if_invalid | ||
if coordinates.size != 2 | ||
raise "GeoJSON::Coordinates must have two coordinates" | ||
end | ||
end | ||
|
||
delegate to_json, to: coordinates | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module GeoJSON | ||
# GeoJSON Object | ||
# | ||
# A GeoJSON object represents a Geometry, Feature, or collection of Features. | ||
# | ||
# * A GeoJSON object is a JSON object. | ||
# * A GeoJSON object has a member with the name "type". The value of | ||
# the member MUST be one of the GeoJSON types. | ||
# `Point`, `MultiPoint`, `LineString`, `MultiLineString`, `Polygon`, `MultiPolygon`, | ||
# `GeometryCollection`, `Feature`, and `FeatureCollection` | ||
# * A GeoJSON object MAY have a "bbox" member, the value of which MUST | ||
# be a bounding box array | ||
# * A GeoJSON object MAY have other members | ||
abstract class Object | ||
include JSON::Serializable | ||
|
||
abstract def type : String | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module GeoJSON | ||
class Point < Object | ||
property type : String = "Point" | ||
|
||
property coordinates : Coordinates | ||
|
||
def initialize(*, longitude, latitude) | ||
@coordinates = Coordinates.new([longitude, latitude]) | ||
end | ||
|
||
delegate longitude, to: coordinates | ||
delegate latitude, to: coordinates | ||
end | ||
end |