GithubHelp home page GithubHelp logo

garrettrayj / php7-mapnik Goto Github PK

View Code? Open in Web Editor NEW
20.0 4.0 8.0 1.13 MB

PHP extension for geospatial rendering with Mapnik

Home Page: https://garrettrayj.github.io/php7-mapnik/

License: MIT License

C++ 53.82% C 2.95% PHP 38.21% HTML 1.55% Shell 0.72% M4 2.41% Dockerfile 0.34%
mapnik php tile-server geospatial php7-mapnik

php7-mapnik's Introduction

PHP7 Mapnik

PHP7 Mapnik

Introduction

This project is an extension for PHP 7 that enables geospatial rendering with Mapnik. Create tile generation scripts, dynamic tile services, or static maps with Mapnik XML and PHP.

Build Status

Requirements

  • PHP >= 7.0
    • Available through brew intall php on MacOS with Homebrew.
    • Available through sudo apt-get install php-dev php-gd on Ubuntu 16.04 Xenial.
  • Mapnik 3.0.x
    • Available through brew install mapnik on MacOS with Homebrew.
    • Available through sudo apt-get install libmapnik-dev on Ubuntu 16.04 Xenial.

Installation

git clone https://github.com/garrettrayj/php7-mapnik.git && cd php7-mapnik
phpize
./configure --with-mapnik
make test
make install
echo "extension=mapnik.so" > /etc/php.d/mapnik.ini

Notes:

  • The PHP configuration directory may differ from above. Run php -i | grep "Scan this dir" to find your system's location.
  • The ICU library path may need to be exported before building on MacOS. export LDFLAGS="-L/usr/local/opt/icu4c/lib"

Tile Server Example

Run the example...

./example/run.sh

...then visit http://localhost:8000/

Usage

<?php

// Register datasource plugins
// Use `mapnik-config --input-plugins` to get input plugin directory
\Mapnik\DatasourceCache::registerDatasources('/usr/local/lib/mapnik/input');

// Create map
$map = new \Mapnik\Map(640, 480);

// Register fonts
// Use `mapnik-config --fonts` to get Mapnik fonts directory
$map->registerFonts('/usr/local/lib/mapnik/fonts');

// Load Mapnik XML
$map->loadXmlFile('my_awesome_map.xml', false, $basePath);

// Situate map content within canvas
$map->zoomAll();

// Create image
$image = new \Mapnik\Image(640, 480);

// Render
$renderer = new \Mapnik\AggRenderer($map, $image);
$renderer->apply();

// Save PNG image file
$image->saveToFile('my_awesome_map.png');

See the API Documentation for a complete list of available objects and methods.

Dev Container

The included Dockerfile builds an image with all the dependencies needed for extension development and testing, including testing for memory leaks.

docker build -t php7-mapnik-dev .
docker run -it --mount type=bind,source=$(pwd),target=/opt/php7-mapnik php7-mapnik-dev:latest

php7-mapnik's People

Contributors

africanrhino avatar garrettrayj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

php7-mapnik's Issues

PECL package

As an end-user
I want php7-mapnik available in PECL,
so I may easily install it with a one liner.

Feasibility

Mapnik requires a tall stack of dependencies that can be hit or miss in repos. While availability has continuously improved, it's still very common to compile from source code. Does it make sense to package the extension when its main dependency is often compiled itself?

The project may need to be renamed and relicensed (PHP License 3.0.1) to comply with PECL standards...

Products derived from this software may not be called "PHP", nor may "PHP" appear in their name, without prior written permission from [email protected]. You may indicate that your software works in conjunction with PHP by saying "Foo for PHP" instead of calling it "PHP Foo" or "phpfoo"

...and...

We strongly encourage contributors to choose the PHP License 3.01 for their extensions, in order to avoid possible troubles for end-users of the extension.

Todo

  • Reach out to pecl-dev mailing list. Inquire about license and project name.
  • Research packaging a C++ extension... Pyrus, pickle, package.xml, etc.

Proj support

Hi
When I call ProjTransform->backward() or ProjTransform->forward() with any projection different from 4326 and 3857 i get segmentation fault.
Mapnik compiled from source with proj4 support, tested on debian and alpine.
example:

$boundingBox = new Box2D($minX, $minY, $maxX, $maxY);
$source = new Projection('+init=epsg:4326');
$destination = new Projection('+init=epsg:32638');
$transform = new ProjTransform($source, $destination);
$tileBoundingBox = $transform->backward($boundingBox);

Fluent object interfaces

Setters and manipulation functions should return the instance of the object, so that code is cleaner and more readable.

Additional Box2D functions

Currently PHP7 Mapnik only implements the bare minimum requirements for constructing Box2D objects. There's plenty of low hanging fruit in the C++ API that would make working with envelopes easier...

  • width() and height()
  • expand_to_include()
  • contains()
  • intersects()
  • re_center()
  • clip()
  • pad()
  • etc.

Should probably do a PHP implementation of the coord class before tackling this.

Code Structure

Hey @garrettrayj I saw your post on the mapnik dev mailing list, I don't have to give a big review but thought I would open a few tickets on your repo here on issues that I might see.

The first issue I see is that you have all your source in the main directory, its not required but its a lot easier if you put it all in a directory. Is this something required by phpize?

Confused by this as it shouldn't be any issue:
Do NOT compile Boost with C++11. On Mac at least, you'll have a bad time with missing symbols.

render bounding box question

is there any way we can get the bbox and scale of what is to be rendered by the map? the zoomToBox zooms the image to fit the bounds of map, but if say you produce a 800X600 image based on a zoomToBox that's 16:9 then the rendered bounding box will be significantly different to the original 16:9. I'm trying to manipulate the data layer to exclude any label on the edge of the map but without knowing what the true bounding box is and without knowing the scale will be makes this difficult. any ideas here?

Render outside map

I would highly suggest for the ease of users who might use your library that you make the agg render method a part of the map object. We do that in node-mapnik, so that you can do map.render(...). I wouldn't suggest that the C++ interface be directly ported basically, I would write it so that the code is more in a "PHP" style.

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.