Skip to content

Commit

Permalink
add OpenSeaMap backend
Browse files Browse the repository at this point in the history
  • Loading branch information
woodpeck committed Aug 21, 2019
1 parent b91bfc6 commit aa4fceb
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,21 @@ install: build
install -m 755 ${INSTALLOPTS} backends/test $(DESTDIR)/usr/lib/tirex/backends
install -m 755 ${INSTALLOPTS} backends/wms $(DESTDIR)/usr/lib/tirex/backends
install -m 755 ${INSTALLOPTS} backends/mapserver $(DESTDIR)/usr/lib/tirex/backends
install -m 755 ${INSTALLOPTS} backends/openseamap $(DESTDIR)/usr/lib/tirex/backends
install -m 755 ${INSTALLOPTS} -d $(DESTDIR)/etc/tirex
install -m 644 ${INSTALLOPTS} etc/tirex.conf.dist $(DESTDIR)/etc/tirex/tirex.conf
install -m 755 ${INSTALLOPTS} -d $(DESTDIR)/etc/tirex/renderer
install -m 755 ${INSTALLOPTS} -d $(DESTDIR)/etc/tirex/renderer/test
install -m 644 ${INSTALLOPTS} etc/renderer/test.conf.dist $(DESTDIR)/etc/tirex/renderer/test.conf
install -m 644 ${INSTALLOPTS} etc/renderer/test/checkerboard.conf.dist $(DESTDIR)/etc/tirex/renderer/test/checkerboard.conf
install -m 755 ${INSTALLOPTS} -d $(DESTDIR)/etc/tirex/renderer/wms
install -m 755 ${INSTALLOPTS} -d $(DESTDIR)/etc/tirex/renderer/openseamap
install -m 755 ${INSTALLOPTS} -d $(DESTDIR)/etc/tirex/renderer/mapserver
install -m 644 ${INSTALLOPTS} etc/renderer/wms.conf.dist $(DESTDIR)/etc/tirex/renderer/wms.conf
install -m 644 ${INSTALLOPTS} etc/renderer/openseamap.conf.dist $(DESTDIR)/etc/tirex/renderer/openseamap.conf
install -m 644 ${INSTALLOPTS} etc/renderer/mapserver.conf.dist $(DESTDIR)/etc/tirex/renderer/mapserver.conf
install -m 644 ${INSTALLOPTS} etc/renderer/wms/demowms.conf.dist $(DESTDIR)/etc/tirex/renderer/wms/demowms.conf
install -m 644 ${INSTALLOPTS} etc/renderer/openseamap/openseamap.conf.dist $(DESTDIR)/etc/tirex/renderer/openseamap/openseamap.conf
install -m 644 ${INSTALLOPTS} etc/renderer/mapserver/msdemo.conf.dist $(DESTDIR)/etc/tirex/renderer/mapserver/msdemo.conf
install -m 644 ${INSTALLOPTS} etc/renderer/mapserver/msdemo.map $(DESTDIR)/etc/tirex/renderer/mapserver/msdemo.map
install -m 644 ${INSTALLOPTS} etc/renderer/mapserver/fonts.lst $(DESTDIR)/etc/tirex/renderer/mapserver/fonts.lst
Expand Down
39 changes: 39 additions & 0 deletions backends/openseamap
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/perl
#-----------------------------------------------------------------------------
#
# Tirex Tile Rendering System
#
# backends/openseamap
#
#-----------------------------------------------------------------------------
# See Tirex::Backend::Test for documentation.
#-----------------------------------------------------------------------------
#
# Copyright (C) 2019 Frederik Ramm <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.
#
#-----------------------------------------------------------------------------

use strict;
use warnings;

use Tirex::Backend::OpenSeaMap;

#-----------------------------------------------------------------------------

my $backend = Tirex::Backend::OpenSeaMap->new();
$backend->main();

#-- THE END ------------------------------------------------------------------
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
tirex (0.6.1) UNRELEASED; urgency=medium

* add openseamap backend

-- Frederik Ramm E <[email protected]> Wed, 21 Aug 2019 16:10:48 +0200

tirex (0.6.0) UNRELEASED; urgency=medium

* tirex-syncd to use ssh master, also allow multiple destinations
Expand Down
7 changes: 7 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ Description: Mapnik backend for the Tirex tile rendering system
The Tirex suite of programs manages map tile rendering and caching.
This is the Mapnik backend for creating maps with the Mapnik renderer.

Package: tirex-backend-openseamap
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, tirex-core, default-jre-headless | java8-runtime-headless
Description: OpenSeaMap backend for the Tirex tile rendering system
The Tirex suite of programs manages map tile rendering and caching.
This is the OpenSeaMap backend for creating maps with the OpenSeaMap renderer.

Package: tirex-syncd
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, tirex-core
Expand Down
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ binary-arch: build install
# the following line handles all packages *except* tirex-core
dh_install --no-package tirex-core --sourcedir=$(CURDIR)/debian/tmp
# the following line handles *only* the tirex-core package, it excludes some perl libraries that should not end up in this package
dh_install --no-package tirex-backend-wms --no-package tirex-backend-mapserver --no-package tirex-backend-mapnik --no-package tirex-munin-plugin --no-package tirex-nagios-plugin --no-package tirex-syncd --no-package --tirex-example-map --exclude Munin --exclude Tirex::Backend::WMS --exclude Tirex::Backend::Mapserver --exclude Backend/WMS --exclude Backend/Mapserver --sourcedir=$(CURDIR)/debian/tmp
dh_install --no-package tirex-backend-wms --no-package tirex-backend-mapserver --no-package tirex-backend-openseamap --no-package tirex-backend-mapnik --no-package tirex-munin-plugin --no-package tirex-nagios-plugin --no-package tirex-syncd --no-package --tirex-example-map --exclude Munin --exclude Tirex::Backend::WMS --exclude Tirex::Backend::Mapserver --exclude Tirex::Backend::OpenSeaMap --exclude Backend/WMS --exclude Backend/Mapserver --exclude Backend/OpenSeaMap --sourcedir=$(CURDIR)/debian/tmp
# dh_installmenu
# dh_installdebconf
# dh_installlogrotate
Expand Down
38 changes: 38 additions & 0 deletions etc/renderer/openseamap.conf.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#-----------------------------------------------------------------------------
#
# Konfiguration for OpenSeaMap renderer
#
# /etc/tirex/renderer/openseamap.conf
#
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# General configuration
#-----------------------------------------------------------------------------

# symbolic name
name=openseamap

# path to executable of renderer
path=/usr/lib/tirex/backends/openseamap

# UDP port where the master can contact this renderer
# must be individual for each renderer
port=9334

# number of processes that should be started
procs=3

# syslog facility
#syslog_facility=daemon

# activate this to see debug messages from renderer
#debug=1

#-----------------------------------------------------------------------------
# Backend specific configuration
#-----------------------------------------------------------------------------

# none

#-- THE END ------------------------------------------------------------------
36 changes: 36 additions & 0 deletions etc/renderer/openseamap/openseamap.conf.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#-----------------------------------------------------------------------------
#
# Configuration for OpenSeaMap map
#
# /etc/tirex/renderer/openseamap/openseamap.conf
#
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# General configuration
#-----------------------------------------------------------------------------

# symbolic name of this map
name=openseamap

# tile directory
tiledir=/var/lib/tirex/tiles/openseamap

# minimum zoom level allowed (default 0)
#minz=0

# maximum zoom level allowed (default 17)
maxz=18

#-----------------------------------------------------------------------------
# Backend specific configuration
#-----------------------------------------------------------------------------

# actual rendering program
jar=/srv/jrenderpgsql/jrenderpgsql.jar

# how to access the database
dburl=jdbc:postgresql:///gis?user=postgres&password=postgres


#-- THE END ------------------------------------------------------------------
123 changes: 123 additions & 0 deletions lib/Tirex/Backend/OpenSeaMap.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#-----------------------------------------------------------------------------
#
# Tirex/Backend/OpenSeaMap.pm
#
#-----------------------------------------------------------------------------

use strict;
use warnings;

use List::Util qw();
use Carp;

use Tirex::Backend;

#-----------------------------------------------------------------------------

package Tirex::Backend::OpenSeaMap;
use base qw( Tirex::Backend );

=head1 NAME
Tirex::Backend::OpenSeaMap - OpenSeaMap backend for Tirex
=head1 DESCRIPTION
This backend calls an external Java program to generate an OpenSeaMap
meta tile. The Java program is here: https://svn.openstreetmap.org/applications/editors/josm/plugins/seachart/jrenderpgsql/
Config parameters for the map file:
=over 8
=item dburl the JDBC database connection URL, with username and password if needed
=item jar the JAR file containing the JRenderPsql class to use
=item scalefactor the scale factor (defaults to 1.0)
=item tilesize the tile size (should be 256 * scalefactor to avoid issues)
=head1 METHODS
=head2 $backend->init()
This method initializes things specific to this backend.
=cut

sub init
{
my $self = shift;

$self->{'border_width'} = 6;
GD::Image->trueColor(1);

}

=head2 $backend->check_map_config($map)
=cut

sub check_map_config
{
my $self = shift;
my $map = shift;

if ($Tirex::METATILE_COLUMNS != $Tirex::METATILE_ROWS)
{
Carp::croak("this plugin cannot work with non-square meta tiles");
}

if (!defined($map->{'jar'}))
{
Carp::croak("must configure renderer in map file");
}

if (!-f $map->{'jar'})
{
Carp::croak("configured renderer " . $map->{'jar'} . " does not exist");
}

if (!defined($map->{'dburl'}))
{
Carp::croak("must configure dburl in map file");
}
}

=head2 $backend->create_metatile()
Create a metatile.
=cut

sub create_metatile
{
my $self = shift;
my $map = shift;
my $metatile = shift;

my $xc = $metatile->get_x();
my $yc = $metatile->get_y();
my $zoom = $metatile->get_z();

my $pixel = $Tirex::PIXEL_PER_TILE;
my $tmpfile = "/tmp/tirex-$$-openseamap.png";
my $cmdline = sprintf("java -jar %s --scale %f --tilesize %d '%s' %d %d %d %s",
$map->{'jar'}, $map->{'scalefactor'}, $map->{'tilesize'} * $Tirex::METATILE_COLUMNS, $map->{'dburl'}, $zoom , $xc, $yc, $tmpfile);

::syslog('debug', 'OpenSeaMap request: %s', $cmdline) if ($Tirex::DEBUG);
system($cmdline);

my $image = GD::Image->new($tmpfile);
$image->alphaBlending(0);
$image->saveAlpha(1);

unlink ($tmpfile);
return $image;
}


1;

#-- THE END ------------------------------------------------------------------

0 comments on commit aa4fceb

Please sign in to comment.