Giter Club home page Giter Club logo

ruby-mapnik's Introduction

Ruby Mapnik

github.com/mapnik/Ruby-Mapnik

Requirements

On OS X install ruby deps like:

sudo gem install rake-compiler rake
export ARCHFLAGS="-arch x86_64"
sudo bash -c 'ARCHFLAGS="-arch x86_64" gem install hoe rice chunky_png cairo'

Description

A set of bindings between Ruby and Mapnik. Supports many of the common uses for Mapnik, and one day, might support all of them. Rendering is available using the standard AGG library, or additionally via Cairo, if the rcairo gem is installed and Mapnik has been compiled with Cairo support.

Installation

If you have checked out this local repository code build like:

rake

The above command will compile the bindings and run the tests.

File issues at github.com/mapnik/Ruby-Mapnik if you hit any compile errors.

To create a gem from your local repository and install it run:

rake gem
gem install pkg/ruby_mapnik-0.x.y.gem

Alternatively, if you wish to install Ruby-Mapnik from the latest tagged release you can do:

gem install ruby_mapnik

Note: on osx the default rake compile will try to build universal, and your mapnik install is unlikely built universal. Check the architecture of libmapnik.dylib like:

file /usr/local/lib/libmapnik.dylib

On a system where your compiler defaults to 64bit you’ll see: ‘Mach-O 64-bit dynamically linked shared library x86_64’

So to avoid a linking warning like:

ld: warning: ignoring file /usr/local/lib/libmapnik.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

You can pass this before rake compile:

export ARCHFLAGS="-arch x86_64"

Synopsis

require 'mapnik'

map = Mapnik::Map.new do |m|

  # A grey background
  m.background = Mapnik::Color.new('#777')

  # Use the Google mercator projection
  m.srs =  Mapnik::Tile::DEFAULT_OUTPUT_PROJECTION

  # Add a layer to the map
  m.layer 'countries' do |l|

    # Add a style to the layer
    l.style do |s|

      # Add a rule to the style (this one is a default rule)
      s.rule do |default|

        #fill the shapes woith polygon symbolizers
        default.fill = Mapnik::Color.new('#880000')
      end
    end

    # set the srs of the layer
    l.srs = "+proj=latlong +datum=WGS84"

    #specify the datasource for the layer
    l.datasource = Mapnik::Datasource.create :type => 'shape', :file => "#{PATH}/../data/TM_WORLD_BORDERS_SIMPL_0.3_MOD"
  end

end

map.zoom_to_box(map.layers.first.envelope) 
map.render_to_file('my_map.png')

Examples

See demo/rundemo.rb for the classic mapnik rundemo. Also see demo/sinatra/demo.rb for a simple tile server (requires the sinatra gem).

Thanks

Thanks to the Mapnik team and especially to Dane Springmeyer!

ruby-mapnik's People

Contributors

elliotlaster avatar gravitystorm avatar alno avatar

Watchers

Matt Amos avatar James Cloos 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.