Coder Social home page Coder Social logo

crgeojson's Introduction

geojson

This shard is meant to provide a simple interface for creating, reading, and writing geoJSON strings and objects that represent them, based on the GeoJSON specification.

Installation

  1. Add the dependency to your shard.yml:
dependencies:
  geojson:
    github: respitesage/crgeojson
  1. Run shards install

Usage

require "geojson"

Once you've required the library, you can use the GeoJSON module to create a geometry and a feature, like so:

point = GeoJSON::Point.new longitude: -91.343, latitude: 0.018

feature = GeoJSON::Feature.new geometry: point, id: "Galapagos"

Note that this library (like the GeoJSON specification) uses positions of the form [longitude, latitude(, optional altitude/elevation)]. This is particularly important when not using named arguments to specify points and positions. Additionally, the id field above is optional. Refer to the documentation of Feature.new for more information.

Now that we have our feature, we can serialize it to GeoJSON:

feature.to_json # => %({"type": "Feature",
                #       "geometry": {"type": "Point", "coordinates": [-91.343, 0.018]},
                #       "id": "Galapagos"})

If we instead had that string and wanted to deserialize it into a feature, we could do so like this:

json_string = %({"type": "Feature",
                 "geometry": {"type": "Point", "coordinates": [-91.343, 0.018]},
                 "id": "Galapagos"})

feature = GeoJSON::Feature.from_json json_string

This library currently conforms with almost all of the GeoJSON Specification, so you can also serialize, deserialize, and programmatically manipulate FeatureCollections, MultiPoints, LineStrings, MultiLineStrings, Polygons, MultiPolygons, and GeometryCollections.

Development

Features still to be developed can be found in TODO.md. Make sure to add specs for any new features.

Contributing

  1. Create a fork of this 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. Create a new Pull Request from your branch to this repository

Contributors

  • Benjamin Wade - creator and maintainer

crgeojson's People

Contributors

kinxer avatar respitesage avatar

Stargazers

 avatar

Watchers

 avatar

crgeojson's Issues

Examples will not work

The examples won't work unless I use:

include GeoJSON
include GeoJSON::Coordinates

Error without this:

In lib/geojson/src/geojson/geometry/pseudo_geometry.cr:42:22

 42 | contents = CoordinateTree.new parser
                 ^-------------
Error: undefined constant CoordinateTree

The bigger problem is that the includes have to be at the top-level, and I'd rather not have it mixed into my whole environment.

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.