PHP extension for geospatial rendering with Mapnik

Overview

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
Comments
  • render bounding box question

    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?

    enhancement question 
    opened by africanrhino 7
  • make test fails on imagecreatefromstring()

    make test fails on imagecreatefromstring()

    Not sure what is going on here but cannot complete the installation steps because make test fails on imagecreatefromstring() image.phpt.

    Naturally, the first thing I checked is the presence of gd and it was present. Next I copied the imagecreatefromstring() example from the PHP docs into a regular .php file and, oddly enough, it works as expected.

    php_test_results_20160416_1939.txt

    Most strange :S

    -Peter

    opened by 3XE 2
  • Code Structure

    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.

    opened by flippmoke 2
  • Proj support

    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);
    
    opened by sokrat 1
  • Update requriments in README.md

    Update requriments in README.md

    The './configure --with-mapnik' part of the installation process will fail unless mapnik-config is available. It seems to be packaged separately from mapnik3.0 on Ubuntu.

    -Peter

    opened by 3XE 1
  • Render outside map

    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.

    opened by flippmoke 1
  • Fix image test broken by PHP upgrade.

    Fix image test broken by PHP upgrade.

    After PHP 7.1.17 update from Webtatic repository (https://webtatic.com/news/2018/05/latest-updates-php-7.2.5-7.1.17-7.0.30-5.6.36/) issues with loading GD and the image.phpt test appeared. This change is a quick fix that simply skips that test if GD is not loaded. It may never be loaded as the --EXTENTIONS-- section of the test can't seem to find the module.

    opened by garrettrayj 0
  • PECL package

    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.
    enhancement 
    opened by garrettrayj 0
  • Additional Box2D functions

    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.

    enhancement 
    opened by garrettrayj 1
Releases(2.0.0)
  • 2.0.0(May 4, 2019)

    PHP7 Mapnik 2.0.0 enhances stability and durability of the extension by implementing best practices and improving code quality. This release does not include new features or major changes to the API, however it does improve exceptions and sets up the project for future additions.

    • Implemented new parameter parsing API.
      • Creating Mapnik objects with invalid arguments now throws a TypeError instead of \Mapnik\Exception.
      • Users should catch \Throwable, \Error, or \TypeError to handle errors from object construction or method invocation with bad arguments. Mapnik related errors, an invalid SRS for example, will still throw \Mapnik\Exception.
      • Utilizing strict types is recommended for the most predictable behavior.
    • Implemented argument info macros for feeding object reflection API.
    • Accessor macros are now used for fetch values from zvals.
    • Reorganized source code, fixed duplicate imports, and significantly improved code quality.
    • Added Dockerfile for creating an image tailored to PHP7 Mapnik extension development.
    • Added tooling for running tests with valgrind for memory leak detection.
      • CI builds now test for leaks.
    Source code(tar.gz)
    Source code(zip)
  • 1.2.3(May 15, 2018)

  • 1.2.2(Sep 17, 2017)

    PHP7 Mapnik 1.2.2 is a patch release with stability and compatibility fixes.

    • Fixes #11. Segmentation fault transforming projections other than EPSG:4326 and EPSG:3857.
    • PHP 7.2 compatibility. Fixed deprecation notices for assert(string) in tests.
    • Improved configuration for including dependencies.
    Source code(tar.gz)
    Source code(zip)
  • 1.2.1(May 8, 2017)

  • 1.2.0(Apr 5, 2017)

    PHP7 Mapnik 1.2.0 includes new features, bug fixes, and documentation.

    • New functions for manipulating and navigating maps. Closes #8.
    • Class prototypes (happy IDEs) and auto-generated API documentation (happy developers).
    • Refactored tests to be object oriented with simple test case class.
    • Fixed issues with builds on Travis CI.
    Source code(tar.gz)
    Source code(zip)
GeoSpatial integration on Laravel 5.2+ that supports MySQL and PostgreSQL.

Features GeoSpatial integration on Laravel 5.2+: Create geospatial columns using Schema and migrations Save and retrieve geospatial attributes using d

Eleven 47 Dec 22, 2022
Free database of geographic place names and corresponding geospatial data

FreeGeoDB Free database of geographic place names and corresponding geospatial data Entities airports cities countries (admin-0) lakes ports railroads

delight.im 1.6k Dec 15, 2022
IP2Location Yii extension enables the user to find the country, region, city, coordinates, zip code, time zone, ISP

IP2Location Yii extension enables the user to find the country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation, usage type, IP address type and IAB advertising category from IP address using IP2Location database. It has been optimized for speed and memory utilization. Developers can use the API to query all IP2Location BIN databases or web service for applications written using Yii.

IP2Location 7 May 21, 2022
GeoJSON implementation for PHP

GeoJson PHP Library This library implements the GeoJSON format specification. The GeoJson namespace includes classes for each data structure defined i

Jeremy Mikola 274 Dec 17, 2022
ESRI ShapeFile library for PHP

shapefile ShapeFile library for PHP Features Currently the 2D and 3D variants except MultiPatch of the ShapeFile format as defined in https://www.esri

phpMyAdmin 23 Jun 29, 2022
The most featured Geocoder library written in PHP.

Geocoder Important: You are browsing the documentation of Geocoder 4.x. Documentation for version 3.x is available here: Geocoder 3.x documentation. D

Geocoder 3.9k Jan 2, 2023
Simple Yet Powerful Geo Library for PHP

phpgeo - A Simple Geo Library for PHP phpgeo provides abstractions to geographical coordinates (including support for different ellipsoids) and allows

Marcus Jaschen 1.4k Dec 27, 2022
Geo-related tools PHP 5.4+ library built atop Geocoder and React libraries

Geotools Geotools is a PHP geo-related library, built atop Geocoder and React libraries. Features Batch geocode & reverse geocoding request(s) in seri

The League of Extraordinary Packages 1.3k Dec 27, 2022
PHP library to access the OpenCage geocoding API

OpenCage Geocoding API Library for PHP A PHP library to use the OpenCage geocoding API. Build Status / Code Quality Overview This library attempts to

OpenCage GmbH 29 Nov 15, 2022
PHP library for determining the physical location of binaries

Bin Locator Library for searching binary files in the operating system. Requirements PHP >= 7.4 Installation Library is available as composer reposito

PHP FFI 8 Jul 27, 2022
PHP library to easily get static image from French Cadastral Government map with markers and lines.

PHP French Cadastral Map Static API PHP library to easily get static image from French Cadastral Government map with markers and lines. Map source : c

Franck Alary 6 Nov 29, 2022
PHP library to easily get static image from OpenStreetMap (OSM) with markers and lines.

PHP OpenStreetMap Static API PHP library to easily get static image from OpenStreetMap with markers and lines. ✨ Supporting ⭐ Star this repository to

Franck Alary 34 Jan 2, 2023
Official PHP library for IPinfo (IP geolocation and other types of IP data)

This is the official PHP client library for the IPinfo.io IP address API, allowing you to lookup your own IP address,

IPinfo 171 Jan 2, 2023
PHP Extension to handle common geospatial functions.

geospatial - PHP Geospatial Extension PHP Extension to handle common geospatial functions. The extension currently has implementations of the Haversin

PHP Geospatial, putting the Elephpant on your globe 56 Dec 29, 2022
GeoSpatial integration on Laravel 5.2+ that supports MySQL and PostgreSQL.

Features GeoSpatial integration on Laravel 5.2+: Create geospatial columns using Schema and migrations Save and retrieve geospatial attributes using d

Eleven 47 Dec 22, 2022
Free database of geographic place names and corresponding geospatial data

FreeGeoDB Free database of geographic place names and corresponding geospatial data Entities airports cities countries (admin-0) lakes ports railroads

delight.im 1.6k Dec 15, 2022
Laravel package to work with geospatial data types and functions.

Laravel Spatial Laravel package to work with geospatial data types and functions. For now it supports only MySql Spatial Data Types and Functions. Sup

Tarfin 47 Oct 3, 2022
Library that provides collection, processing, and rendering functionality for PHP code coverage information.

phpunit/php-code-coverage Provides collection, processing, and rendering functionality for PHP code coverage information. Installation You can add thi

Sebastian Bergmann 8.5k Jan 5, 2023
A PHP class for querying the Twitter API and rendering tweets as an HTML list

TweetPHP A PHP class for querying the Twitter API and rendering tweets as an HTML list. Features Works with Twitter API v1.1 Tweets are cached to avoi

Jonathan Nicol 151 Nov 25, 2022
Rendering markdown from PHP code

JBZoo / Markdown Installing composer require jbzoo/markdown Usage Rendering Table <?php declare(strict_types=1); use JBZoo\Markdown\Table; echo (new

JBZoo Toolbox 1 Dec 26, 2021