Code Monkey home page Code Monkey logo

kml_polygon's Introduction

======= kml_polygon

Google earth doesn't provide polygon primitives, leaving you to generate them as a series of points.

Given only a center-point (longitude/latitude) and radius, this Gem makes it easy to create (n) sided polygons (sufficient sides giving a circle) or stars, for inclusion in a KML file.

All credit to Nick Galbreath for the original code, and for providing it in a portable format. Thanks! (http://blog.client9.com/2007/09/drawing-circles-and-stars-on-google.html)

Installation

Add this line to your application's Gemfile:

gem 'kml_polygon'

And then execute:

$ bundle

Or install it yourself as:

$ gem install kml_polygon

Usage

kml_regular_polygon(longitude, latitude, radius, [sides=20, rotate=0])
kml_star(longitude, latitude, radius, inner_radius, [sides=10, rotate=0])

Returns a string suitable for adding into a KML file.

kml_regular_polygon

kml_regular_polygon(longitude, latitude, radius, [sides=0, rotate=0])

Regular polygon

longitude, latitude - center point in decimal degrees
radius              - radius in meters
segments            - number of sides, > 20 looks like a circle (optional, default: 20)
rotate              - rotate polygon <rotate> degrees (optional, default: 0)

kml_star

kml_star(longitude, latitude, radius, inner_radius, [sides=10, rotate=0])

Make a "star" or "burst" pattern

longitude, latitude - center point in decimal degrees
radius              - radius in meters
inner_radius        - radius in meters, typically < outer_radius
segments            - number of "points" on the star (optional, default: 10)
rotate              - rotate polygon by <rotate> degrees (optional, default: 0)

For Example:

# kml_polygon_example.rb
include kml_polygon
circle = kml_regular_polygon(-95, 50, 70000)
star = kml_star(-95,45, 70000, 50000)
puts "<kml><Document>
      <Style id='polygon1'><PolyStyle><color>7fff0000</color></PolyStyle></Style>
      <Style id='polygon2'><PolyStyle><color>7f0000ff</color></PolyStyle></Style>
      <Placemark><styleUrl>polygon1</styleUrl><Polygon>" << circle << "</Polygon></Placemark>
      <Placemark><styleUrl>polygon2</styleUrl><Polygon>" << star << "</Polygon></Placemark>
      </Document></kml>"

Outputs a minimal but funtional KML file with one circle and one star in semi-transparent colors.

Contributing

  1. Fork it (git clone git://github.com/mbrookes/kml_polygon.git)
  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 new Pull Request

kml_polygon's People

Contributors

mbrookes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.