Skip to content

Commit

Permalink
scafolding for vector tile support
Browse files Browse the repository at this point in the history
  • Loading branch information
tbonfort committed Sep 13, 2015
1 parent 2c12746 commit 50482bf
Show file tree
Hide file tree
Showing 10 changed files with 931 additions and 2 deletions.
17 changes: 16 additions & 1 deletion CMakeLists.txt
Expand Up @@ -117,6 +117,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})

#options suported by the cmake builder
option(WITH_PROJ "Choose if reprojection support should be built in" ON)
option(WITH_PROTOBUFC "Choose if protocol buffers support should be built in (required for vector tiles)" ON)
option(WITH_KML "Enable native KML output support (requires libxml2 support)" OFF)
option(WITH_SOS "Enable SOS Server support (requires PROJ and libxml2 support)" OFF)
option(WITH_WMS "Enable WMS Server support (requires proj support)" ON)
Expand Down Expand Up @@ -232,6 +233,8 @@ set(v8_SOURCES
)
include_directories(mapscript/v8/)

include_directories(renderers/mvt)

#add_definitions(-DHASH_DEBUG=1)
if(WIN32)
set(REGEX_SOURCES ${REGEX_DIR}/regex.c)
Expand Down Expand Up @@ -262,7 +265,7 @@ mapogcfiltercommon.c maprendering.c mapwcs20.c mapogcsld.c
mapresample.c mapwfs.c mapgdal.c mapogcsos.c mapscale.c mapwfs11.c mapwfs20.c
mapgeomtransform.c mapogroutput.c mapwfslayer.c mapagg.cpp mapkml.cpp
mapgeomutil.cpp mapkmlrenderer.cpp fontcache.c textlayout.c maputfgrid.cpp
mapogr.cpp mapcontour.c mapsmoothing.c mapv8.cpp ${REGEX_SOURCES} kerneldensity.c)
mapogr.cpp mapcontour.c mapsmoothing.c mapv8.cpp ${REGEX_SOURCES} kerneldensity.c renderers/mvt/vector_tile.c mapmvt.cpp)

set(mapserver_HEADERS
cgiutil.h dejavu-sans-condensed.h dxfcolor.h fontcache.h hittest.h mapagg.h
Expand Down Expand Up @@ -363,6 +366,17 @@ if(WITH_PROJ)
endif(NOT PROJ_FOUND)
endif (WITH_PROJ)

if(WITH_PROTOBUFC)
find_package(ProtobufC)
if(NOT PROTOBUFC_FOUND)
report_optional_not_found(PROTOBUFC)
else(NOT PROTOBUFC_FOUND)
include_directories(${PROTOBUFC_INCLUDE_DIR})
ms_link_libraries( ${PROTOBUFC_LIBRARY})
set (USE_PBF 1)
endif(NOT PROTOBUFC_FOUND)
endif (WITH_PROTOBUFC)

if(WITH_PIXMAN)
find_package(Pixman)
if(PIXMAN_FOUND)
Expand Down Expand Up @@ -912,6 +926,7 @@ status_optional_component("LIBXML2" "${USE_LIBXML2}" "${LIBXML2_LIBRARY}")
status_optional_component("POSTGIS" "${USE_POSTGIS}" "${POSTGRESQL_LIBRARY}")
status_optional_component("GEOS" "${USE_GEOS}" "${GEOS_LIBRARY}")
status_optional_component("FastCGI" "${USE_FASTCGI}" "${FCGI_LIBRARY}")
status_optional_component("PROTOBUFC" "${USE_PBF}" "${PROTOBUFC_LIBRARY}")
if(USE_ORACLESPATIAL OR USE_ORACLE_PLUGIN)
if(USE_ORACLESPATIAL)
status_optional_component("Oracle Spatial" "${USE_ORACLESPATIAL}" "${ORACLE_LIBRARY}")
Expand Down
111 changes: 111 additions & 0 deletions cmake/FindProtobufC.cmake
@@ -0,0 +1,111 @@
# - Find protobuf-c
# Find protobuf c implementation libraries, includes and the protoc-c compiler
# FindProtobufC was loosely based on FindProtobuf that is shipped with cmake
#
# Module defines:
# PROTOBUFC_FOUND - library, includes and compiler where found
# PROTOBUFC_INCLUDE_DIRS - include directories
# PROTOBUFC_LIBRARIES - protobuf-c libraries
# PROTOBUFC_EXECUTEABLE - protobuf-c compiler
#
# Environment variables:
# PROTOBUFC_ROOTDIR - optional - rootdir of protobuf-c installation
#
# Cache entries:
# PROTOBUFC_LIBRARY - detected protobuf-c library
# PROTOBUF_INCLUDE_DIR - detected protobuf-c include dir(s)
# PROTOBUF_COMPILER - detected protobuf-c compiler
#
####
#
# ====================================================================
# Example:
#
# find_package(ProtobufC REQUIRED)
# include_directories(${PROTOBUFC_INCLUDE_DIRS})
# include_directories(${CMAKE_CURRENT_BINARY_DIR})
# PROTOBUFC_GENERATE_C(PROTO_SOURCES PROTO_HEADERS protobuf.proto)
# add_executable(bar bar.c ${PROTO_SRCn} ${PROTO_HDRS})
# target_link_libraries(bar ${PROTOBUF_LIBRARIES})
#
# NOTE: You may need to link against pthreads, depending
# on the platform.
#
# NOTE: The PROTOBUF_GENERATE_CPP macro & add_executable() or add_library()
# calls only work properly within the same directory.
#
# ====================================================================

#=============================================================================
# Copyright 2013 Thinstuff Technologies GmbH
# Copyright 2013 Bernhard Miklautz <bmiklautz@thinstuff.at>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================

set(PROTBUFC_SOURCE_EXTENSION "pb-c.c")
set(PROTBUFC_HEADER_EXTENSION "pb-c.h")
function(PROTOBUFC_GENERATE_C SOURCES HEADERS)
if(NOT ARGN)
message(SEND_ERROR "Error: PROTOBUFC_GENERATE_C() called without any proto files")
return()
endif(NOT ARGN)

foreach(FIL ${ARGN})
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
get_filename_component(FIL_WE ${FIL} NAME_WE)
get_filename_component(FIL_PATH ${ABS_FIL} PATH)

list(APPEND ${SOURCES} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.${PROTBUFC_SOURCE_EXTENSION}")
list(APPEND ${HEADERS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.${PROTBUFC_HEADER_EXTENSION}")

add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.${PROTBUFC_SOURCE_EXTENSION}"
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.${PROTBUFC_HEADER_EXTENSION}"
COMMAND ${PROTOBUFC_COMPILER}
ARGS --c_out ${CMAKE_CURRENT_BINARY_DIR} -I ${CMAKE_CURRENT_SOURCE_DIR} -I ${FIL_PATH} ${ABS_FIL}
DEPENDS ${ABS_FIL}
COMMENT "Running protobuf-c compiler on ${FIL}"
VERBATIM )
endforeach()
set_source_files_properties(${${SOURCES}} ${${HEADERS}} PROPERTIES GENERATED TRUE)
set(${SOURCES} ${${SOURCES}} PARENT_SCOPE)
set(${HEADERS} ${${HEADERS}} PARENT_SCOPE)
endfunction()

find_library(PROTOBUFC_LIBRARY
NAMES "protobuf-c"
PATHS "/usr" "/usr/local" "/opt" ENV PROTOBUFC_ROOTDIR
PATH_SUFFIXES "lib")
mark_as_advanced(PROTOBUFC_LIBRARY)

find_path(PROTOBUFC_INCLUDE_DIR
NAMES "google/protobuf-c/protobuf-c.h"
PATHS "/usr" "/usr/local" "/opt" ENV PROTOBUFC_ROOTDIR
PATH_SUFFIXES "include")
mark_as_advanced(PROTOBUFC_INCLUDE_DIR)

find_program(PROTOBUFC_COMPILER
NAMES "protoc-c"
PATHS "/usr" "/usr/local" "/opt" ENV PROTOBUFC_ROOTDIR
PATH_SUFFIXES "bin")
mark_as_advanced(PROTOBUFC_COMPILER)

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ProtobufC DEFAULT_MSG PROTOBUFC_LIBRARY PROTOBUFC_COMPILER PROTOBUFC_INCLUDE_DIR )

if (PROTOBUFC_FOUND)
set(PROTOBUFC_LIBRARIES ${PROTOBUFC_LIBRARY})
set(PROTOBUFC_INCLUDE_DIRS ${PROTOBUFC_INCLUDE_DIR})
set(PROTOBUFC_EXECUTEABLE ${PROTOBUFC_COMPILER})
endif(PROTOBUFC_FOUND)
83 changes: 83 additions & 0 deletions mapmvt.cpp
@@ -0,0 +1,83 @@
/******************************************************************************
* $Id$
*
* Project: MapServer
* Purpose: MapBox Vector Tile rendering.
* Author: Thomas Bonfort and the MapServer team.
*
******************************************************************************
* Copyright (c) 1996-2015 Regents of the University of Minnesota.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies of this Software or works derived from this Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/

#include "mapserver.h"

#ifdef USE_PBF
#include "vector_tile.pb-c.h"
#endif

int msPopulateRendererVTableMVT(rendererVTableObj * renderer) {
#ifdef USE_PBF
renderer->compositeRasterBuffer = NULL;
renderer->supports_pixel_buffer = 0;
renderer->use_imagecache = 0;
renderer->supports_clipping = 0;
renderer->supports_svg = 0;
renderer->default_transform_mode = MS_TRANSFORM_SIMPLIFY;
renderer->cleanup = mvtCleanup;
renderer->renderLine = &mvtRenderLine;

renderer->renderPolygon = &mvtRenderPolygon;
renderer->renderPolygonTiled = &mvtRenderPolygon;
renderer->renderLineTiled = &mvtRenderLineTiled;

renderer->renderGlyphs = &mvtRenderGlyphsPath;

renderer->renderVectorSymbol = &mvtRenderVectorSymbol;

renderer->renderPixmapSymbol = &mvtRenderPixmapSymbol;

renderer->renderEllipseSymbol = &mvtRenderEllipseSymbol;

renderer->renderTile = &mvtRenderTile;

renderer->getRasterBufferHandle = NULL;
renderer->getRasterBufferCopy = NULL;
renderer->initializeRasterBuffer = NULL;

renderer->mergeRasterBuffer = NULL;
renderer->loadImageFromFile = NULL;
renderer->createImage = &mvtCreateImage;
renderer->saveImage = &mvtSaveImage;

renderer->startLayer = &mvtStartNewLayer;
renderer->endLayer = &mvtCloseNewLayer;

renderer->freeImage = &mvtFreeImage;
renderer->freeSymbol = &mvtFreeSymbol;
renderer->cleanup = mvtCleanup;

return MS_SUCCESS;
#else
msSetError(MS_MISCERR, "Vector Tile Driver requested but support is not compiled in",
"msPopulateRendererVTableMVT()");
return MS_FAILURE;
#endif
}
18 changes: 18 additions & 0 deletions mapoutput.c
Expand Up @@ -102,6 +102,9 @@ struct defaultOutputFormatEntry defaultoutputformats[] = {
{"jpeg","AGG/JPEG","image/jpeg"},
{"png8","AGG/PNG8","image/png; mode=8bit"},
{"png24","AGG/PNG","image/png; mode=24bit"},
#ifdef USE_PBF
{"pbf","MVT","application/x-protobuf"},
#endif
#ifdef USE_CAIRO
{"pdf","CAIRO/PDF","application/x-pdf"},
{"svg","CAIRO/SVG","image/svg+xml"},
Expand Down Expand Up @@ -202,6 +205,16 @@ outputFormatObj *msCreateDefaultOutputFormat( mapObj *map,
format->extension = msStrdup("jpg");
format->renderer = MS_RENDER_WITH_AGG;
}
#if defined(USE_PBF)
else if( strcasecmp(driver,"MVT") == 0 ) {
if(!name) name="mvt";
format = msAllocOutputFormat( map, name, driver );
format->mimetype = msStrdup("application/x-protobuf");
format->imagemode = MS_IMAGEMODE_RGB;
format->extension = msStrdup("pbf");
format->renderer = MS_RENDER_WITH_MVT;
}
#endif

#if defined(USE_CAIRO)
else if( strcasecmp(driver,"CAIRO/PNG") == 0 ) {
Expand Down Expand Up @@ -904,6 +917,7 @@ void msGetOutputFormatMimeListWMS( mapObj *map, char **mime_list, int max_mime )
strcasecmp(map->outputformatlist[i]->driver, "CAIRO/SVG")==0 ||
strcasecmp(map->outputformatlist[i]->driver, "CAIRO/PDF")==0 ||
strcasecmp(map->outputformatlist[i]->driver, "kml")==0 ||
strcasecmp(map->outputformatlist[i]->driver, "mvt")==0 ||
strcasecmp(map->outputformatlist[i]->driver, "kmz")==0))
mime_list[mime_count++] = map->outputformatlist[i]->mimetype;
}
Expand Down Expand Up @@ -1020,6 +1034,10 @@ int msInitializeRendererVTable(outputFormatObj *format)
return msPopulateRendererVTableAGG(format->vtable);
case MS_RENDER_WITH_UTFGRID:
return msPopulateRendererVTableUTFGrid(format->vtable);
#ifdef USE_PBF
case MS_RENDER_WITH_MVT:
return msPopulateRendererVTableMVT(format->vtable);
#endif
#ifdef USE_CAIRO
case MS_RENDER_WITH_CAIRO_RASTER:
return msPopulateRendererVTableCairoRaster(format->vtable);
Expand Down
1 change: 1 addition & 0 deletions mapserver-config.h.in
Expand Up @@ -2,6 +2,7 @@
#define _MAPSERVER_CONFIG_H

#cmakedefine USE_PROJ 1
#cmakedefine USE_PBF 1
#cmakedefine USE_POSTGIS 1
#cmakedefine USE_GDAL 1
#cmakedefine USE_PIXMAN 1
Expand Down
4 changes: 3 additions & 1 deletion mapserver.h
Expand Up @@ -374,6 +374,7 @@ extern "C" {
#define MS_DRIVER_GDAL(format) (strncasecmp((format)->driver,"gdal/",5)==0)
#define MS_DRIVER_IMAGEMAP(format) (strncasecmp((format)->driver,"imagemap",8)==0)
#define MS_DRIVER_AGG(format) (strncasecmp((format)->driver,"agg/",4)==0)
#define MS_DRIVER_MVT(format) (strncasecmp((format)->driver,"mvt/",4)==0)
#define MS_DRIVER_CAIRO(format) (strncasecmp((format)->driver,"cairo/",6)==0)
#define MS_DRIVER_OGL(format) (strncasecmp((format)->driver,"ogl/",4)==0)
#define MS_DRIVER_TEMPLATE(format) (strncasecmp((format)->driver,"template",8)==0)
Expand All @@ -394,6 +395,7 @@ extern "C" {
#define MS_RENDER_WITH_AGG 105
#define MS_RENDER_WITH_KML 106
#define MS_RENDER_WITH_UTFGRID 107
#define MS_RENDER_WITH_MVT 108

#ifndef SWIG

Expand Down Expand Up @@ -3018,7 +3020,7 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char
MS_DLL_EXPORT int msPopulateRendererVTableUTFGrid( rendererVTableObj *renderer );
MS_DLL_EXPORT int msPopulateRendererVTableKML( rendererVTableObj *renderer );
MS_DLL_EXPORT int msPopulateRendererVTableOGR( rendererVTableObj *renderer );
MS_DLL_EXPORT int msPopulateRendererVTableOGR( rendererVTableObj *renderer );
MS_DLL_EXPORT int msPopulateRendererVTableMVT( rendererVTableObj *renderer );

#ifdef USE_CAIRO
MS_DLL_EXPORT void msCairoCleanup(void);
Expand Down
5 changes: 5 additions & 0 deletions renderers/mvt/vector_tile.c
@@ -0,0 +1,5 @@
#include "mapserver-config.h"

#ifdef USE_PBF
#include "vector_tile.pb-c.c"
#endif

0 comments on commit 50482bf

Please sign in to comment.