geosparql_to_geojson 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bcd9ad346bdd423eb3aebfe0bf821b1a1c87e41f
4
+ data.tar.gz: 7112f7333d3f398292c470a5ecc62609a6e89809
5
+ SHA512:
6
+ metadata.gz: e9b9f0014b2c918f050bc56556f11eec225cc3900ead86774efc4f33401cd17b715f40d9b5d452bff45be834e71837d31cbd6fba46732ea5db5722033a4899c8
7
+ data.tar.gz: b58118a87c46afee15264a93ef67c2cd837dbdc159ce2f5abdfdc095e26eb375a3d0219aff2b30c6bd3d5084d5187ea948b85f957a8bdd2175df6fcb762f370c
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.0
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ sudo: false
2
+ language: ruby
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at c.nevejones@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in geosparql_to_geojson.gemspec
4
+ gemspec
5
+
6
+ gem 'coveralls', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Callum Neve-Jones
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # GeosparqlToGeojson
2
+
3
+ [GeosparqlToGeojson][geosparqltogeojson] is a gem created by the [Parliamentary Digital Service][pds] to take [GeoSparql][geosparql] data and convert it into [GeoJSON][geojson] data.
4
+
5
+ [![Gem][shield-gem]][info-gem] [![Build Status][shield-travis]][info-travis] [![Test Coverage][shield-coveralls]][info-coveralls] [![License][shield-license]][info-license]
6
+
7
+ > **NOTE:** This gem is in active development and is likely to change at short notice. It is not recommended that you use this in any production environment.
8
+
9
+ ### Contents
10
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
11
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
12
+
13
+
14
+ - [Requirements](#requirements)
15
+ - [Installation](#installation)
16
+ - [Usage](#usage)
17
+ - [Getting Started with Development](#getting-started-with-development)
18
+ - [Running the tests](#running-the-tests)
19
+ - [Contributing](#contributing)
20
+ - [License](#license)
21
+
22
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
23
+
24
+ ## Requirements
25
+ [GeosparqlToGeojson][geosparqltogeojson] requires the following:
26
+ * [Ruby][ruby] - [click here][ruby-version] for the exact version
27
+ * [Bundler][bundler]
28
+
29
+ ## Installation
30
+ ```bash
31
+ gem 'geosparql_to_geojson'
32
+ ```
33
+
34
+ ## Usage
35
+ This gem's main function is taking a [GeoSparql][geosparql] string and converting it into [GeoJSON][geojson].
36
+
37
+ Calling `GeosparqlToGeojson#convert_to_geojson` and passing in valid GeoSparql string will convert the GeoSparql to GeoJSON and return a GeosparqlToGeojson::GeoJson object.
38
+
39
+ Properties can optionally be passed in as well as whether the data should be reversed during the convertion.
40
+
41
+ ```ruby
42
+ geosparql = 'POINT(0.1, 51.5)'
43
+ properties = {name: 'London'}
44
+
45
+ point = GeosparqlToGeojson.convert_to_geojson(geosparql_values: geosparql, geosparql_properties: properties, reverse: true)
46
+ #=> GeosparqlToGeojson::GeoJson
47
+ ```
48
+
49
+ Calling `point.geojson` will return a GeoJSON string. For example:
50
+
51
+ ```json
52
+ {"type": "FeatureCollection",
53
+ "features": [
54
+ {
55
+ "type": "Feature",
56
+ "geometry": {
57
+ "type": "Point",
58
+ "coordinates": [
59
+ 51.5,
60
+ 0.1
61
+ ]
62
+ },
63
+ "properties": {"name": "London"}
64
+ }
65
+ ]
66
+ }
67
+ ```
68
+
69
+
70
+
71
+ Calling `point.validate` will return a `GeosparqlToGeojson::Validator` object which can be used to validate the generated GeoJSON.
72
+
73
+ ```ruby
74
+ validated_geojson = GeosparqlToGeojson::Validator.new(point)
75
+
76
+ validated_geojson.valid?
77
+ #=> true
78
+
79
+ validated_geojson.errors
80
+ #=> []
81
+ ```
82
+
83
+ ## Getting Started with Development
84
+ To clone the repository and set up the dependencies, run the following:
85
+
86
+ ```bash
87
+ git clone https://github.com/ukparliament/geosparql_to_geojson.git
88
+ cd geosparql_to_geojson
89
+ bundle install
90
+ ```
91
+
92
+ ### Running the tests
93
+ We use [RSpec][rspec] as our testing framework and tests can be run using:
94
+
95
+ ```bash
96
+ bundle exec rspec
97
+ ```
98
+
99
+ ## Contributing
100
+ If you wish to submit a bug fix or feature, you can create a pull request and it will be merged pending a code review.
101
+
102
+ 1. Fork the repository
103
+ 1. Create your feature branch (`git checkout -b my-new-feature`)
104
+ 1. Commit your changes (`git commit -am 'Add some feature'`)
105
+ 1. Push to the branch (`git push origin my-new-feature`)
106
+ 1. Ensure your changes are tested using [Rspec][rspec]
107
+ 1. Create a new Pull Request
108
+
109
+
110
+
111
+ ## License
112
+ [GeosparqlToGeojson][geosparqltogeojson] is licensed under the [Open Parliament Licence][info-license].
113
+
114
+ [ruby]: https://www.ruby-lang.org/en/
115
+ [bundler]: http://bundler.io
116
+ [rspec]: http://rspec.info
117
+ [geosparqltogeojson]: https://github.com/ukparliament/geosparql_to_geojson
118
+ [pds]: https://www.parliament.uk/mps-lords-and-offices/offices/bicameral/parliamentary-digital-service/
119
+ [geosparql]: http://www.opengis.net/doc/IS/geosparql/1.0
120
+ [geojson]: https://tools.ietf.org/html/rfc7946#appendix-A.2
121
+ [ruby-version]: https://github.com/ukparliament/geosparql_to_geojson/blob/master/.ruby-version
122
+
123
+
124
+ [info-gem]: https://rubygems.org/gems/geosparql_to_geojson
125
+ [shield-gem]: https://img.shields.io/gem/v/geosparql_to_geojson.svg
126
+
127
+ [info-travis]: https://travis-ci.org/ukparliament/geosparql_to_geojson
128
+ [shield-travis]: https://img.shields.io/travis/ukparliament/geosparql_to_geojson.svg
129
+
130
+ [info-coveralls]: https://coveralls.io/github/ukparliament/geosparql_to_geojson
131
+ [shield-coveralls]: https://img.shields.io/coveralls/ukparliament/geosparql_to_geojson.svg
132
+
133
+ [info-license]: http://www.parliament.uk/site-information/copyright/open-parliament-licence/
134
+ [shield-license]: https://img.shields.io/badge/license-Open%20Parliament%20Licence-blue.svg
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "geosparql_to_geojson"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'geosparql_to_geojson/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'geosparql_to_geojson'
8
+ spec.version = GeosparqlToGeojson::VERSION
9
+ spec.authors = ['Callum Neve-Jones']
10
+ spec.email = ['nevejonesc@parliament.uk']
11
+
12
+ spec.summary = %q{Converts GeoSparql to GeoJSON}
13
+ spec.description = %q{Converts GeoSparql to GeoJSON}
14
+ spec.homepage = 'https://github.com/ukparliament/geosparql-to-geojson'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'json-schema', '~> 2.8'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.14'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ spec.add_development_dependency 'simplecov', '~> 0.12'
30
+ end
@@ -0,0 +1,113 @@
1
+ require 'json'
2
+
3
+ module GeosparqlToGeojson
4
+ # Class to convert GeoSparql to GeoJSON data.
5
+ #
6
+ # @since 0.1.0
7
+ class Converter
8
+ # Constant contains every GeoSparql data type.
9
+ GEOMETRY_TYPES = %w[Point Multipoint LineString Multiline Polygon MultiPolygon GeometryCollection].freeze
10
+
11
+ # Creates a new instance of GeosparqlToGeojson::Converter
12
+ #
13
+ # @param [String] geosparql_data the GeoSparql data to be converted into GeoJSON.
14
+ def initialize(geosparql_values, geosparql_properties, reverse)
15
+ @geosparql_values = geosparql_values
16
+ @geosparql_properties = geosparql_properties
17
+ @reverse = reverse
18
+ end
19
+
20
+ # Method calls GeosparqlToGeojson::Converter#collect_geosparql_data to start converting data.
21
+ #
22
+ # @example Converting GeoSparql string into GeoJSON
23
+ # GeosparqlToGeojson::Converter.new('Point(1.23 9.87)').convert
24
+ # #=> '{
25
+ # "type": "FeatureCollection",
26
+ # "features": [
27
+ # {
28
+ # "type": "Feature",
29
+ # "geometry": {
30
+ # "type": "Point",
31
+ # "coordinates": [
32
+ # 1.23,
33
+ # 9.87
34
+ # ]
35
+ # },
36
+ # "properties": {}
37
+ # }'
38
+ def convert
39
+ GeosparqlToGeojson::GeoJson.new(collect_geosparql_data)
40
+ end
41
+
42
+ # Creates a hash of each GeoSparql type present and it's values.
43
+ def collect_geosparql_data
44
+ @data_store = {}
45
+ GEOMETRY_TYPES.each do |geometry_type|
46
+ geosparql_data_match = @geosparql_values.scan(/#{geometry_type}\(+(.*?)\)+/i)
47
+ @data_store[geometry_type.to_sym] = geosparql_data_match unless geosparql_data_match.empty?
48
+ end
49
+
50
+ format_geosparql_data
51
+ end
52
+
53
+ # Splits values into arrays and converts them into floats.
54
+ def format_geosparql_data
55
+ @data_store.keys.each do |key|
56
+ @data_store[key.to_sym].map! do |values|
57
+ format_data(values, key)
58
+ end
59
+ end
60
+
61
+ generate_hash_from_values
62
+ end
63
+
64
+ # Formats GeoSparql data.
65
+ # Will reverse the values if @reverse is set to true.
66
+ #
67
+ # @param [String] values the GeoSparql data to be converted into GeoJSON.
68
+ # @param [Symbol] key the type of GeoSparql data
69
+ #
70
+ # @return [Array]
71
+ def format_data(values, key)
72
+ values = @reverse ? values[0].split(/[\s]|[,]/).map!(&:to_f).reverse : values[0].split(/[\s]|[,]/).map!(&:to_f)
73
+
74
+ values = values.each_slice(2).to_a if key != :Point
75
+ values = [values] if key != :Point && key != :LineString
76
+ values
77
+ end
78
+
79
+ # Created a hash from the GeoSparql values in the GeoJSON 'Feature' format.
80
+ def generate_hash_from_values
81
+ @data_hash_array = []
82
+ @data_store.keys.each do |key|
83
+ @data_store[key.to_sym].each do |data|
84
+ @data_hash_array << generate_feature_hash({ type: key.to_s, coordinates: data })
85
+ end
86
+ end
87
+
88
+ generate_feature_collection
89
+ end
90
+
91
+ # Adds converted GeoSparql data to a GeoJSON 'feature' type.
92
+ #
93
+ # @return [Hash] a hash containing GeoSparql data
94
+ def generate_feature_hash(data_hash)
95
+ {
96
+ type: 'Feature',
97
+ geometry: data_hash,
98
+ properties: @geosparql_properties
99
+ }
100
+ end
101
+
102
+ # Adds GeoJSON 'feature' hash to a GeoJSON 'FeatureCollections' type.
103
+ #
104
+ # @return [String] a string of GeoJSON
105
+ def generate_feature_collection
106
+ data_hash = {
107
+ type: 'FeatureCollection',
108
+ features: @data_hash_array
109
+ }
110
+ data_hash.to_json
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,19 @@
1
+ module GeosparqlToGeojson
2
+ # GeoJSON object
3
+ #
4
+ # @since 0.1.0
5
+ class GeoJson
6
+ attr_reader :geojson
7
+
8
+ def initialize(geojson_string)
9
+ @geojson = geojson_string
10
+ end
11
+
12
+ # Creates new instance of GeosparqlToGeojson::GeojsonValidator
13
+ #
14
+ # @return [GeosparqlToGeojson::GeojsonValidator]
15
+ def validate
16
+ GeosparqlToGeojson::GeojsonValidator.new(geojson)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ require 'json-schema'
2
+
3
+ module GeosparqlToGeojson
4
+ # Class used to validate GeoJSON
5
+ # @since 0.1.0
6
+ class GeojsonValidator
7
+ # Creates a new instance of GeosparqlToGeojson::GeojsonValidator
8
+ #
9
+ # @param [String] geojson the GeoJSON data to be validated
10
+ def initialize(geojson)
11
+ @geojson = geojson
12
+ @schema = JSON.parse(File.read(File.expand_path('../schema/geojson.json', __FILE__)))
13
+ end
14
+
15
+ # Validates GeoJSON data based on JSON and GroJSON schemas
16
+ #
17
+ # @return [Array] any errors with the JSON
18
+ def errors
19
+ JSON::Validator.fully_validate(@schema, @geojson)
20
+ end
21
+
22
+ # Checks whether there are any errors returned by the validator
23
+ #
24
+ # @return [true, false]
25
+ def valid?
26
+ errors.empty?
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,353 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-06/schema#",
3
+ "title": "GeoJSON Object",
4
+ "type": "object",
5
+ "description": "This object represents a geometry, feature, or collection of features.",
6
+ "additionalProperties": true,
7
+ "required": ["type"],
8
+
9
+ "properties": {
10
+
11
+ "type": {
12
+ "title": "Type",
13
+ "type": "string",
14
+ "description": "The type of GeoJSON object.",
15
+ "enum": [
16
+ "Point",
17
+ "MultiPoint",
18
+ "LineString",
19
+ "MultiLineString",
20
+ "Polygon",
21
+ "MultiPolygon",
22
+ "GeometryCollection",
23
+ "Feature",
24
+ "FeatureCollection"
25
+ ]
26
+ },
27
+
28
+ "crs": {
29
+ "title": "Coordinate Reference System (CRS)",
30
+ "description": "The coordinate reference system (CRS) of a GeoJSON object is determined by its `crs` member (referred to as the CRS object below). If an object has no crs member, then its parent or grandparent object's crs member may be acquired. If no crs member can be so acquired, the default CRS shall apply to the GeoJSON object.\n\n* The default CRS is a geographic coordinate reference system, using the WGS84 datum, and with longitude and latitude units of decimal degrees.\n\n* The value of a member named `crs` must be a JSON object (referred to as the CRS object below) or JSON null. If the value of CRS is null, no CRS can be assumed.\n\n* The crs member should be on the top-level GeoJSON object in a hierarchy (in feature collection, feature, geometry order) and should not be repeated or overridden on children or grandchildren of the object.\n\n* A non-null CRS object has two mandatory members: `type` and `properties`.\n\n* The value of the type member must be a string, indicating the type of CRS object.\n\n* The value of the properties member must be an object.\n\n* CRS shall not change coordinate ordering.",
31
+
32
+ "oneOf": [
33
+ { "type": "null" },
34
+ {
35
+ "type": "object",
36
+ "required": ["type", "properties"],
37
+ "properties": {
38
+ "type": {
39
+ "title": "CRS Type",
40
+ "type": "string",
41
+ "description": "The value of the type member must be a string, indicating the type of CRS object.",
42
+ "minLength": 1
43
+ },
44
+ "properties": {
45
+ "title": "CRS Properties",
46
+ "type": "object"
47
+ }
48
+ }
49
+ }
50
+ ],
51
+
52
+ "not": {
53
+ "anyOf": [
54
+
55
+ {
56
+ "properties": {
57
+ "type": { "enum": ["name"] },
58
+ "properties": {
59
+ "not": {
60
+ "required": ["name"],
61
+ "properties": {
62
+ "name": {
63
+ "type": "string",
64
+ "minLength": 1
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
70
+ },
71
+
72
+ {
73
+ "properties": {
74
+ "type": { "enum": ["link"] },
75
+ "properties": {
76
+ "not": {
77
+ "title": "Link Object",
78
+ "type": "object",
79
+ "required": ["href"],
80
+ "properties": {
81
+
82
+ "href": {
83
+ "title": "href",
84
+ "type": "string",
85
+ "description": "The value of the required `href` member must be a dereferenceable URI.",
86
+ "format": "uri"
87
+ },
88
+
89
+ "type": {
90
+ "title": "Link Object Type",
91
+ "type": "string",
92
+ "description": "The value of the optional `type` member must be a string that hints at the format used to represent CRS parameters at the provided URI. Suggested values are: `proj4`, `ogcwkt`, `esriwkt`, but others can be used."
93
+ }
94
+
95
+ }
96
+ }
97
+ }
98
+ }
99
+ }
100
+
101
+ ]
102
+ }
103
+
104
+ },
105
+
106
+ "bbox": {
107
+ "title": "Bounding Box",
108
+ "type": "array",
109
+ "description": "To include information on the coordinate range for geometries, features, or feature collections, a GeoJSON object may have a member named `bbox`. The value of the bbox member must be a 2*n array where n is the number of dimensions represented in the contained geometries, with the lowest values for all axes followed by the highest values. The axes order of a bbox follows the axes order of geometries. In addition, the coordinate reference system for the bbox is assumed to match the coordinate reference system of the GeoJSON object of which it is a member.",
110
+ "minItems": 4,
111
+ "items": {
112
+ "type": "number"
113
+ }
114
+ }
115
+
116
+ },
117
+
118
+ "oneOf": [
119
+
120
+ {
121
+ "title": "Point",
122
+ "description": "For type `Point`, the `coordinates` member must be a single position.",
123
+ "required": ["coordinates"],
124
+ "properties": {
125
+ "type": { "enum": ["Point"] },
126
+ "coordinates": {
127
+ "allOf": [
128
+ { "$ref": "#/definitions/coordinates" },
129
+ { "$ref": "#/definitions/position" }
130
+ ]
131
+ }
132
+ },
133
+ "allOf": [{ "$ref": "#/definitions/geometry" }]
134
+ },
135
+
136
+ {
137
+ "title": "Multi Point Geometry",
138
+ "description": "For type `MultiPoint`, the `coordinates` member must be an array of positions.",
139
+ "required": ["coordinates"],
140
+ "properties": {
141
+ "type": { "enum": ["MultiPoint"] },
142
+ "coordinates": {
143
+ "allOf": [
144
+ { "$ref": "#/definitions/coordinates" },
145
+ {
146
+ "items": { "$ref": "#/definitions/position" }
147
+ }
148
+ ]
149
+ }
150
+ },
151
+ "allOf": [{ "$ref": "#/definitions/geometry" }]
152
+ },
153
+
154
+ {
155
+ "title": "Line String",
156
+ "description": "For type `LineString`, the `coordinates` member must be an array of two or more positions.\n\nA LinearRing is closed LineString with 4 or more positions. The first and last positions are equivalent (they represent equivalent points). Though a LinearRing is not explicitly represented as a GeoJSON geometry type, it is referred to in the Polygon geometry type definition.",
157
+ "required": ["coordinates"],
158
+ "properties": {
159
+ "type": { "enum": ["LineString"] },
160
+ "coordinates": { "$ref": "#/definitions/lineStringCoordinates" }
161
+ },
162
+ "allOf": [{ "$ref": "#/definitions/geometry" }]
163
+ },
164
+
165
+ {
166
+ "title": "MultiLineString",
167
+ "description": "For type `MultiLineString`, the `coordinates` member must be an array of LineString coordinate arrays.",
168
+ "required": ["coordinates"],
169
+ "properties": {
170
+ "type": { "enum": ["MultiLineString"] },
171
+ "coordinates": {
172
+ "allOf": [
173
+ { "$ref": "#/definitions/coordinates" },
174
+ {
175
+ "items": { "$ref": "#/definitions/lineStringCoordinates" }
176
+ }
177
+ ]
178
+ }
179
+ },
180
+ "allOf": [{ "$ref": "#/definitions/geometry" }]
181
+ },
182
+
183
+ {
184
+ "title": "Polygon",
185
+ "description": "For type `Polygon`, the `coordinates` member must be an array of LinearRing coordinate arrays. For Polygons with multiple rings, the first must be the exterior ring and any others must be interior rings or holes.",
186
+ "required": ["coordinates"],
187
+ "properties": {
188
+ "type": { "enum": ["Polygon"] },
189
+ "coordinates": { "$ref": "#/definitions/polygonCoordinates" }
190
+ },
191
+ "allOf": [{ "$ref": "#/definitions/geometry" }]
192
+ },
193
+
194
+ {
195
+ "title": "Multi-Polygon Geometry",
196
+ "description": "For type `MultiPolygon`, the `coordinates` member must be an array of Polygon coordinate arrays.",
197
+ "required": ["coordinates"],
198
+ "properties": {
199
+ "type": { "enum": ["MultiPolygon"] },
200
+ "coordinates": {
201
+ "allOf": [
202
+ { "$ref": "#/definitions/coordinates" },
203
+ {
204
+ "items": { "$ref": "#/definitions/polygonCoordinates" }
205
+ }
206
+ ]
207
+ }
208
+ },
209
+ "allOf": [{ "$ref": "#/definitions/geometry" }]
210
+ },
211
+
212
+ {
213
+ "title": "Geometry Collection",
214
+ "description": "A GeoJSON object with type `GeometryCollection` is a geometry object which represents a collection of geometry objects.\n\nA geometry collection must have a member with the name `geometries`. The value corresponding to `geometries` is an array. Each element in this array is a GeoJSON geometry object.",
215
+ "required": ["geometries"],
216
+ "properties": {
217
+ "type": { "enum": ["GeometryCollection"] },
218
+ "geometries": {
219
+ "title": "Geometries",
220
+ "type": "array",
221
+ "items": { "$ref": "#/definitions/geometry" }
222
+ }
223
+ },
224
+ "allOf": [{ "$ref": "#/definitions/geometry" }]
225
+ },
226
+
227
+ { "$ref": "#/definitions/feature" },
228
+
229
+ {
230
+ "title": "Feature Collection",
231
+ "description": "A GeoJSON object with the type `FeatureCollection` is a feature collection object.\n\nAn object of type `FeatureCollection` must have a member with the name `features`. The value corresponding to `features` is an array. Each element in the array is a feature object as defined above.",
232
+ "required": ["features"],
233
+ "properties": {
234
+ "type": { "enum": ["FeatureCollection"] },
235
+ "features": {
236
+ "title": "Features",
237
+ "type": "array",
238
+ "items": { "$ref": "#/definitions/feature" }
239
+ }
240
+ }
241
+ }
242
+
243
+ ],
244
+
245
+ "definitions": {
246
+
247
+ "coordinates": {
248
+ "title": "Coordinates",
249
+ "type": "array",
250
+ "items": {
251
+ "oneOf": [
252
+ { "type": "array" },
253
+ { "type": "number" }
254
+ ]
255
+ }
256
+ },
257
+
258
+ "geometry": {
259
+ "title": "Geometry",
260
+ "description": "A geometry is a GeoJSON object where the type member's value is one of the following strings: `Point`, `MultiPoint`, `LineString`, `MultiLineString`, `Polygon`, `MultiPolygon`, or `GeometryCollection`.",
261
+ "properties": {
262
+ "type": {
263
+ "enum": [
264
+ "Point",
265
+ "MultiPoint",
266
+ "LineString",
267
+ "MultiLineString",
268
+ "Polygon",
269
+ "MultiPolygon",
270
+ "GeometryCollection"
271
+ ]
272
+ }
273
+ }
274
+ },
275
+
276
+ "feature": {
277
+ "title": "Feature",
278
+ "description": "A GeoJSON object with the type `Feature` is a feature object.\n\n* A feature object must have a member with the name `geometry`. The value of the geometry member is a geometry object as defined above or a JSON null value.\n\n* A feature object must have a member with the name `properties`. The value of the properties member is an object (any JSON object or a JSON null value).\n\n* If a feature has a commonly used identifier, that identifier should be included as a member of the feature object with the name `id`.",
279
+ "required": ["geometry", "properties"],
280
+
281
+ "properties": {
282
+
283
+ "type": { "enum": ["Feature"] },
284
+
285
+ "geometry": {
286
+ "title": "Geometry",
287
+ "oneOf": [
288
+ { "$ref": "#/definitions/geometry" },
289
+ { "type": "null" }
290
+ ]
291
+ },
292
+
293
+ "properties": {
294
+ "title": "Properties",
295
+ "oneOf": [
296
+ { "type": "object" },
297
+ { "type": "null" }
298
+ ]
299
+ },
300
+
301
+ "id": {}
302
+
303
+ }
304
+ },
305
+
306
+ "linearRingCoordinates": {
307
+ "title": "Linear Ring Coordinates",
308
+ "description": "A LinearRing is closed LineString with 4 or more positions. The first and last positions are equivalent (they represent equivalent points). Though a LinearRing is not explicitly represented as a GeoJSON geometry type, it is referred to in the Polygon geometry type definition.",
309
+ "allOf": [
310
+ { "$ref": "#/definitions/lineStringCoordinates" },
311
+ {
312
+ "minItems": 4
313
+ }
314
+ ]
315
+ },
316
+
317
+ "lineStringCoordinates": {
318
+ "title": "Line String Coordinates",
319
+ "description": "For type `LineString`, the `coordinates` member must be an array of two or more positions.",
320
+ "allOf": [
321
+ { "$ref": "#/definitions/coordinates" },
322
+ {
323
+ "minLength": 2,
324
+ "items": { "$ref": "#/definitions/position" }
325
+ }
326
+ ]
327
+ },
328
+
329
+ "polygonCoordinates": {
330
+ "title": "Polygon Coordinates",
331
+ "description": "For type `Polygon`, the `coordinates` member must be an array of LinearRing coordinate arrays. For Polygons with multiple rings, the first must be the exterior ring and any others must be interior rings or holes.",
332
+ "allOf": [
333
+ { "$ref": "#/definitions/coordinates" },
334
+ {
335
+ "items": { "$ref": "#/definitions/linearRingCoordinates" }
336
+ }
337
+ ]
338
+ },
339
+
340
+ "position": {
341
+ "title": "Position",
342
+ "type": "array",
343
+ "description": "A position is the fundamental geometry construct. The `coordinates` member of a geometry object is composed of one position (in the case of a Point geometry), an array of positions (LineString or MultiPoint geometries), an array of arrays of positions (Polygons, MultiLineStrings), or a multidimensional array of positions (MultiPolygon).\n\nA position is represented by an array of numbers. There must be at least two elements, and may be more. The order of elements must follow x, y, z order (easting, northing, altitude for coordinates in a projected coordinate reference system, or longitude, latitude, altitude for coordinates in a geographic coordinate reference system). Any number of additional elements are allowed -- interpretation and meaning of additional elements is beyond the scope of this specification.",
344
+ "minItems": 2,
345
+ "additionalItems": true,
346
+ "items": {
347
+ "type": "number"
348
+ }
349
+ }
350
+
351
+ }
352
+
353
+ }
@@ -0,0 +1,3 @@
1
+ module GeosparqlToGeojson
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,19 @@
1
+ require 'geosparql_to_geojson/version'
2
+ require 'geosparql_to_geojson/converter'
3
+ require 'geosparql_to_geojson/geojson'
4
+ require 'geosparql_to_geojson/geojson_validator.rb'
5
+
6
+ # Namespace for classes and modules that deal with converting GeoSparql to GeoJSON
7
+ # @since 0.1.0
8
+ module GeosparqlToGeojson
9
+ # Convert GeoSparql to GeoJSON
10
+ #
11
+ # @param [String] geosparql_values the GeoSparql values
12
+ # @param [Hash] geosparql_properties the properties to be added to the GeoJSON output
13
+ # @param [true, false] reverse states whether to reverse the GeoJSON coordinates
14
+ #
15
+ # @return [GeosparqlToGeojson::GeoJson]
16
+ def self.convert_to_geojson(geosparql_values: '', geosparql_properties: {}, reverse: false)
17
+ GeosparqlToGeojson::Converter.new(geosparql_values, geosparql_properties, reverse).convert
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geosparql_to_geojson
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Callum Neve-Jones
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json-schema
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.12'
83
+ description: Converts GeoSparql to GeoJSON
84
+ email:
85
+ - nevejonesc@parliament.uk
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".ruby-version"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - geosparql_to_geojson.gemspec
102
+ - lib/geosparql_to_geojson.rb
103
+ - lib/geosparql_to_geojson/converter.rb
104
+ - lib/geosparql_to_geojson/geojson.rb
105
+ - lib/geosparql_to_geojson/geojson_validator.rb
106
+ - lib/geosparql_to_geojson/schema/geojson.json
107
+ - lib/geosparql_to_geojson/version.rb
108
+ homepage: https://github.com/ukparliament/geosparql-to-geojson
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.6.12
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Converts GeoSparql to GeoJSON
132
+ test_files: []