GeosparqlToGeojson

GeosparqlToGeojson is a gem created by the Parliamentary Digital Service to take GeoSparql data and convert it into GeoJSON data.

Gem Build Status Test Coverage License

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.

Contents

Requirements

GeosparqlToGeojson requires the following:

Installation

gem 'geosparql_to_geojson'

Usage

This gem's main function is taking a GeoSparql string and converting it into GeoJSON.

Calling GeosparqlToGeojson#convert_to_geojson and passing in valid GeoSparql string will convert the GeoSparql to GeoJSON and return a GeosparqlToGeojson::GeoJson object.

Properties can optionally be passed in as well as whether the data should be reversed during the convertion.

geosparql = 'POINT(0.1, 51.5)'
properties = {name: 'London'}

point = GeosparqlToGeojson.convert_to_geojson(geosparql_values: geosparql, geosparql_properties: properties, reverse: true)
#=> GeosparqlToGeojson::GeoJson

Calling point.geojson will return a GeoJSON string. For example:

{"type": "FeatureCollection",
  "features": [
    {
       "type": "Feature",
       "geometry": {
         "type": "Point",
         "coordinates": [
          51.5,
          0.1
        ]
      },
      "properties": {"name": "London"}
    }
  ]
}

Calling point.validate will return a GeosparqlToGeojson::Validator object which can be used to validate the generated GeoJSON.

validated_geojson = GeosparqlToGeojson::Validator.new(point)

validated_geojson.valid?
#=> true

validated_geojson.errors
#=> []

Getting Started with Development

To clone the repository and set up the dependencies, run the following:

git clone https://github.com/ukparliament/geosparql_to_geojson.git
cd geosparql_to_geojson
bundle install

Running the tests

We use RSpec as our testing framework and tests can be run using:

bundle exec rspec

Contributing

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.

  1. Fork the repository
  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. Ensure your changes are tested using Rspec
  6. Create a new Pull Request

License

GeosparqlToGeojson is licensed under the Open Parliament Licence.