pax_global_header00006660000000000000000000000064140731214250014511gustar00rootroot0000000000000052 comment=292ea2e2b179b1eb4b99ac0de8457bde4f59a326 mapserver-7.6.4/000077500000000000000000000000001407312142500135335ustar00rootroot00000000000000mapserver-7.6.4/.github/000077500000000000000000000000001407312142500150735ustar00rootroot00000000000000mapserver-7.6.4/.github/workflows/000077500000000000000000000000001407312142500171305ustar00rootroot00000000000000mapserver-7.6.4/.github/workflows/check-crlf.yml000066400000000000000000000010451407312142500216540ustar00rootroot00000000000000# check for Windows CRLF in files # homepage: https://github.com/marketplace/actions/check-crlf name: Check CRLF on: [push, pull_request] jobs: Check-CRLF: name: verify that only LF linefeeds are used runs-on: ubuntu-18.04 steps: - name: Checkout repository contents uses: actions/checkout@v1 - name: Use action to check for CRLF endings uses: erclu/check-crlf@v1.1.2 with: # ignore directories containing *.pdf and *.tab exclude: msautotest/misc/data/ /msautotest/renderers/expected/mapserver-7.6.4/CMakeLists.txt000066400000000000000000001120001407312142500162650ustar00rootroot00000000000000cmake_minimum_required (VERSION 3.0) project (MapServer) if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") message(FATAL_ERROR "In-source builds are not permitted. Make a separate folder for building: mkdir build; cd build; cmake .. Before that, remove the files created by this failed run: rm -rf CMakeCache.txt CMakeFiles") endif("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") include(CheckLibraryExists) include(CheckFunctionExists) include(CheckIncludeFile) include(CheckCSourceCompiles) set (MapServer_VERSION_MAJOR 7) set (MapServer_VERSION_MINOR 6) set (MapServer_VERSION_REVISION 4) set (MapServer_VERSION_SUFFIX "") # Set C++ version # Make CMAKE_CXX_STANDARD available as cache option overridable by user set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard version to use (default is 11)") message(STATUS "Requiring C++${CMAKE_CXX_STANDARD}") set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) message(STATUS "Requiring C++${CMAKE_CXX_STANDARD} - done") # Set C99 version # Make CMAKE_C_STANDARD available as cache option overridable by user set(CMAKE_C_STANDARD 99 CACHE STRING "C standard version to use (default is 99)") message(STATUS "Requiring C${CMAKE_C_STANDARD}") set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS OFF) message(STATUS "Requiring C${CMAKE_C_STANDARD} - done") set(TARGET_VERSION_MAJOR ${MapServer_VERSION_MAJOR}) set(TARGET_VERSION_MINOR ${MapServer_VERSION_MINOR}) MATH(EXPR MapServer_IS_DEV_VERSION "${MapServer_VERSION_MINOR}%2") if(MapServer_IS_DEV_VERSION) set (MapServer_VERSION_STRING "${MapServer_VERSION_MAJOR}.${MapServer_VERSION_MINOR}-dev") else(MapServer_IS_DEV_VERSION) set (MapServer_VERSION_STRING "${MapServer_VERSION_MAJOR}.${MapServer_VERSION_MINOR}.${MapServer_VERSION_REVISION}") set (MapServer_VERSION_STRING "${MapServer_VERSION_STRING}${MapServer_VERSION_SUFFIX}") endif(MapServer_IS_DEV_VERSION) MATH(EXPR MapServer_VERSION_NUM "${MapServer_VERSION_MAJOR}*10000+${MapServer_VERSION_MINOR}*100+${MapServer_VERSION_REVISION}") SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) # Add custom function to check Python modules are installed include(FindPythonModule) if (APPLE) set(CMAKE_FIND_FRAMEWORK "LAST") endif (APPLE) # Offer the user the choice of overriding the installation directories set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries") set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables") set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files") if(WIN32 AND NOT CYGWIN) set(DEF_INSTALL_CMAKE_DIR CMake) else() set(DEF_INSTALL_CMAKE_DIR share/mapserver/cmake) endif() set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") # Make relative paths absolute (needed later on) foreach(p LIB BIN INCLUDE CMAKE) set(var INSTALL_${p}_DIR) if(NOT IS_ABSOLUTE "${${var}}") set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") endif() endforeach() macro (ms_link_libraries) if(BUILD_DYNAMIC) target_link_libraries(mapserver ${ARGV}) endif(BUILD_DYNAMIC) if(BUILD_STATIC) target_link_libraries(mapserver_static ${ARGV}) endif(BUILD_STATIC) endmacro() macro( report_optional_not_found component ) message(SEND_ERROR "${component} library/component/dependency could not be found. HINTS: - disable ${component} support by adding -DWITH_${component}=0 - add the ${component} install directory to the CMAKE_PREFIX_PATH variable (-DCMAKE_PREFIX_PATH=\"/path/to/${component}-install-dir;/path/to/other/dirs\"") endmacro() macro( report_mandatory_not_found component ) message(SEND_ERROR "${component} library/component could not be found and is a mandatory dependency HINT: - add the ${component} install directory to the CMAKE_PREFIX_PATH variable (-DCMAKE_PREFIX_PATH=\"/path/to/${component}-install-dir;/path/to/other/dirs\"") endmacro() macro( report_dependency_error component dependency) message(SEND_ERROR "${component} support requires ${dependency} support, however ${dependency} support has been disabled. HINTS: - re-run with -DWITH_${dependency}=1 (or without -DWITH_${dependency}=0) - disable ${component} support by adding -DWITH_${component}=0" ) endmacro() SET(CMAKE_REQUIRED_INCLUDES "math.h") if(NOT(WIN32)) SET(CMAKE_REQUIRED_LIBRARIES "m") endif(NOT(WIN32)) check_function_exists("strrstr" HAVE_STRRSTR) check_function_exists("strcasecmp" HAVE_STRCASECMP) check_function_exists("strcasestr" HAVE_STRCASESTR) check_function_exists("strlcat" HAVE_STRLCAT) check_function_exists("strlcpy" HAVE_STRLCPY) check_function_exists("strlen" HAVE_STRLEN) check_function_exists("strncasecmp" HAVE_STRNCASECMP) check_function_exists("vsnprintf" HAVE_VSNPRINTF) check_function_exists("lrintf" HAVE_LRINTF) check_function_exists("lrint" HAVE_LRINT) check_include_file(dlfcn.h HAVE_DLFCN_H) check_c_source_compiles(" int main(int argc, char **argv) { long x=0,y=0; for(x=0;x<5;x++) { if(y>1) break; y=__sync_fetch_and_add(&x,1); } }" HAVE_SYNC_FETCH_AND_ADD) include_directories(${CMAKE_CURRENT_BINARY_DIR}) #options suported by the cmake builder 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) option(WITH_FRIBIDI "Choose if FriBidi glyph shaping support should be built in (usefull for right-to-left languages) (requires HARFBUZZ)" ON) option(WITH_HARFBUZZ "Choose if Harfbuzz complex text layout should be included (needed for e.g. arabic and hindi) (requires FRIBIDI)" ON) option(WITH_ICONV "Choose if Iconv Internationalization support should be built in" ON) option(WITH_CAIRO "Choose if CAIRO rendering support should be built in (required for SVG and PDF output)" ON) option(WITH_SVGCAIRO "Choose if SVG symbology support (via libsvgcairo) should be built in (requires cairo, libsvg, libsvg-cairo. Incompatible with librsvg)" OFF) option(WITH_RSVG "Choose if SVG symbology support (via librsvg) should be built in (requires cairo, librsvg. Incompatible with libsvg-cairo)" OFF) option(WITH_MYSQL "Choose if MYSQL joining support should be built in" OFF) option(WITH_FCGI "Choose if FastCGI support should be built in" ON) option(WITH_GEOS "Choose if GEOS geometry operations support should be built in" ON) option(WITH_POSTGIS "Choose if Postgis input support should be built in" ON) option(WITH_CLIENT_WMS "Enable Client WMS Layer support (requires CURL and GDAL support)" OFF) option(WITH_CLIENT_WFS "Enable Client WMS Layer support (requires CURL and OGR support)" OFF) option(WITH_CURL "Enable Curl HTTP support (required for wms/wfs client, and remote SLD)" OFF) option(WITH_WFS "Enable WFS Server support (requires PROJ and OGR support)" ON) option(WITH_WCS "Enable WCS Server support (requires PROJ and GDAL support)" ON) option(WITH_LIBXML2 "Choose if libxml2 support should be built in (used for sos, wcs 1.1,2.0 and wfs 1.1)" ON) option(WITH_THREAD_SAFETY "Choose if a thread-safe version of libmapserver should be built (only recommended for some mapscripts)" OFF) option(WITH_GIF "Enable GIF support (for PIXMAP loading)" ON) option(WITH_PYTHON "Enable Python mapscript support" OFF) option(WITH_PHP "Enable PHP mapscript support" OFF) option(WITH_PHPNG "Enable PHPNG (SWIG) mapscript support" OFF) option(WITH_PERL "Enable Perl mapscript support" OFF) option(WITH_RUBY "Enable Ruby mapscript support" OFF) option(WITH_JAVA "Enable Java mapscript support" OFF) option(WITH_CSHARP "Enable C# mapscript support" OFF) option(WITH_POINT_Z_M "include Z and M coordinates in point structure" ON) option(WITH_ORACLESPATIAL "include oracle spatial database input support" OFF) option(WITH_ORACLE_PLUGIN "include oracle spatial database input support as plugin" OFF) option(WITH_MSSQL2008 "include mssql 2008 database input support as plugin" OFF) option(WITH_EXEMPI "include xmp output metadata support" OFF) option(WITH_XMLMAPFILE "include native xml mapfile support (requires libxslt/libexslt)" OFF) option(WITH_V8 "include javacript v8 scripting" OFF) option(WITH_PIXMAN "use (experimental) support for pixman for layer compositing operations" OFF) option(BUILD_STATIC "Also build a static version of mapserver" OFF) option(LINK_STATIC_LIBMAPSERVER "Link to static version of libmapserver (also for mapscripts)" OFF) option(WITH_APACHE_MODULE "include (experimental) support for apache module" OFF) option(WITH_GENERIC_NINT "generic rounding" OFF) #TODO: USE_OGL? , USE_SDE, USE_CLUSTER_EXTERNAL USE_CLUSTER_PLUGIN, USE_MSSQL2008, USE_MSSQL2008_PLUGIN # SIGNORE_MISSING_DATA, CGI_CL_DEBUG_ARGS, EXTRA DEBUG FLAGS?, # PERLV_ld_DETECT? # Add compiler flags for warnings if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror=format-security") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror=format-security") endif() if(NOT DEFINED CMAKE_INSTALL_LIBDIR) set(_LIBDIR_DEFAULT "lib") # Override this default 'lib' with 'lib64' iff: # - we are on Linux system but NOT cross-compiling # - we are NOT on debian # - we are on a 64 bits system # reason is: amd64 ABI: http://www.x86-64.org/documentation/abi.pdf # Note that the future of multi-arch handling may be even # more complicated than that: http://wiki.debian.org/Multiarch if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT CMAKE_CROSSCOMPILING AND NOT EXISTS "/etc/debian_version") if(NOT DEFINED CMAKE_SIZEOF_VOID_P) message(AUTHOR_WARNING "Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target architecture is known. " "Please enable at least one language before including GNUInstallDirs.") else() if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") set(_LIBDIR_DEFAULT "lib64") endif() endif() endif() set(CMAKE_INSTALL_LIBDIR "${_LIBDIR_DEFAULT}" CACHE PATH "object code libraries (${_LIBDIR_DEFAULT})") endif() SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) SET(CMAKE_MACOSX_RPATH ON) if(LINK_STATIC_LIBMAPSERVER) set(BUILD_STATIC 1) set(BUILD_DYNAMIC 0) set(MAPSERVER_LIBMAPSERVER mapserver_static) else(LINK_STATIC_LIBMAPSERVER) set(BUILD_DYNAMIC 1) set(MAPSERVER_LIBMAPSERVER mapserver) endif(LINK_STATIC_LIBMAPSERVER) set(agg_SOURCES renderers/agg/src/agg_arc.cpp renderers/agg/src/agg_vcgen_dash.cpp renderers/agg/src/agg_vcgen_contour.cpp renderers/agg/src/agg_curves.cpp renderers/agg/src/agg_embedded_raster_fonts.cpp renderers/agg/src/agg_trans_affine.cpp renderers/agg/src/agg_vcgen_stroke.cpp renderers/agg/src/agg_font_freetype.cpp renderers/agg/src/agg_line_aa_basics.cpp renderers/agg/src/clipper.cpp ) include_directories(renderers/agg/include) set(v8_SOURCES mapscript/v8/v8_object_wrap.hpp mapscript/v8/point.cpp mapscript/v8/line.cpp mapscript/v8/shape.cpp mapscript/v8/v8_mapscript.cpp mapv8.cpp ) include_directories(mapscript/v8/) #add_definitions(-DHASH_DEBUG=1) if(WIN32) set(REGEX_SOURCES ${REGEX_DIR}/regex.c) include_directories(${REGEX_DIR}) add_definitions(-DREGEX_MALLOC -DUSE_GENERIC_MS_NINT -DHAVE_STRING_H) add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) set(REGEX_MALLOC 1) set(USE_GENERIC_MS_NINT 1) set(HAVE_STRING_H 0) # Suppress warnings for regex.c set_source_files_properties(${REGEX_SOURCES} PROPERTIES COMPILE_FLAGS /w) else(WIN32) set(REGEX_SOURCES "") endif(WIN32) set(mapserver_SOURCES fontcache.c cgiutil.c mapgeos.c maporaclespatial.c mapsearch.c mapwms.c classobject.c mapgml.c mapoutput.c mapwmslayer.c layerobject.c mapgraticule.c mapows.c mapservutil.c mapxbase.c maphash.c mapowscommon.c mapshape.c mapxml.c mapbits.c maphttp.c mapparser.c mapstring.c mapxmp.c mapcairo.c mapimageio.c mappluginlayer.c mapsymbol.c mapchart.c mapimagemap.c mappool.c maptclutf.c mapcluster.c mapio.c mappostgis.c maptemplate.c mapcontext.c mapjoin.c mappostgresql.c mapthread.c mapcopy.c maplabel.c mapprimitive.c maptile.c mapcpl.c maplayer.c mapproject.c maptime.c mapcrypto.c maplegend.c hittest.c maptree.c mapdebug.c maplexer.c mapquantization.c mapunion.c mapdraw.c maplibxml2.c mapquery.c maputil.c strptime.c mapdrawgdal.c mapraster.c mapuvraster.c mapdummyrenderer.c mapobject.c maprasterquery.c mapwcs.c maperror.c mapogcfilter.c mapregex.c mapwcs11.c mapfile.c mapogcfiltercommon.cpp maprendering.c mapwcs20.c mapogcsld.c mapmetadata.c mapresample.c mapwfs.c mapgdal.c mapogcsos.c mapscale.c mapwfs11.c mapwfs20.c mapgeomtransform.c mapogroutput.cpp 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 mapcompositingfilter.c mapmvt.c) set(mapserver_HEADERS cgiutil.h dejavu-sans-condensed.h dxfcolor.h fontcache.h hittest.h mapagg.h mapaxisorder.h mapcopy.h mapentities.h maperror.h mapfile.h mapgml.h maphash.h maphttp.h mapio.h mapkmlrenderer.h maplibxml2.h mapogcfilter.h mapogcsld.h mapoglcontext.h mapoglrenderer.h mapowscommon.h mapows.h mapparser.h mappostgis.h mapprimitive.h mapproject.h mapraster.h mapregex.h mapresample.h mapserver-api.h mapserver.h mapserv.h mapshape.h mapsymbol.h maptemplate.h mapthread.h maptile.h maptime.h maptree.h maputfgrid.h mapwcs.h uthash.h) if(WIN32) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY) set(mapserver_SOURCES ${mapserver_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/version.rc) endif(WIN32) if(WITH_PROTOBUFC) find_package(ProtobufC) if(NOT PROTOBUFC_FOUND) report_optional_not_found(PROTOBUFC) else(NOT PROTOBUFC_FOUND) list(APPEND ALL_INCLUDE_DIRS ${PROTOBUFC_INCLUDE_DIR}) FILE(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/renderers/mvt) # Create custom command for protoc-c ADD_CUSTOM_COMMAND( COMMAND ${PROTOBUFC_COMPILER} ARGS --c_out=${PROJECT_BINARY_DIR}/renderers/mvt --proto_path=${PROJECT_SOURCE_DIR}/renderers/mvt ${PROJECT_SOURCE_DIR}/renderers/mvt/vector_tile.proto OUTPUT ${PROJECT_BINARY_DIR}/renderers/mvt/vector_tile.pb-c.c ${PROJECT_BINARY_DIR}/renderers/mvt/vector_tile.pb-c.h ) SET_SOURCE_FILES_PROPERTIES(${PROJECT_BINARY_DIR}/renderers/mvt/vector_tile.pb-c.h ${PROJECT_BINARY_DIR}/renderers/mvt/vector_tile.pb-c.c GENERATED) set (vectortile_SOURCES ${PROJECT_BINARY_DIR}/renderers/mvt/vector_tile.pb-c.c) set (USE_PBF 1) endif(NOT PROTOBUFC_FOUND) endif (WITH_PROTOBUFC) if(BUILD_DYNAMIC) add_library(mapserver SHARED ${vectortile_SOURCES} ${mapserver_SOURCES} ${agg_SOURCES} ${v8_SOURCES}) set_target_properties( mapserver PROPERTIES VERSION ${MapServer_VERSION_STRING} SOVERSION 2 ) endif(BUILD_DYNAMIC) if(BUILD_STATIC) add_library(mapserver_static STATIC ${vectortile_SOURCES} ${mapserver_SOURCES} ${agg_SOURCES} ${v8_SOURCES}) set_target_properties( mapserver_static PROPERTIES VERSION ${MapServer_VERSION_STRING} SOVERSION 2 ) endif(BUILD_STATIC) #SOVERSION is not necessarily the same as the #major version. The rule is that any breakage of the ABI must be #indicated by incrementing the SOVERSION. So, adding e.g. functions is no #problem, modifying argument lists or removing functions would required #the SOVERSION to be incremented. Similar rules hold of course for #non-opaque data-structures. add_executable(mapserv mapserv.c) target_link_libraries(mapserv ${MAPSERVER_LIBMAPSERVER}) add_executable(shp2img shp2img.c) target_link_libraries(shp2img ${MAPSERVER_LIBMAPSERVER}) add_executable(shptree shptree.c) target_link_libraries(shptree ${MAPSERVER_LIBMAPSERVER}) add_executable(shptreevis shptreevis.c) target_link_libraries(shptreevis ${MAPSERVER_LIBMAPSERVER}) add_executable(sortshp sortshp.c) target_link_libraries(sortshp ${MAPSERVER_LIBMAPSERVER}) add_executable(legend legend.c) target_link_libraries(legend ${MAPSERVER_LIBMAPSERVER}) add_executable(scalebar scalebar.c) target_link_libraries(scalebar ${MAPSERVER_LIBMAPSERVER}) add_executable(msencrypt msencrypt.c) target_link_libraries(msencrypt ${MAPSERVER_LIBMAPSERVER}) add_executable(tile4ms tile4ms.c) target_link_libraries(tile4ms ${MAPSERVER_LIBMAPSERVER}) add_executable(shptreetst shptreetst.c) target_link_libraries(shptreetst ${MAPSERVER_LIBMAPSERVER}) if (CMAKE_BUILD_TYPE STREQUAL "Debug") set(USE_EXTENDED_DEBUG 1) endif (CMAKE_BUILD_TYPE STREQUAL "Debug") find_package(PNG) if(PNG_FOUND) include_directories(${PNG_INCLUDE_DIR}) ms_link_libraries( ${PNG_LIBRARIES}) list(APPEND ALL_INCLUDE_DIRS ${PNG_INCLUDE_DIR}) set(USE_PNG 1) else(PNG_FOUND) report_mandatory_not_found(PNG) endif(PNG_FOUND) find_package(JPEG) if(JPEG_FOUND) include_directories(${JPEG_INCLUDE_DIR}) ms_link_libraries( ${JPEG_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${JPEG_INCLUDE_DIR}) set(USE_JPEG 1) else(JPEG_FOUND) report_mandatory_not_found(JPEG) endif(JPEG_FOUND) find_package(Freetype) if(NOT FREETYPE_FOUND) report_mandatory_not_found(FREETYPE) endif(NOT FREETYPE_FOUND) include_directories(${FREETYPE_INCLUDE_DIR}) ms_link_libraries( ${FREETYPE_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIR}) find_package(Proj) if(NOT PROJ_FOUND) report_mandatory_not_found(PROJ) endif(NOT PROJ_FOUND) include_directories(${PROJ_INCLUDE_DIR}) ms_link_libraries( ${PROJ_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${PROJ_INCLUDE_DIR}) if(USE_PBF) include_directories(${PROJECT_BINARY_DIR}/renderers/mvt) include_directories(${PROTOBUFC_INCLUDE_DIR}) ms_link_libraries( ${PROTOBUFC_LIBRARY}) endif() if(WITH_PIXMAN) find_package(Pixman) if(PIXMAN_FOUND) include_directories(${PIXMAN_INCLUDE_DIR}) ms_link_libraries(${PIXMAN_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${PIXMAN_INCLUDE_DIR}) set (USE_PIXMAN 1) else(PIXMAN_FOUND) report_optional_not_found(PIXMAN) endif(PIXMAN_FOUND) endif (WITH_PIXMAN) if(WITH_WMS) set(USE_WMS_SVR 1) endif(WITH_WMS) if(WITH_FRIBIDI) find_package(FriBiDi) if(NOT FRIBIDI_FOUND) report_optional_not_found(FRIBIDI) else(NOT FRIBIDI_FOUND) include_directories(${FRIBIDI_INCLUDE_DIR}) ms_link_libraries( ${FRIBIDI_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${FRIBIDI_INCLUDE_DIR}) set (USE_FRIBIDI 1) if(FRIBIDI_LEGACY) message(WARNING "Old Fribidi found, upgrade recommended") endif(FRIBIDI_LEGACY) endif(NOT FRIBIDI_FOUND) endif (WITH_FRIBIDI) if(WITH_HARFBUZZ) find_package(HarfBuzz) if(NOT HARFBUZZ_FOUND) report_optional_not_found(HARFBUZZ) else(NOT HARFBUZZ_FOUND) include_directories(${HARFBUZZ_INCLUDE_DIR}) ms_link_libraries( ${HARFBUZZ_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${HARFBUZZ_INCLUDE_DIR}) set (USE_HARFBUZZ 1) endif(NOT HARFBUZZ_FOUND) endif (WITH_HARFBUZZ) if( USE_HARFBUZZ AND NOT(USE_FRIBIDI) ) report_dependency_error(HARFBUZZ FRIBIDI) endif( USE_HARFBUZZ AND NOT(USE_FRIBIDI) ) if( USE_FRIBIDI AND NOT(USE_HARFBUZZ) ) report_dependency_error(FRIBIDI HARFBUZZ) endif( USE_FRIBIDI AND NOT(USE_HARFBUZZ) ) if(WITH_ICONV) find_package(ICONV) if(ICONV_FOUND) include_directories(${ICONV_INCLUDE_DIR}) ms_link_libraries( ${ICONV_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${ICONV_INCLUDE_DIR}) set (USE_ICONV 1) else(ICONV_FOUND) report_optional_not_found(ICONV) endif(ICONV_FOUND) endif (WITH_ICONV) if(WITH_GENERIC_NINT) set(USE_GENERIC_MS_NINT 1) endif(WITH_GENERIC_NINT) if(WITH_CAIRO) find_package(Cairo) if(CAIRO_FOUND) include_directories(${CAIRO_INCLUDE_DIRS}) ms_link_libraries( ${CAIRO_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${CAIRO_INCLUDE_DIR}) set (USE_CAIRO 1) else(CAIRO_FOUND) report_optional_not_found(CAIRO) endif(CAIRO_FOUND) endif (WITH_CAIRO) if(WITH_MYSQL) find_package(MySQL) if(MYSQL_FOUND) include_directories(${MYSQL_INCLUDE_DIR}) ms_link_libraries( ${MYSQL_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${MYSQL_INCLUDE_DIR}) set (USE_MYSQL 1) else(MYSQL_FOUND) report_optional_not_found(MYSQL) endif(MYSQL_FOUND) endif (WITH_MYSQL) if(WITH_ORACLE_PLUGIN AND WITH_ORACLESPATIAL) message(SEND_ERROR "WITH_ORACLESPATIAL and WITH_ORACLE_PLUGIN cannot be used simultaneously") endif(WITH_ORACLE_PLUGIN AND WITH_ORACLESPATIAL) if(WITH_ORACLESPATIAL OR WITH_ORACLE_PLUGIN) if(NOT DEFINED ENV{ORACLE_HOME}) MESSAGE( SEND_ERROR "ORACLE_HOME environment variable not set, needed for detection") endif() find_package(Oracle) if(ORACLE_FOUND) include_directories(${ORACLE_INCLUDE_DIR}) list(APPEND ALL_INCLUDE_DIRS ${ORACLE_INCLUDE_DIR}) else(ORACLE_FOUND) report_optional_not_found(ORACLESPATIAL) #FIXME: error message here could be misleading, only states ORACLESPATIAL whereas #the request could have been for ORACLE_PLUGIN endif(ORACLE_FOUND) endif(WITH_ORACLESPATIAL OR WITH_ORACLE_PLUGIN) if(ORACLE_FOUND AND WITH_ORACLESPATIAL) ms_link_libraries( ${ORACLE_LIBRARY}) set (USE_ORACLESPATIAL 1) endif(ORACLE_FOUND AND WITH_ORACLESPATIAL) if(ORACLE_FOUND AND WITH_ORACLE_PLUGIN) add_library(msplugin_oracle MODULE maporaclespatial.c) target_link_libraries(msplugin_oracle ${ORACLE_LIBRARY} ${MAPSERVER_LIBMAPSERVER}) set_target_properties(msplugin_oracle PROPERTIES COMPILE_FLAGS -DUSE_ORACLE_PLUGIN) set (USE_ORACLE_PLUGIN 1) endif(ORACLE_FOUND AND WITH_ORACLE_PLUGIN) if(WITH_MSSQL2008) find_package(ODBC) if(ODBC_FOUND) add_library(msplugin_mssql2008 MODULE mapmssql2008.c) target_link_libraries(msplugin_mssql2008 ${ODBC_LIBRARY} ${MAPSERVER_LIBMAPSERVER}) set_target_properties(msplugin_mssql2008 PROPERTIES COMPILE_FLAGS "-DUSE_MSSQL2008_PLUGIN -DUSE_MSSQL2008") list(APPEND ALL_INCLUDE_DIRS ${ODBC_INCLUDE_DIR}) set (USE_MSSQL2008 1) else(ODBC_FOUND) report_optional_not_found(ODBC) endif(ODBC_FOUND) endif(WITH_MSSQL2008) if(WITH_FCGI) find_package(FCGI) if(FCGI_FOUND) include_directories(${FCGI_INCLUDE_DIR}) target_link_libraries(mapserv ${FCGI_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${FCGI_INCLUDE_DIR}) set (USE_FASTCGI 1) else(FCGI_FOUND) report_optional_not_found(FCGI) endif(FCGI_FOUND) endif (WITH_FCGI) if(WITH_GEOS) find_package(GEOS) if(GEOS_FOUND) include_directories(${GEOS_INCLUDE_DIR}) ms_link_libraries( ${GEOS_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${GEOS_INCLUDE_DIR}) set (USE_GEOS 1) else(GEOS_FOUND) report_optional_not_found(GEOS) endif(GEOS_FOUND) endif (WITH_GEOS) if(WITH_POSTGIS) find_package(PostgreSQL) if(POSTGRESQL_FOUND) #uppercase our variables if ( NOT DEFINED POSTGRESQL_LIBRARY ) set( POSTGRESQL_LIBRARY ${PostgreSQL_LIBRARY}) endif() if ( NOT DEFINED POSTGRESQL_INCLUDE_DIR ) set( POSTGRESQL_INCLUDE_DIR ${PostgreSQL_INCLUDE_DIR}) endif() include_directories(${POSTGRESQL_INCLUDE_DIR}) ms_link_libraries( ${POSTGRESQL_LIBRARY}) CHECK_LIBRARY_EXISTS(pq "PQserverVersion" POSTGRESQL_LIBRARY POSTGIS_HAS_SERVER_VERSION) list(APPEND ALL_INCLUDE_DIRS ${POSTGRESQL_INCLUDE_DIR}) set (USE_POSTGIS 1) else(POSTGRESQL_FOUND) report_optional_not_found(POSTGIS) endif(POSTGRESQL_FOUND) endif (WITH_POSTGIS) find_package(GDAL) if(NOT GDAL_FOUND) report_mandatory_not_found(GDAL) endif(NOT GDAL_FOUND) include_directories(${GDAL_INCLUDE_DIR}) ms_link_libraries( ${GDAL_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${GDAL_INCLUDE_DIR}) if(WITH_SVGCAIRO) if(WITH_RSVG) message(SEND_ERROR "WITH_SVGCAIRO cannot be enabled with WITH_RSVG") endif(WITH_RSVG) find_package(SVGCairo) if(SVGCAIRO_FOUND) include_directories(${SVG_INCLUDE_DIR} ${SVGCAIRO_INCLUDE_DIR}) ms_link_libraries( ${SVG_LIBRARY} ${SVGCAIRO_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${SVG_INCLUDE_DIR} ${SVGCAIRO_INCLUDE_DIR}) set (USE_SVG_CAIRO 1) else(SVGCAIRO_FOUND) report_optional_not_found(SVGCAIRO) endif(SVGCAIRO_FOUND) endif (WITH_SVGCAIRO) if(WITH_RSVG) if(WITH_SVGCAIRO) message(SEND_ERROR "WITH_RSVG cannot be enabled with WITH_CAIROSVG") endif(WITH_SVGCAIRO) find_package(RSVG) if(RSVG_FOUND AND GOBJECT_FOUND) include_directories(${RSVG_INCLUDE_DIRS}) ms_link_libraries( ${RSVG_LIBRARY} ) list(APPEND ALL_INCLUDE_DIRS ${RSVG_INCLUDE_DIRS}) include_directories(${GOBJECT_INCLUDE_DIRS}) ms_link_libraries( ${GOBJECT_LIBRARY} ) list(APPEND ALL_INCLUDE_DIRS ${GOBJECT_INCLUDE_DIRS}) set (USE_RSVG 1) else(RSVG_FOUND AND GOBJECT_FOUND) report_optional_not_found(RSVG) endif(RSVG_FOUND AND GOBJECT_FOUND) endif (WITH_RSVG) if(WITH_CLIENT_WMS OR WITH_CLIENT_WFS) set(WITH_CURL ON) endif(WITH_CLIENT_WMS OR WITH_CLIENT_WFS) if(WITH_CURL) find_package(CURL) if(CURL_FOUND) include_directories(${CURL_INCLUDE_DIR}) ms_link_libraries( ${CURL_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) set(USE_CURL 1) else(CURL_FOUND) report_optional_not_found(CURL) endif(CURL_FOUND) endif(WITH_CURL) if(WITH_CLIENT_WMS OR WITH_CLIENT_WFS) if(NOT USE_CURL) if(WITH_CLIENT_WFS) report_dependency_error(CLIENT_WFS CURL) endif(WITH_CLIENT_WFS) if(WITH_CLIENT_WMS) report_dependency_error(CLIENT_WMS CURL) endif(WITH_CLIENT_WMS) endif(NOT USE_CURL) endif(WITH_CLIENT_WMS OR WITH_CLIENT_WFS) if(WITH_CLIENT_WMS) set(USE_WMS_LYR 1) endif(WITH_CLIENT_WMS) if(WITH_CLIENT_WFS) set(USE_WFS_LYR 1) endif(WITH_CLIENT_WFS) if(WITH_WFS) set(USE_WFS_SVR 1) endif(WITH_WFS) if(WITH_WCS) set(USE_WCS_SVR 1) endif(WITH_WCS) if(WITH_LIBXML2) find_package(LibXml2) if(LIBXML2_FOUND) include_directories(${LIBXML2_INCLUDE_DIR}) if(NOT DEFINED LIBXML2_LIBRARY) set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES}) endif() ms_link_libraries( ${LIBXML2_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR}) set (USE_LIBXML2 1) else(LIBXML2_FOUND) report_optional_not_found(LIBXML2) endif(LIBXML2_FOUND) endif (WITH_LIBXML2) if( USE_WCS_SVR AND NOT USE_LIBXML2 ) message(WARNING "WCS 1.1 and 2.0 require libxml2 support but it was not found. WCS 1.1 and 2.0 will not be supported by this build") endif( USE_WCS_SVR AND NOT USE_LIBXML2 ) if( USE_WFS_SVR AND NOT USE_LIBXML2 ) message(WARNING "WFS 1.1 and 2.0 require libxml2 support but it was not found. WFS 1.1 and 2.0 will not be supported by this build") endif( USE_WFS_SVR AND NOT USE_LIBXML2 ) if(WITH_SOS) if(USE_LIBXML2) set(USE_SOS_SVR 1) else(USE_LIBXML2) report_dependency_error(SOS LIBXML2) endif(USE_LIBXML2) endif(WITH_SOS) if(WITH_POINT_Z_M) set(USE_POINT_Z_M 1) endif(WITH_POINT_Z_M) if(WITH_KML) if(USE_LIBXML2) set(USE_KML 1) else(USE_LIBXML2) report_dependency_error(KML LIBXML2) endif(USE_LIBXML2) endif(WITH_KML) if(WITH_THREAD_SAFETY) set( CMAKE_THREAD_PREFER_PTHREAD 1 ) find_package(Threads) if (THREADS_FOUND) ms_link_libraries( ${CMAKE_THREAD_LIBS_INIT}) set(USE_THREAD 1) endif (THREADS_FOUND) endif(WITH_THREAD_SAFETY) if(WITH_XMLMAPFILE) if(NOT USE_LIBXML2) report_dependency_error(KML LIBXML2) endif(NOT USE_LIBXML2) #check for xslt and exslt find_package(LibXslt) if(LIBXSLT_FOUND) if(NOT DEFINED LIBXSLT_LIBRARY) set(LIBXSLT_LIBRARY ${LIBXSLT_LIBRARIES}) endif() include_directories(${LIBXSLT_INCLUDE_DIR}) ms_link_libraries( ${LIBXSLT_LIBRARY} ${LIBXSLT_EXSLT_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${LIBXSLT_INCLUDE_DIR}) set(USE_XMLMAPFILE 1) else(LIBXSLT_FOUND) message(SEND_ERROR "Xml Mapfile support requires XSLT support which was not found. HINTS: - add the libxslt install directory to the CMAKE_PREFIX_PATH variable (-DCMAKE_PREFIX_PATH=\"/path/to/libxslt-install-dir;/path/to/other/dirs\" - disable Xml Mapfile support by adding -DWITH_XMLMAPFILE=0" ) endif(LIBXSLT_FOUND) endif(WITH_XMLMAPFILE) if(WITH_GIF) find_package(GIF) if(GIF_FOUND) include_directories(${GIF_INCLUDE_DIR}) ms_link_libraries( ${GIF_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${GIF_INCLUDE_DIR}) set(USE_GIF 1) else(GIF_FOUND) report_optional_not_found(GIF) endif(GIF_FOUND) endif(WITH_GIF) if(WITH_EXEMPI) find_package(Exempi) if(LIBEXEMPI_FOUND) include_directories(${LIBEXEMPI_INCLUDE_DIR}) ms_link_libraries( ${LIBEXEMPI_LIBRARY}) list(APPEND ALL_INCLUDE_DIRS ${LIBEXEMPI_INCLUDE_DIR}) set(USE_EXEMPI 1) else(LIBEXEMPI_FOUND) report_optional_not_found(EXEMPI) endif(LIBEXEMPI_FOUND) endif(WITH_EXEMPI) if(WITH_PYTHON) add_subdirectory("mapscript/python") set(USE_PYTHON_MAPSCRIPT 1) endif(WITH_PYTHON) if(WITH_V8) FIND_PACKAGE(V8) IF(V8_FOUND EQUAL 1) SET(USE_V8_MAPSCRIPT 1) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${V8_INCLUDE}) list(APPEND ALL_INCLUDE_DIRS ${V8_INCLUDE}) MS_LINK_LIBRARIES( ${V8_LIBS}) ELSE(V8_FOUND) MESSAGE(SEND_ERROR "V8 JavaScript support requested but not found. HINTS: - set V8_ROOT environment variable to the installation path of V8. - add the V8 install directory to the CMAKE_PREFIX_PATH variable (-DCMAKE_PREFIX_PATH=\"/path/to/${component}-install-dir;/path/to/other/dirs\") ") ENDIF() ENDIF(WITH_V8) if(WITH_PHP) add_subdirectory("mapscript/php") set(USE_PHP_MAPSCRIPT 1) endif(WITH_PHP) if(WITH_PHPNG) add_subdirectory("mapscript/phpng") set(USE_PHPNG_MAPSCRIPT 1) endif(WITH_PHPNG) if(WITH_APACHE_MODULE) add_subdirectory("apache") set(USE_APACHE_MODULE 1) endif(WITH_APACHE_MODULE) if(WITH_PERL) add_subdirectory("mapscript/perl") set(USE_PERL_MAPSCRIPT 1) endif(WITH_PERL) if(WITH_RUBY) add_subdirectory("mapscript/ruby") set(USE_RUBY_MAPSCRIPT 1) endif(WITH_RUBY) if(WITH_JAVA) add_subdirectory("mapscript/java") set(USE_JAVA_MAPSCRIPT 1) endif(WITH_JAVA) if(WITH_CSHARP) add_subdirectory("mapscript/csharp") set(USE_CSHARP_MAPSCRIPT 1) endif(WITH_CSHARP) if(UNIX) ms_link_libraries( ${CMAKE_DL_LIBS} m ) endif(UNIX) if (WIN32) ms_link_libraries( ${MS_EXTERNAL_LIBS} ws2_32.lib) if (MSVC) #4701 : Potentially uninitialized local variable 'name' used (https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4701) set_target_properties(mapserver PROPERTIES COMPILE_FLAGS "/EHsc /wd4267 /wd4244 /wd4018 /w14701") endif(MSVC) endif (WIN32) configure_file ( "${PROJECT_SOURCE_DIR}/mapserver-config.h.in" "${PROJECT_BINARY_DIR}/mapserver-config.h" ) configure_file ( "${PROJECT_SOURCE_DIR}/mapserver-version.h.in" "${PROJECT_BINARY_DIR}/mapserver-version.h" ) if(BUILD_DYNAMIC) set_target_properties(mapserver PROPERTIES PUBLIC_HEADER "${mapserver_HEADERS};${PROJECT_BINARY_DIR}/mapserver-config.h;${PROJECT_BINARY_DIR}/mapserver-version.h" ) endif(BUILD_DYNAMIC) macro(status_optional_component component enabled libpath) if("${enabled}" EQUAL "1") message(STATUS " * ${component}: ${libpath}") else() message(STATUS " * ${component}: disabled") endif() endmacro() macro(status_optional_feature feature enabled) if("${enabled}" EQUAL "1") message(STATUS " * ${feature}: ENABLED") else() message(STATUS " * ${feature}: disabled") endif() endmacro() message(STATUS "* Summary of configured options for this build") message(STATUS " * Mandatory components") message(STATUS " * GDAL: ${GDAL_LIBRARY}") message(STATUS " * PROJ: ${PROJ_LIBRARY}") message(STATUS " * png: ${PNG_LIBRARY}") message(STATUS " * jpeg: ${JPEG_LIBRARY}") message(STATUS " * freetype: ${FREETYPE_LIBRARY}") message(STATUS " * Optional components") status_optional_component("GIF" "${USE_GIF}" "${GIF_LIBRARY}") status_optional_component("MYSQL" "${USE_MYSQL}" "${MYSQL_LIBRARY}") status_optional_component("FRIBIDI" "${USE_FRIBIDI}" "${FRIBIDI_LIBRARY}") status_optional_component("HARFBUZZ" "${USE_HARFBUZZ}" "${HARFBUZZ_LIBRARY}") status_optional_component("GIF" "${USE_GIF}" "${GIF_LIBRARY}") status_optional_component("CAIRO" "${USE_CAIRO}" "${CAIRO_LIBRARY}") status_optional_component("SVGCAIRO" "${USE_SVG_CAIRO}" "${SVGCAIRO_LIBRARY}") status_optional_component("RSVG" "${USE_RSVG}" "${RSVG_LIBRARY}") status_optional_component("CURL" "${USE_CURL}" "${CURL_LIBRARY}") status_optional_component("PIXMAN" "${USE_PIXMAN}" "${PIXMAN_LIBRARY}") 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}") else(USE_ORACLESPATIAL) status_optional_component("Oracle Spatial (Built as plugin)" "${USE_ORACLE_PLUGIN}" "${ORACLE_LIBRARY}") endif(USE_ORACLESPATIAL) else(USE_ORACLESPATIAL OR USE_ORACLE_PLUGIN) status_optional_component("Oracle Spatial" "" "${ORACLE_LIBRARY}") endif(USE_ORACLESPATIAL OR USE_ORACLE_PLUGIN) if(USE_MSSQL2008) status_optional_component("MSSQL 2008 (Built as plugin)" "${USE_MSSQL2008}" "${ODBC_LIBRARY}") endif(USE_MSSQL2008) status_optional_component("Exempi XMP" "${USE_EXEMPI}" "${LIBEXEMPI_LIBRARY}") message(STATUS " * Optional features") status_optional_feature("WMS SERVER" "${USE_WMS_SVR}") status_optional_feature("WFS SERVER" "${USE_WFS_SVR}") status_optional_feature("WCS SERVER" "${USE_WCS_SVR}") status_optional_feature("SOS SERVER" "${USE_SOS_SVR}") status_optional_feature("WMS CLIENT" "${USE_WMS_LYR}") status_optional_feature("WFS CLIENT" "${USE_WFS_LYR}") status_optional_feature("ICONV" "${USE_ICONV}") status_optional_feature("Thread-safety support" "${USE_THREAD}") status_optional_feature("KML output" "${USE_KML}") status_optional_feature("Z+M point coordinate support" "${USE_POINT_Z_M}") status_optional_feature("XML Mapfile support" "${USE_XMLMAPFILE}") message(STATUS " * Mapscripts") status_optional_feature("Python" "${USE_PYTHON_MAPSCRIPT}") status_optional_feature("PHP" "${USE_PHP_MAPSCRIPT}") status_optional_feature("PHPNG" "${USE_PHPNG_MAPSCRIPT}") status_optional_feature("PERL" "${USE_PERL_MAPSCRIPT}") status_optional_feature("RUBY" "${USE_RUBY_MAPSCRIPT}") status_optional_feature("JAVA" "${USE_JAVA_MAPSCRIPT}") status_optional_feature("C#" "${USE_CSHARP_MAPSCRIPT}") status_optional_feature("V8 Javascript" "${USE_V8_MAPSCRIPT}") status_optional_feature("Apache Module (Experimental)" "${USE_APACHE_MODULE}") message(STATUS "") message(STATUS "PROJECT_BINARY_DIR is set to ${PROJECT_BINARY_DIR}") message(STATUS "Will install files to ${CMAKE_INSTALL_PREFIX}") message(STATUS "Will install libraries to ${INSTALL_LIB_DIR}") include_directories("${PROJECT_BINARY_DIR}") if(WIN32) set(REGEX_MALLOC 1) set(USE_GENERIC_MS_NINT 1) endif(WIN32) #INSTALL(FILES mapserver-api.h ${PROJECT_BINARY_DIR}/mapserver-version.h DESTINATION include) if(USE_ORACLE_PLUGIN) INSTALL(TARGETS msplugin_oracle DESTINATION ${INSTALL_LIB_DIR}) endif(USE_ORACLE_PLUGIN) if(USE_MSSQL2008) INSTALL(TARGETS msplugin_mssql2008 DESTINATION ${INSTALL_LIB_DIR}) endif(USE_MSSQL2008) INSTALL(TARGETS sortshp shptree shptreevis msencrypt legend scalebar tile4ms shptreetst shp2img mapserv RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin ) if(BUILD_STATIC) INSTALL(TARGETS mapserver_static DESTINATION ${INSTALL_LIB_DIR} COMPONENT staticlib ) endif(BUILD_STATIC) if(BUILD_DYNAMIC) INSTALL(TARGETS mapserver EXPORT mapserverTargets ARCHIVE DESTINATION ${INSTALL_LIB_DIR} COMPONENT shlib LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT shlib PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDE_DIR}/mapserver COMPONENT dev ) # Add all targets to the build-tree export set export(TARGETS mapserver FILE "${PROJECT_BINARY_DIR}/mapserverTargets.cmake" ) # Export the package for use from the build-tree # (this registers the build-tree with a global CMake-registry) export(PACKAGE mapserver) list(APPEND ALL_INCLUDE_DIRS ${INSTALL_INCLUDE_DIR}) list(APPEND ALL_INCLUDE_DIRS ${INSTALL_INCLUDE_DIR}/mapserver) list(REMOVE_DUPLICATES ALL_INCLUDE_DIRS) # Create the mapserver-config.cmake and mapserver-config-version files file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${ALL_INCLUDE_DIRS}") # ... for the build tree set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}") configure_file(mapserver-config.cmake.in "${PROJECT_BINARY_DIR}/mapserver-config.cmake" @ONLY) # ... for the install tree set(CONF_INCLUDE_DIRS "\${MAPSERVER_CMAKE_DIR}/${REL_INCLUDE_DIR}") configure_file(mapserver-config.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/mapserver-config.cmake" @ONLY) # ... for both configure_file(mapserver-config-version.cmake.in "${PROJECT_BINARY_DIR}/mapserver-config-version.cmake" @ONLY) # Install the mapserver-config.cmake and mapserver-config-version.cmake install(FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/mapserver-config.cmake" "${PROJECT_BINARY_DIR}/mapserver-config-version.cmake" DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev ) # Install the export set for use with the install-tree install(EXPORT mapserverTargets DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev ) endif(BUILD_DYNAMIC) mapserver-7.6.4/CONTRIBUTING.md000066400000000000000000000045521407312142500157720ustar00rootroot00000000000000# How to contribute to MapServer Contributions to the MapServer project are most welcome, and can take many forms such as detailed bug reports, documentation, tests, features, and patches. Note that all contributions are managed by the MapServer [Project Steering Committee](https://mapserver.org/psc.html). ## Bugs and Help GitHub issues should only be created to log bugs. For general help and support the MapServer [mailing lists](https://mapserver.org/community/lists.html) should be used. If you are unsure if you have discovered a bug, or may need help with configuring MapServer please post to the [mapserver-users list](https://lists.osgeo.org/mailman/listinfo/mapserver-users). There is also a [MapServer FAQ](https://mapserver.org/faq.html) which may have a solution to your problem. If you have discovered a bug, please refer to the [Bug Submission page](https://mapserver.org/development/bugs.html) for guidelines on creating an issue on GitHub. Please also search the existing issues to see if the bug has already been reported, and add any further details to the existing issue. For professional support please see the [MapServer Service Providers page](https://mapserver.org/community/service_providers.html). ## Development A separate [mapserver-dev mailing list](https://lists.osgeo.org/mailman/listinfo/mapserver-dev) is available for developers working on the MapServer code. Send a short message there to introduce yourself to the community, and mention what you are interested in working on. Details on using GitHub can be found on the [MapServer GitHub page](https://mapserver.org/development/git.html). Request for Comments (RFCs), where upcoming major changes to the source code are proposed, and a description of the various software tests & release plans, can be found on the [MapServer Development page](https://mapserver.org/development/). Additional developer notes can be found in the [MapServer wiki](https://github.com/mapserver/mapserver/wiki#developer-notes), including coding style and guidelines, memory management, and working with Git. ## Documentation The MapServer documentation is stored in a [separate repository](https://github.com/MapServer/MapServer-documentation). Please submit any documentation issues or changes there. See the [Documentation Development Guide](https://mapserver.org/development/documentation.html) for further details. mapserver-7.6.4/HISTORY.TXT000066400000000000000000004642101407312142500153040ustar00rootroot00000000000000 MapServer Revision History ========================== This is a human-readable revision history which will attempt to document required changes for users to migrate from one version of MapServer to the next. Developers are strongly encouraged to document their changes and their impacts on the users here. (Please add the most recent changes to the top of the list.) For a complete change history, please see the Git log comments. For more details about recent point releases, please see the online changelog at: https://mapserver.org/development/changelog/ 7.6.4 release (2021-07-12) -------------------------- - improved performance of GPKG and SpatiaLite queries (#6361) - WFS: fix paging with GPKG/Spatialite datasources and non-point geometries (#6325) - PostGIS: use ST_Intersects instead of && for bounding box (#6348) see detailed changelog for other fixes 7.6.3 release (2021-04-30) ------------------------- - fix security flaw for processing the MAP parameter (#6313) - fix code defects through Coverity Scan warnings (#6307) - add support for PROJ 8 (#6249) see detailed changelog for other fixes 7.6.2 release (2020-12-07) ------------------------- - No major changes, see detailed changelog for bug fixes 7.6.1 release (2020-07-31) ------------------------- - No major changes, see detailed changelog for bug fixes 7.6.0 release (2020-05-08) -------------------------- - for essential WMS client layers set EXCEPTIONS to XML by default (#6066) 7.6.0-rc4 release (2020-05-04) ------------------------------ - Fix case insensitive 'using unique' for PostGIS connections (#6062) - Add handling essential WMS layers (#6061) 7.6.0-rc3 release (2020-04-24) ------------------------------ - Handle special characters in paths on Windows (#5995) - Add attribute binding for label ALIGN, OFFSET, POSITION (#6052) 7.6.0-rc2 release (2020-04-10) ------------------------------ - Fix memory corruption in msGEOSGetCentroid (#6041) 7.6.0-rc1 release (2020-04-05) ------------------------------ - Fix alpha value for hex colors (#6023) 7.6.0-beta2 release (2020-03-28) -------------------------------- - fixed build with PHPNG + gnu_source (#6015) - fixed rendermode with geomtransform (#6021) 7.6.0-beta1 release (2020-03-22) -------------------------------- - Full support for PROJ6 API (#5888) - Enable PointZM data support (X,Y,Z,M coordinates) by default - SLD support enhancements (RFC 124) except PR#5832 - CONNECTIONOPTIONS support in mapfile LAYER (RFC 125) - Enforce C99 and C++11 build requirements (RFC 128) 7.4.4 release (2020-3-20) ------------------------- - Security release, see ticket #6014 for more information. 7.4.3 release (2019-12-16) -------------------------- - No major changes, see detailed changelog for bug fixes 7.4.2 release (2019-9-13) ------------------------- - No major changes, see detailed changelog for bug fixes 7.4.1 release (2019-7-12) ------------------------- - No major changes, see detailed changelog for bug fixes 7.4.0 release (2019-5-14) ------------------------- - No major changes, see detailed changelog for bug fixes 7.4.0-rc2 release (2019-5-10) ---------------------------- - No major changes, see detailed changelog for bug fixes 7.4.0-rc1 release (2019-5-1) ---------------------------- - No major changes, see detailed changelog for bug fixes 7.4.0-beta2 release (2019-4-17) ------------------------------- - Addresses XSS issue with [layers] template tag (fix available in 6.4, 7.0 and 7.2 branches as well) - Added Perl/Mapscript to Travis CI - No other major changes, see detailed changelog for bug fixes 7.4.0-beta1 release (2019-3-29) ------------------------------- - Python MapScript binding is available as installable Wheels with a full test suite and examples - C# MapScript binding is now compatible with .NET Core - PHP 7 MapScript binding support - both PHP/MapScript and Swig/MapScript - Added workaround to allow compiling against Proj 6 (#5766) 7.2.2 release (2019-2-19) -------------------------- - No major changes, see detailed changelog for bug fixes 7.2.1 release (2018-10-1) -------------------------- - No major changes, see detailed changelog for bug fixes 7.2.0 release (2018-07-23) -------------------------- - Fixed issue with ring handling with polygons in MVT support (#5626) - No other major changes, see detailed changelog for bug fixes 7.2.0-beta2 release (2018-6-13) - Update beta1 release notes to remove reference to PHP7 support - No other major changes, see detailed changelog for bug fixes 7.2.0-beta1 release (2018-5-9) -------------------- - Support for Enhanced Layer Metadata Management (RFC82) - Calculate MINDISTANCE from label bounds instead of label center (#5369) - Reposition follow labels on maxoverlapangle colisions (RFC112) - Implement chainable compositing filters (RFC113) - Faster retrieval of shape count (RFC114) - WMS layer groups are now requestable - Support C-style multi-line content types (#5362) - Python 3.x support (#5561) - Support Vendor-Specific OGC FILTER parameter in WMS requests (RFC118) - Mapbox Vector Tile (MVT) Support (RFC119) - INSPIRE download service support for WCS 2.0 (RFC120) 7.0.0 release (2015/07/24) -------------------------- - No major changes, see detailed changelog for bug fixes 7.0.0-beta2 release (2015/06/29) -------------------------------- - No major changes, see detailed changelog for bug fixes 7.0.0-beta1 release (2015/02/12) -------------------------------- - RFC91 Layer Filter Normalization - Implement WCS20 Extensions (#4898) - Require validation of ExternalGraphic OnlineResource (#4883) - Require validation on the CGI queryfile parameter. (#4874) - Apply RFC86 scaletoken substitutions to layer->PROCESSING entries - RFC113 Layer Compositing Pipeline - RFC109 Optimizing Runtime Substitutions - RFC108 Heatmap / Kernel-Density Layers - RFC106 Support of Geomtransform JavaScript Plugin - RFC105 Support for WFS 2.0 (server side) - RFC104 Bitmap Label removal, replaced with inlined truetype font - RFC103 Layer Level Character Encoding - RFC102 Support of Styleitem JavaScript Plugin - RFC99 GD removal - RFC98 Complex Text Rendering / Text Rendering Overhaul - RFC93 UTF Grid Support 6.4 release (2013/09/17) --------------------------- - RFC 101: Support for Content Dependant Legend Rendering - Add Support for librsvg as an alternative to libsvg-cairo - RFC100: Add support for raster tile index with tiles of mixed SRS (TILESRS keyword) - RFC94: Shape Smoothing - RFC95 : add EXPRESSION {value1,value2,...} support to parser (#4648) - RFC92: Migration from autotools to cmake (#4617) - RFC88: Saving MapServer Objects to Strings (#4563) - RFC90: Enable/Disable Layers in OGC Web Services by IP Lists - RFC85,89 Added Simplify,SimplityPT and Generalize geomtransform, implementation of geomtransform at the layer level - RFC86: Scale-dependant token replacements (#4538) - Fix symbol scaling for vector symbols with no height (#4497,#3511) - Implementation of layer masking for WCS coverages (#4469) - Implementation of offsets on follow labels (#4399) 6.2.0 release (git branch-6-2) 2012/11/14: -------------------------------------------------- - Fix WFS GetFeature result bounds are not written in requested projection (#4494) - Fixed wrong size in LegendURL of root layer (#4441) - Fixed wms_style_name in GetMap requests (#4439) - Fix segfault in queryByFilter function in MapScript - Adjusted WCS 2.0 to WCS Core 2.0.1 and GMLCOV 1.0.1 corrigenda (#4003) - Adjusted mediatype to multipart/related in WCS 2.0 (#4003) - Fix symbolObj.getImage seg fault in PHP/MapScript - Fix bad handling of startindex in some drivers (#4011) WFSGetFeature also now uses a global maxfeatures and startindex to support maxfeatures across layers rather than within layers - Fixed bugs with WCS 1.1/2.0 with VSIMEM (#4369) - Add notable changes here. Less important changes should go only in the commit message and not appear here. - Fixed the OGR driver to use point or line spatial filter geometries in degenerated cases (#4420) - implement OFFSET x -99 on ANGLE FOLLOW labels (#4399) Version 6.2 (beta1: 20120629): ------------------------------------------------- - Fix WFS filter is produced as non-standard XML (#4171) - Fix pixmap symbol loading issue (#4329) - Added INSPIRE ExtendedCapabilities and DOCTYPE definition to WMS 1.1.1 (#3608) - Fix wms_enable_request-related errors are not properly tagged (#4187) - Fixed "msGetMarkerSize() called on unloaded pixmap symbol" in mapsymbol.c (#4225) - Fixed PHP MapScript support for PHP 5.4 (#4309) - Fix msOGREscapeSQLParam could return random data (#4335) - Fixed locations of supported and native formats in Capabilities and CoverageDescriptions for WCS 2.0 (#4003) - Made format parameter for WCS 2.0 GetCoverage requests optional (#4003) - Swig mapscript for multi-label support (#4310) - Fix creation of a vector symbolObj in mapscript (#4318) - Added coverage metadata in WCS (#4306) - Ignore unknown requets parameteres in WCS 2.0 (#4307). - Fixed getFeature request with custom output format fails on filter encoding (#4190) - Fixed resolution when UoM changes in WCS 2.0 (#4283) - Added missing DEFRESOLUTION parameter to msCopyMap() function (#4272) - Migrated svn to git, and issue tracking from trac to github - Fixed mapscript is unusable in a web application due to memory leaks (#4262) - Fixed legend image problem with annotation layers with label offsets (#4147) - Add support for mutiple labels per feature (RFC81) - Add support for INSPIRE view service (RFC 75) - Drop support for GDAL/OGR older than 1.5.0 (#4224) - PDF backend: add support for generating geospatial PDF, when GDAL 2.0 with PDF driver is used, and the GEO_ENCODING FORMATOPTION (set to ISO32000 or OGC_BP) is added to the OUTPUTFORMAT definition. (#4216) - Python mapscript: fix swig mappings to work with both python 2.5.and 2.6 (#3940) - Added classgroup CGI parameter support (#4207) - Java mapscript: renamed shared library and completed libtool support (#2595) - Fixed WCS 2.0 axis order (#4191) - Added MS_CJC_* constants in PHP/MapScript (#4183) - Fixed Memory Leak with Fribidi Strings (#4188) - Allow multiple label definitions within a class (RFC 77/#4127) - shp2img: make it possible to specify layers (with -l option) that match GROUP names. - reuse a pre-parsed mapfile across fastcgi loops in case the mapfile is specified with the MS_MAPFILE env variable. (#4018) - Ability to do use PropertyIsLike with a column of a different type than text (postgis) (#4176) - Fixed SLD with FILTER doesn't apply properly to database layers (#4112) - Fixed lexer buffer size issue with single quotes in a string (#4175) - WFS Quote Escape issue (#4087) - Raster layer fails to be drawn if the window is less than half a pixel (#4172) - shptree: Improvement to reduce size of .qix files (#4169) - avoid potential gd fontcache deadlock on fastcgi exit signals(#4093) - Adjusted WCS GetCapabilities for an empty list of layers (#4140) - Adjusted WMS GetCapabilities for an empty list of layers (#3755) - Refactor cgi masperv to not call exit on argument errors (#3099) - Add --with-apache-module configure option to build an apache dso module (#2565) - Use libtool to build object files and libraries - Dynamically link libmapserver to the created binaries by default (requires the make install step to be run) - Python mapscript builds with make instead of setuptools - Fix LABELPNT geomtransform position for non-cached labels (#4121) - Add RFC80 font fallback support (#4114) - Added POLAROFFSET style option for a different symbol transform (#4117) - automatically translate vector symbol points (#4116) - Add RFC79 Layer masking (#4111) - Fixed single pixel coverages in WCS 2.0 (#4110) - Add svg symbols support (#3671) - Fixed subsetting in WCS 2.0 (#4099) - Upgrade clipper library to 4.6.3 - Make openlayers wms template request images with mimetype of outputformat defined in the mapfile's imagetype - Fix memory leak in msSLDParseRasterSymbolizer() - Fix compilation error with clang in renderers/agg/include/agg_renderer_outline_aa.h - Add stable hatch rendering (#3847) - Added vector field rendering (#4094) - Add wms dimensions support (#3466) - Fixed segfault when calling classObj::updateFromString() with SYMBOL (#4062) - Use a renderer native follow text implementation if available. - Fixed layer with inline feature to support multiple classes (#4070) - Add support for rfc45 anchorpoint on marker symbols (#4066) - Add initial gap support for line marker symbols (#3879) - Fix center to center computation of gaps for line marker symbols and polygon tile patterns (#3867) - Add initial gap support for line patterns (#3879) - Fixed grid of thin lines in polygon symbol fills (#3868) - Fixed cannot add a style to a label in PHP/SWIG Mapscript (#4038) - Fixed schema validity issue for WCS 1.1 GetCoverage responses (#4047) - remove default compiler search paths from the GD CFLAGS/LDFLAGS (#4046) - Fixed Python Mapscript does not write COLOR to reference map (#4042) - Added XMP support for metadata embedding, RFC 76, (#3932) - Added GetLegendGraphic Cascading support (#3923) - Rewrite postgres TIME queries to take advantage of indexes (#3374) - Unified OWS requests and applied to WCS (defaults to version 2.0 now) (#3925) - WCS 1.0: Fix crash with some _rangeset_axes values (#4020) - WCS 2.0: Adjusted offset vector and origin (#4006) - Added addParameter() method to MapScript (#3973) - Changed msDrawVectorLayer() not to cache shapes if attribute binding is present after the first style (#3976) - Fix mapscript to build when TRUE macro is not defined (#3926) - Fix mapscript php build issues with MSVC (#4004) - PHP MapScript is missing many styleObj properties (#3901) - PHP/Mapscript: Segmentation fault when getting complex object using PHP 5.2 (#3930) - PHP/Mapscript: Fixed webObj->metadata returns a webObj (#3971) - WCS 1.1: Added check for imageCRS in msOWSCommonBoundingBox() (#3966) - Fixed contains operator in logical expresions (#3974) - WCS 1.0: WCS Exceptions raise mapscript exceptions (#3972) - WMS: LAYERS parameter is optional when sld is given (#1166) - Add runtime substitution for "filename" output format option (#3571) and allow setting defaults in either metadata or validation (preferred) blocks for both layer and output format. - Add non antialiased text rendering for GD (#3896) - Fixed OGC filter using expressions (#3481) - Fix incorrect rendering of GD lines between 1 and 2 pixels wide (#3962) - Add gamma correction to AGG polygon rendering (#3165) - Initialize the scalebar image color to transparent by default (#3957) - Do not divide by zero in io read/write funcs (#4135) IMPORTANT SECURITY FIX: - Fixes to prevent SQL injections through OGC filter encoding (in WMS, WFS and SOS), as well as a potential SQL injection in WMS time support. Your system may be vulnerable if it has MapServer with OGC protocols enabled, with layers connecting to an SQL RDBMS backend, either natively or via OGR (#3903) - Fix performance issue with Oracle and scrollable cursors (#3905) - Fix attribute binding for layer styles (#3941) - Added missing fclose() when writing query files (#3943) - Fix double-free in msAddImageSymbol() when filename is a http resource (#3939) - Fix rendering of lines with outlinewidth set if not on first style (#3935) - Correct SLD with spatial filters bbox and intersects (#3929) - Applied patch for ticket (symbol writing issues) (#3589) - Added WMS GetFeatureInfo Cascading (#3764) - Fixed png lib is not found on multiarch systems (#3921) - Fixed PHP MapScript opacity property of StyleObj no longer works (#3920) - Fixed Using STYLEITEM AUTO, loadExpression fails when the label text contains a space or begins with a double quote (#3481) - Fix for the cluster processing if the shape bounds doesn't overlap with the given extent (#3913) - Add support for dashes on polygon hatches (#3912) - Union layer 3 new processing options added (#3900) - Changed msRemoveStyle to allow removing all styles (#3895) - Fixed mssql2008 to return correct geometries with chart layer type (#3894) - Ensure msLayerSetProcessingKey() supports setting a NULL value to clear a processing key. - Write SYMBOLSET/END tags when saving a symbol file (#3885) - Make java threadtests work again (#3887) - Fix segfault on malformed filters (#3888) - Fixed the query handling problem with the Oracle spatial driver (#3878) - Fixed potential crash with AVERAGE resampling and crazy reprojection (#3886) - Adjusted OperationsMetadata for POST in WCS 2.0 GetCapabilities response - Fix for the warnings in mapunion.c (#3880) - SLD: correct when same layer is used with multiple styles (#1602) - Fixed the build problem in mapunion.c (#3877) - Implement to get all shapes with the clustered layer (#3873) - Union layer: Fixed the crash when styling source layers using attributes (#3870) - Added GEOS difference operator to expression support (#3871) - Improve rangeset item checking so that Bands=1,2,3 is supported with WCS 1.0 (#3919). - Fix GetMapserverUnitUsingProj() for proj=latlong (#3883) - Add support for OGR output of 2.5D geometries (#3906) Version 6.0.0 (2011-05-11) -------------------------- - apply fix for #3834 on legend icon rendering (#3866) - Union layer: Fixed a potential seg fault in msUnionLayerNextShape (#3859) - Cluster layer: Fixed the problem when returning undefined attribute (#3700) - Union layer: Fix for the item initialization at the source layer (#3859) - Union layer: Fixed the potential seg fault when STYLEITEM AUTO is used (#3859) Version 6.0.0-rc2 (2011-05-05) ------------------------------ - Fixed seg fault with [shpxy] tag... (#3860) - Removed obsolete msQueryByOperator() function - Call msLayerClose() before msLayerOpen() in the various query functions (#3692) - Fix WMS 1.3.0 to use full list of epsg codes with inverted axis (#3582) - PHP/Mapscript: Added getResultsBounds() method in layer object (#2967) - Fix SLD containing a PropertyIsLike filter (#3855) - Fixed msUnionLayerNextShape to return correct values (#3859) - Union layer: fix for the failure if one or more of the source layers are not in the current extent (#3858) - Fix memory leak in msResampleGDALToMap() (#3857) - Fix missing initialization of default formats in WCS 1.x. - Fix maxoverlapangle when value is set to 0 (#3856) Version 6.0.0-rc1 (2011-04-27) ------------------------------ - Fix for the styleitem handling with union layer (#3674) - Fixed mindistance label test to check layer indexes. (#3851) - Fixed segmentation fault in PHP/MapScript and improved the php object method calls (#3730) - Fix build issue related to unnecessary use of gdal-config --dep-libs (#3316) Version 6.0.0-beta7 (2011-04-20) -------------------------------- - Union Layer: fix for the STYLEITEM AUTO option (#3674) - Union Layer: Add support for the layer FILTER expressions, add "Union:SourceLayerVisible" predefined attribute (#3674) - fix circle layer drawing for edge case when point1.x==point2.x (#1356) - fix incorrect quantization for images with very large number of colors (#3848) - fix poor performance of polygon hatching (#3846) - upgrade clipper library to 4.2 (related to #3846) - Fix configure output for "WFS Client" (was reporting WMS info, #3842) - KML: latlon bbox for raster layers could end up being wrong for non-square requests (#3840) Version 6.0.0-beta6 (2011-04-13) -------------------------------- - define EQUAL/EQUALN macros if cpl_port.h was not included (#3844) - add configurable PNG/ZLIB compression level (#3841) - SLD: use pixmap size when parameter size is not specified (#2305) - fix memory leaks in mapgraticule.c (#3831) - fix runtime sub validation against web metadata, was using wrong lookup key - clean up the symbolset if we've used an alternate renderer for a layer (#3834,#3616) - fix crash on embeded legend with cairo raster renderer - fix crashes in SVG renderer on polygon symbol fills (#3837) - fix crash/corruptions with raster layers in pdf outputs (#3799) - fix memory leak in msFreeLabelCacheSlot (#3829) - use a circle brush for wide GD lines (#3835) - fix segmentation fault with transparent layers containing symbols (#3834) - fix memory leak on tiled vector polygons - fix segfault with marker symbols on short lines (#3823) - wms_getmap_formatlist causes first defined outputformat to be returned by getmap (#3826) - fix building of mapcluster.c when OGR support is disabled - fix some valgrind found memory leaks (offset symbols, and gd io contexts) - skip marker symbol with no defined SYMBOL (caused some memory leaks with uninitialized vector points) - fix crash in GD lines with floating point dash patterns (#3823) - Check renderer before using it when calculating label size (#3822) - allow palette file path to be relative to mapfile (#2115) - use supplied offset for brushed lines (#3825, #3792) - fix division by 0 error in bar charts for some ill-defined cases (#3218) - add GAP, POSITION and CAPS/JOINS to mapfile writer (#3797) - fix GEOMTRANSFORM rotation orientation for vector symbols (#3802) - GD Driver broken in FastCGI (#3813) - configure: look for libexslt.so under lib64 as well - Coding style and formatting fixes (#3819, #3820, #3821, and more) - More improvements to OpenGL error handling (#3791) - Added WMS GetFeatureInfo RADIUS=bbox vendor-specific option (#3561) Version 6.0.0-beta5 (2011-04-06) -------------------------------- - Fix setting of top-level mapObj member variables in PHP MapScript (#3815) - More robust OpenGL context creation on older video cards and drivers (#3791) - Allow users to set the maximum number of vector features to be drawn (#3739) - Fixed FCGI on Windows problem related to lexer (#3812) - KML: Add ows/kml_exclude_items (#3560) - Removed all refs left to MS_SYMBOL_CARTOLINE (#3798) - Removed GAP, PATTERN, LINECAP/JOIN and POSITION from symbolObj (#3797) - Fixed handling of STYLEITEM AUTO label position codes 10,11,12 (#3806) - Fixed msGEOSGeometry2Shape to handle 'GEOMETRYCOLLECTION EMPTY' as null geometry instead of raising an error (#3811) - Re-added the MYSQL JOIN support. Had been removed with the MYGIS deprecated driver. - Add opacity to legend (#3740) - Updated PHP/MapScript with the new objects properties (#3735) - KML: set layer's projection when it is not defined (#3809) - Updated xml mapfile schema and xsl with the new lexer properties (#3735) - Updated PHP/MapScript for MS RFC 69: clustering. (#3700) - Move allocation of cgiRequestObj paramNames/Values to msAllocCgiObj() (#1888) - Add support for simple aggregates for the cluster layer attributes (#3700) - Improved error reporting in msSaveImage() (#3733) - configure: look for libxslt.so under lib64 as well - added missing ';' before charset in WFS DescribeFeatureType header (#3793) - add brushed line support for agg renderer (#3792) - fix bug with marker symbols along offset line - fix for the cluster layer returning invalid feature count (#3794) - remove some compiler warnings - fix incorrect scaling of hatch symbol spacing (#3773) - fix incorrect background color for INIMAGE exceptions (#3790) Version 6.0.0-beta4 (2011-03-30) -------------------------------- - Fix shp2img's -i flag to honour map level transparent, image quality and interlace settings. - Make sure command-line programs use an exit status other than 0 when an error is encountered. (#3753) - Applied patch to filter unwanted fribidi characters (#3763) - Fixed lexer to set the proper state on URL variable substitutions - Fixed Memory leak in PostGIS driver (#3768) - Fixed PHP/MapScript symbol property setter method - fix memory leak in bar charts - fix some valgrind errors on agg rotated pixmap symbols - WCS 2.0: Adjusted definition of NilValues. - Fixed handling of PROJ_LIB value relative to mapfile path (#3094) - Fixed compilation error with opengl support (#3769) - add support for gml:Box for spatial filters (#3789) - fix query map generation error introduced in beta2 when output format initialized was made as needed. - fix incorrect PATTERN behavior on agg lines (#3787) - report SOS DescribeObservationType in Capabilities (#3777) - Updated lexer to detect time attribute bindings (e.g. `[item]`) in logical expressions - Fixed layer context expressions (REQUIRES/LABELREQUIRES) (#3737) - KML: Output ExtendedData (#3728) - Fixed OWS usage of multiple layers with same name (#3778) - WCS implementation should not lookup wms_* metadata (#3779) - WCS 2.0: Adjusted definition of rangeType. - Fixed OWS GetCapabilities to report only requests/operations that are enabled. - WCS 2.0: Report only bands in the range subset. - OWS requests should be completely blocked by default (#3755) - SLD: check for limit on dash arrays (#3772) - WMS: Apply sld after bbox and srs have been parsed (#3765) Version 6.0.0-beta3 (2011-03-23) -------------------------------- - apply min/max size/width style values to polygon spacing (vaguely related to #3132) - assure that a created tile has a non-zero width and height (#3370) - use png_sig_cmp instead of png_check_sig (#3762) - Rendering: scale style OFFSET and GAP the same way we scale other style attributes. Beforehand, we scaled them proportionaly to the computed width. - KML: fix rounding problem for point feautres (#3767) - KML: update code to reflect output changes. Fix true type symbols. (#3766) - SLD: Text Symbolizer now uses the new expression syntax (#3757) - WFS: correct bbox values for GetFeature with featureid request (#3761) - Mapscript Seg Fault on mapObj->getMetaData (#3738) - Correct double free in msCleanup(). - Initialize default formats in WCS. - Fix csharp Makefile.in (#3758) - Allow run-time subs in class->text (makes sense if you allow it in class->expression). - Fix build problem when --enable-cgi-cl-debug-args is enabled (#2853) Version 6.0.0-beta2 (2011-03-18) -------------------------------- - correct scaling of symbol GAP and PATTERN (#3752) - remove references to SWF/MING - CGI runtime substitution requires a validation pattern (was optional before) (#3522) - add a default png8 outputformat that uses AGG/PNG with quantization - change MS_INIT_COLOR to take alpha as a parameter - stop using style->opacity in rendering code, use alpha from colorObjs. - Fixed big Oracle memory leak when rendering in KML (#3719) - avoid linking in postgres dependencies unnecessarily (#3708) - don't initialize outputformats until they are selected - use "seamless" creation of tiles for polygon fills with vector symbols - Ability to escape single/double quotes inside a string (#3706) - Globally replace msCaseFindSubstring with strcasestr (#3255) - support GROUP layers in shp2img (#3746) - Honour MAXSIZE for WCS 2.0 responses (#3204). - fallback to ows_title for WCS ows:Title of CoverageDescription (#3528) - Added msIO_stripStdoutBufferContentHeaders() to strip off all Content-* headers from a buffer (#3673, #3665). - Added raster classification support for STYLE level OPACITY. - Allow attribute references, that is [itemname], within a TEXT string (#3736) - Fixed segmentation fault when parsing invalid extent arguments in shp2img (#3734) - Make "openlayers mode" work even without OWS support (#3732) - Add a static table to define the axis order for soem epsg codes (#3582) - Add possibility to use KML_NAME_ITEM (#3728) - Fixed mapfile parsing error when a label angle referenced an attribute (e.g. ANGLE [angle]) #3727 - Removed executable flag on some source files (#3726) - Fixed SQL Spatial to be able to use UniqueIdentifier field as unique key (#3722) - Fix PHP Windows build (#3714) - Fixed --with-opengl build issue: Look for OpenGL libs under /usr/lib64 as well (#3724) Version 6.0.0-beta1 (2011-03-09) -------------------------------- - Fixed Core Dump from Format=KML/Z with Oracle Spatial layers (#3713) - Call msPluginFreeVirtualTableFactory from msCleanup (#2164) - Avoid the crash if anglemode 'FOLLOW' is specified with bitmap fonts. (#3379) - Add argument check for processTemplate, processLegendTemplate and processQueryTemplate in the C# bindings (#3699) - Remove shapeObj.line, shapeObj.values, lineObj.point from the SWIG API which are redundant and undocumented. (#3269) - Remove map-oriented query modes (e.g. QUERYMAP). Use qformat parameter instead. (#3712) - Implement single-pass query handling in mssql2008 driver as per RFC 65. - Fixed Sql Server 2008 key column name truncation (#3654) - Added label position binding (#3612) and label shadow size binding (#2924) - Implement MS RFC 69: Support for clustering of features in point layers (#3700) - Implement MS RFC 68: Support for combining features from multiple layers (#3674) - Add support for WCS 1.1 Post (#3710) - Fixed OGR query handling according to RFC 65 (#3647) - Implement CLOSE_CONNECTION=ALWAYS to suppress the connection pooling for a particular layer. - Implemented RFC 67: Enable/Disable layers in ogc web services (#3703) - Class title can now be used in legends. It's value takes precedence over class name. Previously title was not used any place in the code but it is supported for read/write. (#3702) - Allow definition of nodata attribute for layers without results (via resultset tag). (#3701) - mapprojhack.c: restructure to avoid needing projects, or any internal knowledge of PROJ.4. - Fix newlines around part boundaries in WCS multipart results (#3672) - Added minfeaturesize support at layer or class level (#1340) - Implemented support in for classifying rasters using the new expression parsing (msGetClass()...) (#3663) - Implemented RFC 65 which improves and simplifies one-pass query support. This causes a few MapScript regressions with getShape/getFeature/getResultsShape. (#3647) - Support setting filenames for WCS GetCoverage results (#3665) - OGR auto-styling: use the color parameter and set the style's opacity when it is available. Allow symbols that can be stored externally (#3660) - Add possiblity to use symbols stored externally, accessed through http (#3662) - Better handling of temporary files (#3354) - Support curved features in PostGIS (#3621) - NODATA values now excluded from autoscaling min/max for non-eight scaling computations (#3650) - Fixed missing time in msDrawMap logging (#3651) - Fixed Auto Angle - incorrectly placed Labels (#3648) - Fixed Improper validation of symbol index values (#3641) - Removed BACKGROUNDCOLOR, BACKGROUNDSHADOWCOLOR and BACKGROUNDSHADOWOFFSET label parameters (#3609) - Fixed Transformation from XML to MapFile only handles one PROCESSING element (#3631) - Fixed 16bit classification support - problem introduced with new renderer architecture (#3624) - Cleanup open gdal datasets in msGDALCleanup() (if we have a very new GDAL). This makes it easier to identify memory leaks. - Add support for per layer tuning of the shape to pixel conversion (SIMPLIFY, ROUND, SNAPTOGRID, FULLRESOLUTION) - Fixed: Memory allocation results should always be checked (#3559) - Fixed free(): invalid next size in mapfile.c (#3604) - Added a built-in OpenLayers map viewer (#3549) - Fixed issues with static buffers and sprintf (#3537) - Fix for the memory corruption when mapping the string data type in the Java bindings (3491) - Fixed double free in shp2img.c (#3497) - Fixed number of CGI params is limited to 100 (#3583) - Fixed duplicated XML and HTML errors from WFS GetFeature (#3571) - Support group names for GetLegendGraphic and GetStyles (#3411) - apply patch (thanks rouault) to advertise resultType=hits in WFS 1.1 Capabilities (#3575) - mapshape.c: Fix writing of geometries with z/m and fail gracefully attempting to create such files if USE_POINT_Z_M is not enabled (#3564) - sortshp.c: improve error handling (#3564) - MSSQL2008: Add support for geography data type by extending the DATA syntax to 'geometry_column(geometry_type) from table_name' - Fixed ability to get the error message and code of an OWS exception (#3554) - Fixed msOGRGetSymbolId according to the changes in gdal 1.8 (#3556) - Support holding WMS client requests in RAM instead of writing to disk (#3555) - RFC-61: Enhance MapServer Feature Style Support (#3544) - Restrict cascaded WMS requests based on EXTENT (#3543) - Avoid EPSG lookups for WMS client layers if possible (#3533) - RFC-60: Add ability to skip ANGLE FOLLOW labels with too much character overlap (#3523) - Fixed SWF: not a valid Bitmap FillStyle (#3548) - Set dependency on libxml2 when building --with-wfs (#3512) - Fixed TRUE is undefined in shptreevis (#3545) - shptreevis: bug truncates visualization shapefile if there are more nodes in the tree than there are shapes being indexed! - Fixed multiple include tags not supported in xml mapfiles (#3530) - Support reading .dbf files between 2GB and 4GB (#3514) - Avoid warnings about ms_cvsid being unused with gcc. - Ensure the class is not marked BeforeFieldInit causing memory corruption with C#/CLR4 (#3438) - Fixed MSSQL2008 driver returning invalid extent (#3498) - Added coordinate scaling to shpxy tag via parameters scale, scale_x or scale_y. - Fix computation of shape bounds when the first line contains no points (#3119)(fixes #3383) - Allow map relative specification in the PROJ_LIB config item (#3094) - Try to report reprojection errors in SLD Filter evaluation (#3495) - Disabled some insecure (and potentially exploitable) mapserv command-line debug arguments (#3485). The --enable-cgi-cl-debug-args configure switch can be used to re-enable them for devs who really cannot get away without them and who understand the potential security risk (not recommended for production servers or those who don't understand the security implications). - Fixed segmentation fault in ogr driver when shape type is null - Fixed synchronized MS_UNITS and inchesPerUnits array (#3173) - Fixed possible buffer overflow in msTmpFile() (#3484) - Fixed Using STYLEITEM AUTO, loadExpression fails when the label text contains a double quote (#3481) - PHP/MapScript: Expose getGeomTransform/setGeomTransform instead of exposing the private vars for rfc48 (#2825) - PHP/MapScript: Fixed updateFromString functions to resolve symbol names (#3273) - PHP/MapScript: ability to use the php clone keyword (#3472) - Modified mapserver units enum order to fix some problems with external softwares (#3173) - Fixed configure does not detect libGD version dependencies (#3478) - Fixed Drawing inline text not working (bitmap) (#3475) - ensure well formed XML when msWCSGetCapabilities_CoverageOfferingBrief returns MS_FAILURE (#3469) - Fixed msQueryByRect does not use tolerance (#3453) - Fixed MapScript processTemplate and processQueryTemplate seg fault (#3468) - Fixed shapeObj->toWkt() returns single point for multipoint geometry (#2762) - Fixed Internal server error when Oracle returns ora-28002 code (#3457) - Fixed PHP/MapScript ms_iogetstdoutbufferbytes() always returning 0 bytes written (#3041) - MapScript resultsGetShape() method fails with a OracleSpatial layer (#3462) - PHP/MapScript circular references between objects (#3405) - Handle null results with gml:Null/gml:null according to version (#3299) - Reworked mapfile writing to use helper functions so that core types (e.g. numbers, strings, colors, keywords, etc...) are always written consistently. - Ensure mapwmslayer.c does not unlink file before closing connection on it (#3451) - Fix security exception issue in C# with MSVC2010 (#3438) - Write out join CONNECTIONTYPE when saving a mapfile. (#3435) - Fixed attribute queries to use an extent stored (and cached) as part of the queryObj rather than the map->extent. (#3424) - Reverted msLayerWhichItems() to 5.4-like behavior although still supporting retrieving all items (#3356,#3342) - Grid layer: remove drawing of unnecessary gird lines (#3433) - Avoid errors and debug output for CONNECTION-less OGR layers in mappool.c if they have a tileindex. - Implement support for raw imagemodes to use NULLVALUE formatoption to set the background value of result images, and to try and mark nodata (#1709) - Implement support for wcs_rangeset_nullvalue to set NULLVALUE and return null value definition in describe coverage result (#655) - Try to avoid exhausting the color table when rendering 24bit key images into 8bit results (#1594) - Avoid crash, and ensure error report when loading keyimage fails (#1594) - Improve the handling of simple string comparisons for raster classified values (#3425) - Generate good SQL when using !BOX! token and no filter. (#3422) - Implement non-shapefile tileindex support for raster query (#2796). - Improve support for [red/green/blue] classification expressions for raster query (#1021) - Fixed imageObj->saveImage() sends unnecessary headers (#3418) - Avoid automatically regenerating maplexer.c (#2310) - Change rounding rules for average resampling (#1932) - Implement support for filename encryption per RFC 18 for rasters (#3416) - Fixed segfault when using shapefile with empty geometry and tileindex (#3365) - Avoid race condition on core_lock on win32 mutex init (#3396) - Avoid use of inline keyword for C code (#3327) - Support WFS parsing through libxml2 (#3364) - Fixed PHP/MapScript imageObj->saveImage() function (#3410) - Implement wms_nonsquare_ok metadata item for WMS servers that do not support non-square pixels (#3409) - Fixed MapScript shape->classindex is always 0 (#3406) - Fixed PHP MapScript integer passing broken on 64bit systems (#3412) - Fix MS_NONSQUARE to work in mode=map (#3413) - Support inclusion of raster layers in query map drawing even if the results may not be that useful (#1842). - Fixed auto angle: incorrectly rotated Labels. Added AUTO2 angle mode. (#1688) - Preliminary implementation of validity mask (imageObj->img_mask) for raw raster data (#2181) - Added libgd < 2.0.30 compatibility (#3293) - Incorporate support for GDAL nodata on RGB images (#2404) - Incorporated support for GDAL masks (GDAL RFC 15) (#2640) - Fixed XML transformation issues with expressions and symbols (#3397) - Check error returns from mapstring functions (#2988) - Add support for multiliple srs in WFS 1.1.0 (#3227) - Fixed PHP/MapScript owsRequestObj->loadParams() method when using php in a non cgi/fcgi/cli mode. (#1975) - Ensure that non-file raster datasets work (#3253) - Correct mutex locking problem with rasters with no inherent georef. (#3368) - Correct ungeoreferenced defaults via GetExtent() on raster layer (#3368) - PHP Mapscript refactoring: take full advantage of PHP 5 / Zend Engine 2 (#3278)" - Fixed msRemoveHashTable() to return the proper value on failure/success. - Correct one pass query problems and OGC filter query (#3305) - Fixed msMSSQL2008CloseConnection() to free the statement handle properly (#3244) - Fixed the query handling with the MSSQL2008 driver (#3058) - Fixed swig zoomRectangle() method: the maxy in the rect object have to be < miny value (#3286) - Fix crash with GRID layers with no classes (#3352) - Remove "legacy" raster support, all raster rendering via GDAL now. - Very preliminary render plugin support for raster rendering. (RFC 54) - support correct MIME type output for WFS 1.1.0 (#3295) - add WMS 1.3.0 LayerLimit support (#3284) - fix WFS 1.1.0 exception attributes (#3301) - add more useful error message when query file extension test fails (#3302) - s/gml:null/gml:Null for empty WFS GetFeature responses (#3299) - Support metatiling and buffers in mode=tile (#3323) - Enhance error messages in msGetTruetypeTextBBox() (#3314) - Report parsing errors in INCUDEd files using the line number within the file (#3329) - Avoid memory error when building SQL bbox (#3324) - Reproject rectangles as polygons to get datelin wrapping (#3179) - Add support for the WMS capabilities items AuthorityURL, Identifier (#3251) - Added support to write a null shape in a shape file. (#3277) - Apply ON_MISSING_DATA to zero-length WMS client calls (#2785, #3243) - PHP/Mapscript: added labelCacheMember object and mapObj::getLabel() method (#1794) - Add shplabel tag support in templates (#3241) - Bumped GEOS requirement to version 3.0+ (#3215) - Fixed memory leak related to templates (#2996) - Added support of 44xx gtypes in oracle spatial driver (#2830) - Fixed curl proxy auth support for http connections (#571) - PHP/MapScript: removed deprecated class properties (#2170) - Fixed OGR datasource double free (#3261) - Fix compilation warnings around use of strcasestr (#3257) - Made %substitution% strings case insensitive (#3250) - Added support to get the extent of a raster layer that use a tileindex (#3252) - Fixed configure to support FTGL 2.1.2 (#3247) - Changed msSaveImageBufferGD to be in accordance with msSaveImageGD (#3201) - PHP/Mapscript: added layerObj units property (#3249) - Changed the query map rendering implementation without adding extra layers to the map (#3069) - SQL Server 2008 plugin is not handling null field values correctly (#2893) - Hatch symbol not properly saved (#2905) - Expose symbolObj.inmapfile to the SWIG API, have already been exposed to PHP (#3233) - Expose getGeomTransform/setGeomTransform to SWIG instead of exposing the private vars for rfc48 (#3214) - Fixed writeSymbol to support writing 'ANGLE AUTO' (#3214) - Fixed problems with point queries not working via the CGI (mode=query or mode=nquery) (#3246) - Support QueryByShape() with point and line geometries (#3248) - Honour MAXSIZE for WCS responses (#3204) - Implemented RFC 52 LayerResultsGetShape support for OGR connection type. - Fixed uninitialized variable with malloc used in osPointCluster() (#3236) - Oracle driver: remove BLOB columns instead of changing them to null (#3228) - Fixed ogc sld functions to return proper values (#2165) - MAP EXTENT truncates GetFeature requests for data outside bounds (#1287) - Added msStringSplitComplex function (#471) - Mapserver WFS should send maxfeatures to the spatial database (#2605) - WFS paging support (#2799) - Fixed joins do not accept crypted passwords (#2912) - Fixed HTML legend image samples truncated (#2636) - WMS GetFeatureInfo should respect the scale like GetMap does (#842) - Filter encoding: simple filters using propertyislike not applied properly #2720, #2840 - Fix VBAR Chart production when using GD for rendering (#3482) Version 5.6.0 (2009-12-04): --------------------------- - WFS hits count is incorrect if the request contain 2 layers or more (#3244) - Fixed a problem with layer plugin where copyVirtualTable didn't copy the LayerResultsGetShape function pointer (#3223) Version 5.6.0-rc1 (2009-11-27): ------------------------------- - Fixed a problem with shape-based queries against projected layers when using a tolerance (#3211) - Fixed long expression evaluation (#2123) - Added simplfy and topologyPreservingSimplify to MapScript (#2753) - Fixed Oracle FastCGI memory leak (#3187) - layer->project flag not being reset properly for drawquerylayer (#673 #2079) - OGC SLD: support multi-polygons geometries for filters embedded in an SLD (#3097) - [WMC] embedded SLD in context does not work with namespace prefix (#3115) - Support name aliases used in sld text symbolizer (#3114) - decode html and unicode entities for polygon truetype symbol fills (#3203) - Parse PropertyName parameter for wfs requests (#675) - Fixed when saving a map, layer->transform isn't written properly in all cases. (#3198) - Fixed buffer overflow in oracle spatial driver with large sql data (#2694) - Improve FastCGI include file finding logic (#3200) Version 5.6.0-beta5 (2009-11-04): --------------------------------- - Apply a minimum width on label outline (new outlines were too thin by default) - Don't apply scalefactor to polygon outline widths (but apply the resolutionfactor) - Fix vector symbol size calculation (#2896) - Applied code clean up patch for mapsearch.c. (#3189) - Fixed labels centering when the label is longer than the line (#2867) - Ensure Python MapScript building doesn't reorder the libraries, support the 'subprocess' module where available for setup.py, and default to using the "super" swig invocation described in the Python MapScript README when mapscript_wrap.c isn't available on the file system. #2663 contains the reordering issue. - Fixed memory leak with shapefiles associated with one-pass query implementation (#3188) - Fix abs/fabs usage that prevented angle follow labels to be discarded if they were too wrapped on themselves - Allow CGI mapshape and imgshape variables to consume WKT strings (#3185) - Added support for nautical miles unit (#3173) - Fixed encoding metadata ignored by a few wcs/wfs 1.1 and sos requests (#3182) - PHP/Mapscript: added "autofollow" and "repeatdistance" in labelObj (#3175) - Added charset in content-type http header for wms/wfs/sos/wcs requests (#2583) - Python/MapScript: improve compatibility for different swig versions (#3180) - maprasterquery.c: a few fixes since beta4 (#3181, #3168). - mapows.c: Generate WMS LatLongBoundingBox in WGS84 datum (#2578) Version 5.6.0-beta4 (2009-10-18): --------------------------------- - Allow processing of single shapefiles with no items (e.g. an empty dbf file) (#3147) - Added resolution scaling for swf, svg, pdf and imagemap drivers (#3157) - Correct cases where a valid WFS Layer might return errors if map extent does not overlap the layer extent (#3139) - fix problem with 0-length line patterns in AGG - Fixed problem of text/html WMS GetFeatureInfo which was returning HTML image map output instead of the expected text/html template output. This was done by changing the imagemap outputformat to use the "text/html; driver=imagemap" mime type (#3024) - more resolution fixes for resolution scaling (symbolscale case) (#3157) - Make sure layer extents are saved when a mapfile is written (#2969) - Fixed CurvePolygons from oracle not drawn (#2772) - Fixed raster queries (broken by RFC 52 changes) (#3166) - Fixed coordinate projection problem in some cases with WMS GetFeatureInfo output in GML2 format (#2989) - Added resolution scaling of some properties for GD driver (#3157) - Modified GD functions API to be consistent with all others drivers (#3157) - OGC Filter: strip all namespaces (not only ogc, gml) (#1350) - Use decimal values for size and width in SVG output format (#2835) - Correct invalid test when loading movies in an swf ouput (#2524) - Return WMS GetCapabilities v1.3.0 by default as required by spec (#3169) - Fixed mapObj.zoomScale() and mapobj.zoomRectangle() scaling problem in Mapscript (#3131) - Few more fixes for high res output (#3157) - Allow "DRIVER 'TEMPLATE'" or "DRIVER TEMPLATE" in output formats - Correct sld generated from mapserver classes (#3133) - Correct libjpeg v7 compatability issue in old jpeg interface code (#3167) - Correct FEATURE_COUNT limits on WMS GetFeatureInfo raster queries (#3168) - Correct SCALE_BUCKETS issue with 16bit raster scaling (#3174) Version 5.6.0-beta3 (2009-10-07): --------------------------------- - make RFC55 highres output be friendly with scaledependant rendering (#3157) - avoid fractured and overlapping glyphs with angle follow (#2812) - Fixed SDE layer seg fault (#3152) - Fixed placement of labels using ANGLE AUTO which were not always positioned correctly (#3160) - Enable output of geometry in GML GetFeatureInfo if wms_geometries and wms_geom_type are specified (#2989) - fix URN typo in mapwfs.c for urn:EPSG:geographicCRS:... - don't apply scalefactor to label outlines (#3157) - update namespaces and schema pointers (#2872) - add RFC49 and RFC40 keywords to copy functions (#2865) - minor fix to correct numberOfResults when maxfeatures is set in mapfile (#2907) - Fixed possible crash with WFS GetFeature when no projection is specified at the map level (#3129) - Fixed anchor point of vertically stacked bar graphs - Fixed TEXT property that cannot be removed in the CLASS object. PHP/Mapscript (#3063) - Fixed use of minfeaturesize auto with curved labels (#3151) - Fixed msRemoveHashTable function when 2 keys have the same hash (#3146) - Fix raster thread deadlock condition on posix/linux (#3145) - Do not route thread debug output through msDebug which requires locking. - Fix WCS coverage metadata handling if size/resolution missing (#2683). - Fix WCS crash with use of datasets that aren't physical files (#2901). - Fix WCS failure with WCS 1.1 OGC URN (urn:ogc:def:crs:OGC::CRS84) (#3161). Version 5.6.0-beta2 (2009-10-01): --------------------------------- - Fixed a couple of issues with Oracle Spatial and single pass queries (#3069) - Added layer.resultsGetShape() to PHP MapScript for use with queries (#3069) - Fixed query maps under the new single pass query process (#3069) - WFS Client seg fault (OGR layer not opened) (#3136) - Reduce use of sqrt() calls when determining distances (#3134) - support axis ordering for WFS 1.1 (#2899) - const changes to avoid warnings with msLoadProjectionString() - mapgd.c: removed unused drawVectorSymbolGD() function. - Use http://www.mapserver.org/mapserver namespace URI in XML mapfile schema (#3142) - Fixed issue with PHP_REGEX_INC in mapscript/php3/Makefile.in (#3078) Version 5.6.0-beta1 (2009-09-23): --------------------------------- - WMS 1.3.0 expects a CRS parameter instead of SRS (#2979) - Allow users to set wms getmap and getlegendgraphic image format list (#455) - Fixed MapScript shapeObj->toWkt() segfaults (#2763) - add vertical bar charts to dynamic charting (#3128) - Get the intersection points and labels #3101 - Fixed shp2img not to cause a crash when the map couldn't be loaded - Fix problem with overflowing shape->index for (most) query modes (#2850) - Useful error message when PK is missing and data is subselect (#3124) - Add WMS root Layer metadata support (#3121) - Fixed build problem of PHP/Mapscript when php is compiled with gd as a shared extension (#3117) - Improve safety of srcx/y checks in nearest neighbour raster resampler (#3120) - Added support for 4d geometry types and oci bind variables for Oracle (#3107) - Implement SECTION support for the WCS 1.1 GetCapabilities request (#3105) - Fixed WCS processing when both crs and response_crs are specified (#3083) - Fixed msFreeMap causing memory corruption in msFreeOutputFormat (#3113) - Fix WMC XML output when Dimension is used (#3110) - Enable LOAD_WHOLE_IMAGE processing option by default when rendering WMS client layer images (#3111). - add default values for CGI %key% substitutions (#3108) - fix clipping of polygon shapes in line layers (#3059) - RFC 51 implementation: XML Mapfiles Format (#2872) - Fix output for valid WCS 1.1 XML (#3086) - Avoid double free with postgresql joins. (#2936) - Don't attempt to project layers given in pixel coordinates (layer->transform != MS_TRUE) (#3096) - Modify loading imagery from GDAL to load all bands at once to avoid multiple passes through pixel interleaved data (mapdrawgdal.c). This is just an optimization - there should be no change in results or features. - Modern GDALs clear the config when destroying driver manager. Skip this call to avoid TLS leakage on cleanup (mapgdal.c). - Fixed msMSSQL2008LayerGetShape to retrieve proper wkb geometries (#3082) - Fixed the shape index for the inline layers (#3074) - Fixed MINDISTANCE not considering label size on lines (#3050) - Labeling enhancements: ability to repeat labels along a line/multiline (#3030) - Modified STYLEITEM code to use the new way of rendering thick lines (#3025) - Fixed template processor to respect layer order. (#2619) - Add MS_DEBUGLEVEL and MS_ERRORFILE commandline switches for mapserv.c. - Exposed msMapOffsetExtent, msMapScaleExtent and msMapSetCenter methods in PHP/Mapscript (#2460) - Removed ZEND_DEBUG define in PHP/Mapscript (#2717) - Fixed PHP/Mapscript to support PHP 5.3 (#3065, #3066) - remove -O optimization flags to configure script if configured with --enable-debug - Fixed performance bottleneck when computing a polygon center of gravity for label point computation. (#3053) - make WFS numberOfFeatures match maxFeatures if passed (#2907) - Add logging in layer visibility tests to help users find why layers don't draw (#3054) - include PNG libs first (#3046) - merge graphics branch: RFC54 implementation, cairo rendering (png, svg, pdf), opengl rendering (non functionnal yet) - Do pre-emptive test for map.extent/layer.extent interaction (#3043) - Add centroid geomtransform (#2825) - Test database connections before using them (#2932) - Support non-numeric join criteria (#2006) - Ensure there's enough room in the SQL to hold a long (#1284) - Fix filter error in multi-clause filters (#2937) - Fix agg freetype character lookup when no unicode charmap is present (#3018) - Fix memory leak in SQL building (#2997) - Fork AGG rendering library in our trunk - Fixed a memory leak when unescaping quotes in logical expressions (#2938) - Fixed template code for item, shpxy and extent tags to properly initialize tag arguments in cases where there are mutiple tags in one chunk of template (#2990) - Fix mapogcfilter.c not to cause syntax error if PROJ.4 is not compiled in (#2987) - Rework Python MapScript's setup.py to be more like Python's to fix a number of issues including (#2637) and to use mapserver-config and ditch the old mapscriptvars approach - Prevent from changing the connection type to MS_RASTER when setConnectionType(MS_WMS) is used (#2908) - Improve rounding logic for computing the src_xoff/yoff (#2976) - Fix filename path processing for raster queries and WCS get coverage so that non-filesystem filenames are not altered (#2901) - Improved security relative to untrusted directories and mapfiles (RFC 56) - Fixed several security issues found in an audit of the CGI application (#2939, #2941, #2942, #2943, #2944) - setConnectionType(MS_WMS) doesn't work with mapscript (#2908) - Perl Mapscript: improvement of imageObj wrapper (#2962) - Improve control of output resolution (RFC 55, #2948) - mapraster.c: use GDALOpenShared(), and CLOSE_CONNECTION=DEFERRED (#2815) - AGG font outline method change (#1243) - Change mapbit.c bitmask type from char to new 32bit ms_bitarray (#2930) - Added resolution writing in image files (#2891) - Try to save resolution values to GeoTIFF via GDAL (#2891) - Refactor legend icon drawing (remove renderer specific versions) Add label styling or markers for annotation layer legend icons (#2917) - Update EXTENT warning message (#2914) - add support for SRSNAME parameter (#2899) - add support for resultType (#2907) - WFS 1.1.0 should use OWS Common 1.0.0 (#2925) - clean up GEOS init and cleanup functions (#2929) - add support for disabling SLD (#1395) - fix to output gml:boundedBy again (#2907) - fix warning for change in bitmask type (#2930) - fix time advertising in WMS 1.3.0 (#2935) - fix SOS blockSeparator output (#3014) - fix MIME type support (#3020) Version 5.4.0-beta3 (2009-3-5): -------------------------------- - SLD: Correct crash with large class names (#2915) - Added Java MapScript WIN64 support (#2250) - Fixed a problem with long running processes, embedded scalebars/legends and AGG. (#2887) - Applied patch to deal with a couple of WCS issues (time ranges, #2487) and PostGIS tileindex-based time filters (#1856) - Adding -DUSE_GENERIC_MS_NINT to the WIN64 MapScript builds (#2250) - Fixed C# the compiler options for MSVC 2008 (#2910) - Fix build problem with mapogcsld.c when OWS services are not available (#473) - Fix build on windows (maputil.c) Version 5.4.0-beta2 (2009-2-25): -------------------------------- - Fixed a problem where default shade symbols (solid fill, no size) were being scaled and not rendered as expected (related to #2896 I believe) - Fixed a problem with offset polylines (AGG only) (#2868) - Generate SLD version 1.1.0 (#473) - Tracking original geometry type so we can make better decisions on what positions to use with POSITION AUTO and annotation layers. (#2770) - Setting up the same size units between the OGR auto-style and the OGR label attribute binding option (#2900) - Take better care of the extra items with the inline layers to prevent from memory corruption (#2870) - Fixed the compiler options for MSVC 2008 (#2898) Version 5.4.0-beta1 (2009-2-18): -------------------------------- - restored much of the pre-5.0 capabilities to update a mapfile via URL but in a more secure manner (RFC44) - WMS 1.3.0 support added (#473) - OWS GetCapabilities should skip layers with status == MS_DELETE (#2582) - Set the default symbol size to 1 instead of 0 (#2896) - fix WMS LegendURL to print sld_version for 1.3.0 Capabilities (#473) - add GetSchemaExtension to WMS to support GetStyles in Capabilities XML (#473) - move xlink declaration to root of WMS 1.3.0 DescribeLayerResponse - Fixed a scalebar rounding problem causing to draw zero scalebar width (#2890) - SLD: if it contains a Filter Encoding tag, try to always set the layer's FILTER element (#2889) - Add support for rendering INLINE layers with layer attributes (items) (#2870) - Fix mapserver crash when rendering a query map in HILITE mode and there are is no STYLE defined (#2803) - Added projection support to [...ext] tags for template output. - Removed the error generation when the OGR layer contains no fields (#2883) - Added enhancements to mapogr.cpp for style annotations (#2879) - Fixed memory leaks when using msUpdate*FromString methods. (#2857) - Fixed the problem when removing the attribute binding in mapscript. - SOS XML validity fixes (#2646) - add WFS calls for schema resolution (#2646) - add gml:id to om:Observation (#2646) - fix some XML validity issues (#2646) - Fixed endianness issues with wide character strings for ArcSDE (#2878). Thanks Russell McOrmond - Fixed WMS request with LAYERS parameter: may cause segmentation fault (#2871) - fix when layer status = DEFAULT and passing list of layers (#2066) - Fixed msAddLabel may cause access violation in certain conditions - Changed base type of labelObj size, minsize and maxsize from int to double (#2766) - add support for WMS Server title in LAYER object (#885) - Fixed build problem using --with-gd=static and freetype (#2697) - RFC49 implementation (#2865) - Fixed Blobs not filtered in OracleSpatial Attribute/WFS queries (#2829) - Fixed memory leak of map::setProjection in PHP/MapScript (#2861) - Fixed "internal PHP GC memory leaks" in PHP/MapScript (#2767) - Fixed bug with wms layer group hierarchy (#2810) - Added updateFromString() methods for several objects in PHP/Mapscript (#2298) - Added ms_newMapObjFromString mapObj constructor in PHP/Mapscript (#2399) - Add support to compile mssql2008 when SDE or ORACLE is not compiled (#2851) - Add support for creating debug builds for the plugins on Windows - Correct half pixel error in WMS layer's BBOX request to remote WMS (#2843) - Expose Map/Layer's Projection objects in PHP/MapScript (#2845) - Added getUnits() methods to projectionObj in Mapscript (#2798) - Improved Tag parsing in template code. (#2781) - Added hashtable object and metadata methods for php-mapscript (#2773) - mappostgis.c: Fix trailing spaces in fixed varchar fields (#2817) - RFC48 implementation: GEOMTRANSFORM on styleObj (#2825) - mapwms.c: cleanup warnings with recent gcc versions (#2822) - mapogcsos.c: Cleanup warning and error messages - mapagg.cpp: Fix center of rotation for truetype marker symbols - mapowscommon.c: use msLibXml2GenerateList to generate listed XML elements - mapowscommon.c: output version string correctly (#2821) - Added removeLayer function to mapObj in PHP/MapScript. (#762) - Exposed PIXELS value via URL configuration - Add Support for SLD TextSymbolizer HALO and ANGLE (#2806) - IGNORE_MISSING_DATA: largely replaced by run-time CONFIG property, ON_MISSING_DATA, which supports three modes: FAIL, LOG, and IGNORE. (#2785) ms-rfc-47.txt - mapstring.c: msStringTrim(*char str), front-and-back whitespace trimmer - mappostgis.c: re-write to remove binary cursors and break up logic into smaller parts, add support for maxfeatures - mapogcfilter.c: increase array size (code was assigning to out of bounds subscript) - MapScript: Added getBinding method to label and style object (#2670) - mapowscommon.c: use strcasecmp to check for language value - raster query fix for tileindex with relative paths (#2722) - Fixed msOGRGetValues function to return default values if the object type is not TEXT. (#2311) - Fix for the access violation caused by msMSSQL2008LayerGetShape (#2795) - Fixed msMSSQL2008LayerGetItems to retrieve the column names properly (#2791) - Prevent from calling msMSSQL2008CloseConnection from msMSSQL2008LayerClose causing memory corruption issues (#2790) - new polygon label placement algorithm (#2793) - stop drawing an artificial outline around polygons to ensure continuity - users needing this feature will have to explicitely add an outlinecolor of the same color as the fill color - added formatoption QUANTIZE_NEW to force going through the pngquant quantization algorithm instead of the GD one for imagemode RGB (the GD one can be kind of buggy) - fix some integer rounding errors in the agg line offseter (#2659) - fix a bug with shapes with duplicate end points. was causing nans in the angle follow placement code (#2695) - refactor msGetLabelSizeEx (now merged with msGetLabelSize) (#2390) - native label size computation for AGG when using angle follow (#2357) - memory leak in msInsertLayer, from Ned Harding (#2784) - label size computation refactoring (#2390) - don't draw label background if we're using angle follow. (#2726) - legend keyimage resampling with agg (#2715) - tileindexed rasters when DATA is manipulated via mapscript work (#2783) - styleObj width now supports attribute binding - RFC40 implementation: label text wrapping and alignment (#2383) - baseline adjustment for multiline labels (#1449) - Added support to access to the labelObj OUTLINEWIDTH property in PHP/MapScript - PHP paste image should also work with AGG (#2682) - Fixed bug when QUERYMAP hilite color is set and the shape's color in a layer is from a data source (#2769) - Decoupled AUTO label placement from the positions enum in mapserver.h. Added explicit case for POLYGON layers where CC is the default and then we try UC, LC, CL and CR. (#2770) - Changed base type of styleObj size and width from int to double (#2766) - Correct allocation error in mapmssql2008.c - Add possibility to use a full resolution setting for svg output (#1706) - Fixed GetFeature through tileindex bug: the tileindex of the shape found wasn't set properly in the resultcache object. (#2359) - Removed comma to correct WCS 1.1 Coverages formatting in payload directory. (#2764) - Correct bug when LABEL_NO_CLIP in combination with minfeaturesize (#2758) - Fix a label size computation for AGG bug when scalefactor is used (#2756) - various SOS updates for CITE compliance (#2646) - Added support for static linking with the lib gd in configure script (#2696) - Support OpenLayer's ol:opacity extension to OGC Web Map Context docs (#2746) - Added MS_VERSION_NUM for use with #if statements in code based on libmapserver (#2750) - Fixed the configure script: failed to detect php5 on ubuntu. (#2365) - Fixed a memory leak associated with not deleting the lexer buffer before parsing certain types of strings. (#2729) - Added legend graphics for layer of type annotation for the AGG and GD renderer (#1523) - Masking the out-of-range characters to avoid the crash in the AGG renderer (#2739) - Accept WMS requests in which the optional SERVICE parameter is missing. A new test was incorrectly added in 5.2.0 that resulted in the error "Incomplete WFS request: SERVICE parameter missing" when the SERVICE parameter was missing in WMS requests in which the SERVICE parameter is optional (#2737) - Support for the MapInfo style zoom layering option (#2738) - Implement Equals and GetHashCode properly for the mapscript C# classes - Expose msConnectLayer to the SWIG mapscript interface with a new layerObj.setConnectionType() method that should be used instead of setting the layerObj.connectiontype directly (#2735) - SLD: when creating well known symbols on the fly the pen-up value used should be -99. - SWF: Button names reflects the layer id and shape id (#2691) - Support reading projection parameter for OGC filters (#2712) - Several enhancements to STYLEITEM AUTO support for labels (#2708) and TTF symbols (#2721) in OGR layers - Expose special attributes OGR:LabelText, OGR:LAbelAngle, OGR:LabelSize and OGR:LabelColor to MapScript getShape() calls (#2719) Version 5.2.0 (2008-07-16): --------------------------- - mapfile.c: Fixed a bug that prevented using named symbols via URL configuration. (#2700) Version 5.2.0-rc1 (2008-07-09): ------------------------------- - mapowscommon.c: fix support multiple namespaces (#2690) - Fix OGC simple filters on SDE layers (#2685) - wfs11 getcapabilities: correct memory corruption (#2686) - Allow building against Curl 7.10.6 and older which lack CURLOPT_PROXYAUTH option required for *_proxy_auth_type metadata (#571) - Avoid fatal error when creating new ShapeFileObj with MapScript (#2674) - Fixed problem with WMS INIMAGE exceptions vs AGG output formats (#2438) - mapshape.c: Fixed integer pointer math being applied to uchars (#2667) - Fixed seg fault with saveImage() in PHP MapScript due to #2673 (#2677) - Fixed configure error related to new fribidi2 pkg-config support (#2664) - Fixed windows build problem (#2676) - Fix raster query bounds problem (#2679) Version 5.2.0-beta4 (2008-07-02): --------------------------------- - Added support in configure script for pkg-config for fribidi2 (#2664) - Added more debug/tuning output to mapserv and shp2img at debug level 2 (#2673) - maptemplate.c: removed extra line feeds from mime header output. (#2672) - mapresample.c: fix for bug 2540 when using raster resampling and AGG. - mapsde.c: Check at compile time that we have SE_connection_test_server, which appears to only be available for ArcSDE 9+ (#2665). - mapshape.c: restore old behavior of tiled shapes relative to shapepath with new behavior for when shapepath is undefined (#2369) - maputil.c: fix a bug for offset lines with agg, when the first segment was horizontal (#2659) - mapraster.c: fix for tiled rasters with relative shape paths defined, from dfurhy (#2369) - maptemplate.c: fixed a problem with extent tags with _esc extension not working (#2666) Version 5.2.0-beta3 (2008-06-26): --------------------------------- - mapsde.c: processing option added to allow using fully qualified names for attributes (#2423). - mapsde.c: Test for an active connection before closing it (#2498). - mapdraw.c: Fixed issue where path following labels were not being drawn if FORCEd. (#2600) - mapshape.c: Applied patch to make the location of tiled data relative to the tileindex directory if SHAPEPATH is not set. (#2369) - maptemplate.c: Fixed issues in RFC 36 implementation that prevented mapscript mapObj->processQueryTemplate() method from working. - WMS/WFS: extend warning message (#1396) - WFS: Respect units for the DWhitin parameter (#2297) - WFS: correct OGC Contains filter (#2306) - WMS: set srsName correctly for GetFeatureInfo (#2502) - SOS: detect invalid time strings (#2560) - SOS: more srsName support (#2558) - mapserv.c, maptemplate.c: fixed problem with arguments to msGenerateImages(). (#2655) - WMS: produce warning if layer extent is null (#1396) - WFS: project LatLongBoundingBox if required (#2579) - SOS: generate error for some invalid filters (#2604) - SLD: Use style's width paramater when generating sld (#1192) Version 5.2.0-beta2 (2008-06-18): --------------------------------- - mapogcsos.c: support invalid procedure in GetObservation (#2561) - Fixed possible buffer overrun with Oracle Spatial driver (#2572) - mapogcsos.c: support srsName in GetObservation (#2414) - Filter Encoding: Modify DWithin definition (#2564) - Added webObj legendformat and browseformat mapping in PHP MapScript (#2309) - Removed static buffer size limit in msIO_*printf() functions (#2214) - Fixed libiconv detection in configure for OSX 10.5 64 bit (#2396) - mapstring.c: possible buffer overflow in msGetPath (#2649) - maputil.c: Correct expression evaluation with text containing apostrophes (#2641) - mapwfs.c: Possibly generate an error message when applying filter encoding (#2444) - Added MS_LABEL_BINDING constants for SWIG MapScript (#2643) - mapogcsos.c: fix POST support (#2379) - maplibxml2.c: helper functions XML POST fix (#2379) - mapwfs.c: fix segfault when srsName is not passed on BBOX Filter (#2644) - mapwfs.c: do not return error for empty query results (#2444) - Remove C++-style comments and most other warnings thrown by -pedantic (#2598) - mapwfs.c/mapwfs11.c: set GML MIME type correctly - mapogcsos.c: advertise supported SRS list via MAP.WEB.METADATA.sos_srs (#2414) - mapwfs.c: set layer extent to map extent for default GetFeature requests with no spatial predicates (#1287) Version 5.2.0-beta1 (2008-06-11): --------------------------------- - WMS/WFS layers can now specify a proxy servert (#571) - mapwmslayer.c: set QUERY_LAYERS correctly (#2001) - mapwcs.c: handle PARAMETER values correctly (#2509) - SOS: fix various memory leaks (#2412) - mapwcs.c: advertise temporal support in GetCapabilities (#2487) - Fixed flaw in findTag() in maptemplate.c that prevented multiple tags on the same line being processed under certain conditions. (#2633) - Return results even when extents are missing (#2420) - Avoid displaying OGR connection strings in error messages (#2629) - WCS: respect wcs_name metadata for GetCoverage and DescribeCoverage requests (#2036) - CGI: added -nh option to allow for the suppression of content headers from the command line (#2594) - PostGIS: fix postgis idle-in-transaction problem (#2626) - AGG: enable ellipse symbol rotation for POINT/ANNOTATION layers (#2617) - RFC36: add more extensions to support templates (#2576) - AGG: allow dashed hatch symbols (#2614) - AGG: enable offset lines of type x -99 (#2588) - AGG: use an agg specific label size calculation function where possible (#2357) - mapogcsld.c: fetch TextSymbolizer/Label/ogc:PropertyName correctly (#2611) - Don't ignore .qix file when DATA reference includes .shp extension (#590) - CGI able to alter layers with space and underscores (#2516) - WFS Multipoint query with PostGIS bug fixed (#2443) - Tiling API (RFC 43) mode=tile, tilemode=spheremerc, tile=x y zoom (#2581) - Remove C++-style comments and most other warnings thrown by -pedantic (#2598) - Fix PostGIS transaction behavior in fcgi situations (#2497, #2613) - Improve performance for large shape files (#2282) - encode WMS parameters correctly (#1296) - Added alignment option within a scalebar (#2468) - RFC-42 HTTP Cookie Forwarding (#2566) - Fixed handling of encrypted connection strings in postgis driver (#2563) - mapagg.cpp: AGG: add opacity at the style level (#1155) - mapwms.c: add Cache-Control max-age HTTP header support (#2551) - mapogcsos.c: support URI encoded procedures correctly (#2547) - Added support for EMPTY template with WMS GetFeatureInfo (#546) - Throw an exception if the WCS request does not overlap layer (#2503) - Acquire TLOCK_PROJ for pj_transform() calls (#2533). - Fixed problem with large imagemaps generating no output (#2526) - mapwms.c: make version optional for GetCapabilities again (#2528) - support URN scheme for components of observed property elements (#2522) - Fixed gdImagePtr gdPImg memory leak in msSaveImageBufferGD() (#2525) - mapogcsos.c: handle invalid POST requests (#2521) - mapogcsos.c: handle ACCEPTVERSIONS parameter (#2515) - mapwcs.c/mapwcs11.c: s/neighbour/neighbor/g (#2518) - mapwms.c: relax FORMAT parameter restrictions for GetFeatureInfo (#2517) - mapwcs.c: support COVERAGE lists for DescribeCoverage (#2508) - mapwcs.c: fix lonLatEnvelope/@srsName (#2507) - mapwcs.c: omit VendorSpecificCapabilities (#2506) - mapwcs.c: test for either resx/resy OR width/height (#2505) - mapwcs.c: make GetCoverage demand one of TIME or BBOX (#2504) - mapwms.c: make GetLegendGraphic listen to TRANSPARENT in OUTPUTFORMAT (#2494) - OWS: support updatesequence (#2384) - mapwms.c: test VERSION after service=WMS (#2475) - OWS: output Capabilities XML updateSequence if set (#2384) - mapwcs.c: better handling of REQUEST parameter (#2490) - mapwcs.c: point to correct exception schema (#2481) - mapows.c: add version negotiation (#996) - mapwfs.c: return default GML2 when invalid OUTPUTFORMAT passed (#2479) - mapowscommon.c: add OWS Common style version negotiation (#996) - mapwcs.c: better section parameter handling for CITE (#2485) - mapwfs.c: point to the correct schema for exceptions (#2480) - shp2img.c/shp2pdf.c: clean up usage text, check for invalid layers (#2066) - completed implementation of RFC24 (#2442, #2032) - mapwcs.c: require VERSION parameter for DescribeCoverage and GetCoverage (#2473) - mapwcs.c: change error token to MS_WCSERR instead of MS_WMSERR (#2474) - mapwcs.c: set exception MIME type to application/vnd.ogc.se_xml for 1.0.0 (#2470) - mapwcs.c: Generate a decently formatted exception if an WCS XML POST request is received (#2476). - mapowscommon.c: support OWS Common 1.1.0 as well (#2071) - mapogcsos.c: support SOS 1.0.0 (#2246) - Implement mapObj.setCenter, mapObj.offsetExtent, mapObj.scaleExtent, rectObj.getCenter at the SWIG API (#2346) - mapogcfilter.c: use USE_LIBXML2 in ifdefs (#2416) - clean up naming conventions of Shapefile API (#599) - use msComputeBounds() instead, since it's already in the codebase (#2087) - set shapeObj bounds from WKT (#2087) - fixed issue where path following labels sometimes used the supplied setting for position. In all cases with ANGLE FOLLOW we want to force position MS_CC regardless of what is set in the mapfile. - enforce (-99 -99) to be the penup value for vector symbols (#1036) - Support for labeling features (polygon & line) prior to clipping. This results in stable label positions regardless of map extent. (#2447) - Support for quantization and forced palette png output with RGBA images (#2436) - SLD using a single BBOX filter should generate an SQL ststement for oracle/postgis/ogr (#2450) - Accurate Calculation of legend size for WMS LegendURL (#2435) - Converted mapogr.cpp to use OGR C API instead of C++ classes to allow GDAL/OGR updates without having to recompile MapServer (#545, #697) - add missing space on dashed polygon outlines with svg (#2429) - Restored behavior of MS 4.10 and made WMS STYLES parameter optional again in GetMap and GetFeatureInfo requests (#2427) - Speed up forced palette rendering (#2422) - WMS GetFeatureInfo: honour FEATURE_COUNT for any INFO_FORMAT and apply the FEATURE_COUNT per layer instead of globally (#2423, #1686) - enable soft outlines on truetype labels. This is triggered with a new keyword OUTLINEWIDTH for the LABEL block (#2417) - fix clipping rectangle to take width as well as size into account (#2411) - AGG: added and use a line and polygon adaptor to avoid copying shapeObj points to an agg path_storage. avoids a few mallocs and a few copies. - fixed symbolsetObj not to set the SWIG immutable flag permanently don't expose refcount and the symbol attributes (Ticket #2407) - fix for support of entity encoded text in angle follow text (#2403) - AGG: initial support for native computation of label sizes (#2357) - AGG: support text symbols specified by their character number (#2398) - AGG: fix angle orientation for various symbols - allow scientific notation for attributes binded to an int (#2394) - merge GD and AGG label cache drawing functions (#2390) - Enable AGG rendering of bitmap font labels instead of falling back to GD (#2387) - clean up treatment of encoding and wrap caracter - Fix legend label placement for multiline labels (#2382) - enforce WRAP parameter in legend label (#2382) - AGG: pixel level simplification for line and polygon shapes (#2381) - fixed blue/green color swapping for space delimited strings bound to an attribute. (bug 2378) - don't remove points that are checked as being colinear (#2366) - add initial(?) support for reading a pie chart's size from an attribute (#2136) - don't bail out in map parsing if the outputformat had to be modified (bug #2321) - use a renderer agnostic legend icon drawing function which switches to the GD or AGG specific one depending on the outputformat (#2348) - AGG: switch alpha buffer when drawing query layer - Fixed legend icons not drawing when using maxscaledenom - AGG: fix embedded scalebar rendering when using postlabelcache (#2327) - AGG: allow for fast and aliased rendering of simple lines and polygons thick lines and patterns (i.e. dashes)aren't supported. this is triggered when the symbol is of TYPE SYMBOL *and* its ANTIALIAS is off (wating to find a better solution to trigger this). - AGG: the pixmap of pixmap symbols is now cached in an agg-compatible state the first time it is accessed. this avoids rereading and retransforming it each time that symbol is used. - AGG: the imageObj now stores in what state it's alpha channel is in. The number ofmsAlphaGD2AGG/AGG2GD calls is now reduced, but most importantly each of these calls is usually just a check for this state and does no computation. - AGG: fixed a few artifacts in embedded legend rendering on rgba images. - Fixed modulus operator in the parser (#2323) - maprasterquery.c: Fix crash when queryies on done on raster layers with no styles (#2343) - maprasterquery.c: Modify msRASTERLayerOpen() to create a defaulted raster layer info if there isn't one, to avoid the errors about open only being supported after a query. Also wipe the raster layer info in case of an empty result set, or failures of a query to reduce likelyhood of leaking the raster layer info. - Improve out of memory handling in mapdrawgdal.c, and mapgd.c. (#2351) - Improve configuration logic for fastcgi (#2355). - WMS: image/wbmp should be image/vnd.wap.wbmp (#2360) - SOS: support maxfeatures for GetObservation requests (#2353) - mapdraw.c,mapquery.c: Reset layer->project flag for each full layer drawing or query so that need to reproject will be reconsidered (#673). - PHP MapScript: fix for getStdoutBufferString() and getStdoutBufferBytes() functions on win32 (#2401) - mapowscommon.c: fix namespace leak issues (#2375) - mapogcsos.c: add SWE DataBlock support (#2248) - mapogcsos.c: fix build warnings, namespace and schema pointers (#2248) - mappdf.c: support output in fastcgi case via msIO_fwrite() (#2406) - mapogcsos.c: Initial support for POST requests (#2379) and updated msSOSDispatch() handling - mapogr.cpp: Use pooling api to ensure per-thread sharing of connections only (#2408) - mapogcsos.c: change substituted variable from sensorid to procedure (#2409) - maplibxml2.c: Initial implementation of libxml2 convenience functions - configure: Modified so libxml2 support is requested for WCS and SOS, and is indicated by USE_LIBXML2 definition. Use @ALL_ENABLED@ in DEFINEs and mapscriptvars generation. - mapresample.c: Fixed support for multi-band data in RAW mode for bilinear and nearest neighbour resamplers (#2364). - mapdraw.c: Improve error reporting if a raster layer requested in a query map (#1842). - mapfile.c: add simple urn:ogc:def:crs:OGC::CRS84 support. Version 5.0.0 (2007-09-17) -------------------------- - AGG: Fix angle computation for truetype marker symbols on lines (#2316) - Fix support for bilinear resampling of raster data with AGG (#2303) Version 5.0.0-rc2 (2007-09-10) ------------------------------ - Prevent seg fault in msWMSLoadGetMapParams when request is missing (#2299) - Fixed calculation of scale in PHP MapScript mapObj.zoomScale() (#2300) - Fixed conflict between runtime substitution validation and qstring validation. - Fixed agg configure logic (now should work with --with-agg alone) (#2295) - Fixed interleaving of multi-band results for raster query (#2294). Version 5.0.0-rc1 (2007-09-05) ------------------------------ - Fixed "MinFeatureSize AUTO" labeling for polygon layers, works for polygon annotation layers too (#2232) - Fixed path following labels with short (2/3 character) strings (#2223) - AGG fix a bug when rendering polygons with tiled pixmaps - Added requirement to provide validation pattern for cgi-based attribute queries using the layer metadata key 'qstring_validation_pattern' (#2286) - Fixed msDebug causing a crash with VS2005 (#2287) - Added stronger checks on libpdf version in configure script (#2278) - Added msGetVersionInt() to MapScript (ms_GetVersionInt() in PHP) (#2279) - _isnan prototype for MSVC builds from #2277 - AGG: Fix a bug when rendering brushed lines with vector or pixmap symbols (artifacts could appear on outline) - AGG: Adjust symbol height when brushing a line with a vector symbol so that the line width isn't truncated - Only include process.h on win32 (non-cygwin) systems, moved from maptemplate.h to mapserver.h. (#2276) Version 5.0.0-beta6 (2007-08-29) -------------------------------- - Fixed problem with outline of polygons rendered twice with OGR STYLEITEM AUTO and AGG output (#2271) - Fixed problem compiling with only WMS/WFS client but none of the WMS, WFS, WCS or SOS server options enabled (#2272) - Fixed buffer overflow in handling of WMS SRS=AUTO:... (#1824) - AGG: render thick lines and polygon outlines with round caps and joins by default - Typo in mapfile writing (#2267) - Fixed mapping of class->keyimage in PHP MapScript (#2268) - Look for libagg under lib64 subdir as well in configure (#2265) - AGG: revert previous optimizations. now use caching of the rendering object to avoid the re-creation of some structures each time a shape is drawn - AGG: optimizations for faster rendering. we now do not initialize the font cache when no text is to be rendered - AGG: fixed rendering of polygons with holes (#2264) - AGG - raster layers: fix typo in mapresample.c that produced random background colors when using OFFSITE (#2263) - AGG: Fix a bug when rendering tiled polygons with truetype, pixmap or vector symbols (usually only affected bright colors) - Avoid passing null to msInsertHashTable in processLegendTemplate when layer.name or layer.group not specified (#2261) - Fixed problems with fonts in PDF output (#2142) - AGG: smooth font shadows Version 5.0.0-beta5 (2007-08-22) -------------------------------- - Fixed XSS vulnerabilities (#2256) - Allow building with AGG from source when libaggfontfreetype is missing. configure --with-agg=DIR now automatically tries to build agg_font_freetype.o from source if libaggfontfreetype is missing (#2215) - Fixed possible buffer overflow in template processing (#2252) - fix blending of transparent layers with RGBA images - AGG: speed up rendering of pixmap marker symbols - Implement OGR thread-safety via use of an OGR lock (#1977). - Fixed compile warnings (#2226) - Fixed mappdf.c compile warnings, PDF support was probably unusable before that fix (#2251) - Adding -DUSE_GENERIC_MS_NINT to the WIN64 builds (#2250) - Adding msSaveImageBuffer and use that function from the mapscript library instead of the renderer specific functions. (#2241) - Split each format into it's own element in WCS describe coverage results (#2244). - Support to run the mapscript c# examples on x64 platform (#2240) - Fixed problem introduced in 5.0.0-beta4: all HTML legend icons were empty white images (#2243) - Fixed WMS Client to always send STYLES parameter with WMS GetMap requests (#2242) - Fixed support for label encoding in SVG output (#2239) - Added support for label encoding in legend (#2239) - Fixed PHP MapScript layer->queryByAttributes() to not accept empty or null qitem arg (#480) - AGG: fixed incorrect rendering of pixmaps on MSB architectures (#2235) - Added layer.getFeature() in PHP MapScript with optional tileindex arg, and deprecated layer.getShape() to match what we had in SWIG (#900) - Added class.getTextString() and deprecated/renamed class.getExpression() and layer.getFilter() to class.getExpressionString() and layer.getFilterString() to match what we have in SWIG MapScript (#1892) Version 5.0.0-beta4 (2007-08-15) -------------------------------- - Updated msImageCreateAGG to only allow RGB or RGBA pixel models (#2231) - Fixed problem with symbol.setImagePath() when file doesn't exist (#1962) - Python MapScript failures (#2230) - msInsertLayer should not free the incoming layer anymore (#2229) - Include only parsed in the first mapfile (#2021) - Incorrect lookup of symbol in symbolset (#2227) - Mapfile includes and MapScript (#2089) - Fixed alignment of GetLegendGraphic output when mapfile contains no legend object (#966) - Fixed seg. fault when generaing HTML legend for raster layers with no classes (#2228). The same issue was also causing several Chameleon apps using HTML legend to seg fault (#2218) - Do not use case sensitive searches in string2list, which is used for msWhichItems (#2067) - Ensure that we can write AGG images with Python MapScript's write() method - Support unicode attributes for ArcSDE 9.2 and above (#2225) - GD: Truetype line symbolization should follow line orientation only if GAP is <=0 - AGG: Added truetype symbolization for lines and polygons - AGG: Draw an outline of size 1 of the fill color around polygons if an outlinecolor isn't specified (avoids faint outline) - Added summary of options at end of configure output (#1966) - Updated configure script to detect and require GEOS 2.2.2+ (#1896) - Renamed --enable-coverage configure option to --enable-gcov to avoid confusion with WCS or Arc/Info coverages (#2217) - Fixed --enable-gcov (formerly --enable-coverage) option to work with php_mapscript.so (#2216) - check for OGR support in if SLD is used (#1998) - msWMSLoadGetMapParams: fixed handling of required parameters (#1088) - if any of srs, bbox, format, width, height are NOT found, throw exception - if styles AND sld are NOT found, throw an exception - NOTE: this may cause issues with some existing clients who do not pass required parameters Version 5.0.0-beta3 (2007-08-08) -------------------------------- Known issues: - This beta contains significant improvements and fixes on the AGG rendering front. However some build issues remain on some platforms. Please see ticket #2215 if building with AGG support doesn't work with the default configure script: http://trac.osgeo.org/mapserver/ticket/2215 Bug fixes: - mapagg.cpp rewrite - the AGG renderer should now support all the GD features - Use AGG when requested for drawing the legend - Fixed problems with very large HTML legends producing no output (#1946) - Use OGR-specific destructors for objects that have them rather than 'delete' (#697) - Include style-related info in HTML legend icon filenames to solve issues with caching of icons when the class or style params are changed (#745) - Fixed issues with wms_layer_group metadata in WMS GetCapabilities (#2122) - Use msSaveImageBufferAGG for AGG formats in getBytes (#2205). - Make sure to emit $(AGG) to mapscriptvars because of conditional inclusion of stuct members to imageObj. (#2205) - Make imageextra field in imageObj not conditional (not #ifdef'ed) (#2205) - AGG/PNG and AGG/JPEG are the only valid agg drivers. Imagetypes aggpng24 and aggjpeg can be used to refer to the default output formats. (#2195) - Fix memory leak with labepath object (#2199) - Fix memory leak msImageTruetypePolyline (#2200) - SWF: Fix incorrect symbol assignements (#2198) - Fixed memory leaks in processing of WFS requests (#2077) - Avoid use of uninitialised memory in msCopySymbol() (#2194) Version 5.0.0-beta2 (2007-08-01) -------------------------------- - Oracle Spatial: Fixed some issues related with the maporaclespatial.c source code: warnings with calls in gcc 4.x versions (#1845), gtype translation error, generating memory problem (#2056), problems with items allocation (#1961 and #1736), and some memory-leaks errors (#1662). - AGG: Fixed a significant number of rendering issues including conflicts with OPACITY ALPHA and ANTIALIAS TRUE settings w/regards to polygon fills. Fixed ellipse and vector markers. Fixed AGG/GD alpha channel conflicts by writing conversion to/from functions. (#2191-partial, #2173, #2177) - SOS: Turn layer off if eventTime is not in the sos_offering_timeextent (#2154) - WFS: Correct bugs related to query by featureid support (#2102) - WMS: Add svg as a supported format for GetMap request (#1347) - WMS: Correct WMS time overriding Filter paramter (#1261) - Fix problem with LUT scaling ranges with explicit value for 255 (#2167). - WCS: Fixed resampling/reprojecting for tileindex datasets (#2180) - Fixed formatting of configure --help (#2182) - Fixed AGG configure option to use 'test -f' instead of 'test -e' which doesn't work on Solaris (#2183) - Fixed mapwms.c to support selecting AGG/ outputformats via FORMAT=. - Removed unused styleObj.isachild member (#2169) Version 5.0.0-beta1 (2007-07-25) -------------------------------- New features in 5.0: - MS RFC 19: Added Style and Label attribute binding - MS RFC 21: Raster Color Correction via color lookup table - MS RFC 27: Added label priority - MS RFC 29: Added dynamic charting (pie and bar charts) - MS RFC 31: New mechanism to load/set objects via URL using mapfile syntax - MS RFC 32: Added support for map rendering using the AGG library for better output quality Long time issues resolved in 5.0: - MS RFC 17: Use dynamic allocation for symbols, layers, classes and styles (got rid of the static limit on the number of instances of each in a map) - MS RFC 24: Improved memory management and garbage collection for MapScript - MS RFC 26: Terminology cleanup (layer transparency renamed to opacity, scale becomes scaledenom, symbol style becomes symbol pattern) - MS RFC 28: Enhanced the debug/logging mechanism to facilitate troubleshooting and tuning applications. Added support for multiple debug levels and more control on output location. Other fixes/enhancements in this beta: - Upgrade Filter encoding to use geos and support all missing operators (#2105) - Use of static color Palette support for gd output (#2096) - MapServer's main header file map.h has been renamed mapserver.h (#1437) - A mapserver-config script has been created - Single and double quotes escaping in string expressions used by FILTER. (Resolves tickets #2123 and #2141) - SLD: Support of Graphic Stroke for a Linesymbolizer (#2139) - GD : draw symbols along a line using pixmap symbols (#2121) - SVG : Polygons should not be filled if color is not given (#2055) - WMS : fixed request with a BBOX and and SLD containing Filter encoding (2079) - SWF : use highlight color from querymap (2074) - Support for embedding manifests as resources for the VS2005 builds. (ticket #2048) - Changed OGRLayerGetAutoStyle not to pass NULL pointer to GetRGBFromString causing access violation (bug 1950). - Fix SDE returning the row_id_column multiple times (bug 2040). - Fix text outline bug. (bug 2027) - Improve error reporting when OWS services are requested but the support is not compiled in. (bug 2025) - Fix support for OFFSITE for simple greyscale rasters (bug 2024). - [SLD] : Error on last class in raster class names based on the ColorMapEntry (bug 1844) - [Filter Encoding] : Check if Literal value in Filter is empty (bug 1995) - [SLD] : Else filters are now generated at the end of classes (bug 1925) - Enabled setting of a layer tileindex (e.g. map_layername_tileindex) via the CGI program. (bug 1992) - Added feature to the CGI to check runtime substitutions against patterns defined in layer metadata. (bug 1918) - Exposed label point computation to mapscript (bug 1979) - [SLD]: use the url as symbol name for external symbols (bug 1985) - [SLD] : support of mixing static text with column names (bug 1857) - maperror.c: fix for wrapping long in image errors, thanks to Chris Schmidt (bug 1963) - maperror.c: fix closing of stderr/stdout after writing error msg (bug 1970) - Preliminary implementation of RFC 21 (Raster Color Correction). - [SLD] : when reading an SLD, sequence of classes was reversed (Bug 1925) - Fixed a bug with SDE capability requests where we were double freeing because sde->row_id_column wasn't set to NULL in msSDELayerOpen - [OGC:SOS] : Fixed bugs realted to metadata and xml output (1731, 1739, 1740, 1741). Fixed bug with large xml output (bug 1938) - fixed performance problem in raster reprojection (bug 1944) - added msOWSGetLanguage function in mapows.c/h (bug 1955) - added mapowscommon.c/mapowscommon.h and updated mapogcsos.c to use mapowscommon.c functions (bug 1954) - added more Perl mapscript examples in mapscript/perl/examples/, most of which exemplify recently added GEOS functionality - php_mapscript.c: Fixed setRotation() method to check for MS_SUCCESS, not MS_TRUE (bug 1968) - mapobject.c: Fixed msMapSetExtent() to avoid trying to calcuate the scale if the map size hasn't been set yet (bug 1968) - mapobject.c: ensure msMapComputeGeotransform() returns MS_FAILURE, not MS_FALSE (bug 1968) - mapdraw.c: Actually report that we aren't configure with wms client support if that is why we can't draw a layer. - mapows.c: fixed XML error (bug 2070) - mapwms.c: Fixed text/plain output duplicate (bug 1379) - mapwms.c: Attribution element output in GetCapabilities only 1.0.7 and higher (bug 2080) - mapwms.c: UserDefinedSymbolization element output in GetCapabilities only 1.0.7 and higher (bug 2081) - mapwms.c: GetLegendGraphic and GetStyles only appear in 1.1.1 and higher responses (bug 1826) - mapwcs.c: - msWCSDescribeCoverage: throw Exception if Coverage doesn't exist (bug 649) - msWCSException: updated as per WCS 1.0 Appendix A.6 - mapogcsos.c: Added ability to output gml:id via MAP/LAYER/METADATA ows/sos/gml_featureid (bug 1754) - mapcontext.c: Added ogc namespace (#2002) - Note that starting with this release the source code is now managed in Subversion (SVN) instead of CVS and we have migrated from bugzilla to Trac for bug tracking. Version 4.10.0 (2006-10-04) --------------------------- - No source code changes since 4.10.0-rc1 Known issues in 4.10.0: - PHP5 not detected properly on Mandriva Linux (bug 1923) - Mapfile INCLUDE does not work with relative paths on Windows (bug 1880) - Curved labels don't work with multibyte character encodings (bug 1921) - Quotes in DATA or CONNECTION strings produce parsing errors (bug 1549) Version 4.10.0-RC1 (2006-09-27) ------------------------------- - SLD: quantity values for raster sld can be float values instead of just being integer - Hiding labelitemindex, labelsizeitemindex, labelangleitemindex from the SWIG interface (bug 1906) - Fixed computation of geotransform to match BBOX (to edges of image) not map.extent (to center of edge pixels). (bug 1916) - mapraster.c: Use msResampleGDALToMap() for "upside down" images. (bug 1904) Version 4.10.0-beta3 (2006-09-06) --------------------------------- - Web Map Context use format metadata when formatlist not available. (bug 1723) - Web Map Context boolean values true/false now interpreted. (bug 1692) - Added support for MULTIPOLYGON, MULTILINESTRING, and MULTIPOINT in msShapeFromWKT() when going through OGR (i.e. GEOS disabled) (bug 1891) - Fixed MapScript getExpressionString() that was failing on expressions longer that 256 chars (SWIG) and 512 chars (PHP). (bug 1428) - WMSSLD: use Title of Rule if Name not present (bug 1889) - Fixed syntax error (for visual c++) in mapimagemap.c. - Fixed mapgeos.c problems with multipoint and multilinestring WKT (bug 1897). - Implemented translation via OGR to WKT for multipoint, multiline and multipolygon (bug 1618) Version 4.10.0-beta2 (2006-08-28) --------------------------------- - Applied patch supplied by Vilson Farias for extra commas with imagemap output (bug 760). - Fixed possible heap overflow with oversized POST requests (bug 1885) - Set ./lib and ./include properly for MING support (bug 1866) - More robust library checking on OSX (bug 1867) - Removed mpatrol support (use valgrind instead for something similar and less intrusive). (bug 1883) - Added mapserver compilation flags to the SWIG c# command line (bug 1881) - Fix OSX shared library options for PHP (bug 1877). - Added setSymbolByName to styleObj for the SWIG mapscript in order to set both the symbol and the symbolname members (bug 1835) - Generate ogc filters now outputs the ocg name space (bug 1863) - Don't return a WCS ref in WMS DescribeLayer responses when layer type is CONNECTIONTYPE WMS (cascaded WMS layers not supported for WCS) (bug 1874) - Correct partly the problem of translating regex to ogc:Literal (bug 1644) - schemas.opengeospatial.net has been shutdown, use schemas.opengis.net instead as the default schema repository for OGC services (bug 1873) - MIGRATION_GUIDE.TXT has been created to document backwards incompatible changes between 4.8 and 4.10 - Modify mapgd.c to use MS_NINT_GENERIC to avoid rounding issues. (bug 1716) - added --disable-fast-nint configure directive (bug 1716) - Fixed php_mapscript Windows build that was broken in beta1 (bug 1872) - Supported tag in SLD label (Bug 1857) - Use the label element in the ColorMapEntry for the raster symbolizer (Bug 1844) - Adding Geos functions to php mapscript (bug 1327) - Added a type cast to msio.i so as to eliminate the warning with the SWIG unix/osx builds - Fixed csharp/Makefile.in for supporting the OSX builds and creating the platform dependent mapscript_csharp.dll.config file. - Fixed error in detection of libpdf.sl in configure.in (bug 1868). Version 4.10.0-beta1 (2006-08-17) --------------------------------- - Marking the following SWIG object members immutable (bug 1803) layerObj.metadata, classObj.label, classObj.metadata, fontSetObj.fonts, legendObj.label, mapObj.symbolset, mapObj.fontset, mapObj.labelcache, mapObj.reference, mapObj.scalebar, mapObj.legend, mapObj.querymap mapObj.web, mapObj.configoptions, webObj.metadata, imageObj.format, classObj.layer, legendObj.map, webObj.map, referenceMapObj.map labelPathObj was made completely hidden (according to Steve's suggestion) - Fixed problem with PHP MapScript's saveWebImage() filename collisions when mapscript was loaded in php.ini with PHP as an Apache DSO (bug 1322) - Produce warning in WFS GetFeature output if ???_featureid is specified but corresponding item is not found in layer (bug 1781). Also produce a warning in GetCapabilities if ???_featureid not set (bug 1782) - Removed the default preallocation of 4 values causing memory leaks. (related to bug 1801) Added initValues to achieve the similar functionality if needed. - Fixed error in msAddImageSymbol() where a symbol's imagepath was not set (bug 1832). - Added INCLUDE capability in mapfile parser (bug 279) - Revert changes to mapzoom.i that swapped miny and maxy (Bug 1817). - MapScript (swig) creation of an outputFormatObj will now set the inmapfile flag so that it gets written out to saved maps by default (Bug 1816). - Converted GEOS support to use the GEOS C-API (versiopn 2.2.2 and higher). Wrapped remaining relevant GEOS functionality and exposed via SWIG-based MapScript. - If a layer has wms_timedefault metadata, make sure it is applied even if there is no TIME= item in the url. (Bug 1810) - Support for GEOS/ICONV/XML2 use flags in Java Makefile.in (related to bug 1801) - Missing GEOS support caused heap corruption using shapeObj C# on linux (Bug 1801) - Fix time filter propogation for raster layers to their tileindex layers. New code in maprasterquery.c (bug 1809) - Added logic to collect LD_SHARED even if PHP not requested in configure. - Fix problems with msio/rfc16 stuff on windows. Don't depend on comparing function pointers or "stdio" handles. (mapio.c, mapio.h, msio.i) - Support WMC Min/Max scale in write mode (bug 1581) - Fixed leak of shapefile handles (shp/shx/dbf) on tiled layers (bug 1802) - Added webObj constructor and destructor to swig interface with calls to initWeb and freeWeb (bug 1798). - mapows.c: ensure msOWSDispatch() is always available even if there are no services to dispatch. This makes mapscript binding easier. - FLTAddToLayerResultCache wasn't properly closing the layer after it was done with it. - Added ability to encrypt tokens (passwords, etc.) in database connection strings (MS-RFC-18, bug 1792) - Fixed zoomRectangle in mapscript: miny and maxy were swapped, making it impossible to zoom by rect; also the error message was referring to the wrong rect. There were no open issues on bugzilla. Reverted because of 1817. - Implementation of RFC 16 mapio services (bug 1788). - Use lp->layerinfo for OGR connections (instead of ogrlayerinfo) (bug 331) - Support treating POLYGONZ as MS_SHAPE_POLYGON. (bug 1784) - Complete support for international languages in Java Mapscript (bug 1753) - Output feature id as @fid instead of @gml:id in WFS 1.0.0 / GML 2.1.2 GetFeature requests (bug 1759) - Allow use of wms/ows_include_items and wms/ows_exclude_items to control which items to output in text/plain GetFeatureInfo. Making the behavior of this INFO_FORMAT consistent with the new behavior of GML GetFeatureInfo output introduced in v4.8. (bug 1761) IMPORTANT NOTE: With this change if the *_include_items metadata is not specified for a given layer then no items are output for that layer (previous behavior was to always all items by default in text/plain) - Make sure mappostgis.c closes MYCURSOR in layer close function so that CLOSE_CONNECTION=DEFER works properly. (bug 1757) - Support large (>2GB) raster files relative to SHAPEPATH. (bug 1748) - Set User-Agent in HTTP headers of client WMS/WFS connections (bug 1749) - Detection of os-dependent Java headers for Java mapscript (bug 1209) - Preventing to take ownership of the memory when constructing objects with parent objects using C# mapscript (causing nullreference exception, Bug 1743) - SWF: Adding format option to turn off loading movies automatically (Bug 1696) - Fixed FP exception in mapgd.c when pixmap symbol 'sizey' not set (bug 1735) - Added config file for mapping the library file so the DllImport is looking for to its unix equivalent (Bug 1596) Thanks to Scott Ellington - Added /csharp/Makefile.in for supporting the creation of Makefile during configuration with MONO/Linux (fix for bug 1595 and 1597) - Added C# typemaps for char** and outputFormatObj** - Support for dispatching multiple error messages to the MapScript interface (bug 1704). - Fix inter-tile "cracking" problem (Bug 1715). - OGC FILTER: Correct bug when generating an sql expression containing an escape character. - Allow a user to set a PROCESSING directive for an SDE layer to specify using the attributes or spatial index first. (bug 1708). - Cheap and easy way of fudging the boundary extents for msSDEWhichShapes in the case where the rectangle is really a point (bug 1699). - Implement QUANTIZE options for GD/PNG driver (Bug 1690, Bug 1701). - WMS: Publish the GetStyles operation in the capabilities document. - PHP_MAPSCRIPT: Add antialias parameter in the style object (Bug 1685) - WFS: Add the possiblity to set wfs_maxfeatures to 0 (Bug 1678) - SLD: set the default color on the style when using default settings in PointSymbolizer. (bug 1681) - Incorporate range coloring support for rasters (bug 1673) - Fixed mapthread.c looking for the unix compiler symbol rather than just testing whether or not _WIN32 is defined for the usage of posix threads because unix is not defined on compilers like GCC 4.0.1 for OS X. - Fixed the fuzzy brush support so that the transition between 1 pixel aa lines and brushes is less obvious. The old code would not allow for a 3x3 fuzzy brush to be built. (bug 1659) - Added missing mapscript function msConnPoolCloseUnreferenced() (bug 1661) We need to make conn. pooling handling transparent to mapscript users so that they do not have to call this function once in a while, for instance by creating an evictor thread. - Added calls to msSetup/msCleanup() at MapScript load/unload time (bug 1665) - Reorganized nmake.opt to be more focused on functionality groups rather than the propensity of a section to be edited. Default values are now all set to be pointed at the MapServer Build Kit, which can be obtained at http://hobu.stat.iastate.edu/mapserver/ - configure.in/Makefile.in: Use PROJ_LIBS instead of PROJ_LIB. PROJ_LIB is sometimes defined in the environment, but points to $prefix/share/proj not the proj link libraries. - Update Web Map Context to 1.1.0, add the dimension support. (bug 1581) - Support SLD body in context document. (bug 887) - When generating an ogc filter for class regex expressions, use the backslah as the default escape character (Bug 1637) - Add connectiontype initialization logic when the layer's virtual table is initialized (Bug 1615) - Added modulus operator to mapparser.y. - Added new support for [item...] tag in CGI-based templates (bug 1636) - Reverted behaviour to pre-1.61: do not allow for use of the FILTERITEM attribute (bug 1629) - Treat classindex as an int instead of a char in resultCacheMemberObj to prevent problems with more than 128 classes (bug 1633) - WMS : SLD / stretch images when using FE (Bug 1627) - Add gml:lineStringMember in GML2 MultiLineString geometry (bug 1569). - PHP : add shape->sontainsshape that uses geos lib (Bug 1623). - Move gBYTE_ORDER inside the pg layerinfo structure to allow for differently byte ordered connections (bug 1587). - Fix the memory allocation bug in sdeShapeCopy (Bug 1606) - Fixed OGR WKT support (Bug 1614). - Added shapeObj::toWkt() and ms_shapeObjFromWkt() to PHP MapScript (bug 1466) - Finished implementation of OGR Shape2WKT function (Bug 1614). - Detect/add -DHAVE_VSNPRINTF in configure script and prevent systematic buffer overflow in imagemap code when vsnprintf() not available (bug 1613) - Default layer->project to MS_TRUE even if no projection is set, to allow geotransforms (nonsquare pixels, etc) to be applied (bug 1645). - Force stdin into binary mode on win32 when reading post bodies. (bug 1768) Version 4.8.0-rc2 (2006-01-09) ------------------------------ - Commit fix for GD on win32 when different heaps are in use. (Bug 1513) - Correct bound reprojection issue with ogc filer (Bug 1600) - Correct mapscript windows build problem when flag USE_WMS_SVR was not set (Bug 1529) - Fix up allocation of the SDE ROW_ID columns and how the functions that call it were using it. (bug 1605) - Fixed crash with 3D polygons in Oracle Spatial (bug 1593) Version 4.8.0-rc1 (2005-12-22) ------------------------------ - Fixed shape projection to recompute shape bounds. (Bug 1586) - Fixed segfault when copying/removing styles via MapScript. (Bug 1565) - Fixed segfault when doing attribute queries on layers with a FILTER already set but with no FILTERITEM. Version 4.8.0-beta3 (2005-12-16) -------------------------------- - Initialize properly variable in php mapscript (Bug 1584) - New support for pseudo anti-aliased fat lines using brushes with variable transparency. - Arbitrary rotation support for vector symbols courtesy of Map Media. - Support for user-defined mime-types for CGI-based browse and legend templates (bug 1518). - mapraster.c: Allow mapresample.c code to be called even if projections are not set on the map or layer object. This is no longer a requirement. (Bug 1562) - Fix problem with WMS 1.1.1 OGC test problem with get capabilites dtd (Bug 1576) - PDF : adding dash line support (Bug 492) - Fixed configure/build problem (empty include dir) when iconv.h is not found (bug 1419) - PDF : segfault on annotation layer when no style is set (Bug 1559) - PostGIS layer test cases and fix for broken views and sub-selects (bug 1443). - SDE: Removed (commented out) support for SDE rasters at this time. As far as I know, I'm the only one to ever get it to work, it hasn't kept up with the connection pooling stuff we did, and its utility is quite limited in comparison to regular gdal-based raster support (projections, resampling, etc) (HB - bug 1560). - SDE: Put msSDELayerGetRowIDColumn at the top of mapsde.c so things would compile correctly. This function is not included (or necessary) in the rest of the MS RFC 3 layer virtualization at this time. - WFS : TYPENAME is manadatory for GetFeature request (Bug 1554). - SLD : error parsing font parameters with the keyword "normal" (Bug 1552) - mapgraticule.c: Use MIN/MAXINTERVAL value when we define grid position and interval (bug 1530) - mapdrawgdal.c: Fix bug with nodata values not in the color table when rendering some raster layers (bug 1541). - mapogcsld.c : If a RULE name is not given, set the class name to "Unknown" (Bug 1451) Version 4.8.0-beta2 (2005-11-23) -------------------------------- - Use dynamic allocation for ellipse symbol's STYLE array, avoiding the static limitation on the STYLE argument values. (bug 1539) - Fix bug in mapproject.c when splitting over the horizon lines. - Fix Tcl mapscript's getBytes method (bug 1533). - Use mapscript.i in-place when building Ruby mapscript, copying not necessary (bug 1528). - Expose maximum lengths of layer, class, and style arrays in mapscript (bug 1522). - correct msGetVersion to indicate if mapserver was build with MYGIS support. - Fixed hang in msProjectRect() for very small rectangles due to round off problems (bug 1526). Version 4.8.0-beta1 (2005-11-04) -------------------------------- - Bug 1509: Fixed bounding box calculation in mapresample.c. The bottom right corner was being missed in the calculation. - MS RFC 2: added OGR based shape<->WKT implementation. - mapgdal.c: fixed some mutex lock release issues on error conditions. - MS RFC 8: External plugin layer providers (bug 1477) - SLD : syntax error when auto generating external symbols (Bug 1508). - MS RFC 3: Layer vtable architecture (bug 1477) - wms time : correct a problem when hadling wms times with tile index rasters (bug 1506). - WMS TIME : Add suuport for multiple interval extents (Bug 1498) - Removed deprecated --with-php-regex-dir switch (bug 1468) - support wms_attribution element for LAYER's (Bug 1502) - Correct php/mapscript bug : initialization of scale happens when preparequery is called (Bug 1334). - msProjectShape() will now project the lines it can, but completely delete lines that cannot be projected properly and "NULL" the shape if there are no lines left. (Bug 411) - Expose msLayerWhichShapes and msLayerNextShape in MapScript. (bug 1481) - Added support to MapScript to change images in a previously defined symbol. (bug 1471) - mapogcfiler.c : bug 1490. Crash when size of sld filters was huge. - Fixed --enable-point-z-m fix in configure.in (== -> =) (bug 1485). - Extra scalebar layer creation is prevented with a typo fix in mapscale.c. Good catch, Tamas (bug 1480). - mapwmslayer.c : use transparency set at the layer level on wms client layers (Bug 1458) - mapresample.c: added BILINEAR/AVERAGE resampling options. - mapfile.c: avoid tail recursion in freeFeatureList(). - maplegend.c: fixed leak of imageObj when embedding legends. - msGDALCleanup(): better error handler cleanup. - Modified msResetErrorList() to free the last error link too, to ensure msCleanup() scrubs all error related memory. - Fix in msGetGDALGetTransform() to use default geotransform even if GDALGetGeoTransform() fails but alters the geotransform array. - Typemaps for C# to enable imageObj.getBytes() method (bug 1389). - Enable -DUSE_ZLIB via configure for compressed SVG output (bug 1307). - maputil.c/msAddLine(): rewrite msAddLine() to call msAddLineDirectly, and use realloc() in msAddLineDirectly() to optimize growth of shapeObjs. (bug 1432) - msTmpFile: ensure counter is incremented to avoid duplicate temporary filenames. (bug 1312) - SLD external graphic symbol format tests now for mime type like image/gif instead of just GIF. (bug 1430) - Added support for OGR layers to use SQL type filers (bug 1292) - mapio/cgiutil - fixed POST support in fastcgi mode. (bug 1259) - mapresample.c - ensure that multi-band raw results can be resampled. (bug 1372) - Add support in OGC FE for matchCase attribute on PropertyIsEqual and PropertyIsLike (bug 1416) - Fixed sortshp.c to free shapes after processing to avoid major memory leak. (bug 1418) - fixed msHTTPInit() not ever being called which prevented msHTTPCleanup() from properly cleaning up cUrl with curl_global_cleanup(). (bug 1417) - mapsde.c: add thread locking in msSDELCacheAdd - fixed mappool.c so that any thread can release a connection, not just it's allocator. (bug 1402) - mapthread.c/h: Added TLOCK_SDE and TLOCK_ORACLE - not used yet. - Fixed copying of layer and join items. (bug 1403) - Fixed copying of processing directives within copy of a layer. (bug 1399) - Problems with string initialization. (bug 1312) - Fix svg output for multipolygons. (bug 1390) - Added querymapObj to PHP MapScript (bug 535) Version 4.6.0 (2005-06-14) -------------------------- - Bug 1163 : Filter Encoding spatial operator is Intersects and not Intersect. - Fixed GEOS to shapeObj for multipolgon geometries. Version 4.6.0-rc1 (2005-06-09) ------------------------------ - Bug 1375: Fixed seg fault in mapscript caused by the USE_POINT_Z_M flag. This flag was not carried to the mapscript Makefile(s). - Bug 1367: Fixed PHP MapScript's symbolObj->setPoints() to correctly set symbolObj->sizex/sizey - Bug 1373: Added $layerObj->removeClass() to PHP MapScript (was already in SWIG MapScript) Version 4.6.0-beta3 (2005-05-27) -------------------------------- - Bug 1298 : enable Attribution element in wms Capabilities XML - Bug 1354: Added a regex wrapper, allowing MapServer to build with PHP compiled with its builtin regex - Bug 1364: HTML legend templates: support [if] tests on "group_name" in leg_group_html blocks, and for "class_name" in leg_class_html blocks. - Bug 1149: From WMS 1.1.1, SRS are given in individual tags in root Layer element. - First pass at properly handling XML exceptions from CONNECTIONTYPE WMS layers. Still needs some work. (bug 1246) - map.h/mapdraw.c: removed MAX/MIN macros in favour of MS_MAX/MS_MIN. - Bug 1341, 1342 : Parse the unit parameter for DWithin filter request. Set the layer tolerance and toleranceunit with paramaters parsed. - Bug 1277 : Support of multiple logical operators in Filter Encoding. - mapwcs.c: If msDrawRasterLayerLow() fails, ensure that the error message is posted as a WCS exception. - Added experimental support for "labelcache_map_edge_buffer" metadata to define a buffer area with no labels around the edge of a map (bug 1353) Version 4.6.0-beta2 (2005-05-11) -------------------------------- - Bug 179 : add a small buffer around the cliping rectangle to avoid lines around the edges. - Finished code to convert back and forth between GEOS geometries. Buffer and convex hull operations are exposed in mapscript. - fontset.fonts hash now exposed in mapscript (bug 1345). - Bug 1336 : Retreive distance value for DWithin filter request done with line and polygon shapes/ - Bug 985 / 1015: Don't render raster layers as classified if none of the classes has an expression set (gdal renderer only). - Bug 1344: Fixed several issues in writing of inline SYMBOLS when saving mapfile (missing quotes around CHARACTER and other string members of SYMBOL object, check for NULLs, and write correct identifiers for POSITION, LINECAP and LINEJOIN). Version 4.6.0-beta1 (2005-04-26) -------------------------------- - Bug 1305: Added support for gradient coloring in class styles - Bug 1335 : missing call to msInitShape in function msQueryByShape - Bug 804 : SWF output : Make sure that the layer index is consistent when saving movies if some of the layers are not drawn (because the status is off or out of scale ...) - Bug 1332 - shptreevis.c: fixed setting of this_rec, as the output dbf file was not getting any records at all. - Fixed Makefile.vc to make .exe files depend on the DLL, so if the DLL fails to build, things will stop. Avoids the need for unnecessary cleans on win32. Also fixed the rule for MS_VERSION for mapscriptvars. - Bug 1262 : the SERVICE parameter is now required for wms and wfs GetCapbilities request. It is not required for other WMS requests. It is required for all WFS requests. - Bug 1302 : the wfs/ows_service parameter is not used any more. The service is always set to WFS for WFS layers. - Bug 791: initialize some fields in msDBFCreate() - avoids crashes in some circumstances. - Bug 1329 : Apply sld named layer on all layers of the same group - Bug 1328 : support style's width parameter for line and polygon layers. - Bug 564: Fixed old problem with labels occasionally drawn upside down - Bug 1325: php mapscript function $class->settext needs only 1 argument. - Bug 1319: Fixed mutex creation (was creator-owned) in mapthread.c. win32 issue only. - Bug 1103: Set the default tolerance value based on the layer type. The default is now 3 for point and line layers and 0 for all the others. - Bug 1244: Removing Z and M parameter from pointObj by default. A new compilation option is available to active those option --enable-point-z-m. This gives an overall performance gain around 7 to 10%. - Bug 1225: MapServer now requires GD 2.0.16 or more recent - MapScript: shapeObj allocates memory for 4 value strings, shapeObj.setValue() lets users set values of a shapeObj. - MapScript: imageObj.getBytes() replaces imageObj.write() (bugs 1176, 1064). - Bug 1308: Correction of SQL expression generated on wfs filters for postgis/oracle layers. - Bug 1304: Avoid extra white space in gml:coordinates for gml:Box. - mapogr.c: Insure that tile index reading is restarted in msOGRLayerInitItemInfo() or else fastcgi repeat requests for a layer may fail on subsequent renders. - mapogr.c: Set a real OGRPolygon spatial filter, not just an OGRLinearRing. Otherwise GEOS enabled OGR builds will do expensive, and incorrect Intersects() tests. - mapogr.cpp / mapprimitive.c: Optimize msAddLine() and add msAddLineDirectly() - mapprimitive.c: Optimizations in msTransformShapeToPixel() (avoid division) - map.h: Made MS_NINT inline assembly for win32, linux/i86. - mapprimitive.c: optimized msClipPolygonRect and msClipPolylineRect for case where the shape is completely inside the clip rect. - Add support for SVG output. See Bug 1281 for details. - Bug 1231: use mimetype "image/png; mode=24bits" for 24bit png format. This makes it seperately selectable by WMS. - Bug 1206: Applied locking patch for expression parser for rasters. - Bug 1273: Fixed case in msProjectPoint() were in or out are NULL and a failure occurs to return NULL. Fixed problem of WMS capabilities with 'inf' in it. - SLD generation bug 1150 : replacing tag to - Fixed bug 1118 in msOWSGetLayerExtent() (mapows.c). - Fixed ogcfilter bug #1252 - Turned all C++ (//) comments into C comments (bug 1238) - mapproject.h/configure.in: Don't check for USE_PROJ_API_H anymore. Assume we have a modern PROJ.4. - Bug 839: Fix memory leak of font name in label cache (in mapfile.c). - Added msForceTmpFileBase() and mapserv -tmpbase switch to allow overriding temporary file naming conventions. Mainly intended to make writing testscripts using mapserv easier. FrankW. - maporaclespatil.c: Bug fix for: #1109, #1110, #1111, #1112, #1136, #1210, #1211, #1212, #1213. Support for compound polygons, fixed internal sql to stay more accurate for geodetic data, added the support for getextent function. Added VERSION token for layer data string. - mapimagemap.c: Preliminary implementation of support for emitting MS_SYMBOL_VECTOR symbols in msDrawMarkerSymbolIM(). - Bug 1204: Added multi-threading support in mapthread.c. List of connections is managed within a mutex lock, and connections are only allowed to be used by one thread at a time. - Bug 1185 : php/mapscript : add constant MS_GD_ALPHA - Bug 1173: In HTML legend, added opt_flag support for layer groups. - Bug 1179: added --with-warnings configure switch, overhauled warning logic. - Bug 1168: Improve autoscaling through classification rounding issues. - Fixed bug writing RGB/RGBA images via GDAL output on bigendian systems. - Bug 1152 : Fix WMS style capabilities output for FastCGI enabled builds. - Bug 1135 : Added support for rotating labels with the map if they were rendered with some particular angle already. - Bug 1143 : Missing call to msInitShape. - Fixed PHP5 support for windows : Bug 1100. - Correct bug 1151 : generates twice a tag when generating an SLD. This was happening the style did not have a size set. - Oracle Spatial. Fixed problem with LayerClose function. Added token NONE for DATA statement. Thanks Valik with the hints about the LayerClose problem and Francois with the hints about NONE token. - numpoints and stylelength memebers of the symbol object needs to be in sync with the low level values after calles to setpoints ans setstyle (Bug 1137). - Use doubles instead of integers in function php3_ms_symbol_setPoints (Bug 1137). - Change the output of the expression when using a wild card for PropertyIsLike (Bug 1107). - Delete temporary sld file created on disk (Bug 1123) - Fixed msFreeFileCtx() to call free() instead of gdFree() as per bug 1125. Also renamed gdFreeFileCtx() to msFreeFileCtx(). - Ensure error stack is cleared before accepting another call in FastCGI mode in mapserv.c. Bug 1122 - Support translation of all geometry types to points in mapogr.cpp (now also supports multipolygon, multilinestring and geometrycollection. bug 1124. - Added support for passing OGR layer FILTER queries down to OGR via the SetAttributeFilter() method if prefixed with WHERE keyword. Bug 1126. - Fixed support for SIZEUNITS based scaling of text when map is rotated. Bug 1127. Version 4.4.0 (2004-11-29) -------------------------- - Fixed WMS GetCapabilities 1.1.0 crash when wms_style_<...>_legendurl_* metadata were used (bug 1096) - WCS GetCapabilities : Added ResponsibleParty support. - WMS GetCapabilities : Service online resource was not url encoded (bug 1093) - Fixed php mapscript problem with wfs_filter selection : Bug 1092. - Fixed encoding problem with WFS server when wfs_service_onlineresource was not explicitly specified (bug 1082) - Add trailing "?" or "&" to connection string when required in WFS client layers using GET method (bug 1082) - Fixed : SLD rasters was failing when there was Spatial Filter (Bug 1087) - Fixed mapwfslayer.c build error when WFS was not enabled (bug 1083) - Check that we have vsnprintf in mapimagemap.c before using it. Version 4.4.0-beta3 (2004-11-22) -------------------------------- - Added tests to mimimize the threat of recursion problems when evaluating LAYER REQUIRES or LABELREQUIRES expressions. Note that via MapScript it is possible to circumvent that test by defining layers with problems after running prepareImage. Other things crop up in that case too (symbol scaling dies) so it should be considered bad programming practice (bug 1059). - Added --with-sderaster configure option. - Make sure that msDrawWMSLayerLow calls msDrawLayer instead of msDrawRasterLayerLow directly ensuring that some logic (transparency) that are in msDrawLayer are applied (bug 541). - Force GD/JPEG outputFormatObjects to IMAGEMODE RGB and TRANSPARENT OFF if they are RGBA or ON. Makes user error such as in bug 1703 less likely. - Advertize only gd and gdal formats for wms capabilities (bug 455). - Pass config option GML_FIELDTYPES=ALWAYS_STRING to OGR so that all GML attributes are returned as strings to MapServer. This is most efficient and prevents problems with autodetection of some attribute types (bug 1043). - msOGCWKT2ProjectionObj() now uses the OGRSpatialReference::SetFromUserInput() method. This allows various convenient setting options, including the ability to handle ESRI WKT by prefixing the WKT string with "ESRI::". - Fixed GetLegendGraphic in WMS Capabilities that were missing the '?' or '&' separator if it was not included in wms_onlineresource (bug 1065). - Updated WMS/WFS client and server code to lookup "ows_*" metadata names in addition to the default "wms_*" (or "wfs_*") metadatas (WCS was already implemented this way). This reduces the amount of duplication in mapfiles that support multiple OGC interfaces since "ows_*" metadata can be used almost everywhere for common metadata items shared by multiple OGC interfaces (bug 568). - Added ows_service_onlineresource metadata for WMS/WFS to distinguish between service and GetMap/Capabilities onlineresources (bug 375). - Added map->setSize() to PHP MapScript (bug 1066). - Re-enabled building PHP MapScript using PHP's bundled regex/*.o. This is needed to build in an environment with PHP configured as an Apache DSO (bugs 990, 520). - Fixed problem with raster dither support on windows (related to ascii encoding pointers) (bug 722). - Moved PHP/SWIG MapScript layer->getExtent() logic down to msLayerGetExtent() to avoid code duplication (bug 1051). - Added SDE Raster drawing support (experimental). - HTML legends: Added [leg_header_html] and [leg_footer_html] (bug 1032). - Added "z" support in SWIG MapScript for pointObj (bug 871). - In PHP Mpascript when using ms_newrectobj, the members minx, miny, maxx, maxy are initialized to -1 (bug 788). - Write out proper world file with remote WMS result, it was off by half a pixel (bug 1050). - Send a warning in the wms capabilities if the layer status is set to default (bug 638). - Fixed PHP MapScript compile warnings: dereferencing type-punned pointer will break strict-aliasing rules (bug 1053). - Added $layer->isVisible() to PHP MapScript (bug 539). - Ported $layer->getExtent() to PHP MapScript (bug 826). - wms_group_abstract can now be used in the capabilities (bug 754). - If wms_stylelist is an empty string, do not output the tag for MapContexts (bug 595). - Avoid passing FILE* to GD library by utilizing GD's gdIOCtx interface (bug 1047). - Output warning in wms/wfs capabilities document if layer,group,map names have space in them (bug 486, bug 646). - maporaclespatial.c: fixed declarations problems (bug 1044). - Allow use of msOWSPrintURLType with no metadata. In this case the default parameters will be used (bug 1001). - Ensure the outputFormatObj attached to msImageLoadGDStream() results reflect the interlacedness of the loaded image. Also ensure that the RGB PNG reference images work (make imagemode match gdImg) (bug 1039). - Fixed support for non-square pixels in WCS (bug 1014). - Expose only GD formats for GetLegendGraphic in the capabilities (bug 1001). - Check for supported formats when process a GetLegendGraphic request (bug 1030). - mapraster.c: fixed problem with leaks in tileindexed case where the tile index is missing (bug 713). - Oracle Spatial: implemented connection pool support for Oracle Spatial. New layer data parameters to support query functions, added "using unique ". Added "FILTER", "RELATE" and "GEOMRELATE" parameters, now permit users to choose the Oracle Spatial Filter. Modified the internal SQL to always apply FILTER function. And improve the Oracle Spatial performance. - Centralize "stdout binary mode setting" for win32 in msIO_needBinaryStdout(). Use it when writing GDAL files to stdout in mapgdal.c. Fixes problems with output of binary files from GDAL outputformat drivers on win32 via WMS/WCS. - MapServer now provides one default style named (default), title and LegendURL when generating capabilities. Added also the possibility to use the keyword default for STYLES parameter when doing a GetMap (..&STYLES=default,defeault,...) (bug 1001). - Add xlink:type="simple" in WMS MetadataURL (bug 1027). Version 4.4.0-beta2 (2004-11-03) -------------------------------- - free mapServObj properly in mapserv.c in OWS dispatch case to fix minor memory leaks. - modified msCloseConnections() to also close raster layers so that held raster query results will be freed. - modified raster queries to properly set the classindex in the resultcache. - modified msDrawQueryCache() to be very careful to not try and lookup information on out-of-range classindex values. This seems to occur when default shapes come back witha classindex of 0 even if there are no classes. (ie. raster query results). - the loadmapcontext function has changed it behaviour. Before the 4.4 relase when loading layers from a map context, the layer name was built using a unique prefix + the name found in the context (eg for the 2nd layer in map context named park, the layer name generated would possibly be l:2:park). Now the loadmapcontext takes a 2nd optional argument to force the creation of the unique names. The default behaviour is now to have the layer name equals to the name found in the context file (bug 1023). - Fixed problem with WMS GetCapabilities aborting when wms_layer_group is used for some layers but not for all (bug 1024). - Changed raster queries to return the list of all pixel values as an attribute named "value_list" rather than "values" to avoid conflict with special [values] substitution rule in maptemplate.c. - Fixed raster queries to reproject results back to map projection, and to do point queries distance checking against the correct projection (bug 1021). - Get rid of WMS 1.0.8 support. It's not an officially supported verison of the spec anyway: it's synonymous for 1.1.0 (bug 1022). - Allow use of '=' inside HTML template tag parser (bug 978). - Use metadata ows_schema_location for WMS/WFS/WCS/SLD (bugs 999, 1013, 938). The default value if metadata is not found is http://schemas.opengeospatial.net. - Generate a RULE tag when generating an SLD (bug 1010). - WMS GetLegendGraphic uses now the RULE value to return an icon for a class that has the same name as the RULE value (bug 843). - Add msOWSPrintURLType: This funciton is a generic URL printing fuction for OGC specification metadata (WMS, WFS, WCS, WMC, etc.) (bug 944). - Support MetadataURL, DataURL and LegendURL tags in WMS capabilities document and MetadataURL in WFS capabilities. - SWIG mapscript: clone methods for layerObj, classObj, styleObj (bug 1012). - Implemented an intarray helper class for SWIG mapscript which allows for multi-language manipulation of layer drawing order (bugs 853, 1005). - Fixed WMS GetLegendGraphic which was returning an exception (GD error) when requested layer was out of scale (bug 1006). - Fixed maplexer.l to work with flex 2.5.31 (bug 975). - WMS GetMap requests now have MS_NONSQUARE enabled by default. This means that if the width/height ratio doesn't match the extent's x/y ratio then the map is stretched as stated in the WMS specification (bug 862). - In WMS, layers with no explicit projection defined will receive a copy of the map's projectionObj if a new SRS is specified in the GetMap request or if MS_NONSQUARE is enabled. This will prevent the problem with layers that don't show up in WMS request when the server administrator forgets to explicitly set projections on all the layers in a WMS mapfile (bug 947). - Implemented FastCGI cleanup support for win32 and unix in mapserv.c. - Solved configure/compile issues with libiconv (bugs 909, 1017). Version 4.4.0-beta1 (2004-10-21) -------------------------------- - "shared" compilation target now supports some kind of versioning, should at least prevent libmap.so version collisions when upgrading MapServer on a server (bug 982). - When no RULE parameter has been specified in the WMS request a legend should be returned with all classes for the specified LAYER. Changes has been made in mapwms.c (bug 653). Also if the SCALE parameter is provided in the WMS request is will be used to determine whether the legend of the specified layer should be drawn in the case that the layer is scale dependant (big 809). - Nested layers in the capabilities are supported by using a new metadata tag WMS_LAYER_GROUP (bug 776). - Added greyscale+alpha render support if mapdrawgdal.c (bug 965). - Added --with-fastcgi support to configure. - support OGC mapcontext through mapserver cgi (bug 946). - support for reading 3d shape file (z) (bug 869). - add php mapscript functions to expose the z element (bug 870). - imageObj::write() method for SWIG mapscript (bug 941). - Protect users from 3 potential sources of threading problems: parsing expression strings outside of msLoadMap, evaluating mapserver logical expressions, and loading symbol set files outside of msLoadMap (bug 339). - Various fixes allowing unit tests to run leak free under valgrind on i686. Memory is now properly freed when exiting from common error states (bug 927). - Restored ability to render transparent (indexed or alpha) pixmap symbols on RGB map images, including annotation layers and embedded scalebars. This feature remains OFF by default for map layers and is enabled by specifying TRANSPARENCY ALPHA (bugs 926, 490). - mapserv_fcgi.c removed. Committed new comprehensive FastCGI support. - New mapserver exceptions for Java mapscript thanks to Umberto Nicoletti (bug 895). - Removed mapindex.c, mapindex.h, shpindex.c components of old unused shapefile indexing method. - Use the symbol size instead of 1 for the default style size value. This is done by setting the default size to -1 and adding msSymbolGetDefaultSize() everywhere to get the default symbolsize (Bug 751). - Correct Bug with GML BBOX output when using a with a GetFeature request (Bug 913). - Encode all metadatas and mapfile parameters outputed in a xml document (Bug 802). - Implement the ENCODING label parameter to support internationalization. Note this require the iconv library (Bug 858). - New and improved Java mapscript build provided by unicoletti@prometeo.it and examples by Y.K. Choo (bug 876). - MapContext: Cleanup code to make future integration more easily and output SRS and DataURL in the order required by the spec. - Fixed issue with polygon outline colors and brush caching (bug 868). - New C# mapscript makefiles and examples provided by Y.K. Choo committed under mapscript/csharp/ (bug 867). - Renamed 'string' member of labelCacheMemberObj to 'text' to avoid conflicts in SWIG mapscript with C# and Java types (bug 852). - Fixed Bug 866 : problem when generating an sld on a pplygon layer - SWIG mapscript: map's output image width and height should be set simultaneously using new mapObj::setSize() method. This performs necessary map geotransform computation. Direct setting of map width and height is deprecated (bug 836). - Fixed bug 832 (validate srs value) : When the SRS parameter in a GetMap request contains a SRS that is valid for some, but not all of the layers being requested, then the server shall throw a Service Exception (code = "InvalidSRS"). Before this fix, mapserver use to reproject the layers to the requested SRS. - Fixed bug 834: SE_ROW_ID in SDE not initialized for unregistered SDE tables - Fixed bug 823 : adding a validation of the SRS parameter when doing a GetMap request on a wms server. Here is the OGC statement : 'When the SRS parameter in a GetMap request contains a SRS that is valid for some, but not all of the layers being requested, then the server shall throw a Service Exception (code = "InvalidSRS").' - Set the background color of polygons or circles when using transparent PIXMAP symbol. - SWIG mapscript class extensions are completely moved from mapscript.i into separate interface files under mapscript/swiginc. - Overhaul of mapscript unit testing framework with a comprehensive test runner mapscript/python/tests/runtests.py. - Modified the MS_VALID_EXTENT macro to take an extent as its argument instead of the quartet of members. MapServer now checks that extents input through the mapfile are valid in mapfile.c (web, map, reference, and layer). Modified msMapSetExtent in mapobject.c to use the new macro instead of its home-grown version. Modified all cases that used MS_VALID_EXTENT to the new use case. - Layers now accept an EXTENT through the mapfile (bug 786). Nothing is done with it at this point, and getExtent still queries the datasource rather than getting information from the mapfile-specified extent. - Fixed problem with WMS GetFeatureInfo when map was reprojected. Was a problem with msProjectRect and zero-size search rectangles (bug 794) - MapServer version now output to mapscriptvars and read by Perl Makefile.PL and Python setup.py (bug 795). - Map.web, layer, and class metadata are exposed in SWIG mapscript as first-class objects (bug 737). - Add support for spatial filters in the SLD (Bug 782) - A few fixes to allow php_mapscript to work with both PHP4 and PHP5. PHP5 support should still be considered experimental. (bug 718) - Fixed SDE only recognizing SE_ROW_ID as the unique column (bug 536). The code now autosenses the unique row id column. - Enhanced SDE support to include support for queries against user-specified versions. The version name can be specified as the last parameter of the CONNECTION string. - Fixed automated generation of onlineresource in OWS GetCapabilities when the xxx_onlineresource metadata is not specified: the map= parameter used to be omitted and is now included in the default onlineresource if it was explicitly set in QUERY_STRING (bug 643) - Fixed possible crash when producing WMS errors INIMAGE (bug 644) - Fixed automated generation of onlineresource in OWS GetCapabilities when the xxx_onlineresource metadata is not specified: the map= parameter used to be omitted and is now included in the default onlineresource if it was explicitly set in QUERY_STRING (bug 643) - Fixed an issue with annotation label overlap. There was an issue with the way msRectToPolygon was computing it's bounding box. (bug 618) - Removed "xbasewohoo" debug output when using JOINs and fixed a few error messages related to MySQL joins (bug 652) - Fixed "raster cracking" problem (bug 493) - Improvements to Makefile.vc, and nmake.opt so that a mapscriptvars file can be produced on windows. - Updated setup.py so Python MapScript builds on win32. - Added preliminary raster query support. - No more Python-stopping but otherwise benign errors raised from msDrawWMSLayer() (bug 650). - Finished prototyping all MapServer functions used by SWIG-Mapscript and added 'void' to prototypes of no-arg functions, eliminating all but two SWIG-Mapscript build warnings (bug 658). - Mapscript: resolved issue with pens and dynamic drawing of points (bug 663). - Mapscript: fixes to tests of shape copying and new image symbols. - Mapscript: new OWSRequest class based on cgiRequestObj structure in cgiutil.h is a first step to allow programming with MapServer's OWS dispatching (bug 670). - Mapscript: styles member of classObj structure is no longer exposed to SWIG (bug 611). - Implementation geotransform/rotation support in cgi core, and mapscript.i. - Testing: fixed syntax error, 'EPSG' -> 'epsg' in test.map (bug 687). Added an embedded scalebar which demonstrates that bug 519 is fixed. The test data package is also made more complete by including two fonts from Bitstream's open Vera fonts (bug 694). - Mapscript (SWIG): remove promote and demote methods from layerObj. Use of container's moveLayerUp/moveLayerDown is better, and this brings the module nearer to PHP-Mapscript (bug 692). - mapogr.cpp: Now echos CPLGetLastErrorMsg() results if OGR open fails. - mapraster.c: fixed tile index corruption problem (bug 698) - Mladen Turk's map copying macros in mapcopy.h clean up map cloning and allow for copying of fontset and symbolset. Added cloning tests in python/tests/testCloneMap.py and refactored testing suite (bugs 640 & 701). - Mapscript: removing obsolete python/setup_wnone.py file. - CONFIG MS_NONSQUARE YES now enables non-square pixel mode (mostly for WMS). Changes in mapdraw.c (msDrawMap()) to use the geotransform "hack" to allow non-square pixels. - When using the text/html mime type in a GetFeature request, if the layer's template is not set to a valid file, errors occur. Correction is : the text/html is not advertized by default and will only be advertized if the user has defined "WMS_FEATURE_INFO_MIME_TYPE" "text/html" (bug 736) - Make PHP MapScript's layer->open() produce a PHP Warning instead of a Fatal error (bug 742) - MapServer hash tables are now a structure containing a items pointer to hashObj. See maphash.h for new prototypes of hash table functions. In SWIG mapscript, Map, Layer, and Class metadata are now instances of the new hashTableObj class. fontset.fonts and Map.configoptions are also instances of hashTableObj. The older getMetaData/setMetaData and metadata iterator methods can be deprecated (bug 737). - Mapscript-SWIG: made the arguments of mapObj and layerObj constructors optional. A layerObj can now exist outside of a map and can be added to a mapObj using the insertLayer method. mapObj.removeLayer now returns a copy of the removed Layer rather than an integer (bug 759). - Fixed $map->processTemplate() which was always returning NULL. Bug introduced in version 4.0 in all flavours of MapScript (bug 410) Version 4.2-beta1 (2004-04-17) ------------------------------ - Added support for WMS 1.1.1 in the WMS interface. - Added support for WMS-SLD in client and server mode. - Added support for attribute filters in the WFS interface. - WMS Interface: several fixes to address issues found in running tests against the OGC testsuite. One of the side-effects is that incomplete GetMap requests that used to work in previous versions will produce errors now (see bug 622). - Modified configure scripts to be able to configure/build PHP MapScript using an installed PHP instead of requiring the full source tree. - Added ability to combine multiple WMS connections to the same server into a single request when the layers are adjacent and compatible. (bug 116) - Support POSTed requests without Content-Length set. - Added support for proper classification of non-8bit rasters. - Added support for BYTE rawmode output type. - Added support for multiple bands of output in rawmode. - MySQL joins available - Fixed problems with detection of OGRRegisterAll() with GDAL 1.1.9 in configure due to GDAL's library name change. Fixed a few other minor issues with GDAL/OGR in configure. - Modified configure to disable native TIFF/PNG/JPEG/GIF support by default if GDAL is enabled. You can still enable them explicitly if you like. - Replace wms_style_%s_legendurl, wms_logourl, wms_descriptionurl, wms_dataurl and wms_metadataurl metadata by four new metadata by metadata replaced. The new metadata are called legendurl_width, legendurl_height, legendurl_format, legendurl_href, logourl_width, etc... Old dependancy to the metadata with four value in it , space separated, are not kept. - Implement DataURL, MetadataURL and DescriptionURL metadata in mapcontext.c (bug 523) - PHP MapScript's pasteImage() now takes a hex color value (e.g. 0xrrggbb) for the transparent color instead of a color index. (bug 463) - OGR data sources with relative paths are now checked relative to SHAPEPATH first, and if not found then we try again relative to the mapfile location. (bug 295) - There is a new mapObj parameter called MAXSIZE to control maximum image size to serve via the CGI and WMS interfaces. The default is 2048 as before but it can be changed in the map file now. (bug 435) - Added simple dataset for unit and regression tests (bug 453) - PostGIS: added postresql_NOTICE_HANDLER() sending output via msDebug() and only when layer->debug is set (bug 418) - Added Apache version detection in configure and added non-blocking flag on stderr in msDebug() to work around Apache 2.x bug (bug 458) - MapScript rectObj: added optional bounding value args to constructor and extended rectObj class with a toPolygon method (bug 508). - MapScript pointObj: added optional x/y args to constructor (bug 508). - MapScript colorObj: added optional RGB color value args to colorObj constructor, and extended colorObj class with setRGB, setHex, and toHex methods. The hex methods use hex color strings like '#ffffff' rather than '0xffffff' for compatibility with HTML (bug 509). - MapScript outputFormatObj: extended with a getOption method (bug 510). - MapScript imageObj: added optional mapObj argument to the save method resolving bug 549 without breaking current API. Also added optional driver and filename arguments to constructor which allows imageObj instances to be created with a specified driver or from files on disk (bug 530). Added new code to Python MapScript which extends the filename option to Python file-like objects (bug 550). This means StringIO and urllib's network objects! - MapScript classObj and styleObj: added a new styleObj shadow class and extended classObj with getStyle, insertStyle, and removeStyle methods. MapScript now supports multiple styles for dynamically created classes (bug 548). - MapScript layerObj: added getExtent, getNumFeatures extension methods, allowing getShape to access inline features (bug 562). - Added fixes for AMD64/Linux in configure (bug 565) - Removed OGR_STATIC stuff in configure script that used to allow us to build with OGR statically by pointing to the OGR source tree. That means you can only build with OGR when *installed* as part of GDAL, but that's what everyone is doing these days anyway. - Mapscript outputFormatObj: extended constructor to allow format names, and mapObj methods to append and remove output formats from the outputformatlist (bug 511). - New SWIG mapscript development documentation in the spirit of the PHP-Mapscript readme file, but using reST (bug 576). - Paving way for future changes to SWIG mapscript API with new features enabled by NEXT_GENERATION_API symbol (bug 586). - Added ability to set string member variables to NULL in PHP MapScript (bug 591) - New key iterators for map, layer, and class metadata hash tables (bug 434) and fontset fonts hash table (bug 439). - Fixed potential crash when using nquery with a querymap enabled and some layers have a template set at the layer level instead of inside classes (bug 569). - New CONFIG keyword in the MAP object in a .map file to be used to set external configuration parameters such as PROJ_LIB and control of some GDAL and OGR driver behaviours (bug 619) Version 4.0 (2003-08-01) ------------------------ - Fixed problem with truncated expressions (bugs 242 and 340) - Attempt at fixing GD vs libiconv dependency problems (bug 348) - Fixed problem with invalid BoundingBox tag in WMS capabilities (bug 34) - Fixed problems with SIZEUNITS not working properly (bug 373) - Fixed MacOSX configure problems for linking php_mapscript (bug 208) - Fixed problem with reference map marker symbol not showing up (bug 378) - Use in WMS 1.0.0 capabilities instead of (bug 129) - One-to-one and one-to-many joins now work for Xbase files and are available to query templates. Low level one-to-one Xbase joins are available via OGR. Version 4.0-beta2 (2003-07-11) ------------------------------ - Added prototype of FastCGI support in mapserv_fcgi.c (not built by default). - Report full error stack in the mapserv CGI and PHP MapScript (bug 346) - Old index (.qix) format is deprecated (bug 273) - Fixed problem with embedded legend and scalebar that would result in layers being added to the HTML legends (bug 171) - Changed joins (XBase only at this point) over to the open-prepare-next... next-close way of doing things. Compiles fine, but needs more testing. One-to-many support should work now but it needs to be hooked into the template code yet. Last thing before a candidate 4.0 release. - Added ability to generate images in MapScript processQueryTemplate (bug 341) - Added saving of output formats in msSaveMap() - Fixed problem in PHP MapScript with variables that were not dereferenced before their values were changed by the MapScript wrappers (bug 323) - Added support for Web Map Context 1.0.0 - Treat zero-length template values as NULL so that it's possible to set("template", "") from MapScript to make layer non-queryable (bug 338) - Ditched the shapepath argument to the shapefileObj constructor - CARTOLINE join style default changed to MS_CJC_NONE - Tweaked code in legend builder to handle polygon layers slightly different. Now if a polygon layer contains only outlines and no fills (i.e. a polyline) then it is drawn using the zigzag legend shape rather than the box. I'll add legend outlines back in shortly. - Restored legend key outlines (triggered by setting OUTLINECOLOR). If an outline is requested then line symbols are clipped to the outline, otherwise lines are allowed to bleed a pixel or two beyond those boundaries- for most cases this looks fine but for fat lines it is gonna look goofy regardless. In those cases use the KEYIMAGE. - Fixed a bug in the scanline writer so that x coordinates can be in any order when passed in to the function. (bug 336) - Updated loadExpressionString in mapfile.c to be a bit more tolerant of input. Now if a string does not match the logical or regex pattern it is automatically cast as a string expression. Removes the need for silly quotes. Version 4.0-beta1 (2003-06-06) ------------------------------ - Added imagemap outputformat, which makes possible use of client-side imagemaps in browsers. - Added MySQL support for non-spatial OpenGIS Simple Features SQL stored data - msQueryByShape and msQueryByFeature honor layer tolerances. In effect you can to buffered queries now. At the momoment only polygon select features are supported, but there's nothing inherent in the underlying computations that says lines won't work as well. - Simple one-to-one joins are working again. Reworked the join code so that table connections are persistant within a join (across joins is a todo). Joins, like layers are wrapped with a connection neutral front end, that sets us up to do MySQL or whatever in addition to XBase. - Removed shapepath argument to all layer access functions (affects MapScript). It's still used but we leverage the layer pointer back to the parent mapObj so the API is cleaner. - Changed default presentation of feature attributes to escape a few problematic characters for HTML display (eg. > becomes >). Added [itemname_raw] substitution to allow access to unaltered data. - Added initial version of Jan Hartman's connection pooling code. - Replaced libwww with libcurl for WMS/WFS client HTTP requests. (libcurl 7.10 required, see http://curl.haxx.se/libcurl/c/) - Added CONNECTION to the list of mapfile parameters that can accept %variable% substitutions when processed by the cgi version. This is useful for passing in username and/or passwords to database data sources. - Added support for DATA and TEMPLATE (header/footer/etc...) filtering using an regex declared in the mapfile (DATAPATTERN and TEMPLATEPATTERN). Certain parameters in a mapfile cannot be changed via a URL without first being filtered. - Added support for enviroment variable MS_MAPFILE_PATTERN. This allows you to override the default regex in favor of one more restrictive (I would hope) of your own. - Disabled CGI SAVEMAP option. - Removed CGI TEMPLATE option since you can use the map_web_template syntax. Simplifies security maintenance by only having to deal with this option in a single place. - Added offset support (styleObj) for raster based output (GD for sure, not quite sure how OGR output is created although I believe is uses GD anyway). This allows for feature drop shadows and support for cool linear symbols like used to be supported in pre-3.4 versions. These offsets are not scalable at the moment. - Null shapes (attributes but no vertices) are skipped for shapefiles using the msLayerNextShape interface. Otherwise applications should check the shapeObj type member for MS_SHAPE_NULL. - Changed where label cache is allocated and cleared. Now it isn't allocated until drawing takes place. Any old cache is cleared before a new one is allocated. The cache is still intact following rendering for post-processing using MapScript. - Fixed screw up in pre-processing of logical expressions for item lists. Under certain circumstances that list could get corrupted and expressions would fail. - Added NOT operator to expression parser. - Added layer and map level DEBUG options to map file. - Major changes to support vector output (PDF, SWF, GML, ...): imageObj is used by all rendering functions instead of gdImagePtr, New msSaveImage() prototype - Support for GD-2.0, including 24 bits output. Dropped support for GD 1.x - Support for output to any GDAL-supported format via the new OUTPUTFORMAT object. - New styleObj to replace the OVERLAY* parameter in classes. - PostGIS: Added Sean Gillies 's patch for "using unique ". Added "using SRID=#" to specify a spatial reference for an arbitrary sql query. - ... and numerous fixes not listed here... Version 3.6.0-beta1 (2002-04-30) -------------------------------- - MapScript: qitem and qstring params added to layer->queryByAttribute(). Instead of being driven by the layer's FILTER/FILTERITEM, the query by attribute is now driven by the values passed via qitem,qstring, and the layer's FILTER/FILTERITEM are ignored. - Symbol and MapFile changes: ANTIALIAS and FILLED keywords now take a boolean (TRUE/FALSE) argument i.e. ANTIALIAS becomes ANTIALIAS TRUE and FILLED becomes FILLED TRUE - Reference Map: Added options to show a different marker when the reference box becomes too small. See the mapfile reference docs for more details on the new reference object parameters (MARKER, MARKERSIZE, MAXBOXSIZE, MINBOXSIZE) - Added MINSCALE/MAXSCALE at the CLASS level. - Support for tiled OGR datasets. - PHP 4.1.2 and 4.2.0 support for PHP MapScript. - Added LAYER TRANSPARENCY, value between 1-100 - Fixes to the SWIG interface for clean Java build. - New HTML legend templates for CGI and MapScript. See HTML-Legend-HOWTO. - WMS server now supports query results using HTML query templates instead of just plain/text. - Added support functions for thread safety (--with-thread). Still not 100% thread-safe. Version 3.5.0 (2002-12-18) -------------------------- - No Revision history before version 3.5 mapserver-7.6.4/INSTALL000066400000000000000000000006661407312142500145740ustar00rootroot00000000000000Visit http://www.mapserver.org/ for full documentation and installation instructions. Unix compilation instructions ----------------------------- See INSTALL.CMAKE or the document on the MapServer website at Win32 compilation instructions ------------------------------ See README.WIN32 or the document on the MapServer website at mapserver-7.6.4/INSTALL.CMAKE000066400000000000000000000224061407312142500154070ustar00rootroot00000000000000CMake Build Instructions ======================== Since version 6.4, MapServer is built with the CMake build tool instead of the previous autotools chain. CMake is opensource and free of charge and is usually included in distribution packages, or can be downloaded and compiled with no third party dependencies. CMake itself does not do the actual compiling of the MapServer source code, it mainly creates platform specific build files that can then be used by standard build utilities (make on unixes, visual studio on windows, xcode on osx, etc...) Install CMake ------------- MapServer now requires at least CMake version 3.0, although the CMake process was first implemented in MapServer 6.4 with CMake 2.6.0. Distro Packaged Version ....................... Linux distributions usually include the cmake package, that can be installed with your usual package manager: apt-get, yum, yast, etc... Installing Your Own ................... Head over to http://www.cmake.org/cmake/resources/software.html to download a source tarball (for unixes) or a binary installer (for windows). If you are building from source, the build process is detailed in the tarball readme files, and consists only in $ tar xzf cmake-x.y.z.tar.gz $ cd cmake-x.y.z $ ./bootstrap $ make # make install Creating the MapServer platform specific project with CMake ----------------------------------------------------------- Although you can run and build from MapServer's source directory as created by downloading a tarball or using a git clone, it is **highly** recommended to run "out-of-source" builds, i.e. having all build files be compiled and created in a different directory than the actual MapServer sources. This allows to have different configurations running alongside each other (e.g. release and debug builds, cross-compiling, enabled features, etc...). Running CMake From the Command Line ................................... mkdir build cd build cmake .. ## fix dependency issues make Running the GUI version of cmake ................................ CMake can be run in graphical mode, in which case the list of available options are presented in a more user-friendly manner mkdir build cd build ccmake .. ## follow instructions, fix dependency issues make Options and Dependencies ........................ Depending on what packages are available in the default locations of your system, the previous "cmake .." step will most probably have failed with messages indicating missing dependencies (by default, MapServer has *many* of those). The error message that CMake prints out should give you a rather good idea of what steps you should take next, depending on wether the failed dependency is a feature you require in your build or not. - Either disable the dependency by rerunning cmake with -DWITH_DEPENDENCY=0, e.g. $ cmake .. -DWITH_CAIRO=0 - Or, if the failed dependency relates to a feature you want built in, and that cmake has not been able to find it's installation location, there are 3 possible reasons: 1 You have not installed the third party package, and/or the third party development headers. Use your standard package manager to install the failing package, along with it's development headers. The development packages on linux usually end with "-dev" or "-devel", e.g. libcairo2-devel , libpng-dev, etc... $ (sudo) apt-get install libcairo-dev $ cmake .. 2 You have installed the third party package in a non standard location, which you must give to cmake so it can find the required headers and libraries $ cmake .. -DCMAKE_PREFIX_PATH=/opt/cairo-1.18.2 Cmake expects these nonstandard prefixes to contain standard subdirectories, i.e. /opt/cairo-1.18.2/include/cairo.h and /opt/cairo-1.18.2/lib/libcairo.so. You can specify multiple prefixes on the cmake command line by separating them with the platform specific separator (e.g. ":" on unixes), e.g. $ cmake .. -DCMAKE_PREFIX_PATH=/opt/cairo-1.18.2:/opt/freeware 3 If you're certain that the packages development headers are installed, and/or that you pointed to a valid installation prefix, but cmake is still failing, then there's an issue with MapServer's cmake setup, and you can bring this up on the mailing list or issue tracker. Available Options ----------------- Following is a list of option, taken from MapServer's CMakeLists.txt configuration file. After the description of the option, the ON/OFF flag states if the option is enabled by default (in which case the cmake step will fail if the dependency cannot be found). All of these can be enabled or disabled by passing "-DWITH_XXX=0" or "-DWITH_XXX=1" to the "cmake .." invocation in order to override a default selection. This Readme file may be out of sync with the actual CMakeLists files shipped. Refer to the CMakeLists.txt file for up-to-date options. - option(WITH_PROJ "Choose if reprojection support should be built in" 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) - option(WITH_FRIBIDI "Choose if FriBidi glyph reordering should be enabled (usefull for left-to-right languages)(requires harfbuzz)" ON) - option(WITH_HARFBUZZ "Choose if Harfbuzz complex script glyph shaping support should be built in (requires fribidi)" ON) - option(WITH_ICONV "Choose if Iconv Internationalization support should be built in" ON) - option(WITH_CAIRO "Choose if CAIRO rendering support should be built in (required for SVG and PDF output)" ON) - option(WITH_SVGCAIRO "Choose if SVG symbology support (via libsvgcairo) should be built in (requires cairo, libsvg, libsvg-cairo. Incompatible with librsvg)" OFF) - option(WITH_RSVG "Choose if SVG symbology support (via librsvg) should be built in (requires cairo, librsvg. Incompatible with libsvg-cairo)" OFF) - option(WITH_MYSQL "Choose if MYSQL joining support should be built in" OFF) - option(WITH_FCGI "Choose if FastCGI support should be built in" ON) - option(WITH_GEOS "Choose if GEOS geometry operations support should be built in" ON) - option(WITH_POSTGIS "Choose if Postgis input support should be built in" ON) - option(WITH_GDAL "Choose if GDAL input raster support should be built in" ON) - option(WITH_OGR "Choose if OGR/GDAL input vector support should be built in" ON) - option(WITH_CURL "Enable Curl HTTP support (required for wms/wfs client, remote SLDs and pixmap symbols)" OFF) - option(WITH_CLIENT_WMS "Enable Client WMS Layer support (requires CURL and GDAL support)" OFF) - option(WITH_CLIENT_WFS "Enable Client WMS Layer support (requires CURL and OGR support)" OFF) - option(WITH_WFS "Enable WFS Server support (requires PROJ and OGR support)" ON) - option(WITH_WCS "Enable WCS Server support (requires PROJ and GDAL support)" ON) - option(WITH_LIBXML2 "Choose if libxml2 support should be built in (used for sos, wcs 1.1,2.0 and wfs 1.1)" ON) - option(WITH_THREAD_SAFETY "Choose if a thread-safe version of libmapserver should be built (only recommended for some mapscripts)" OFF) - option(WITH_GIF "Enable GIF support (for PIXMAP loading)" ON) - option(WITH_PYTHON "Enable Python mapscript support" OFF) - option(WITH_PHP "Enable PHP mapscript support" OFF) - option(WITH_PERL "Enable Perl mapscript support" OFF) - option(WITH_RUBY "Enable Ruby mapscript support" OFF) - option(WITH_JAVA "Enable Java mapscript support" OFF) - option(WITH_CSHARP "Enable C# mapscript support" OFF) - option(WITH_ORACLESPATIAL "include oracle spatial database input support" OFF) - option(WITH_ORACLE_PLUGIN "include oracle spatial database input support as plugin" OFF) - option(WITH_MSSQL2008 "include mssql 2008 database input support as plugin" OFF) - option(WITH_SDE_PLUGIN "include ArcSDE support as a plugin (must specify SDE_INCLUDE_DIR and SDE_LIBRARY_DIR)." OFF) - option(WITH_SDE "include ArcSDE support. Add -DSDE_VERSION=91 to use 9.1 arcSDE version" OFF) - option(WITH_EXEMPI "include xmp output metadata support" OFF) - option(WITH_XMLMAPFILE "include native xml mapfile support (requires libxslt/libexslt)" OFF) - option(WITH_V8 "include javacript v8 scripting" OFF) The following options are for advanced users, i.e. you should not enable them unless you know what you are doing: - option(BUILD_STATIC "Also build a static version of mapserver" OFF) - option(LINK_STATIC_LIBMAPSERVER "Link to static version of libmapserver (also for mapscripts)" OFF) - option(WITH_APACHE_MODULE "include (experimental) support for apache module" OFF) - option(WITH_GENERIC_NINT "generic rounding" OFF) - option(WITH_POINT_Z_M "include Z and M coordinates in point structure (advanced, not recommended)" OFF) The following are some common CMake options not specific to MapServer itself: - CMAKE_INSTALL_PREFIX : path where mapserver binaries and libraries should be installed. Defaults to /usr/local on unix. - CMAKE_PREFIX_PATH : platform-specific separator separated list of prefixes where dependencies will be looked for, e.g. "-DCMAKE_PREFIX_PATH=/opt/freeware:/opt/jdk-1.5.6" - CMAKE_BUILD_TYPE : Specify the build type. Usually one of 'Debug' or 'Release', e.g. "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_BUILD_TYPE=Debug" You can find a more extensive list of cmake variables here: http://www.cmake.org/Wiki/CMake_Useful_Variables mapserver-7.6.4/MIGRATION_GUIDE.txt000066400000000000000000000011311407312142500165360ustar00rootroot00000000000000***************************************************************************** MapServer Migration Guide ***************************************************************************** The current version of the MapServer Migration Guide is available online at https://mapserver.org/MIGRATION_GUIDE.html. For developers: The main copy of the MIGRATION_GUIDE is now located in the root of the /MapServer/MapServer-documentation source tree ( https://github.com/MapServer/MapServer-documentation ). Developers are welcome and encouraged to edit/update the guide in the documentation tree directly. mapserver-7.6.4/Makefile000066400000000000000000000071451407312142500152020ustar00rootroot00000000000000AUTOTEST_OPTS?=--strict_mode PHP_MAPSCRIPT=build/mapscript/php/php_mapscript.so PYTHON_MAPSCRIPT_PATH=build/mapscript/python JAVA_MAPSCRIPT_PATH=build/mapscript/java CSHARP_MAPSCRIPT_PATH=build/mapscript/csharp PERL_MAPSCRIPT_PATH=build/mapscript/perl BUILDPATH=../../build FLEX=flex YACC=yacc CMAKEFLAGS=-DCMAKE_C_FLAGS="--coverage ${CMAKE_C_FLAGS}" -DCMAKE_CXX_FLAGS="--coverage ${CMAKE_CXX_FLAGS}" \ -DCMAKE_SHARED_LINKER_FLAGS="-lgcov" -DWITH_CLIENT_WMS=1 \ -DWITH_CLIENT_WFS=1 -DWITH_KML=1 -DWITH_SOS=1 -DWITH_CSHARP=1 -DWITH_PHP=1 -DWITH_PERL=1 \ -DWITH_PYTHON=1 -DWITH_JAVA=1 -DWITH_THREAD_SAFETY=1 -DWITH_FRIBIDI=1 -DWITH_FCGI=0 -DWITH_EXEMPI=1 \ -DCMAKE_BUILD_TYPE=Release -DWITH_RSVG=1 -DWITH_CURL=1 -DWITH_HARFBUZZ=1 -DWITH_POINT_Z_M=1 -DWITH_MSSQL2008=ON ${EXTRA_CMAKEFLAGS} all: cmakebuild cmakebuild: lexer parser if test ! -s build/Makefile; then mkdir -p build ; cd build ; cmake .. $(CMAKEFLAGS); fi cd build && $(MAKE) $(MFLAGS) warning: $(error "This Makefile is used to run the \"test\" target") wxs-testcase: cd msautotest/wxs && chmod 777 tmp && rm -f result/* && export PATH=$(BUILDPATH):$(PATH) && (./run_test.py $(AUTOTEST_OPTS) || /bin/true) renderers-testcase: cd msautotest/renderers && rm -f result/* && export PATH=$(BUILDPATH):$(PATH) && (./run_test.py $(AUTOTEST_OPTS) || /bin/true) misc-testcase: cd msautotest/misc && rm -f result/* && export PATH=$(BUILDPATH):$(PATH) && (./run_test.py $(AUTOTEST_OPTS) || /bin/true) gdal-testcase: cd msautotest/gdal && rm -f result/* && export PATH=$(BUILDPATH):$(PATH) && (./run_test.py $(AUTOTEST_OPTS) || /bin/true) query-testcase: cd msautotest/query && rm -f result/* && export PATH=$(BUILDPATH):$(PATH) && (./run_test.py $(AUTOTEST_OPTS) || /bin/true) sld-testcase: cd msautotest/sld && rm -f result/* && export PATH=$(BUILDPATH):$(PATH) && (./run_test.py $(AUTOTEST_OPTS) || /bin/true) mspython-testcase: test -f "$(PYTHON_MAPSCRIPT_PATH)/_mapscript.so" && (export PYTHONPATH="../../$(PYTHON_MAPSCRIPT_PATH)" && cd msautotest/mspython && python run_all_tests.py) mspython-wheel: cd build && cmake --build . --target pythonmapscript-wheel php-testcase: test -f "$(PHP_MAPSCRIPT)" && (export PHP_MAPSCRIPT_SO="../../$(PHP_MAPSCRIPT)" && cd msautotest/php && ./run_test.sh) java-testcase: test -d "$(JAVA_MAPSCRIPT_PATH)" && (export JAVA_MAPSCRIPT_SO="../../$(JAVA_MAPSCRIPT_PATH)" && cd mapscript/java && ./run_test.sh) csharp-testcase: test -d "$(CSHARP_MAPSCRIPT_PATH)" && (export CSHARP_MAPSCRIPT_SO="../../$(CSHARP_MAPSCRIPT_PATH)" && cd mapscript/csharp && ./run_test.sh) perl-testcase: cd "$(PERL_MAPSCRIPT_PATH)" \ && PERL5LIB=`pwd` \ && prove tests \ && perl examples/RFC24.pl ../../../tests/test.map \ && perl examples/shp_in_shp.pl --infile1 ../../../tests/line.shp --infile1_shpid 0 --infile2 ../../../tests/polygon.shp --infile2_shpid 0 \ && perl examples/dump.pl --file ../../../tests/line.shp \ && perl examples/thin.pl --input ../../../tests/polygon --output examples/junk --tolerance=5 test: cmakebuild @$(MAKE) $(MFLAGS) wxs-testcase renderers-testcase misc-testcase gdal-testcase query-testcase sld-testcase mspython-testcase @./print-test-results.sh @$(MAKE) $(MFLAGS) php-testcase @$(MAKE) $(MFLAGS) csharp-testcase @$(MAKE) $(MFLAGS) perl-testcase asan_compatible_tests: cmakebuild @$(MAKE) $(MFLAGS) wxs-testcase renderers-testcase misc-testcase gdal-testcase query-testcase sld-testcase @./print-test-results.sh lexer: maplexer.c parser: mapparser.c maplexer.c: maplexer.l $(FLEX) --nounistd -Pmsyy -i -o$(CURDIR)/maplexer.c maplexer.l mapparser.c: mapparser.y $(YACC) -d -o$(CURDIR)/mapparser.c mapparser.y mapserver-7.6.4/README.WIN32000066400000000000000000000256251407312142500152260ustar00rootroot00000000000000-------------------------------------------------------------------- README.WIN32 - Microsoft Visual C++ Build instructions for MapServer -------------------------------------------------------------------- IMPORTANT - READ THIS FIRST: ---------------------------- The Win32 build process is not very friendly for unexperienced users. So it is strongly recommended that you use one of the precompiled binaries available on the MapServer site: http://www.mapserver.org/download.html#windows There are precompiled Win32 binaries available for the last stable release and the latest nightly build and they include the most common options... so you shouldn't have to compile your own executables. If for some reason you still decide to compile Win32 binaries yourself, then don't do it unless you really know what you're doing... and hopefully the rest of this file contains some hints that may help you. Good Luck! -------------------------------------------------------------------- The easyest way to build Mapserver on Windows on your own is to use the build-system from http://gisinternals.com/. GISInternals provide a complete set of sources and dependencies and even makefiles for the full version of Visual Studio (not Express oder Community). You don't have to download and compile them all by your own. If you are not using full version of Visual Studio you can not use the makefiles from GISInternals but you can still use the downloads to make your life easier. Building with the full version of Visual Studio is easy. Download the SDK for you version and follow the readme inside the packages. This Readme will cover the compilation with Visual Studio 2012 Express on Windows with CMake and the GISInternals-Packages for the following reasons: - not everybody wants to buy Visual Studio and there is no reason to force you to buy it just tu build Mapserver on Windows - CMake is the configuration-system for Linux. Why should you use something else which needs to be maintainerd? - as of today, PHP-Mapscript is not suppored for PHP-7. PHP-5.6 is build with VC11. To make PHP-Mapscript compatible with the downloadable PHP-Version you need to build with VC11 wich is Visual Studio 2012. - GISInternals Downloads contain most dependencies. it's way easier If you want to compile Mapserver with any other version of Visual Studio you can for sure use this documentation as help but maybe, some things here won't work for you. -------------------------------------------------------------------- Prerequisites -------------------------------------------------------------------- To build Mapserver on Windows with Visual Studio 2012 Express you need Visual Studio 2012 Express installed. Install CMake (https://cmake.org/) and add CMake bin-directory to your PATH environment variable. You can even to this after opening VS2012 x86 Native Tools Command Prompt by entering: set PATH=%PATH%;"C:\Program Files\CMake\bin" ... if CMake is installed to "C:\Program Files\CMake" ;) -------------------------------------------------------------------- Downloading dependencies -------------------------------------------------------------------- For our first build, we will use stable releases to build mapserver. Download MSVC 2012 win32 Packages for GDAL-2.1.2 and Mapserver-7.0.2 from http://gisinternals.com/release.php. We need "Compiled binaries in a single .zip package", "GDAL and MapServer sources" and "Compiled libraries and headers". Download the MSVC 2012 win32 Developement Kit from http://gisinternals.com/sdk.php. Extract everything to C:\dev\work\release-1700-gdal-2-1-2-mapserver-7-0-2. There should be the directories inside now: bin, doc, gdal, include, lib, regex-0.12, relase-1700, ... After you got this done, feel free to use other packages which fit your needs better. -------------------------------------------------------------------- Mapserver-sources -------------------------------------------------------------------- Download at least Mapserver-7.0.3 or current 7.0-Branch from github and extract or clone from github to C:\dev\work\mapserver. -------------------------------------------------------------------- Building Mapserver -------------------------------------------------------------------- After downloading and extracting everything, to build Mapserver, follow this steps: 1. Open VS2012 x86 Native Tools Command Prompt (i'm german, hope it is translated correctly). 2. Add CMake-bin to your PATH: set PATH=%PATH%;"C:\Program Files\CMake\bin" 3. Create build-Directory: mkdir C:\dev\work\mapserver\build cd C:\dev\work\mapserver\build 4. Configure: cmake .. -G "NMake Makefiles" -DBUILD_SHARED_LIBS=1 -DCMAKE_BUILD_TYPE=Release -Wno-dev cmake .. -DCMAKE_PREFIX_PATH=C:\dev\work\release-1700-gdal-2-1-2-mapserver-7-0-2;C:\dev\work\release-1700-gdal-2-1-2-mapserver-7-0-2\bin;C:\dev\work\release-1700-gdal-2-1-2-mapserver-7-0-2\lib;C:\dev\work\release-1700-gdal-2-1-2-mapserver-7-0-2\include cmake .. -DREGEX_DIR=C:\dev\work\release-1700-gdal-2-1-2-mapserver-7-0-2\regex-0.12 cmake .. -DWITH_POSTGIS=0 -DWITH_SOS=1 -DWITH_KML=1 cmake .. -DWITH_CLIENT_WMS=1 -DWITH_CLIENT_WFS=1 cmake .. -DWITH_THREAD_SAFETY=1 -DWITH_FCGI=1 cmake .. -DWITH_CAIRO=1 -DCAIRO_LIBRARY=C:\dev\work\release-1700-gdal-2-1-2-mapserver-7-0-2\lib\cairo.lib cmake .. -DWITH_SVGCAIRO=1 -DSVGCAIRO_LIBRARY=C:\dev\work\release-1700-gdal-2-1-2-mapserver-7-0-2\lib\libsvg-cairo.lib cmake .. -DSVG_LIBRARY=1 -DSVG_LIBRARY=C:\dev\work\release-1700-gdal-2-1-2-mapserver-7-0-2\lib\libsvg.lib 5. build nmake Thats it. You can use all CMake parameters and options as you are used from CMake to fit mapserver to your needs from here. Enjoy! -------------------------------------------------------------------- MapScript -------------------------------------------------------------------- To compile the various versions of MapScript (Perl, PHP, etc) first compile the main mapserver directory and then see the README files in the mapscript/perl, mapscript/php or mapscript/python directory for specific instructions. -------------------------------------------------------------------- Dependencies Part 2 -------------------------------------------------------------------- The following sections descripe how to get mapserver dependencies when not downloading GISInternals packages. -------------------------------------------------------------------- GD library -------------------------------------------------------------------- - MapServer uses the GD library from http://boutell.com/ and the Win32 makefiles are set by default to work with the pre-built GD version 2.0.33 provided by Boutell.com. These predefine "gdwin32" binaries include freetype2, libpng, libjpeg, libz, and libgif built-in. This is very convenient to get a mapserver build going quickly. If you are building GD and it's supporting libraries (libpng, libjpeg, libgif, and freetype) from source then it is very important to make sure that you update the -DUSE_GD_* flags and various subcomponent paths in the nmake.opt. You will also have to take great care to build the various components in a way that is compatible with MapServer. For instance, if the various components are statically linked into MapServer you will need to use the same build options (ie. /MT or /MT) for all components. Here are some useful pointers: - The original GD library: http://boutell.com/gd/ - libpng: http://www.libpng.org/pub/png/libpng.html - zlib: http://www.info-zip.org/pub/infozip/zlib/ - libjpeg: ftp://ftp.uu.net/graphics/jpeg/ - Freetype: http://www.freetype.org/download.html -------------------------------------------------------------------- REGEX library -------------------------------------------------------------------- - MapServer uses the REGEX library which is standard on all the Unix systems that I know of, but does not come with VC++. If the MapServer distribution did not include a copy of the REGEX library, then you can get a copy from: ftp://ftp.gnu.org/pub/gnu/regex/regex-0.12.tar.gz The default in the nmake.opt is set to compile with GNU regex-0.12 located in the "regex-0.12" directory. - If you are planning to compile the PHP3_MAPSCRIPT.DLL module, then it is important to make sure that the main Makefile.vc creates MAPSERVER.LIB with the same version of REGEX that PHP uses. See the notes in the main Makefile.vc about that. -------------------------------------------------------------------- Notes on Freetype build. -------------------------------------------------------------------- - You can use the Visual Workspace in freetype/lib/arch/win32 to build the library. -------------------------------------------------------------------- Notes on the proj module -------------------------------------------------------------------- - The Proj.4 (cartographic projection routines) is located at http://www.remotesensing.org/proj/ Note on the epsg files location and the nad directory : * there is an environnemnt variable PROJ_LIB_DIR that can be set to locate the directory where the epsg file is located * if you build this module, at the top of the makefile (./src/makefile.vc), you can set the PROJ_LIB variable and this setting will be used to locate the proj support files. ---------------------------------------------------------------------- Notes on libcurl ---------------------------------------------------------------------- Notes libcurl : used to support WMS client connection Mapserver 5.x is using libcurl instead of libwww for WMS client support. - the library is located at http://curl.haxx.se/download.html Quick notes on how to build the library using MSVC++: - Download and extract the library (at this time it is known to work with version 7.10.2 or more recent) - Open the workspace curlib.dsw located under curl-XXX/lib - Build libcurl.dll. Note that the default active configuraion of the project is Win32 Debug. You can modify the configuarion to Release version (Build/Set Active Configuration) Notes on mapserver's nmake.opt modifications : - uncomment the flag WMSCLIENT= -DUSE_WMS_LYR - uncomment and modify according to your installation the flags related to libcurl : * CURL_INC = -I../curl-7.10.2/include * CURL_LIB = ../curl-7.10.2/lib/Relase/libcurl.lib * WINSOCK_LIB = "C:\Program Files\Microsoft Visual Studio\VC98\Lib\WSOCK32.LIB" You also need to install the libcurl.dll in your system directory. (The dll will be located in libc-XXX/lib/Relase abfter your build of the library) ------------------------------------------------------------ Notes on GDAL ------------------------------------------------------------ - If you are compiling the GDAL library (http://www.gdal.org/) with the PNG support, make sure that the libpng that you use in mapserver is the same as the one used in GDAL. $Id$ mapserver-7.6.4/README.rst000066400000000000000000000074751407312142500152370ustar00rootroot00000000000000MapServer ========= | |Build Status| |Appveyor Build Status| |Coveralls Status| ------- Summary ------- MapServer is a system for developing web-based GIS applications. The basic system consists of a CGI program that can be configured to respond to a variety of spatial requests like making maps, scalebars, and point, area and feature queries. Virtually all aspects of an application, from web interface to map appearance can be developed without any programming. For the more ambitious user, MapServer applications can be enhanced using Python, PHP, Java, JavaScript or many other web technologies. For more information and complete documentation please visit: https://mapserver.org/ Bug reports and enhancement submissions can be reported in the MapServer issue tracker at the following url. If you do make changes and/or enhancements, please let us know so that they might be incorporated into future releases. https://github.com/MapServer/MapServer/issues Join the MapServer user mailing list online at: https://mapserver.org/community/lists.html Credits ------- MapServer was originally written by Stephen Lime. Major funding for development of MapServer has been provided by NASA through cooperative argreements with the University of Minnesota, Department of Forest Resources. PHP/MapScript developed by DM Solutions Group. GDAL/OGR support and significant WMS support provided by DM Solutions Group which received funding support from Canadian Government's GeoConnections Program and the Canadian Forest Service. Raster support developed by Pete Olson of the State of Minnesota, Land Management Information Center, and maintained by Frank Warmerdam (DM Solutions). PostGIS spatial database support provided by Dave Blasby of Refractions Research. PDF support developed by Jeff Spielberg and Jamie Wall of Market Insite Group, Inc. OracleSpatial support developed by Rodrigo Cabral of CTTMAR/UNIVALI, Brazil. Portions Copyright (c) 1998 State of Minnesota, Land Management Information Center. Portions derived from Shapelib, Copyright 1995-1999 Frank Warmerdam. Supporting packages are covered by their own copyrights. License ------- :: Copyright (c) 2008-2021 Open Source Geospatial Foundation. Copyright (c) 1996-2008 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. .. |Build Status| image:: https://travis-ci.com/MapServer/MapServer.svg?branch=main :target: https://travis-ci.com/MapServer/MapServer .. |Appveyor Build Status| image:: https://ci.appveyor.com/api/projects/status/vw1n07095a8bg23u?svg=true :target: https://ci.appveyor.com/project/mapserver/mapserver .. |Coveralls Status| image:: https://coveralls.io/repos/github/mapserver/mapserver/badge.svg?branch=master :target: https://coveralls.io/github/mapserver/mapserver?branch=master mapserver-7.6.4/Vagrantfile000066400000000000000000000032341407312142500157220ustar00rootroot00000000000000# -*- mode: ruby -*- # vi: set ft=ruby : require 'socket' # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! VAGRANTFILE_API_VERSION = "2" $set_environment_variables = <\n" " \n" " \n" " \n" "
\n" " \n" "\n" ""; static char *olLayerMapServerTag = \ "var mslayer = new OpenLayers.Layer.MapServer( \"MapServer Layer\",\n" " \"[mapserv_onlineresource]\",\n" " {layers: '[layers]'},\n" " {singleTile: \"true\", ratio:1} )"; static char *olLayerWMSTag = \ "var mslayer = new OpenLayers.Layer.WMS('MapServer Simple Viewer\',\n" " '[mapserv_onlineresource]',\n" " {layers: '[LAYERS]',\n" " bbox: '[minx],[miny],[maxx],[maxy]',\n" " width: [mapwidth], height: [mapheight], version: '[VERSION]', format:'[openlayers_format]'}," " {singleTile: \"true\", ratio:1, projection: '[openlayers_projection]'});\n"; static char *processLine(mapservObj *mapserv, char *instr, FILE *stream, int mode); static int isValidTemplate(FILE *stream, const char *filename) { char buffer[MS_BUFFER_LENGTH]; if(fgets(buffer, MS_BUFFER_LENGTH, stream) != NULL) { if(!strcasestr(buffer, MS_TEMPLATE_MAGIC_STRING)) { msSetError(MS_WEBERR, "Missing magic string, %s doesn't look like a MapServer template.", "isValidTemplate()", filename); return MS_FALSE; } } return MS_TRUE; } /* * Redirect to (only use in CGI) * */ int msRedirect(char *url) { msIO_setHeader("Status","302 Found"); msIO_setHeader("Uri","%s",url); msIO_setHeader("Location","%s",url); msIO_setHeader("Content-Type","text/html"); msIO_sendHeaders(); return MS_SUCCESS; } /* ** Sets the map extent under a variety of scenarios. */ int setExtent(mapservObj *mapserv) { double cellx,celly,cellsize; if(mapserv->Mode == TILE) { if(MS_SUCCESS != msTileSetExtent(mapserv)) { return MS_FAILURE; } } switch(mapserv->CoordSource) { case FROMUSERBOX: /* user passed in a map extent */ break; case FROMIMGBOX: /* fully interactive web, most likely with java front end */ cellx = MS_CELLSIZE(mapserv->ImgExt.minx, mapserv->ImgExt.maxx, mapserv->ImgCols); celly = MS_CELLSIZE(mapserv->ImgExt.miny, mapserv->ImgExt.maxy, mapserv->ImgRows); mapserv->map->extent.minx = MS_IMAGE2MAP_X(mapserv->ImgBox.minx, mapserv->ImgExt.minx, cellx); mapserv->map->extent.maxx = MS_IMAGE2MAP_X(mapserv->ImgBox.maxx, mapserv->ImgExt.minx, cellx); mapserv->map->extent.maxy = MS_IMAGE2MAP_Y(mapserv->ImgBox.miny, mapserv->ImgExt.maxy, celly); /* y's are flip flopped because img/map coordinate systems are */ mapserv->map->extent.miny = MS_IMAGE2MAP_Y(mapserv->ImgBox.maxy, mapserv->ImgExt.maxy, celly); break; case FROMIMGPNT: cellx = MS_CELLSIZE(mapserv->ImgExt.minx, mapserv->ImgExt.maxx, mapserv->ImgCols); celly = MS_CELLSIZE(mapserv->ImgExt.miny, mapserv->ImgExt.maxy, mapserv->ImgRows); mapserv->mappnt.x = MS_IMAGE2MAP_X(mapserv->ImgPnt.x, mapserv->ImgExt.minx, cellx); mapserv->mappnt.y = MS_IMAGE2MAP_Y(mapserv->ImgPnt.y, mapserv->ImgExt.maxy, celly); mapserv->map->extent.minx = mapserv->mappnt.x - .5*((mapserv->ImgExt.maxx - mapserv->ImgExt.minx)/mapserv->fZoom); /* create an extent around that point */ mapserv->map->extent.miny = mapserv->mappnt.y - .5*((mapserv->ImgExt.maxy - mapserv->ImgExt.miny)/mapserv->fZoom); mapserv->map->extent.maxx = mapserv->mappnt.x + .5*((mapserv->ImgExt.maxx - mapserv->ImgExt.minx)/mapserv->fZoom); mapserv->map->extent.maxy = mapserv->mappnt.y + .5*((mapserv->ImgExt.maxy - mapserv->ImgExt.miny)/mapserv->fZoom); break; case FROMREFPNT: cellx = MS_CELLSIZE(mapserv->map->reference.extent.minx, mapserv->map->reference.extent.maxx, mapserv->map->reference.width); celly = MS_CELLSIZE(mapserv->map->reference.extent.miny, mapserv->map->reference.extent.maxy, mapserv->map->reference.height); mapserv->mappnt.x = MS_IMAGE2MAP_X(mapserv->RefPnt.x, mapserv->map->reference.extent.minx, cellx); mapserv->mappnt.y = MS_IMAGE2MAP_Y(mapserv->RefPnt.y, mapserv->map->reference.extent.maxy, celly); mapserv->map->extent.minx = mapserv->mappnt.x - .5*(mapserv->ImgExt.maxx - mapserv->ImgExt.minx); /* create an extent around that point */ mapserv->map->extent.miny = mapserv->mappnt.y - .5*(mapserv->ImgExt.maxy - mapserv->ImgExt.miny); mapserv->map->extent.maxx = mapserv->mappnt.x + .5*(mapserv->ImgExt.maxx - mapserv->ImgExt.minx); mapserv->map->extent.maxy = mapserv->mappnt.y + .5*(mapserv->ImgExt.maxy - mapserv->ImgExt.miny); break; case FROMBUF: mapserv->map->extent.minx = mapserv->mappnt.x - mapserv->Buffer; /* create an extent around that point, using the buffer */ mapserv->map->extent.miny = mapserv->mappnt.y - mapserv->Buffer; mapserv->map->extent.maxx = mapserv->mappnt.x + mapserv->Buffer; mapserv->map->extent.maxy = mapserv->mappnt.y + mapserv->Buffer; break; case FROMSCALE: cellsize = (mapserv->ScaleDenom/mapserv->map->resolution)/msInchesPerUnit(mapserv->map->units,0); /* user supplied a point and a scale denominator */ mapserv->map->extent.minx = mapserv->mappnt.x - cellsize*(mapserv->map->width-1)/2.0; mapserv->map->extent.miny = mapserv->mappnt.y - cellsize*(mapserv->map->height-1)/2.0; mapserv->map->extent.maxx = mapserv->mappnt.x + cellsize*(mapserv->map->width-1)/2.0; mapserv->map->extent.maxy = mapserv->mappnt.y + cellsize*(mapserv->map->height-1)/2.0; break; default: /* use the default in the mapfile if it exists */ if((mapserv->map->extent.minx == mapserv->map->extent.maxx) && (mapserv->map->extent.miny == mapserv->map->extent.maxy)) { msSetError(MS_WEBERR, "No way to generate map extent.", "mapserv()"); return MS_FAILURE; } } mapserv->RawExt = mapserv->map->extent; /* save unaltered extent */ return MS_SUCCESS; } int checkWebExtent(mapservObj *mapserv) { return MS_SUCCESS; } int checkWebScale(mapservObj *mapserv) { int status; rectObj work_extent = mapserv->map->extent; mapserv->map->cellsize = msAdjustExtent(&(work_extent), mapserv->map->width, mapserv->map->height); /* we do this cause we need a scale */ if((status = msCalculateScale(work_extent, mapserv->map->units, mapserv->map->width, mapserv->map->height, mapserv->map->resolution, &mapserv->map->scaledenom)) != MS_SUCCESS) return status; if((mapserv->map->scaledenom < mapserv->map->web.minscaledenom) && (mapserv->map->web.minscaledenom > 0)) { if(mapserv->map->web.mintemplate) { /* use the template provided */ if(TEMPLATE_TYPE(mapserv->map->web.mintemplate) == MS_FILE) { if((status = msReturnPage(mapserv, mapserv->map->web.mintemplate, BROWSE, NULL)) != MS_SUCCESS) return status; } else { if((status = msReturnURL(mapserv, mapserv->map->web.mintemplate, BROWSE)) != MS_SUCCESS) return status; } } else { /* force zoom = 1 (i.e. pan) */ mapserv->fZoom = mapserv->Zoom = 1; mapserv->ZoomDirection = 0; mapserv->CoordSource = FROMSCALE; mapserv->ScaleDenom = mapserv->map->web.minscaledenom; mapserv->mappnt.x = (mapserv->map->extent.maxx + mapserv->map->extent.minx)/2; /* use center of bad extent */ mapserv->mappnt.y = (mapserv->map->extent.maxy + mapserv->map->extent.miny)/2; setExtent(mapserv); mapserv->map->cellsize = msAdjustExtent(&(mapserv->map->extent), mapserv->map->width, mapserv->map->height); if((status = msCalculateScale(mapserv->map->extent, mapserv->map->units, mapserv->map->width, mapserv->map->height, mapserv->map->resolution, &mapserv->map->scaledenom)) != MS_SUCCESS) return status; } } else { if((mapserv->map->scaledenom > mapserv->map->web.maxscaledenom) && (mapserv->map->web.maxscaledenom > 0)) { if(mapserv->map->web.maxtemplate) { /* use the template provided */ if(TEMPLATE_TYPE(mapserv->map->web.maxtemplate) == MS_FILE) { if((status = msReturnPage(mapserv, mapserv->map->web.maxtemplate, BROWSE, NULL)) != MS_SUCCESS) return status; } else { if((status = msReturnURL(mapserv, mapserv->map->web.maxtemplate, BROWSE)) != MS_SUCCESS) return status; } } else { /* force zoom = 1 (i.e. pan) */ mapserv->fZoom = mapserv->Zoom = 1; mapserv->ZoomDirection = 0; mapserv->CoordSource = FROMSCALE; mapserv->ScaleDenom = mapserv->map->web.maxscaledenom; mapserv->mappnt.x = (mapserv->map->extent.maxx + mapserv->map->extent.minx)/2; /* use center of bad extent */ mapserv->mappnt.y = (mapserv->map->extent.maxy + mapserv->map->extent.miny)/2; setExtent(mapserv); mapserv->map->cellsize = msAdjustExtent(&(mapserv->map->extent), mapserv->map->width, mapserv->map->height); if((status = msCalculateScale(mapserv->map->extent, mapserv->map->units, mapserv->map->width, mapserv->map->height, mapserv->map->resolution, &mapserv->map->scaledenom)) != MS_SUCCESS) return status; } } } return MS_SUCCESS; } int msReturnTemplateQuery(mapservObj *mapserv, char *queryFormat, char **papszBuffer) { imageObj *img = NULL; int i, status; outputFormatObj *outputFormat=NULL; mapObj *map = mapserv->map; if(!queryFormat) { msSetError(MS_WEBERR, "Return format/mime-type not specified.", "msReturnTemplateQuery()"); return MS_FAILURE; } msApplyDefaultOutputFormats(map); i = msGetOutputFormatIndex(map, queryFormat); /* queryFormat can be a mime-type or name */ if(i >= 0) outputFormat = map->outputformatlist[i]; if(outputFormat) { if( MS_RENDERER_PLUGIN(outputFormat) ) { msInitializeRendererVTable(outputFormat); } /* if( MS_RENDERER_MVT(outputFormat) ) { if( mapserv != NULL ) checkWebScale(mapserv); status = msMVTWriteFromQuery(map, outputFormat, mapserv->sendheaders); return status; } */ if( MS_RENDERER_OGR(outputFormat) ) { if( mapserv != NULL ) checkWebScale(mapserv); status = msOGRWriteFromQuery(map, outputFormat, mapserv->sendheaders); return status; } if( !MS_RENDERER_TEMPLATE(outputFormat) ) { /* got an image format, return the query results that way */ outputFormatObj *tempOutputFormat = map->outputformat; /* save format */ if( mapserv != NULL ) checkWebScale(mapserv); map->outputformat = outputFormat; /* override what was given for IMAGETYPE */ img = msDrawMap(map, MS_TRUE); if(!img) return MS_FAILURE; map->outputformat = tempOutputFormat; /* restore format */ if(mapserv == NULL || mapserv->sendheaders) { msIO_setHeader("Content-Type", "%s", MS_IMAGE_MIME_TYPE(outputFormat)); msIO_sendHeaders(); } status = msSaveImage(map, img, NULL); msFreeImage(img); return status; } } /* ** At this point we know we have a template of some sort, either the new style that references a or the old ** style made up of external files slammed together. Either way we may have to compute a query map and other ** images. We only create support images IF the querymap has status=MS_ON. */ if(map->querymap.status && mapserv != NULL ) { checkWebScale(mapserv); if(msGenerateImages(mapserv, MS_TRUE, MS_TRUE) != MS_SUCCESS) return MS_FAILURE; } if(outputFormat) { const char *file = msGetOutputFormatOption( outputFormat, "FILE", NULL ); if(!file) { msSetError(MS_WEBERR, "Template driver requires \"FILE\" format option be set.", "msReturnTemplateQuery()"); return MS_FAILURE; } if(mapserv == NULL || mapserv->sendheaders) { const char *attachment = msGetOutputFormatOption( outputFormat, "ATTACHMENT", NULL ); if(attachment) msIO_setHeader("Content-disposition","attachment; filename=%s", attachment); msIO_setHeader("Content-Type", "%s", outputFormat->mimetype); msIO_sendHeaders(); } if((status = msReturnPage(mapserv, (char *) file, BROWSE, papszBuffer)) != MS_SUCCESS) return status; } else { if((status = msReturnNestedTemplateQuery(mapserv, queryFormat, papszBuffer)) != MS_SUCCESS) return status; } return MS_SUCCESS; } /* ** Is a particular layer or group on, that is was it requested explicitly by the user. */ int isOn(mapservObj *mapserv, char *name, char *group) { int i; for(i=0; iNumLayers; i++) { if(name && strcmp(mapserv->Layers[i], name) == 0) return(MS_TRUE); if(group && strcmp(mapserv->Layers[i], group) == 0) return(MS_TRUE); } return(MS_FALSE); } /************************************************************************/ /* int sortLayerByOrder(mapObj *map, char* pszOrder) */ /* */ /* sorth the displaying in ascending or descending order. */ /************************************************************************/ int sortLayerByOrder(mapObj *map, const char* pszOrder) { int *panCurrentOrder = NULL; int i = 0; if(!map) { msSetError(MS_WEBERR, "Invalid pointer.", "sortLayerByOrder()"); return MS_FAILURE; } /* ==================================================================== */ /* The flag "ascending" is in fact not useful since the */ /* default ordering is ascending. */ /* ==================================================================== */ /* -------------------------------------------------------------------- */ /* the map->layerorder should be set at this point in the */ /* sortLayerByMetadata. */ /* -------------------------------------------------------------------- */ if(map->layerorder) { panCurrentOrder = (int*)msSmallMalloc(map->numlayers * sizeof(int)); for (i=0; inumlayers ; i++) panCurrentOrder[i] = map->layerorder[i]; if(strcasecmp(pszOrder, "DESCENDING") == 0) { for (i=0; inumlayers; i++) map->layerorder[i] = panCurrentOrder[map->numlayers-1-i]; } free(panCurrentOrder); } return MS_SUCCESS; } /*! * This function set the map->layerorder * index order by the metadata collumn name */ static int sortLayerByMetadata(mapObj *map, const char* pszMetadata) { int nLegendOrder1; int nLegendOrder2; int i, j; int tmp; if(!map) { msSetError(MS_WEBERR, "Invalid pointer.", "sortLayerByMetadata()"); return MS_FAILURE; } /* * Initiate to default order (Reverse mapfile order) */ if(map->layerorder) { int *pnLayerOrder; /* Backup the original layer order to be able to reverse it */ pnLayerOrder = (int*)msSmallMalloc(map->numlayers * sizeof(int)); for (i=0; inumlayers ; i++) pnLayerOrder[i] = map->layerorder[i]; /* Get a new layerorder array */ free(map->layerorder); map->layerorder = (int*)msSmallMalloc(map->numlayers * sizeof(int)); /* Reverse the layerorder array */ for (i=0; inumlayers ; i++) map->layerorder[i] = pnLayerOrder[map->numlayers - i - 1]; free(pnLayerOrder); } else { map->layerorder = (int*)msSmallMalloc(map->numlayers * sizeof(int)); for (i=0; inumlayers ; i++) map->layerorder[i] = map->numlayers - i - 1; } if(!pszMetadata) return MS_SUCCESS; /* * Bubble sort algo (not very efficient) * should implement a kind of quick sort * alog instead */ for (i=0; inumlayers-1; i++) { for (j=0; jnumlayers-1-i; j++) { const char* pszLegendOrder1 = msLookupHashTable(&(GET_LAYER(map, map->layerorder[j+1])->metadata), pszMetadata); const char* pszLegendOrder2 = msLookupHashTable(&(GET_LAYER(map, map->layerorder[j])->metadata), pszMetadata); if(!pszLegendOrder1 || !pszLegendOrder2) continue; nLegendOrder1 = atoi(pszLegendOrder1); nLegendOrder2 = atoi(pszLegendOrder2); if(nLegendOrder1 < nLegendOrder2) { /* compare the two neighbors */ tmp = map->layerorder[j]; /* swap a[j] and a[j+1] */ map->layerorder[j] = map->layerorder[j+1]; map->layerorder[j+1] = tmp; } } } return MS_SUCCESS; } /* ** This function return a pointer ** at the begining of the first occurence ** of pszTag in pszInstr. ** ** Tag can be [TAG] or [TAG something] */ char *findTag(char *pszInstr, char *pszTag) { char *pszTag1, *pszStart=NULL; char *pszTemp; int done=MS_FALSE; int length; if(!pszInstr || !pszTag) { msSetError(MS_WEBERR, "Invalid pointer.", "findTag()"); return NULL; } length = strlen(pszTag) + 1; /* adding [ character to the beginning */ pszTag1 = (char*) msSmallMalloc(length+1); strcpy(pszTag1, "["); strcat(pszTag1, pszTag); pszTemp = pszInstr; while(!done) { pszStart = strstr(pszTemp, pszTag1); if(pszStart == NULL) done = MS_TRUE; /* tag not found */ else if((*(pszStart+length) == ']' || *(pszStart+length) == ' ')) done = MS_TRUE; /* valid tag */ else pszTemp += length; /* skip ahead and start over */ } free(pszTag1); return pszStart; } /* ** This function return a pointer ** to the end of the tag in pszTag ** ** The end of a tag is the next ** non-quoted ']' character. ** Return NULL if not found. */ char *findTagEnd(const char *pszTag) { char *pszEnd = NULL, *pszTmp = (char*)pszTag; while (pszTmp != NULL) { if (*pszTmp == '"') pszTmp = strchr(pszTmp+1,'"'); if ((pszTmp == NULL) || (*pszTmp == ']')) { pszEnd = pszTmp; pszTmp = NULL; } else pszTmp++; } return pszEnd; } /* ** Return a hashtableobj from instr of all ** arguments. hashtable must be freed by caller. */ int getTagArgs(char* pszTag, char* pszInstr, hashTableObj **ppoHashTable) { char *pszStart, *pszEnd, *pszArgs; int nLength; char **papszArgs, **papszVarVal; int nArgs, nDummy; int i; if(!pszTag || !pszInstr) { msSetError(MS_WEBERR, "Invalid pointer.", "getTagArgs()"); return MS_FAILURE; } /* set position to the begining of tag */ pszStart = findTag(pszInstr, pszTag); if(pszStart) { /* find ending position */ pszEnd = findTagEnd(pszStart); if(pszEnd) { /* skip the tag name */ pszStart = pszStart + strlen(pszTag) + 1; /* get length of all args */ nLength = pszEnd - pszStart; if(nLength > 0) { /* is there arguments ? */ pszArgs = (char*)msSmallMalloc(nLength + 1); strlcpy(pszArgs, pszStart, nLength+1); if(!(*ppoHashTable)) *ppoHashTable = msCreateHashTable(); /* put all arguments seperate by space in a hash table */ papszArgs = msStringTokenize(pszArgs, " ", &nArgs, MS_TRUE); /* msReturnTemplateQuerycheck all argument if they have values */ for (i=0; i 0) { *pszResult = (char*)msSmallMalloc(nLength + 1); /* copy string beetween start and end tag */ strlcpy(*pszResult, pszStart, nLength+1); (*pszResult)[nLength] = '\0'; } } else { msSetError(MS_WEBERR, "Malformed [%s] tag.", "getInlineTag()", pszTag); return MS_FAILURE; } } msFree(pszEndTag); return MS_SUCCESS; } /*! * this function process all if tag in pszInstr. * this function return a modified pszInstr. * ht mus contain all variables needed by the function * to interpret if expression. * * If bLastPass is true then all tests for 'null' values will be * considered true if the corresponding value is not set. */ int processIfTag(char **pszInstr, hashTableObj *ht, int bLastPass) { /* char *pszNextInstr = pszInstr; */ char *pszStart, *pszEnd=NULL; const char *pszName, *pszValue, *pszOperator, *pszHTValue; char *pszThen=NULL; char *pszIfTag; char *pszPatIn=NULL, *pszPatOut=NULL, *pszTmp; int nInst = 0; int bEmpty = 0; int nLength; hashTableObj *ifArgs=NULL; if(!*pszInstr) { msSetError(MS_WEBERR, "Invalid pointer.", "processIfTag()"); return MS_FAILURE; } /* find the if start tag */ pszStart = findTag(*pszInstr, "if"); while (pszStart) { pszPatIn = findTag(pszStart, "if"); pszPatOut = strstr(pszStart, "[/if]"); pszTmp = pszPatIn; do { if(pszPatIn && pszPatIn < pszPatOut) { nInst++; pszTmp = pszPatIn; } if(pszPatOut && ((pszPatIn == NULL) || pszPatOut < pszPatIn)) { pszEnd = pszPatOut; nInst--; pszTmp = pszPatOut; } pszPatIn = findTag(pszTmp+1, "if"); pszPatOut = strstr(pszTmp+1, "[/if]"); } while (pszTmp != NULL && nInst > 0); /* get the then string (if expression is true) */ if(getInlineTag("if", pszStart, &pszThen) != MS_SUCCESS) { msSetError(MS_WEBERR, "Malformed then if tag.", "processIfTag()"); return MS_FAILURE; } /* retrieve if tag args */ if(getTagArgs("if", pszStart, &ifArgs) != MS_SUCCESS) { msSetError(MS_WEBERR, "Malformed args if tag.", "processIfTag()"); return MS_FAILURE; } pszName = msLookupHashTable(ifArgs, "name"); pszValue = msLookupHashTable(ifArgs, "value"); pszOperator = msLookupHashTable(ifArgs, "oper"); if(pszOperator == NULL) /* Default operator if not set is "eq" */ pszOperator = "eq"; bEmpty = 0; if(pszName) { /* build the complete if tag ([if all_args]then string[/if]) */ /* to replace if by then string if expression is true */ /* or by a white space if not. */ nLength = pszEnd - pszStart; pszIfTag = (char*)msSmallMalloc(nLength + 6); strlcpy(pszIfTag, pszStart, nLength+1); pszIfTag[nLength] = '\0'; strcat(pszIfTag, "[/if]"); pszHTValue = msLookupHashTable(ht, pszName); if(strcmp(pszOperator, "neq") == 0) { if(pszValue && pszHTValue && strcasecmp(pszValue, pszHTValue) != 0) { *pszInstr = msReplaceSubstring(*pszInstr, pszIfTag, pszThen); } else if(pszHTValue) { *pszInstr = msReplaceSubstring(*pszInstr, pszIfTag, ""); bEmpty = 1; } } else if(strcmp(pszOperator, "eq") == 0) { if(pszValue && pszHTValue && strcasecmp(pszValue, pszHTValue) == 0) { *pszInstr = msReplaceSubstring(*pszInstr, pszIfTag, pszThen); } else if(pszHTValue) { *pszInstr = msReplaceSubstring(*pszInstr, pszIfTag, ""); bEmpty = 1; } } else if(strcmp(pszOperator, "isnull") == 0) { if(pszHTValue != NULL) { /* We met a non-null value... condition is false */ *pszInstr = msReplaceSubstring(*pszInstr, pszIfTag, ""); bEmpty = 1; } else if(bLastPass) { /* On last pass, if value is still null then condition is true */ *pszInstr = msReplaceSubstring(*pszInstr, pszIfTag, pszThen); } } else if(strcmp(pszOperator, "isset") == 0) { if(pszHTValue != NULL) { /* Found a non-null value... condition is true */ *pszInstr = msReplaceSubstring(*pszInstr, pszIfTag, pszThen); } else if(bLastPass) { /* On last pass, if value still not set then condition is false */ *pszInstr = msReplaceSubstring(*pszInstr, pszIfTag, ""); bEmpty = 1; } } else { msSetError(MS_WEBERR, "Unsupported operator (%s) in if tag.", "processIfTag()", pszOperator); return MS_FAILURE; } if(pszIfTag) free(pszIfTag); pszIfTag = NULL; } if(pszThen) free (pszThen); pszThen=NULL; msFreeHashTable(ifArgs); ifArgs=NULL; /* find the if start tag */ if(bEmpty) pszStart = findTag(pszStart, "if"); else pszStart = findTag(pszStart + 1, "if"); } return MS_SUCCESS; } /* Helper function to return the text before the supplied string2 in string1. */ static char *getPreTagText(const char *string1, const char *string2) { int n; char *result, *tmpstr; if((tmpstr = strstr(string1, string2)) == NULL) return msStrdup(""); /* return an empty string */ n = strlen(string1) - strlen(tmpstr); result = (char *) msSmallMalloc(n + 1); strlcpy(result, string1, n+1); return result; } /* Helper function to retunr the text after the supplied string2 in string1. */ static char *getPostTagText(const char *string1, const char *string2) { char *tmpstr; if((tmpstr = strstr(string1, string2)) == NULL) return msStrdup(""); /* return an empty string */ tmpstr += strlen(string2); /* skip string2 */ return msStrdup(tmpstr); } /* ** Function to process a [feature ...] tag. This tag can *only* be found within ** a [resultset ...][/resultset] block. */ static int processFeatureTag(mapservObj *mapserv, char **line, layerObj *layer) { char *preTag, *postTag; /* text before and after the tag */ const char *argValue; char *tag, *tagInstance, *tagStart; hashTableObj *tagArgs=NULL; int limit=-1; const char *trimLast=NULL; int i, j, status; if(!*line) { msSetError(MS_WEBERR, "Invalid line pointer.", "processFeatureTag()"); return(MS_FAILURE); } tagStart = findTag(*line, "feature"); if(!tagStart) return(MS_SUCCESS); /* OK, just return; */ /* check for any tag arguments */ if(getTagArgs("feature", tagStart, &tagArgs) != MS_SUCCESS) return(MS_FAILURE); if(tagArgs) { argValue = msLookupHashTable(tagArgs, "limit"); if(argValue) limit = atoi(argValue); argValue = msLookupHashTable(tagArgs, "trimlast"); if(argValue) trimLast = argValue; } if(strstr(*line, "[/feature]") == NULL) { /* we know the closing tag must be here, if not throw an error */ msSetError(MS_WEBERR, "[feature] tag found without closing [/feature].", "processFeatureTag()"); msFreeHashTable(tagArgs); return(MS_FAILURE); } if(getInlineTag("feature", *line, &tag) != MS_SUCCESS) { msSetError(MS_WEBERR, "Malformed feature tag.", "processFeatureTag()"); msFreeHashTable(tagArgs); return MS_FAILURE; } preTag = getPreTagText(*line, "[feature"); postTag = getPostTagText(*line, "[/feature]"); /* start rebuilding **line */ free(*line); *line = preTag; /* we know the layer has query results or we wouldn't be in this code */ #if 0 status = msLayerOpen(layer); /* open the layer */ if(status != MS_SUCCESS) return status; status = msLayerGetItems(layer); /* retrieve all the item names */ if(status != MS_SUCCESS) return status; #endif if(layer->numjoins > 0) { /* initialize necessary JOINs here */ for(j=0; jnumjoins; j++) { status = msJoinConnect(layer, &(layer->joins[j])); if(status != MS_SUCCESS) { msFreeHashTable(tagArgs); msFree(postTag); msFree(tag); return status; } } } mapserv->LRN = 1; /* layer result counter */ mapserv->resultlayer = layer; msInitShape(&(mapserv->resultshape)); if(limit == -1) /* return all */ limit = layer->resultcache->numresults; else limit = MS_MIN(limit, layer->resultcache->numresults); for(i=0; iresultshape), &(layer->resultcache->results[i])); if(status != MS_SUCCESS) { msFreeHashTable(tagArgs); msFree(postTag); msFree(tag); return status; } mapserv->resultshape.classindex = msShapeGetClass(layer, layer->map, &mapserv->resultshape, NULL, -1); /* prepare any necessary JOINs here (one-to-one only) */ if(layer->numjoins > 0) { for(j=0; jnumjoins; j++) { if(layer->joins[j].type == MS_JOIN_ONE_TO_ONE) { msJoinPrepare(&(layer->joins[j]), &(mapserv->resultshape)); msJoinNext(&(layer->joins[j])); /* fetch the first row */ } } } /* ** if necessary trim a few characters off the end of the tag */ if(trimLast && (i == limit-1)) { char *ptr; if((ptr = strrstr(tag, trimLast)) != NULL) *ptr = '\0'; } /* process the tag */ tagInstance = processLine(mapserv, tag, NULL, QUERY); /* do substitutions */ *line = msStringConcatenate(*line, tagInstance); /* grow the line */ free(tagInstance); msFreeShape(&(mapserv->resultshape)); /* init too */ mapserv->RN++; /* increment counters */ mapserv->LRN++; } /* msLayerClose(layer); */ mapserv->resultlayer = NULL; /* necessary? */ *line = msStringConcatenate(*line, postTag); /* ** clean up */ free(postTag); free(tag); msFreeHashTable(tagArgs); return(MS_SUCCESS); } /* ** Function to process a [resultset ...] tag. */ static int processResultSetTag(mapservObj *mapserv, char **line, FILE *stream) { char lineBuffer[MS_BUFFER_LENGTH]; int foundTagEnd; char *preTag, *postTag; /* text before and after the tag */ char *tag, *tagStart; hashTableObj *tagArgs=NULL; const char *layerName=NULL; const char *nodata=NULL; int layerIndex=-1; layerObj *lp; if(!*line) { msSetError(MS_WEBERR, "Invalid line pointer.", "processResultSetTag()"); return(MS_FAILURE); } tagStart = findTag(*line, "resultset"); if(!tagStart) return(MS_SUCCESS); /* OK, just return; */ while (tagStart) { /* initialize the tag arguments */ layerName = NULL; /* check for any tag arguments */ if(getTagArgs("resultset", tagStart, &tagArgs) != MS_SUCCESS) return(MS_FAILURE); if(tagArgs) { layerName = msLookupHashTable(tagArgs, "layer"); nodata = msLookupHashTable(tagArgs, "nodata"); } if(!layerName) { msSetError(MS_WEBERR, "[resultset] tag missing required 'layer' argument.", "processResultSetTag()"); msFreeHashTable(tagArgs); return(MS_FAILURE); } layerIndex = msGetLayerIndex(mapserv->map, layerName); if(layerIndex>=mapserv->map->numlayers || layerIndex<0) { msSetError(MS_MISCERR, "Layer named '%s' does not exist.", "processResultSetTag()", layerName); msFreeHashTable(tagArgs); return MS_FAILURE; } lp = GET_LAYER(mapserv->map, layerIndex); if(strstr(*line, "[/resultset]") == NULL) { /* read ahead */ if(!stream) { msSetError(MS_WEBERR, "Invalid file pointer.", "processResultSetTag()"); msFreeHashTable(tagArgs); return(MS_FAILURE); } foundTagEnd = MS_FALSE; while(!foundTagEnd) { if(fgets(lineBuffer, MS_BUFFER_LENGTH, stream) != NULL) { *line = msStringConcatenate(*line, lineBuffer); if(strstr(*line, "[/resultset]") != NULL) foundTagEnd = MS_TRUE; } else break; /* ran out of file */ } if(foundTagEnd == MS_FALSE) { msSetError(MS_WEBERR, "[resultset] tag found without closing [/resultset].", "processResultSetTag()"); msFreeHashTable(tagArgs); return(MS_FAILURE); } } if(getInlineTag("resultset", *line, &tag) != MS_SUCCESS) { msSetError(MS_WEBERR, "Malformed resultset tag.", "processResultSetTag()"); msFreeHashTable(tagArgs); return MS_FAILURE; } preTag = getPreTagText(*line, "[resultset"); /* TODO: need to handle tags in these */ postTag = getPostTagText(*line, "[/resultset]"); /* start rebuilding **line */ free(*line); *line = preTag; if(lp->resultcache && lp->resultcache->numresults > 0) { /* probably will need a while-loop here to handle multiple instances of [feature ...] tags */ if(processFeatureTag(mapserv, &tag, lp) != MS_SUCCESS) { msFreeHashTable(tagArgs); return(MS_FAILURE); /* TODO: how to handle */ } *line = msStringConcatenate(*line, tag); } else if(nodata) { *line = msStringConcatenate(*line, nodata); } *line = msStringConcatenate(*line, postTag); /* clean up */ free(postTag); free(tag); tagStart = findTag(*line, "resultset"); } msFreeHashTable(tagArgs); return(MS_SUCCESS); } /* ** Function process a [include src="..."] tag. ** ** TODO's: ** - allow URLs */ static int processIncludeTag(mapservObj *mapserv, char **line, FILE *stream, int mode) { char *tag, *tagStart, *tagEnd; hashTableObj *tagArgs=NULL; int tagOffset, tagLength; char *content=NULL, *processedContent=NULL; const char *src=NULL; FILE *includeStream; char buffer[MS_BUFFER_LENGTH], path[MS_MAXPATHLEN]; if(!*line) { msSetError(MS_WEBERR, "Invalid line pointer.", "processIncludeTag()"); return(MS_FAILURE); } tagStart = findTag(*line, "include"); /* It is OK to have no include tags, just return. */ if( !tagStart ) return MS_SUCCESS; while( tagStart ) { tagOffset = tagStart - *line; /* check for any tag arguments */ if(getTagArgs("include", tagStart, &tagArgs) != MS_SUCCESS) return(MS_FAILURE); if(tagArgs) { src = msLookupHashTable(tagArgs, "src"); } if(!src) return(MS_SUCCESS); /* don't process the tag, could be something else so return MS_SUCCESS */ if((includeStream = fopen(msBuildPath(path, mapserv->map->mappath, src), "r")) == NULL) { msSetError(MS_IOERR, "%s", "processIncludeTag()", src); return MS_FAILURE; } if(isValidTemplate(includeStream, src) != MS_TRUE) { fclose(includeStream); return MS_FAILURE; } while(fgets(buffer, MS_BUFFER_LENGTH, includeStream) != NULL) content = msStringConcatenate(content, buffer); /* done with included file handle */ fclose(includeStream); /* find the end of the tag */ tagEnd = findTagEnd(tagStart); tagEnd++; /* build the complete tag so we can do substitution */ tagLength = tagEnd - tagStart; tag = (char *) msSmallMalloc(tagLength + 1); strlcpy(tag, tagStart, tagLength+1); /* process any other tags in the content */ processedContent = processLine(mapserv, content, stream, mode); /* do the replacement */ *line = msReplaceSubstring(*line, tag, processedContent); /* clean up */ free(tag); tag = NULL; msFreeHashTable(tagArgs); tagArgs=NULL; free(content); free(processedContent); if((*line)[tagOffset] != '\0') tagStart = findTag(*line+tagOffset+1, "include"); else tagStart = NULL; } return(MS_SUCCESS); } /* ** Function to process an [item ...] tag: line contains the tag, shape holds the attributes. */ enum ITEM_ESCAPING {ESCAPE_HTML, ESCAPE_URL, ESCAPE_JSON, ESCAPE_NONE}; static int processItemTag(layerObj *layer, char **line, shapeObj *shape) { int i, j; char *tag, *tagStart, *tagEnd; hashTableObj *tagArgs=NULL; int tagLength; char *encodedTagValue=NULL, *tagValue=NULL; const char *argValue=NULL; const char *name=NULL, *pattern=NULL; const char *format=NULL, *nullFormat=NULL; int precision; int padding; int uc, lc, commify; int escape; if(!*line) { msSetError(MS_WEBERR, "Invalid line pointer.", "processItemTag()"); return(MS_FAILURE); } tagStart = findTag(*line, "item"); if(!tagStart) return(MS_SUCCESS); /* OK, just return; */ while (tagStart) { format = "$value"; /* initialize the tag arguments */ nullFormat = ""; precision = -1; padding = -1; name = pattern = NULL; uc = lc = commify = MS_FALSE; escape=ESCAPE_HTML; /* check for any tag arguments */ if(getTagArgs("item", tagStart, &tagArgs) != MS_SUCCESS) return(MS_FAILURE); if(tagArgs) { argValue = msLookupHashTable(tagArgs, "name"); if(argValue) name = argValue; argValue = msLookupHashTable(tagArgs, "pattern"); if(argValue) pattern = argValue; argValue = msLookupHashTable(tagArgs, "precision"); if(argValue) precision = atoi(argValue); argValue = msLookupHashTable(tagArgs, "padding"); if (argValue) padding = atoi(argValue); argValue = msLookupHashTable(tagArgs, "format"); if(argValue) format = argValue; argValue = msLookupHashTable(tagArgs, "nullformat"); if(argValue) nullFormat = argValue; argValue = msLookupHashTable(tagArgs, "uc"); if(argValue && strcasecmp(argValue, "true") == 0) uc = MS_TRUE; argValue = msLookupHashTable(tagArgs, "lc"); if(argValue && strcasecmp(argValue, "true") == 0) lc = MS_TRUE; argValue = msLookupHashTable(tagArgs, "commify"); if(argValue && strcasecmp(argValue, "true") == 0) commify = MS_TRUE; argValue = msLookupHashTable(tagArgs, "escape"); if(argValue && strcasecmp(argValue, "url") == 0) escape = ESCAPE_URL; else if(argValue && strcasecmp(argValue, "none") == 0) escape = ESCAPE_NONE; else if(argValue && strcasecmp(argValue, "json") == 0) escape = ESCAPE_JSON; /* TODO: deal with sub strings */ } if(!name) { msSetError(MS_WEBERR, "Item tag contains no name attribute.", "processItemTag()"); return(MS_FAILURE); } for(i=0; inumitems; i++) if(strcasecmp(name, layer->items[i]) == 0) break; if(i == layer->numitems) { msSetError(MS_WEBERR, "Item name (%s) not found in layer item list.", "processItemTag()", name); return(MS_FAILURE); } /* ** now we know which item so build the tagValue */ if(shape->values[i] && strlen(shape->values[i]) > 0) { char *itemValue=NULL; /* set tag text depending on pattern (if necessary), nullFormat can contain $value (#3637) */ if(pattern && msEvalRegex(pattern, shape->values[i]) != MS_TRUE) tagValue = msStrdup(nullFormat); else tagValue = msStrdup(format); if(precision != -1) { char numberFormat[16]; itemValue = (char *) msSmallMalloc(64); /* plenty big */ snprintf(numberFormat, sizeof(numberFormat), "%%.%dlf", precision); snprintf(itemValue, 64, numberFormat, atof(shape->values[i])); } else itemValue = msStrdup(shape->values[i]); if(commify == MS_TRUE) itemValue = msCommifyString(itemValue); /* apply other effects */ if(uc == MS_TRUE) for(j=0; j 0 && padding < 1000) { int paddedSize = strlen(tagValue) + padding + 1; char *paddedValue = NULL; paddedValue = (char *) msSmallMalloc(paddedSize); snprintf(paddedValue, paddedSize, "%-*s", padding, tagValue); msFree(tagValue); tagValue = paddedValue; } if(!tagValue) { msSetError(MS_WEBERR, "Error applying item format.", "processItemTag()"); return(MS_FAILURE); /* todo leaking... */ } } else { tagValue = msStrdup(nullFormat); /* attribute value is NULL or empty */ } /* find the end of the tag */ tagEnd = findTagEnd(tagStart); tagEnd++; /* build the complete tag so we can do substitution */ tagLength = tagEnd - tagStart; tag = (char *) msSmallMalloc(tagLength + 1); strlcpy(tag, tagStart, tagLength+1); /* do the replacement */ switch(escape) { case ESCAPE_HTML: encodedTagValue = msEncodeHTMLEntities(tagValue); *line = msReplaceSubstring(*line, tag, encodedTagValue); break; case ESCAPE_JSON: encodedTagValue = msEscapeJSonString(tagValue); *line = msReplaceSubstring(*line, tag, encodedTagValue); break; case ESCAPE_URL: encodedTagValue = msEncodeUrl(tagValue); *line = msReplaceSubstring(*line, tag, encodedTagValue); break; case ESCAPE_NONE: *line = msReplaceSubstring(*line, tag, tagValue); break; default: break; } /* clean up */ free(tag); tag = NULL; msFreeHashTable(tagArgs); tagArgs=NULL; msFree(tagValue); tagValue=NULL; msFree(encodedTagValue); encodedTagValue=NULL; tagStart = findTag(*line, "item"); } return(MS_SUCCESS); } /* ** Function process any number of MapServer extent tags (e.g. shpext, mapext, etc...). */ static int processExtentTag(mapservObj *mapserv, char **line, char *name, rectObj *extent, projectionObj *rectProj) { char *tag, *tagStart, *tagEnd; hashTableObj *tagArgs=NULL; int tagOffset, tagLength; char *encodedTagValue=NULL, *tagValue=NULL; rectObj tempExtent; int escape; char number[64]; /* holds a single number in the extent */ char numberFormat[16]; if(!*line) { msSetError(MS_WEBERR, "Invalid line pointer.", "processExtentTag()"); return(MS_FAILURE); } tagStart = findTag(*line, name); /* this supports any extent */ /* It is OK to have no include tags, just return. */ if(!tagStart) return MS_SUCCESS; /* hack to handle tags like 'mapext_esc' easily */ if(strstr(name, "_esc")) escape = ESCAPE_URL; while(tagStart) { double xExpand = 0, yExpand = 0; /* set tag argument defaults */ int precision = -1; const char* format = "$minx $miny $maxx $maxy"; const char* projectionString = NULL; if(strstr(name, "_esc")) escape = ESCAPE_URL; else escape = ESCAPE_HTML; tagOffset = tagStart - *line; /* check for any tag arguments */ if(getTagArgs(name, tagStart, &tagArgs) != MS_SUCCESS) return(MS_FAILURE); if(tagArgs) { const char* argValue = msLookupHashTable(tagArgs, "expand"); if(argValue) { if(strchr(argValue, '%') != NULL) { float f; sscanf(argValue, "%f%%", &f); xExpand = ((f/100.0)*(extent->maxx-extent->minx))/2; yExpand = ((f/100.0)*(extent->maxy-extent->miny))/2; } else { xExpand = atof(argValue); yExpand = xExpand; } } argValue = msLookupHashTable(tagArgs, "escape"); if(argValue && strcasecmp(argValue, "url") == 0) escape = ESCAPE_URL; else if(argValue && strcasecmp(argValue, "none") == 0) escape = ESCAPE_NONE; argValue = msLookupHashTable(tagArgs, "format"); if(argValue) format = argValue; argValue = msLookupHashTable(tagArgs, "precision"); if(argValue) precision = atoi(argValue); argValue = msLookupHashTable(tagArgs, "proj"); if(argValue) projectionString = argValue; } tempExtent.minx = extent->minx - xExpand; tempExtent.miny = extent->miny - yExpand; tempExtent.maxx = extent->maxx + xExpand; tempExtent.maxy = extent->maxy + yExpand; /* no big deal to convert from file to image coordinates, but what are the image parameters */ if(rectProj && projectionString && strcasecmp(projectionString,"image") == 0) { precision = 0; /* if necessary, project the shape to match the map */ if(msProjectionsDiffer(rectProj, &(mapserv->map->projection))) msProjectRect(rectProj, &mapserv->map->projection, &tempExtent); /* convert tempExtent to image coordinates based on the map extent and cellsize */ tempExtent.minx = MS_MAP2IMAGE_X(tempExtent.minx, mapserv->map->extent.minx, mapserv->map->cellsize); tempExtent.miny = MS_MAP2IMAGE_Y(tempExtent.miny, mapserv->map->extent.maxy, mapserv->map->cellsize); tempExtent.maxx = MS_MAP2IMAGE_X(tempExtent.minx, mapserv->map->extent.minx, mapserv->map->cellsize); tempExtent.maxy = MS_MAP2IMAGE_Y(tempExtent.miny, mapserv->map->extent.maxy, mapserv->map->cellsize); } else if(rectProj && projectionString) { projectionObj projection; msInitProjection(&projection); msProjectionInheritContextFrom(&projection, &mapserv->map->projection); if(MS_SUCCESS != msLoadProjectionString(&projection, projectionString)) return MS_FAILURE; if(msProjectionsDiffer(rectProj, &projection)) msProjectRect(rectProj, &projection, &tempExtent); } tagValue = msStrdup(format); if(precision != -1) snprintf(numberFormat, sizeof(numberFormat), "%%.%dlf", precision); else snprintf(numberFormat, sizeof(numberFormat), "%%f"); snprintf(number, sizeof(number), numberFormat, tempExtent.minx); tagValue = msReplaceSubstring(tagValue, "$minx", number); snprintf(number, sizeof(number), numberFormat, tempExtent.miny); tagValue = msReplaceSubstring(tagValue, "$miny", number); snprintf(number, sizeof(number), numberFormat, tempExtent.maxx); tagValue = msReplaceSubstring(tagValue, "$maxx", number); snprintf(number, sizeof(number), numberFormat, tempExtent.maxy); tagValue = msReplaceSubstring(tagValue, "$maxy", number); /* find the end of the tag */ tagEnd = findTagEnd(tagStart); tagEnd++; /* build the complete tag so we can do substitution */ tagLength = tagEnd - tagStart; tag = (char *) msSmallMalloc(tagLength + 1); strlcpy(tag, tagStart, tagLength+1); /* do the replacement */ switch(escape) { case ESCAPE_HTML: encodedTagValue = msEncodeHTMLEntities(tagValue); *line = msReplaceSubstring(*line, tag, encodedTagValue); break; case ESCAPE_URL: encodedTagValue = msEncodeUrl(tagValue); *line = msReplaceSubstring(*line, tag, encodedTagValue); break; case ESCAPE_NONE: *line = msReplaceSubstring(*line, tag, tagValue); break; default: break; } /* clean up */ free(tag); tag = NULL; msFreeHashTable(tagArgs); tagArgs=NULL; msFree(tagValue); tagValue=NULL; msFree(encodedTagValue); encodedTagValue=NULL; if((*line)[tagOffset] != '\0') tagStart = findTag(*line+tagOffset+1, name); else tagStart = NULL; } return(MS_SUCCESS); } // RFC 77 TODO: Need to validate these changes with Assefa... static int processShplabelTag(layerObj *layer, char **line, shapeObj *origshape) { char *tag, *tagStart, *tagEnd; char *tagValue=NULL; hashTableObj *tagArgs=NULL; int tagOffset, tagLength; const char *format; const char *argValue=NULL; const char *projectionString=NULL; shapeObj tShape; int precision=0; int clip_to_map=MS_TRUE; int use_label_settings=MS_FALSE; double cellsize=0; int labelposvalid = MS_FALSE; pointObj labelPos; int status; char number[64]; /* holds a single number in the extent */ char numberFormat[16]; shapeObj *shape = NULL; if(!*line) { msSetError(MS_WEBERR, "Invalid line pointer.", "processShplabelTag()"); return(MS_FAILURE); } if(msCheckParentPointer(layer->map,"map") == MS_FAILURE) return MS_FAILURE; tagStart = findTag(*line, "shplabel"); /* It is OK to have no shplabel tags, just return. */ if(!tagStart) return MS_SUCCESS; if(!origshape || origshape->numlines <= 0) { /* I suppose we need to make sure the part has vertices (need shape checker?) */ msSetError(MS_WEBERR, "Null or empty shape.", "processShplabelTag()"); return(MS_FAILURE); } while(tagStart) { if(shape) msFreeShape(shape); shape = (shapeObj *) msSmallMalloc(sizeof(shapeObj)); msInitShape(shape); msCopyShape(origshape, shape); projectionString = NULL; format = "$x,$y"; tagOffset = tagStart - *line; if(getTagArgs("shplabel", tagStart, &tagArgs) != MS_SUCCESS) return(MS_FAILURE); if(tagArgs) { argValue = msLookupHashTable(tagArgs, "format"); if(argValue) format = argValue; argValue = msLookupHashTable(tagArgs, "precision"); if(argValue) precision = atoi(argValue); argValue = msLookupHashTable(tagArgs, "proj"); if(argValue) projectionString = argValue; argValue = msLookupHashTable(tagArgs, "clip_to_map"); if(argValue) { if(strcasecmp(argValue,"false") == 0) clip_to_map = MS_FALSE; } argValue = msLookupHashTable(tagArgs, "use_label_settings"); if(argValue) { if(strcasecmp(argValue,"true") == 0) use_label_settings = MS_TRUE; } } labelPos.x = -1; labelPos.y = -1; msInitShape(&tShape); tShape.type = MS_SHAPE_LINE; tShape.line = (lineObj *) msSmallMalloc(sizeof(lineObj)); tShape.numlines = 1; tShape.line[0].point = NULL; /* initialize the line */ tShape.line[0].numpoints = 0; if(layer->map->cellsize <= 0) cellsize = MS_MAX(MS_CELLSIZE(layer->map->extent.minx, layer->map->extent.maxx, layer->map->width), MS_CELLSIZE(layer->map->extent.miny, layer->map->extent.maxy, layer->map->height)); else cellsize = layer->map->cellsize ; if(shape->type == MS_SHAPE_POINT) { labelposvalid = MS_FALSE; if(shape->numlines > 0 && shape->line[0].numpoints > 0) { labelposvalid = MS_TRUE; labelPos = shape->line[0].point[0]; if(layer->transform == MS_TRUE) { if(layer->project && msProjectionsDiffer(&(layer->projection), &(layer->map->projection))) { if( layer->reprojectorLayerToMap == NULL ) { layer->reprojectorLayerToMap = msProjectCreateReprojector( &layer->projection, &layer->map->projection); } if( layer->reprojectorLayerToMap ) { msProjectShapeEx(layer->reprojectorLayerToMap, shape); } } labelPos = shape->line[0].point[0]; labelPos.x = MS_MAP2IMAGE_X(labelPos.x, layer->map->extent.minx, cellsize); labelPos.y = MS_MAP2IMAGE_Y(labelPos.y, layer->map->extent.maxy, cellsize); } } } else if(shape->type == MS_SHAPE_LINE) { labelposvalid = MS_FALSE; if(layer->transform == MS_TRUE) { if(layer->project && msProjectionsDiffer(&(layer->projection), &(layer->map->projection))) { if( layer->reprojectorLayerToMap == NULL ) { layer->reprojectorLayerToMap = msProjectCreateReprojector( &layer->projection, &layer->map->projection); } if( layer->reprojectorLayerToMap ) { msProjectShapeEx(layer->reprojectorLayerToMap, shape); } } if(clip_to_map) msClipPolylineRect(shape, layer->map->extent); msTransformShapeToPixelRound(shape, layer->map->extent, cellsize); } else msOffsetShapeRelativeTo(shape, layer); if(shape->numlines > 0) { struct label_auto_result lar; memset(&lar,0,sizeof(struct label_auto_result)); if(UNLIKELY(MS_FAILURE == msPolylineLabelPoint(layer->map, shape, NULL, NULL, &lar, 0))) { free(lar.angles); free(lar.label_points); return MS_FAILURE; } if(lar.num_label_points > 0) { /* convert to geo */ labelPos.x = lar.label_points[0].x; labelPos.y = lar.label_points[0].y; labelposvalid = MS_TRUE; } free(lar.angles); free(lar.label_points); } } else if (shape->type == MS_SHAPE_POLYGON) { labelposvalid = MS_FALSE; if(layer->transform == MS_TRUE) { if(layer->project && msProjectionsDiffer(&(layer->projection), &(layer->map->projection))) { if( layer->reprojectorLayerToMap == NULL ) { layer->reprojectorLayerToMap = msProjectCreateReprojector( &layer->projection, &layer->map->projection); } if( layer->reprojectorLayerToMap ) { msProjectShapeEx(layer->reprojectorLayerToMap, shape); } } if(clip_to_map) msClipPolygonRect(shape, layer->map->extent); msTransformShapeToPixelRound(shape, layer->map->extent, cellsize); } else msOffsetShapeRelativeTo(shape, layer); if(shape->numlines > 0) { if(msPolygonLabelPoint(shape, &labelPos, -1) == MS_SUCCESS) { if(labelPos.x == -1 && labelPos.y == -1) labelposvalid = MS_FALSE; else labelposvalid = MS_TRUE; } } } if(labelposvalid == MS_TRUE) { pointObj p1 = {0,0,0,0}; // initialize pointObj p2 = {0,0,0,0}; int label_offset_x, label_offset_y; labelObj *label=NULL; label_bounds lbounds; lineObj lbounds_line; pointObj lbounds_point[5]; double tmp; p1.x =labelPos.x; p1.y =labelPos.y; p2.x =labelPos.x; p2.y =labelPos.y; if(use_label_settings == MS_TRUE) { /* RFC 77: classes (and shapes) can have more than 1 piece of annotation, here we only use the first (index=0) */ if(shape->classindex >= 0 && layer->class[shape->classindex]->numlabels > 0) { label = layer->class[shape->classindex]->labels[0]; if(msGetLabelStatus(layer->map,layer,shape,label) == MS_ON) { char *annotext = msShapeGetLabelAnnotation(layer,shape,label); if(annotext) { textSymbolObj ts; initTextSymbol(&ts); msPopulateTextSymbolForLabelAndString(&ts, label, annotext, layer->scalefactor, 1.0, 0); label_offset_x = (int)(label->offsetx*layer->scalefactor); label_offset_y = (int)(label->offsety*layer->scalefactor); lbounds.poly = &lbounds_line; lbounds_line.numpoints = 5; lbounds_line.point = lbounds_point; p1 = get_metrics(&labelPos, label->position, ts.textpath, label_offset_x, label_offset_y, label->angle* MS_DEG_TO_RAD, 0, &lbounds); /* should we use the point returned from get_metrics?. From few test done, It seems to return the UL corner of the text. For now use the bounds.minx/miny */ p1.x = lbounds.bbox.minx; p1.y = lbounds.bbox.miny; p2.x = lbounds.bbox.maxx; p2.y = lbounds.bbox.maxy; freeTextSymbol(&ts); } } } } /* y's are flipped because it is in image coordinate systems */ p1.x = MS_IMAGE2MAP_X(p1.x, layer->map->extent.minx, cellsize); tmp = p1.y; p1.y = MS_IMAGE2MAP_Y(p2.y, layer->map->extent.maxy, cellsize); p2.x = MS_IMAGE2MAP_X(p2.x, layer->map->extent.minx, cellsize); p2.y = MS_IMAGE2MAP_Y(tmp, layer->map->extent.maxy, cellsize); if(layer->transform == MS_TRUE) { if(layer->project && msProjectionsDiffer(&(layer->projection), &(layer->map->projection))) { msProjectPoint(&layer->map->projection, &layer->projection, &p1); msProjectPoint(&layer->map->projection, &layer->projection, &p2); } } msAddPointToLine(&(tShape.line[0]), &p1); msAddPointToLine(&(tShape.line[0]), &p2); } else tShape.numlines = 0; if(projectionString && strcasecmp(projectionString,"image") == 0) { precision = 0; /* if necessary, project the shape to match the map */ if(msProjectionsDiffer(&(layer->projection), &(layer->map->projection))) { if( layer->reprojectorLayerToMap == NULL ) { layer->reprojectorLayerToMap = msProjectCreateReprojector( &layer->projection, &layer->map->projection); } if( layer->reprojectorLayerToMap ) { msProjectShapeEx(layer->reprojectorLayerToMap, &tShape); } } msClipPolylineRect(&tShape, layer->map->extent); msTransformShapeToPixelRound(&tShape, layer->map->extent, layer->map->cellsize); } else if(projectionString) { projectionObj projection; msInitProjection(&projection); msProjectionInheritContextFrom(&projection, &layer->map->projection); status = msLoadProjectionString(&projection, projectionString); if(status != MS_SUCCESS) return MS_FAILURE; if(msProjectionsDiffer(&(layer->projection), &projection)) msProjectShape(&layer->projection, &projection, &tShape); } /* find the end of the tag */ tagEnd = findTagEnd(tagStart); tagEnd++; /* build the complete tag so we can do substitution */ tagLength = tagEnd - tagStart; tag = (char *) msSmallMalloc(tagLength + 1); strlcpy(tag, tagStart, tagLength+1); /* do the replacement */ tagValue = msStrdup(format); if(precision > 0) snprintf(numberFormat, sizeof(numberFormat), "%%.%dlf", precision); else snprintf(numberFormat, sizeof(numberFormat), "%%f"); if(tShape.numlines > 0) { if(strcasestr(tagValue, "$x") != 0) { snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[0].x); tagValue = msReplaceSubstring(tagValue, "$x", number); } if(strcasestr(tagValue, "$y") != 0) { snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[0].y); tagValue = msReplaceSubstring(tagValue, "$y", number); } if(strcasestr(tagValue, "$minx") != 0) { snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[0].x); tagValue = msReplaceSubstring(tagValue, "$minx", number); } if(strcasestr(tagValue, "$miny") != 0) { snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[0].y); tagValue = msReplaceSubstring(tagValue, "$miny", number); } if(strcasestr(tagValue, "$maxx") != 0) { snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[1].x); tagValue = msReplaceSubstring(tagValue, "$maxx", number); } if(strcasestr(tagValue, "$maxy") != 0) { snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[1].y); tagValue = msReplaceSubstring(tagValue, "$maxy", number); } } /* find the end of the tag */ tagEnd = findTagEnd(tagStart); tagEnd++; /* build the complete tag so we can do substitution */ tagLength = tagEnd - tagStart; tag = (char *) msSmallMalloc(tagLength + 1); strlcpy(tag, tagStart, tagLength+1); *line = msReplaceSubstring(*line, tag, tagValue); /* clean up */ msFreeShape(&tShape); free(tag); tag = NULL; msFreeHashTable(tagArgs); tagArgs=NULL; msFree(tagValue); tagValue=NULL; if((*line)[tagOffset] != '\0') tagStart = findTag(*line+tagOffset+1, "shplabel"); else tagStart = NULL; } if(shape) msFreeShape(shape); return(MS_SUCCESS); } /* ** Function to process a [date ...] tag */ static int processDateTag(char **line) { struct tm *datetime; time_t t; int result; char *tag=NULL, *tagStart, *tagEnd; hashTableObj *tagArgs=NULL; int tagOffset, tagLength; #define DATE_BUFLEN 1024 char datestr[DATE_BUFLEN]; const char *argValue=NULL; const char *format, *tz; /* tag parameters */ if(!*line) { msSetError(MS_WEBERR, "Invalid line pointer.", "processDateTag()"); return(MS_FAILURE); } tagStart = findTag(*line, "date"); /* It is OK to have no date tags, just return. */ if( !tagStart ) return MS_SUCCESS; while (tagStart) { /* set tag params to defaults */ format = DEFAULT_DATE_FORMAT; tz = ""; tagOffset = tagStart - *line; /* check for any tag arguments */ if(getTagArgs("date", tagStart, &tagArgs) != MS_SUCCESS) return(MS_FAILURE); if(tagArgs) { argValue = msLookupHashTable(tagArgs, "format"); if(argValue) format = argValue; argValue = msLookupHashTable(tagArgs, "tz"); if(argValue) tz = argValue; } t = time(NULL); if( strncasecmp( tz, "gmt", 4 ) == 0 ) { datetime = gmtime(&t); } else { datetime = localtime(&t); } result = strftime(datestr, DATE_BUFLEN, format, datetime); /* Only do the replacement if the date was successfully written */ if( result > 0 ) { /* find the end of the tag */ tagEnd = findTagEnd(tagStart); tagEnd++; /* build the complete tag so we can do substitution */ tagLength = tagEnd - tagStart; tag = (char *) msSmallMalloc(tagLength + 1); strlcpy(tag, tagStart, tagLength+1); /* do the replacement */ *line = msReplaceSubstring(*line, tag, datestr); } /* clean up */ msFree(tag); tag = NULL; msFreeHashTable(tagArgs); tagArgs=NULL; if((*line)[tagOffset] != '\0') tagStart = findTag(*line+tagOffset+1, "date"); else tagStart = NULL; } return(MS_SUCCESS); } /* ** Function to process a [shpxy ...] tag: line contains the tag, shape holds the coordinates. ** ** TODO's: ** - May need to change attribute names. ** - Need generalization routines (not here, but in mapprimative.c). ** - Try to avoid all the realloc calls. */ static int processShpxyTag(layerObj *layer, char **line, shapeObj *shape) { int i,j,p; int status; char *tag, *tagStart, *tagEnd; hashTableObj *tagArgs=NULL; int tagOffset, tagLength; const char *argValue=NULL; char *pointFormat1=NULL, *pointFormat2=NULL; int pointFormatLength; /* ** Pointers to static strings, naming convention is: ** char 1/2 - x=x, y=y, c=coordinate, p=part, s=shape, ir=inner ring, or=outer ring ** last char - h=header, f=footer, s=seperator */ const char *xh, *xf, *yh, *yf; const char *cs; const char *ph, *pf, *ps; const char *sh, *sf; const char *irh, *irf; /* inner ring: necessary for complex polygons */ const char *orh, *orf; /* outer ring */ int centroid; int precision; double scale_x, scale_y; const char *projectionString=NULL; shapeObj tShape; char *coords=NULL, point[128]; if(!*line) { msSetError(MS_WEBERR, "Invalid line pointer.", "processShpxyTag()"); return(MS_FAILURE); } if( msCheckParentPointer(layer->map,"map")==MS_FAILURE ) return MS_FAILURE; tagStart = findTag(*line, "shpxy"); /* It is OK to have no shpxy tags, just return. */ if( !tagStart ) return MS_SUCCESS; if(!shape || shape->numlines <= 0) { /* I suppose we need to make sure the part has vertices (need shape checker?) */ msSetError(MS_WEBERR, "Null or empty shape.", "processShpxyTag()"); return(MS_FAILURE); } while (tagStart) { #ifdef USE_GEOS double buffer = 0; int bufferUnits = -1; #endif xh = yh = yf = ph = pf = sh = sf = ""; /* initialize the tag arguments */ xf= ","; irh = irf = orh = orf = ""; ps = cs = " "; centroid = MS_FALSE; precision = 0; scale_x = scale_y = 1.0; projectionString = NULL; tagOffset = tagStart - *line; /* check for any tag arguments */ if(getTagArgs("shpxy", tagStart, &tagArgs) != MS_SUCCESS) return(MS_FAILURE); if(tagArgs) { argValue = msLookupHashTable(tagArgs, "xh"); if(argValue) xh = argValue; argValue = msLookupHashTable(tagArgs, "xf"); if(argValue) xf = argValue; argValue = msLookupHashTable(tagArgs, "yh"); if(argValue) yh = argValue; argValue = msLookupHashTable(tagArgs, "yf"); if(argValue) yf = argValue; argValue = msLookupHashTable(tagArgs, "cs"); if(argValue) cs = argValue; argValue = msLookupHashTable(tagArgs, "irh"); if(argValue) irh = argValue; argValue = msLookupHashTable(tagArgs, "irf"); if(argValue) irf = argValue; argValue = msLookupHashTable(tagArgs, "orh"); if(argValue) orh = argValue; argValue = msLookupHashTable(tagArgs, "orf"); if(argValue) orf = argValue; argValue = msLookupHashTable(tagArgs, "ph"); if(argValue) ph = argValue; argValue = msLookupHashTable(tagArgs, "pf"); if(argValue) pf = argValue; argValue = msLookupHashTable(tagArgs, "ps"); if(argValue) ps = argValue; argValue = msLookupHashTable(tagArgs, "sh"); if(argValue) sh = argValue; argValue = msLookupHashTable(tagArgs, "sf"); if(argValue) sf = argValue; #ifdef USE_GEOS argValue = msLookupHashTable(tagArgs, "buffer"); if(argValue) { buffer = atof(argValue); if(strstr(argValue, "px")) bufferUnits = MS_PIXELS; /* may support others at some point */ } #endif argValue = msLookupHashTable(tagArgs, "precision"); if(argValue) precision = atoi(argValue); argValue = msLookupHashTable(tagArgs, "scale"); if(argValue) { scale_x = atof(argValue); scale_y = scale_x; } argValue = msLookupHashTable(tagArgs, "scale_x"); if(argValue) scale_x = atof(argValue); argValue = msLookupHashTable(tagArgs, "scale_y"); if(argValue) scale_y = atof(argValue); argValue = msLookupHashTable(tagArgs, "centroid"); if(argValue) if(strcasecmp(argValue,"true") == 0) centroid = MS_TRUE; argValue = msLookupHashTable(tagArgs, "proj"); if(argValue) projectionString = argValue; } /* build the per point format strings (version 1 contains the coordinate seperator, version 2 doesn't) */ pointFormatLength = strlen(xh) + strlen(xf) + strlen(yh) + strlen(yf) + strlen(cs) + 12 + 1; pointFormat1 = (char *) msSmallMalloc(pointFormatLength); snprintf(pointFormat1, pointFormatLength, "%s%%.%dlf%s%s%%.%dlf%s%s", xh, precision, xf, yh, precision, yf, cs); pointFormat2 = (char *) msSmallMalloc(pointFormatLength); snprintf(pointFormat2, pointFormatLength, "%s%%.%dlf%s%s%%.%dlf%s", xh, precision, xf, yh, precision, yf); /* make a copy of the original shape or compute a centroid if necessary */ msInitShape(&tShape); if(centroid == MS_TRUE) { pointObj p; p.x = (shape->bounds.minx + shape->bounds.maxx)/2; p.y = (shape->bounds.miny + shape->bounds.maxy)/2; tShape.type = MS_SHAPE_POINT; tShape.line = (lineObj *) msSmallMalloc(sizeof(lineObj)); tShape.numlines = 1; tShape.line[0].point = NULL; /* initialize the line */ tShape.line[0].numpoints = 0; msAddPointToLine(&(tShape.line[0]), &p); } #ifdef USE_GEOS else if(buffer != 0 && bufferUnits != MS_PIXELS) { shapeObj *bufferShape=NULL; bufferShape = msGEOSBuffer(shape, buffer); if(!bufferShape) { free(pointFormat1); free(pointFormat2); return(MS_FAILURE); /* buffer failed */ } msCopyShape(bufferShape, &tShape); msFreeShape(bufferShape); } #endif else { status = msCopyShape(shape, &tShape); if(status != 0) { free(pointFormat1); free(pointFormat2); return(MS_FAILURE); /* copy failed */ } } /* no big deal to convert from file to image coordinates, but what are the image parameters */ if(projectionString && strcasecmp(projectionString,"image") == 0) { precision = 0; /* if necessary, project the shape to match the map */ if(msProjectionsDiffer(&(layer->projection), &(layer->map->projection))) { if( layer->reprojectorLayerToMap == NULL ) { layer->reprojectorLayerToMap = msProjectCreateReprojector( &layer->projection, &layer->map->projection); } if( layer->reprojectorLayerToMap ) { msProjectShapeEx(layer->reprojectorLayerToMap, &tShape); } } switch(tShape.type) { case(MS_SHAPE_POINT): /* no clipping necessary */ break; case(MS_SHAPE_LINE): msClipPolylineRect(&tShape, layer->map->extent); break; case(MS_SHAPE_POLYGON): msClipPolygonRect(&tShape, layer->map->extent); break; default: /* TO DO: need an error message here */ return(MS_FAILURE); break; } msTransformShapeToPixelRound(&tShape, layer->map->extent, layer->map->cellsize); #ifdef USE_GEOS if(buffer != 0 && bufferUnits == MS_PIXELS) { shapeObj *bufferShape=NULL; bufferShape = msGEOSBuffer(&tShape, buffer); if(!bufferShape) { if(!msIsDegenerateShape(&tShape)) /* If shape is degenerate this is expected. */ return(MS_FAILURE); /* buffer failed */ } else { msFreeShape(&tShape); /* avoid memory leak */ msCopyShape(bufferShape, &tShape); msFreeShape(bufferShape); } } #endif } else if(projectionString) { projectionObj projection; msInitProjection(&projection); msProjectionInheritContextFrom(&projection, &(layer->projection)); status = msLoadProjectionString(&projection, projectionString); if(status != MS_SUCCESS) return MS_FAILURE; if(msProjectionsDiffer(&(layer->projection), &projection)) msProjectShape(&layer->projection, &projection, &tShape); } /* TODO: add thinning support here */ /* ** build the coordinate string */ if(strlen(sh) > 0) coords = msStringConcatenate(coords, sh); /* do we need to handle inner/outer rings */ if(tShape.type == MS_SHAPE_POLYGON && strlen(orh) > 0 && strlen(irh) > 0) { int *outers; int firstPart; /* to keep track of inserting part separators before each part after the first */ outers = msGetOuterList( &tShape ); firstPart = 1; /* loop over rings looking for outers*/ for(i=0; i 0)) coords = msStringConcatenate(coords, ps); firstPart = 0; if(strlen(ph) > 0) coords = msStringConcatenate(coords, ph); coords = msStringConcatenate(coords, orh); for(p=0; p 0) coords = msStringConcatenate(coords, pf); } } /* end of loop over outer rings */ free( outers ); } else { /* output without ring formatting */ for(i=0; i 0) coords = msStringConcatenate(coords, ph); for(p=0; p 0) coords = msStringConcatenate(coords, pf); if((i < tShape.numlines-1) && (strlen(ps) > 0)) coords = msStringConcatenate(coords, ps); } } if(strlen(sf) > 0) coords = msStringConcatenate(coords, sf); msFreeShape(&tShape); /* find the end of the tag */ tagEnd = findTagEnd(tagStart); tagEnd++; /* build the complete tag so we can do substitution */ tagLength = tagEnd - tagStart; tag = (char *) msSmallMalloc(tagLength + 1); strlcpy(tag, tagStart, tagLength+1); /* do the replacement */ *line = msReplaceSubstring(*line, tag, coords); /* clean up */ free(tag); tag = NULL; msFreeHashTable(tagArgs); tagArgs=NULL; free(pointFormat1); pointFormat1 = NULL; free(pointFormat2); pointFormat2 = NULL; free(coords); coords = NULL; if((*line)[tagOffset] != '\0') tagStart = findTag(*line+tagOffset+1, "shpxy"); else tagStart = NULL; } return(MS_SUCCESS); } /*! * this function process all metadata * in pszInstr. ht mus contain all corresponding * metadata value. * * this function return a modified pszInstr */ int processMetadata(char** pszInstr, hashTableObj *ht) { /* char *pszNextInstr = pszInstr; */ char *pszEnd, *pszStart; char *pszMetadataTag; const char *pszHashName; const char *pszHashValue; int nLength, nOffset; hashTableObj *metadataArgs = NULL; if(!*pszInstr) { msSetError(MS_WEBERR, "Invalid pointer.", "processMetadata()"); return MS_FAILURE; } /* set position to the begining of metadata tag */ pszStart = findTag(*pszInstr, "metadata"); while (pszStart) { /* get metadata args */ if(getTagArgs("metadata", pszStart, &metadataArgs) != MS_SUCCESS) return MS_FAILURE; pszHashName = msLookupHashTable(metadataArgs, "name"); pszHashValue = msLookupHashTable(ht, pszHashName); nOffset = pszStart - *pszInstr; if(pszHashName && pszHashValue) { /* set position to the end of metadata start tag */ pszEnd = strchr(pszStart, ']'); pszEnd++; /* build the complete metadata tag ([metadata all_args]) */ /* to replace it by the corresponding value from ht */ nLength = pszEnd - pszStart; pszMetadataTag = (char*)msSmallMalloc(nLength + 1); strlcpy(pszMetadataTag, pszStart, nLength+1); *pszInstr = msReplaceSubstring(*pszInstr, pszMetadataTag, pszHashValue); free(pszMetadataTag); pszMetadataTag=NULL; } msFreeHashTable(metadataArgs); metadataArgs=NULL; /* set position to the begining of the next metadata tag */ if((*pszInstr)[nOffset] != '\0') pszStart = findTag(*pszInstr+nOffset+1, "metadata"); else pszStart = NULL; } return MS_SUCCESS; } /*! * this function process all icon tag * from pszInstr. * * This func return a modified pszInstr. */ int processIcon(mapObj *map, int nIdxLayer, int nIdxClass, char** pszInstr, char* pszPrefix) { int nWidth, nHeight, nLen; char szImgFname[1024], *pszFullImgFname=NULL, *pszImgTag; char szPath[MS_MAXPATHLEN]; hashTableObj *myHashTable=NULL; FILE *fIcon; if(!map || nIdxLayer > map->numlayers || nIdxLayer < 0 ) { msSetError(MS_WEBERR, "Invalid pointer.", "processIcon()"); return MS_FAILURE; } /* find the begining of tag */ pszImgTag = strstr(*pszInstr, "[leg_icon"); while (pszImgTag) { int i; char szStyleCode[512] = ""; classObj *thisClass=NULL; /* It's okay to have no classes... we'll generate an empty icon in this case */ if(nIdxClass >= 0 && nIdxClass < GET_LAYER(map, nIdxLayer)->numclasses) thisClass = GET_LAYER(map, nIdxLayer)->class[nIdxClass]; if(getTagArgs("leg_icon", pszImgTag, &myHashTable) != MS_SUCCESS) return MS_FAILURE; /* if no specified width or height, set them to map default */ if(!msLookupHashTable(myHashTable, "width") || !msLookupHashTable(myHashTable, "height")) { nWidth = map->legend.keysizex; nHeight= map->legend.keysizey; } else { nWidth = atoi(msLookupHashTable(myHashTable, "width")); nHeight = atoi(msLookupHashTable(myHashTable, "height")); } /* Create a unique and predictable filename to cache the legend icons. * Include some key parameters from the first 2 styles */ for(i=0; i<2 && thisClass && inumstyles; i++) { styleObj *style; char *pszSymbolNameHash = NULL; style = thisClass->styles[i]; if(style->symbolname) pszSymbolNameHash = msHashString(style->symbolname); snprintf(szStyleCode+strlen(szStyleCode), 255, "s%d_%x_%x_%x_%d_%s_%g", i, MS_COLOR_GETRGB(style->color), MS_COLOR_GETRGB(style->backgroundcolor), MS_COLOR_GETRGB(style->outlinecolor), style->symbol, pszSymbolNameHash?pszSymbolNameHash:"", style->angle); msFree(pszSymbolNameHash); } snprintf(szImgFname, sizeof(szImgFname), "%s_%d_%d_%d_%d_%s.%s%c", pszPrefix, nIdxLayer, nIdxClass, nWidth, nHeight, szStyleCode, MS_IMAGE_EXTENSION(map->outputformat),'\0'); pszFullImgFname = msStrdup(msBuildPath3(szPath, map->mappath, map->web.imagepath, szImgFname)); /* check if icon already exist in cache */ if((fIcon = fopen(pszFullImgFname, "r")) != NULL) { /* File already exists. No need to generate it again */ fclose(fIcon); } else { /* Create an image corresponding to the current class */ imageObj *img=NULL; if(thisClass == NULL) { /* Nonexistent class. Create an empty image */ img = msCreateLegendIcon(map, NULL, NULL, nWidth, nHeight, MS_TRUE); } else { img = msCreateLegendIcon(map, GET_LAYER(map, nIdxLayer), thisClass, nWidth, nHeight, MS_TRUE); } if(!img) { if(myHashTable) msFreeHashTable(myHashTable); msSetError(MS_IMGERR, "Error while creating image.", "processIcon()"); return MS_FAILURE; } /* save it with a unique file name */ if(msSaveImage(map, img, pszFullImgFname) != MS_SUCCESS) { if(myHashTable) msFreeHashTable(myHashTable); msFreeImage(img); msSetError(MS_IOERR, "Error saving GD image to disk (%s).", "processIcon()", pszFullImgFname); msFree(pszFullImgFname); return MS_FAILURE; } msFreeImage(img); } msFree(pszFullImgFname); pszFullImgFname = NULL; nLen = (strchr(pszImgTag, ']') + 1) - pszImgTag; if(nLen > 0) { char *pszTag; /* rebuid image tag ([leg_class_img all_args]) */ /* to replace it by the image url */ pszTag = (char*)msSmallMalloc(nLen + 1); strlcpy(pszTag, pszImgTag, nLen+1); pszFullImgFname = (char*)msSmallMalloc(strlen(map->web.imageurl) + strlen(szImgFname) + 1); strcpy(pszFullImgFname, map->web.imageurl); strcat(pszFullImgFname, szImgFname); *pszInstr = msReplaceSubstring(*pszInstr, pszTag, pszFullImgFname); msFree(pszFullImgFname); pszFullImgFname = NULL; msFree(pszTag); /* find the begining of tag */ pszImgTag = strstr(*pszInstr, "[leg_icon"); } else { pszImgTag = NULL; } if(myHashTable) { msFreeHashTable(myHashTable); myHashTable = NULL; } } return MS_SUCCESS; } /*! * Replace all tags from group template * with correct value. * * this function return a buffer containing * the template with correct values. * * buffer must be freed by caller. */ int generateGroupTemplate(char* pszGroupTemplate, mapObj *map, char* pszGroupName, hashTableObj *oGroupArgs, char **pszTemp, char* pszPrefix) { hashTableObj *myHashTable; char pszStatus[3]; char *pszClassImg; const char *pszOptFlag = NULL; int i, j; int nOptFlag = 15; int bShowGroup; *pszTemp = NULL; if(!pszGroupName || !pszGroupTemplate) { msSetError(MS_WEBERR, "Invalid pointer.", "generateGroupTemplate()"); return MS_FAILURE; } /* * Get the opt_flag is any. */ if(oGroupArgs) pszOptFlag = msLookupHashTable(oGroupArgs, "opt_flag"); if(pszOptFlag) nOptFlag = atoi(pszOptFlag); /* * Check all layers, if one in the group * should be visible, print the group. * (Check for opt_flag) */ bShowGroup = 0; for (j=0; jnumlayers; j++) { if(GET_LAYER(map, map->layerorder[j])->group && strcmp(GET_LAYER(map, map->layerorder[j])->group, pszGroupName) == 0) { /* dont display layer is off. */ if( (nOptFlag & 2) == 0 && GET_LAYER(map, map->layerorder[j])->status == MS_OFF ) bShowGroup = 0; else bShowGroup = 1; /* dont display layer is query. */ if( (nOptFlag & 4) == 0 && GET_LAYER(map, map->layerorder[j])->type == MS_LAYER_QUERY ) bShowGroup = 0; /* dont display layer if out of scale. */ if((nOptFlag & 1) == 0) { if(map->scaledenom > 0) { if((GET_LAYER(map, map->layerorder[j])->maxscaledenom > 0) && (map->scaledenom > GET_LAYER(map, map->layerorder[j])->maxscaledenom)) bShowGroup = 0; if((GET_LAYER(map, map->layerorder[j])->minscaledenom > 0) && (map->scaledenom <= GET_LAYER(map, map->layerorder[j])->minscaledenom)) bShowGroup = 0; } } /* The group contains one visible layer */ /* Draw the group */ if( bShowGroup ) break; } } if( ! bShowGroup ) return MS_SUCCESS; /* * Work from a copy */ *pszTemp = (char*)msSmallMalloc(strlen(pszGroupTemplate) + 1); strcpy(*pszTemp, pszGroupTemplate); /* * Change group tags */ *pszTemp = msReplaceSubstring(*pszTemp, "[leg_group_name]", pszGroupName); /* * Create a hash table that contain info * on current layer */ myHashTable = msCreateHashTable(); /* * Check for the first layer * that belong to this group. * Get his status and check for if. */ for (j=0; jnumlayers; j++) { if(GET_LAYER(map, map->layerorder[j])->group && strcmp(GET_LAYER(map, map->layerorder[j])->group, pszGroupName) == 0) { snprintf(pszStatus, sizeof(pszStatus), "%d", GET_LAYER(map, map->layerorder[j])->status); msInsertHashTable(myHashTable, "layer_status", pszStatus); msInsertHashTable(myHashTable, "layer_visible", msLayerIsVisible(map, GET_LAYER(map, map->layerorder[j]))?"1":"0" ); msInsertHashTable(myHashTable, "layer_queryable", msIsLayerQueryable(GET_LAYER(map, map->layerorder[j]))?"1":"0" ); msInsertHashTable(myHashTable, "group_name", pszGroupName); if(processIfTag(pszTemp, myHashTable, MS_FALSE) != MS_SUCCESS) return MS_FAILURE; if(processIfTag(pszTemp, &(GET_LAYER(map, map->layerorder[j])->metadata), MS_FALSE) != MS_SUCCESS) return MS_FAILURE; if(processMetadata(pszTemp, &GET_LAYER(map, map->layerorder[j])->metadata) != MS_SUCCESS) return MS_FAILURE; break; } } msFreeHashTable(myHashTable); /* * Process all metadata tags * only web object is accessible */ if(processMetadata(pszTemp, &(map->web.metadata)) != MS_SUCCESS) return MS_FAILURE; /* * check for if tag */ if(processIfTag(pszTemp, &(map->web.metadata), MS_TRUE) != MS_SUCCESS) return MS_FAILURE; /* * Check if leg_icon tag exist * if so display the first layer first class icon */ pszClassImg = strstr(*pszTemp, "[leg_icon"); if(pszClassImg) { /* find first layer of this group */ for (i=0; inumlayers; i++) if(GET_LAYER(map, map->layerorder[i])->group && strcmp(GET_LAYER(map, map->layerorder[i])->group, pszGroupName) == 0) processIcon(map, map->layerorder[i], 0, pszTemp, pszPrefix); } return MS_SUCCESS; } /*! * Replace all tags from layer template * with correct value. * * this function return a buffer containing * the template with correct values. * * buffer must be freed by caller. */ int generateLayerTemplate(char *pszLayerTemplate, mapObj *map, int nIdxLayer, hashTableObj *oLayerArgs, char **pszTemp, char* pszPrefix) { hashTableObj *myHashTable; char szStatus[10]; char szType[10]; int nOptFlag=0; const char *pszOptFlag = NULL; char *pszClassImg; char szTmpstr[128]; /* easily big enough for the couple of instances we need */ *pszTemp = NULL; if(!pszLayerTemplate || !map || nIdxLayer > map->numlayers || nIdxLayer < 0 ) { msSetError(MS_WEBERR, "Invalid pointer.", "generateLayerTemplate()"); return MS_FAILURE; } if(oLayerArgs) pszOptFlag = msLookupHashTable(oLayerArgs, "opt_flag"); if(pszOptFlag) nOptFlag = atoi(pszOptFlag); /* don't display deleted layers */ if(GET_LAYER(map, nIdxLayer)->status == MS_DELETE) return MS_SUCCESS; /* dont display layer is off. */ /* check this if Opt flag is not set */ if((nOptFlag & 2) == 0 && GET_LAYER(map, nIdxLayer)->status == MS_OFF) return MS_SUCCESS; /* dont display layer is query. */ /* check this if Opt flag is not set */ if((nOptFlag & 4) == 0 && GET_LAYER(map, nIdxLayer)->type == MS_LAYER_QUERY) return MS_SUCCESS; /* dont display layer if out of scale. */ /* check this if Opt flag is not set */ if((nOptFlag & 1) == 0) { if(map->scaledenom > 0) { if((GET_LAYER(map, nIdxLayer)->maxscaledenom > 0) && (map->scaledenom > GET_LAYER(map, nIdxLayer)->maxscaledenom)) return MS_SUCCESS; if((GET_LAYER(map, nIdxLayer)->minscaledenom > 0) && (map->scaledenom <= GET_LAYER(map, nIdxLayer)->minscaledenom)) return MS_SUCCESS; } } /* * Work from a copy */ *pszTemp = msStrdup(pszLayerTemplate); /* * Change layer tags */ *pszTemp = msReplaceSubstring(*pszTemp, "[leg_layer_name]", GET_LAYER(map, nIdxLayer)->name); *pszTemp = msReplaceSubstring(*pszTemp, "[leg_layer_group]", GET_LAYER(map, nIdxLayer)->group); snprintf(szTmpstr, sizeof(szTmpstr), "%d", nIdxLayer); *pszTemp = msReplaceSubstring(*pszTemp, "[leg_layer_index]", szTmpstr); snprintf(szTmpstr, sizeof(szTmpstr), "%g", GET_LAYER(map, nIdxLayer)->minscaledenom); *pszTemp = msReplaceSubstring(*pszTemp, "[leg_layer_minscale]", szTmpstr); *pszTemp = msReplaceSubstring(*pszTemp, "[leg_layer_minscaledenom]", szTmpstr); snprintf(szTmpstr, sizeof(szTmpstr), "%g", GET_LAYER(map, nIdxLayer)->maxscaledenom); *pszTemp = msReplaceSubstring(*pszTemp, "[leg_layer_maxscale]", szTmpstr); *pszTemp = msReplaceSubstring(*pszTemp, "[leg_layer_maxscaledenom]", szTmpstr); /* * Create a hash table that contain info * on current layer */ myHashTable = msCreateHashTable(); /* * for now, only status and type is required by template */ snprintf(szStatus, sizeof(szStatus), "%d", GET_LAYER(map, nIdxLayer)->status); msInsertHashTable(myHashTable, "layer_status", szStatus); snprintf(szType, sizeof(szType), "%d", GET_LAYER(map, nIdxLayer)->type); msInsertHashTable(myHashTable, "layer_type", szType); msInsertHashTable(myHashTable, "layer_name", (GET_LAYER(map, nIdxLayer)->name)? GET_LAYER(map, nIdxLayer)->name : ""); msInsertHashTable(myHashTable, "layer_group", (GET_LAYER(map, nIdxLayer)->group)? GET_LAYER(map, nIdxLayer)->group : ""); msInsertHashTable(myHashTable, "layer_visible", msLayerIsVisible(map, GET_LAYER(map, nIdxLayer))?"1":"0" ); msInsertHashTable(myHashTable, "layer_queryable", msIsLayerQueryable(GET_LAYER(map, nIdxLayer))?"1":"0" ); if(processIfTag(pszTemp, myHashTable, MS_FALSE) != MS_SUCCESS) return MS_FAILURE; if(processIfTag(pszTemp, &(GET_LAYER(map, nIdxLayer)->metadata), MS_FALSE) != MS_SUCCESS) return MS_FAILURE; if(processIfTag(pszTemp, &(map->web.metadata), MS_TRUE) != MS_SUCCESS) return MS_FAILURE; msFreeHashTable(myHashTable); /* * Check if leg_icon tag exist * if so display the first class icon */ pszClassImg = strstr(*pszTemp, "[leg_icon"); if(pszClassImg) { processIcon(map, nIdxLayer, 0, pszTemp, pszPrefix); } /* process all metadata tags * only current layer and web object * metaddata are accessible */ if(processMetadata(pszTemp, &GET_LAYER(map, nIdxLayer)->metadata) != MS_SUCCESS) return MS_FAILURE; if(processMetadata(pszTemp, &(map->web.metadata)) != MS_SUCCESS) return MS_FAILURE; return MS_SUCCESS; } /*! * Replace all tags from class template * with correct value. * * this function return a buffer containing * the template with correct values. * * buffer must be freed by caller. */ int generateClassTemplate(char* pszClassTemplate, mapObj *map, int nIdxLayer, int nIdxClass, hashTableObj *oClassArgs, char **pszTemp, char* pszPrefix) { hashTableObj *myHashTable; char szStatus[10]; char szType[10]; char *pszClassImg; int nOptFlag=0; const char *pszOptFlag = NULL; char szTmpstr[128]; /* easily big enough for the couple of instances we need */ *pszTemp = NULL; if(!pszClassTemplate || !map || nIdxLayer > map->numlayers || nIdxLayer < 0 || nIdxClass > GET_LAYER(map, nIdxLayer)->numclasses || nIdxClass < 0) { msSetError(MS_WEBERR, "Invalid pointer.", "generateClassTemplate()"); return MS_FAILURE; } if(oClassArgs) pszOptFlag = msLookupHashTable(oClassArgs, "Opt_flag"); if(pszOptFlag) nOptFlag = atoi(pszOptFlag); /* don't display deleted layers */ if(GET_LAYER(map, nIdxLayer)->status == MS_DELETE) return MS_SUCCESS; /* dont display class if layer is off. */ /* check this if Opt flag is not set */ if((nOptFlag & 2) == 0 && GET_LAYER(map, nIdxLayer)->status == MS_OFF) return MS_SUCCESS; /* dont display class if layer is query. */ /* check this if Opt flag is not set */ if((nOptFlag & 4) == 0 && GET_LAYER(map, nIdxLayer)->type == MS_LAYER_QUERY) return MS_SUCCESS; /* dont display layer if out of scale. */ /* check this if Opt flag is not set */ if((nOptFlag & 1) == 0) { if(map->scaledenom > 0) { if((GET_LAYER(map, nIdxLayer)->maxscaledenom > 0) && (map->scaledenom > GET_LAYER(map, nIdxLayer)->maxscaledenom)) return MS_SUCCESS; if((GET_LAYER(map, nIdxLayer)->minscaledenom > 0) && (map->scaledenom <= GET_LAYER(map, nIdxLayer)->minscaledenom)) return MS_SUCCESS; } } /* * Work from a copy */ *pszTemp = (char*)msSmallMalloc(strlen(pszClassTemplate) + 1); strcpy(*pszTemp, pszClassTemplate); /* * Change class tags */ *pszTemp = msReplaceSubstring(*pszTemp, "[leg_class_name]", GET_LAYER(map, nIdxLayer)->class[nIdxClass]->name); *pszTemp = msReplaceSubstring(*pszTemp, "[leg_class_title]", GET_LAYER(map, nIdxLayer)->class[nIdxClass]->title); *pszTemp = msReplaceSubstring(*pszTemp, "[leg_layer_name]", GET_LAYER(map, nIdxLayer)->name); snprintf(szTmpstr, sizeof(szTmpstr), "%d", nIdxClass); *pszTemp = msReplaceSubstring(*pszTemp, "[leg_class_index]", szTmpstr); snprintf(szTmpstr, sizeof(szTmpstr), "%g", GET_LAYER(map, nIdxLayer)->class[nIdxClass]->minscaledenom); *pszTemp = msReplaceSubstring(*pszTemp, "[leg_class_minscale]", szTmpstr); *pszTemp = msReplaceSubstring(*pszTemp, "[leg_class_minscaledenom]", szTmpstr); snprintf(szTmpstr, sizeof(szTmpstr), "%g", GET_LAYER(map, nIdxLayer)->class[nIdxClass]->maxscaledenom); *pszTemp = msReplaceSubstring(*pszTemp, "[leg_class_maxscale]", szTmpstr); *pszTemp = msReplaceSubstring(*pszTemp, "[leg_class_maxscaledenom]", szTmpstr); /* * Create a hash table that contain info * on current layer */ myHashTable = msCreateHashTable(); /* * for now, only status, type, name and group are required by template */ snprintf(szStatus, sizeof(szStatus), "%d", GET_LAYER(map, nIdxLayer)->status); msInsertHashTable(myHashTable, "layer_status", szStatus); snprintf(szType, sizeof(szType), "%d", GET_LAYER(map, nIdxLayer)->type); msInsertHashTable(myHashTable, "layer_type", szType); msInsertHashTable(myHashTable, "layer_name", (GET_LAYER(map, nIdxLayer)->name)? GET_LAYER(map, nIdxLayer)->name : ""); msInsertHashTable(myHashTable, "layer_group", (GET_LAYER(map, nIdxLayer)->group)? GET_LAYER(map, nIdxLayer)->group : ""); msInsertHashTable(myHashTable, "layer_visible", msLayerIsVisible(map, GET_LAYER(map, nIdxLayer))?"1":"0" ); msInsertHashTable(myHashTable, "layer_queryable", msIsLayerQueryable(GET_LAYER(map, nIdxLayer))?"1":"0" ); msInsertHashTable(myHashTable, "class_name", (GET_LAYER(map, nIdxLayer)->class[nIdxClass]->name)? GET_LAYER(map, nIdxLayer)->class[nIdxClass]->name : ""); if(processIfTag(pszTemp, myHashTable, MS_FALSE) != MS_SUCCESS) return MS_FAILURE; if(processIfTag(pszTemp, &(GET_LAYER(map, nIdxLayer)->metadata), MS_FALSE) != MS_SUCCESS) return MS_FAILURE; if(processIfTag(pszTemp, &(map->web.metadata), MS_TRUE) != MS_SUCCESS) return MS_FAILURE; msFreeHashTable(myHashTable); /* * Check if leg_icon tag exist */ pszClassImg = strstr(*pszTemp, "[leg_icon"); if(pszClassImg) { processIcon(map, nIdxLayer, nIdxClass, pszTemp, pszPrefix); } /* process all metadata tags * only current layer and web object * metaddata are accessible */ if(processMetadata(pszTemp, &GET_LAYER(map, nIdxLayer)->metadata) != MS_SUCCESS) return MS_FAILURE; if(processMetadata(pszTemp, &(map->web.metadata)) != MS_SUCCESS) return MS_FAILURE; return MS_SUCCESS; } char *generateLegendTemplate(mapservObj *mapserv) { FILE *stream; char *file = NULL; int length; char *pszResult = NULL; char *legGroupHtml = NULL; char *legLayerHtml = NULL; char *legClassHtml = NULL; char *legLayerHtmlCopy = NULL; char *legClassHtmlCopy = NULL; char *legGroupHtmlCopy = NULL; char *legHeaderHtml = NULL; char *legFooterHtml = NULL; char *pszPrefix = NULL; char *pszMapFname = NULL; struct stat tmpStat; const char *pszOrderMetadata = NULL; const char *pszOrder = NULL; int i,j,k; char **papszGroups = NULL; int nGroupNames = 0; int nLegendOrder = 0; const char *pszOrderValue; hashTableObj *groupArgs = NULL; hashTableObj *layerArgs = NULL; hashTableObj *classArgs = NULL; ms_regex_t re; /* compiled regular expression to be matched */ int *panCurrentDrawingOrder = NULL; char szPath[MS_MAXPATHLEN]; if(ms_regcomp(&re, MS_TEMPLATE_EXPR, MS_REG_EXTENDED|MS_REG_NOSUB|MS_REG_ICASE) != 0) { msSetError(MS_IOERR, "Error regcomp.", "generateLegendTemplate()"); return NULL; } if(ms_regexec(&re, mapserv->map->legend.template, 0, NULL, 0) != 0) { /* no match */ msSetError(MS_IOERR, "Invalid template file name.", "generateLegendTemplate()"); ms_regfree(&re); return NULL; } ms_regfree(&re); /* -------------------------------------------------------------------- */ /* Save the current drawing order. The drawing order is reset */ /* at the end of the function. */ /* -------------------------------------------------------------------- */ if(mapserv && mapserv->map && mapserv->map->numlayers > 0) { panCurrentDrawingOrder = (int *)msSmallMalloc(sizeof(int)*mapserv->map->numlayers); for (i=0; imap->numlayers; i++) { if(mapserv->map->layerorder) panCurrentDrawingOrder[i] = mapserv->map->layerorder[i]; else panCurrentDrawingOrder[i] = i; } } /* * build prefix filename * for legend icon creation */ for(i=0; irequest->NumParams; i++) /* find the mapfile parameter first */ if(strcasecmp(mapserv->request->ParamNames[i], "map") == 0) break; if(i == mapserv->request->NumParams) { if( getenv("MS_MAPFILE")) pszMapFname = msStringConcatenate(pszMapFname, getenv("MS_MAPFILE")); } else { if(getenv(mapserv->request->ParamValues[i])) /* an environment references the actual file to use */ pszMapFname = msStringConcatenate(pszMapFname, getenv(mapserv->request->ParamValues[i])); else pszMapFname = msStringConcatenate(pszMapFname, mapserv->request->ParamValues[i]); } if(pszMapFname) { if(stat(pszMapFname, &tmpStat) != -1) { int nLen; nLen = (mapserv->map->name?strlen(mapserv->map->name):0) + 50; pszPrefix = (char*)msSmallMalloc((nLen+1) * sizeof(char)); snprintf(pszPrefix, nLen, "%s_%ld_%ld", mapserv->map->name, (long) tmpStat.st_size, (long) tmpStat.st_mtime); pszPrefix[nLen] = '\0'; } free(pszMapFname); pszMapFname = NULL; } else { /* -------------------------------------------------------------------- */ /* map file name may not be avaible when the template functions */ /* are called from mapscript. Use the time stamp as prefix. */ /* -------------------------------------------------------------------- */ char pszTime[20]; snprintf(pszTime, sizeof(pszTime), "%ld", (long)time(NULL)); pszPrefix = msStringConcatenate(pszPrefix, pszTime); } /* open template */ if((stream = fopen(msBuildPath(szPath, mapserv->map->mappath, mapserv->map->legend.template), "r")) == NULL) { msSetError(MS_IOERR, "Error while opening template file.", "generateLegendTemplate()"); if(pszResult) free(pszResult); pszResult=NULL; goto error; } fseek(stream, 0, SEEK_END); length = ftell(stream); rewind(stream); file = (char*)msSmallMalloc(length + 1); /* * Read all the template file */ IGUR_sizet(fread(file, length, 1, stream)); /* E. Rouault: the below issue is due to opening in "r" mode, which is a * synonymous of "rt" on Windows. In that mode \r\n are turned into \n, * consequently less bytes are written in the output buffer than requested. * A potential fix might be to open in "rb" mode, but is the code ready * to deal with Windows \r\n end of lines ? */ /* Disabled for now due to Windows issue, see ticket #3814 if( 1 != fread(file, length, 1, stream)) { msSetError(MS_IOERR, "Error while reading template file.", "generateLegendTemplate()"); free(file); fclose(stream); return NULL; } */ file[length] = '\0'; if(msValidateContexts(mapserv->map) != MS_SUCCESS) { /* make sure there are no recursive REQUIRES or LABELREQUIRES expressions */ if(pszResult) free(pszResult); pszResult=NULL; goto error; } /* * Seperate header/footer, groups, layers and class */ getInlineTag("leg_header_html", file, &legHeaderHtml); getInlineTag("leg_footer_html", file, &legFooterHtml); getInlineTag("leg_group_html", file, &legGroupHtml); getInlineTag("leg_layer_html", file, &legLayerHtml); getInlineTag("leg_class_html", file, &legClassHtml); /* * Retrieve arguments of all three parts */ if(legGroupHtml) if(getTagArgs("leg_group_html", file, &groupArgs) != MS_SUCCESS) { if(pszResult) free(pszResult); pszResult=NULL; goto error; } if(legLayerHtml) if(getTagArgs("leg_layer_html", file, &layerArgs) != MS_SUCCESS) { if(pszResult) free(pszResult); pszResult=NULL; goto error; } if(legClassHtml) if(getTagArgs("leg_class_html", file, &classArgs) != MS_SUCCESS) { if(pszResult) free(pszResult); pszResult=NULL; goto error; } mapserv->map->cellsize = msAdjustExtent(&(mapserv->map->extent), mapserv->map->width, mapserv->map->height); if(msCalculateScale(mapserv->map->extent, mapserv->map->units, mapserv->map->width, mapserv->map->height, mapserv->map->resolution, &mapserv->map->scaledenom) != MS_SUCCESS) { if(pszResult) free(pszResult); pszResult=NULL; goto error; } /* start with the header if present */ if(legHeaderHtml) pszResult = msStringConcatenate(pszResult, legHeaderHtml); /********************************************************************/ /* * order layers if order_metadata args is set * If not, keep default order */ pszOrderMetadata = msLookupHashTable(layerArgs, "order_metadata"); if(sortLayerByMetadata(mapserv->map, pszOrderMetadata) != MS_SUCCESS) { if(pszResult) free(pszResult); pszResult=NULL; goto error; } /* -------------------------------------------------------------------- */ /* if the order tag is set to ascending or descending, the */ /* current order will be changed to correspond to that. */ /* -------------------------------------------------------------------- */ pszOrder = msLookupHashTable(layerArgs, "order"); if(pszOrder && ((strcasecmp(pszOrder, "ASCENDING") == 0) || (strcasecmp(pszOrder, "DESCENDING") == 0))) { if(sortLayerByOrder(mapserv->map, pszOrder) != MS_SUCCESS) { if(pszResult) free(pszResult); pszResult=NULL; goto error; } } if(legGroupHtml) { /* retrieve group names */ papszGroups = msGetAllGroupNames(mapserv->map, &nGroupNames); for (i=0; imap, papszGroups[i], groupArgs, &legGroupHtmlCopy, pszPrefix) != MS_SUCCESS) { if(pszResult) free(pszResult); pszResult=NULL; goto error; } /* concatenate it to final result */ pszResult = msStringConcatenate(pszResult, legGroupHtmlCopy); /* if(!pszResult) { if(pszResult) free(pszResult); pszResult=NULL; goto error; } */ if(legGroupHtmlCopy) { free(legGroupHtmlCopy); legGroupHtmlCopy = NULL; } /* for all layers in group */ if(legLayerHtml) { for (j=0; jmap->numlayers; j++) { /* * if order_metadata is set and the order * value is less than 0, dont display it */ pszOrderMetadata = msLookupHashTable(layerArgs, "order_metadata"); if(pszOrderMetadata) { pszOrderValue = msLookupHashTable(&(GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->metadata), pszOrderMetadata); if(pszOrderValue) { nLegendOrder = atoi(pszOrderValue); if(nLegendOrder < 0) continue; } } if(mapserv->hittest && mapserv->hittest->layerhits[mapserv->map->layerorder[j]].status == 0) { continue; } if(GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->group && strcmp(GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->group, papszGroups[i]) == 0) { /* process all layer tags */ if(generateLayerTemplate(legLayerHtml, mapserv->map, mapserv->map->layerorder[j], layerArgs, &legLayerHtmlCopy, pszPrefix) != MS_SUCCESS) { if(pszResult) free(pszResult); pszResult=NULL; goto error; } /* concatenate to final result */ pszResult = msStringConcatenate(pszResult, legLayerHtmlCopy); if(legLayerHtmlCopy) { free(legLayerHtmlCopy); legLayerHtmlCopy = NULL; } /* for all classes in layer */ if(legClassHtml) { for (k=0; kmap, mapserv->map->layerorder[j])->numclasses; k++) { /* process all class tags */ if(!GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->class[k]->name) continue; if(mapserv->hittest && mapserv->hittest->layerhits[mapserv->map->layerorder[j]].classhits[k].status == 0) { continue; } if(generateClassTemplate(legClassHtml, mapserv->map, mapserv->map->layerorder[j], k, classArgs, &legClassHtmlCopy, pszPrefix) != MS_SUCCESS) { if(pszResult) free(pszResult); pszResult=NULL; goto error; } /* concatenate to final result */ pszResult = msStringConcatenate(pszResult, legClassHtmlCopy); if(legClassHtmlCopy) { free(legClassHtmlCopy); legClassHtmlCopy = NULL; } } } } } } else if(legClassHtml) { /* no layer template specified but class and group template */ for (j=0; jmap->numlayers; j++) { /* * if order_metadata is set and the order * value is less than 0, dont display it */ pszOrderMetadata = msLookupHashTable(layerArgs, "order_metadata"); if(pszOrderMetadata) { pszOrderValue = msLookupHashTable(&(GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->metadata), pszOrderMetadata); if(pszOrderValue) { nLegendOrder = atoi(pszOrderValue); if(nLegendOrder < 0) continue; } } if(mapserv->hittest && mapserv->hittest->layerhits[mapserv->map->layerorder[j]].status == 0) { continue; } if(GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->group && strcmp(GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->group, papszGroups[i]) == 0) { /* for all classes in layer */ if(legClassHtml) { for (k=0; kmap, mapserv->map->layerorder[j])->numclasses; k++) { /* process all class tags */ if(!GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->class[k]->name) continue; if(mapserv->hittest && mapserv->hittest->layerhits[mapserv->map->layerorder[j]].classhits[k].status == 0) { continue; } if(generateClassTemplate(legClassHtml, mapserv->map, mapserv->map->layerorder[j], k, classArgs, &legClassHtmlCopy, pszPrefix) != MS_SUCCESS) { if(pszResult) free(pszResult); pszResult=NULL; goto error; } /* concatenate to final result */ pszResult = msStringConcatenate(pszResult, legClassHtmlCopy); if(legClassHtmlCopy) { free(legClassHtmlCopy); legClassHtmlCopy = NULL; } } } } } } } } else { /* if no group template specified */ if(legLayerHtml) { for (j=0; jmap->numlayers; j++) { /* * if order_metadata is set and the order * value is less than 0, dont display it */ pszOrderMetadata = msLookupHashTable(layerArgs, "order_metadata"); if(pszOrderMetadata) { pszOrderValue = msLookupHashTable(&(GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->metadata), pszOrderMetadata); if(pszOrderValue) { nLegendOrder = atoi(pszOrderValue); if(nLegendOrder < 0) continue; } else nLegendOrder=0; } if(mapserv->hittest && mapserv->hittest->layerhits[mapserv->map->layerorder[j]].status == 0) { continue; } /* process a layer tags */ if(generateLayerTemplate(legLayerHtml, mapserv->map, mapserv->map->layerorder[j], layerArgs, &legLayerHtmlCopy, pszPrefix) != MS_SUCCESS) { if(pszResult) free(pszResult); pszResult=NULL; goto error; } /* concatenate to final result */ pszResult = msStringConcatenate(pszResult, legLayerHtmlCopy); if(legLayerHtmlCopy) { free(legLayerHtmlCopy); legLayerHtmlCopy = NULL; } /* for all classes in layer */ if(legClassHtml) { for (k=0; kmap, mapserv->map->layerorder[j])->numclasses; k++) { /* process all class tags */ if(!GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->class[k]->name) continue; if(mapserv->hittest && mapserv->hittest->layerhits[mapserv->map->layerorder[j]].classhits[k].status == 0) { continue; } if(generateClassTemplate(legClassHtml, mapserv->map, mapserv->map->layerorder[j], k, classArgs, &legClassHtmlCopy, pszPrefix) != MS_SUCCESS) { if(pszResult) free(pszResult); pszResult=NULL; goto error; } /* concatenate to final result */ pszResult = msStringConcatenate(pszResult, legClassHtmlCopy); if(legClassHtmlCopy) { free(legClassHtmlCopy); legClassHtmlCopy = NULL; } } } } } else { /* if no group and layer template specified */ if(legClassHtml) { for (j=0; jmap->numlayers; j++) { /* * if order_metadata is set and the order * value is less than 0, dont display it */ pszOrderMetadata = msLookupHashTable(layerArgs, "order_metadata"); if(pszOrderMetadata) { pszOrderValue = msLookupHashTable(&(GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->metadata), pszOrderMetadata); if(pszOrderValue) { nLegendOrder = atoi(pszOrderValue); if(nLegendOrder < 0) continue; } } if(mapserv->hittest && mapserv->hittest->layerhits[mapserv->map->layerorder[j]].status == 0) { continue; } for (k=0; kmap, mapserv->map->layerorder[j])->numclasses; k++) { if(!GET_LAYER(mapserv->map, mapserv->map->layerorder[j])->class[k]->name) continue; if(mapserv->hittest && mapserv->hittest->layerhits[mapserv->map->layerorder[j]].classhits[k].status == 0) { continue; } if(generateClassTemplate(legClassHtml, mapserv->map, mapserv->map->layerorder[j], k, classArgs, &legClassHtmlCopy, pszPrefix) != MS_SUCCESS) { if(pszResult) free(pszResult); pszResult=NULL; goto error; } pszResult = msStringConcatenate(pszResult, legClassHtmlCopy); if(legClassHtmlCopy) { free(legClassHtmlCopy); legClassHtmlCopy = NULL; } } } } } } /* finish with the footer if present */ if(legFooterHtml) pszResult = msStringConcatenate(pszResult, legFooterHtml); /* * if we reach this point, that mean no error was generated. * So check if template is null and initialize it to . */ if(pszResult == NULL) { pszResult = msStringConcatenate(pszResult, " "); } /********************************************************************/ error: if(papszGroups) { for (i=0; imap->layerorder) { for (i=0; imap->numlayers; i++) mapserv->map->layerorder[i] = panCurrentDrawingOrder[i]; free(panCurrentDrawingOrder); } return pszResult; } char *processOneToManyJoin(mapservObj* mapserv, joinObj *join) { int records=MS_FALSE; FILE *stream=NULL; char *outbuf; char line[MS_BUFFER_LENGTH], *tmpline; char szPath[MS_MAXPATHLEN]; if((outbuf = msStrdup("")) == NULL) return(NULL); /* empty at first */ msJoinPrepare(join, &(mapserv->resultshape)); /* execute the join */ while(msJoinNext(join) == MS_SUCCESS) { /* First time through, deal with the header (if necessary) and open the main template. We only */ /* want to do this if there are joined records. */ if(records == MS_FALSE) { if(join->header != NULL) { if(stream) fclose(stream); if((stream = fopen(msBuildPath(szPath, mapserv->map->mappath, join->header), "r")) == NULL) { msSetError(MS_IOERR, "Error while opening join header file %s.", "processOneToManyJoin()", join->header); msFree(outbuf); return(NULL); } if(isValidTemplate(stream, join->header) != MS_TRUE) { fclose(stream); msFree(outbuf); return NULL; } /* echo file to the output buffer, no substitutions */ while(fgets(line, MS_BUFFER_LENGTH, stream) != NULL) outbuf = msStringConcatenate(outbuf, line); fclose(stream); stream = NULL; } if((stream = fopen(msBuildPath(szPath, mapserv->map->mappath, join->template), "r")) == NULL) { msSetError(MS_IOERR, "Error while opening join template file %s.", "processOneToManyJoin()", join->template); msFree(outbuf); return(NULL); } if(isValidTemplate(stream, join->template) != MS_TRUE) { fclose(stream); msFree(outbuf); return NULL; } records = MS_TRUE; } while(fgets(line, MS_BUFFER_LENGTH, stream) != NULL) { /* now on to the end of the template */ if(strchr(line, '[') != NULL) { tmpline = processLine(mapserv, line, NULL, QUERY); /* no multiline tags are allowed in a join */ if(!tmpline) { msFree(outbuf); fclose(stream); return NULL; } outbuf = msStringConcatenate(outbuf, tmpline); free(tmpline); } else /* no subs, just echo */ outbuf = msStringConcatenate(outbuf, line); } rewind(stream); IGUR_voidp(fgets(line, MS_BUFFER_LENGTH, stream)); /* skip the first line since it's the magic string */ } /* next record */ if(records==MS_TRUE && join->footer) { if(stream) fclose(stream); if((stream = fopen(msBuildPath(szPath, mapserv->map->mappath, join->footer), "r")) == NULL) { msSetError(MS_IOERR, "Error while opening join footer file %s.", "processOneToManyJoin()", join->footer); msFree(outbuf); return(NULL); } if(isValidTemplate(stream, join->footer) != MS_TRUE) { msFree(outbuf); fclose(stream); return NULL; } /* echo file to the output buffer, no substitutions */ while(fgets(line, MS_BUFFER_LENGTH, stream) != NULL) outbuf = msStringConcatenate(outbuf, line); fclose(stream); stream = NULL; } /* clear any data associated with the join */ msFreeCharArray(join->values, join->numitems); join->values = NULL; if(stream) fclose(stream); return(outbuf); } /* ** Process a single line in the template. A few tags (e.g. [resultset]...[/resultset]) can be multi-line so ** we pass the filehandle to look ahead if necessary. */ static char *processLine(mapservObj *mapserv, char *instr, FILE *stream, int mode) { int i, j; #define PROCESSLINE_BUFLEN 5120 char repstr[PROCESSLINE_BUFLEN], substr[PROCESSLINE_BUFLEN], *outstr; /* repstr = replace string, substr = sub string */ struct hashObj *tp=NULL; char *encodedstr; rectObj llextent; pointObj llpoint; outstr = msStrdup(instr); /* work from a copy */ if(strstr(outstr, "[version]")) outstr = msReplaceSubstring(outstr, "[version]", msGetVersion()); snprintf(repstr, PROCESSLINE_BUFLEN, "%s%s%s.%s", mapserv->map->web.imageurl, mapserv->map->name, mapserv->Id, MS_IMAGE_EXTENSION(mapserv->map->outputformat)); outstr = msReplaceSubstring(outstr, "[img]", repstr); snprintf(repstr, PROCESSLINE_BUFLEN, "%s%sref%s.%s", mapserv->map->web.imageurl, mapserv->map->name, mapserv->Id, MS_IMAGE_EXTENSION(mapserv->map->outputformat)); outstr = msReplaceSubstring(outstr, "[ref]", repstr); if(strstr(outstr, "[errmsg")) { char *errmsg = msGetErrorString(";"); if(!errmsg) errmsg = msStrdup("Error message buffer is empty."); /* should never happen, but just in case... */ outstr = msReplaceSubstring(outstr, "[errmsg]", errmsg); encodedstr = msEncodeUrl(errmsg); outstr = msReplaceSubstring(outstr, "[errmsg_esc]", encodedstr); free(errmsg); free(encodedstr); } if(strstr(outstr, "[legend]")) { /* if there's a template legend specified, use it */ if(mapserv->map->legend.template) { char *legendTemplate; legendTemplate = generateLegendTemplate(mapserv); if(legendTemplate) { outstr = msReplaceSubstring(outstr, "[legend]", legendTemplate); free(legendTemplate); } else /* error already generated by (generateLegendTemplate()) */ return NULL; } else { /* if not display gif image with all legend icon */ snprintf(repstr, PROCESSLINE_BUFLEN, "%s%sleg%s.%s", mapserv->map->web.imageurl, mapserv->map->name, mapserv->Id, MS_IMAGE_EXTENSION(mapserv->map->outputformat)); outstr = msReplaceSubstring(outstr, "[legend]", repstr); } } snprintf(repstr, PROCESSLINE_BUFLEN, "%s%ssb%s.%s", mapserv->map->web.imageurl, mapserv->map->name, mapserv->Id, MS_IMAGE_EXTENSION(mapserv->map->outputformat)); outstr = msReplaceSubstring(outstr, "[scalebar]", repstr); if(mapserv->savequery) { snprintf(repstr, PROCESSLINE_BUFLEN, "%s%s%s%s", mapserv->map->web.imagepath, mapserv->map->name, mapserv->Id, MS_QUERY_EXTENSION); outstr = msReplaceSubstring(outstr, "[queryfile]", repstr); } if(mapserv->savemap) { snprintf(repstr, PROCESSLINE_BUFLEN, "%s%s%s.map", mapserv->map->web.imagepath, mapserv->map->name, mapserv->Id); outstr = msReplaceSubstring(outstr, "[map]", repstr); } if(strstr(outstr,"[mapserv_onlineresource]")) { char *ol; #if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR) || defined(USE_WMS_LYR) || defined(USE_WFS_LYR) ol = msOWSGetOnlineResource(mapserv->map, "O", "onlineresource", mapserv->request); #else ol = msBuildOnlineResource(mapserv->map, mapserv->request); #endif outstr = msReplaceSubstring(outstr, "[mapserv_onlineresource]",ol); msFree(ol); } if(getenv("HTTP_HOST")) { snprintf(repstr, PROCESSLINE_BUFLEN, "%s", getenv("HTTP_HOST")); outstr = msReplaceSubstring(outstr, "[host]", repstr); } if(getenv("SERVER_PORT")) { snprintf(repstr, PROCESSLINE_BUFLEN, "%s", getenv("SERVER_PORT")); outstr = msReplaceSubstring(outstr, "[port]", repstr); } snprintf(repstr, PROCESSLINE_BUFLEN, "%s", mapserv->Id); outstr = msReplaceSubstring(outstr, "[id]", repstr); repstr[0] = '\0'; /* Layer list for a "POST" request */ for(i=0; iNumLayers; i++) { strlcat(repstr, mapserv->Layers[i], sizeof(repstr)); strlcat(repstr, " ", sizeof(repstr)); } msStringTrimBlanks(repstr); encodedstr = msEncodeHTMLEntities(repstr); outstr = msReplaceSubstring(outstr, "[layers]", encodedstr); free(encodedstr); encodedstr = msEncodeUrl(repstr); outstr = msReplaceSubstring(outstr, "[layers_esc]", encodedstr); free(encodedstr); strcpy(repstr, ""); /* list of ALL layers that can be toggled */ repstr[0] = '\0'; for(i=0; imap->numlayers; i++) { if(GET_LAYER(mapserv->map, i)->status != MS_DEFAULT && GET_LAYER(mapserv->map, i)->name != NULL) { strlcat(repstr, GET_LAYER(mapserv->map, i)->name, sizeof(repstr)); strlcat(repstr, " ", sizeof(repstr)); } } msStringTrimBlanks(repstr); outstr = msReplaceSubstring(outstr, "[toggle_layers]", repstr); encodedstr = msEncodeUrl(repstr); outstr = msReplaceSubstring(outstr, "[toggle_layers_esc]", encodedstr); free(encodedstr); for(i=0; imap->numlayers; i++) { /* Set form widgets (i.e. checkboxes, radio and select lists), note that default layers don't show up here */ if(isOn(mapserv, GET_LAYER(mapserv->map, i)->name, GET_LAYER(mapserv->map, i)->group) == MS_TRUE) { if(GET_LAYER(mapserv->map, i)->group) { snprintf(substr, PROCESSLINE_BUFLEN, "[%s_select]", GET_LAYER(mapserv->map, i)->group); outstr = msReplaceSubstring(outstr, substr, "selected=\"selected\""); snprintf(substr, PROCESSLINE_BUFLEN, "[%s_check]", GET_LAYER(mapserv->map, i)->group); outstr = msReplaceSubstring(outstr, substr, "checked=\"checked\""); } if(GET_LAYER(mapserv->map, i)->name) { snprintf(substr, PROCESSLINE_BUFLEN, "[%s_select]", GET_LAYER(mapserv->map, i)->name); outstr = msReplaceSubstring(outstr, substr, "selected=\"selected\""); snprintf(substr, PROCESSLINE_BUFLEN, "[%s_check]", GET_LAYER(mapserv->map, i)->name); outstr = msReplaceSubstring(outstr, substr, "checked=\"checked\""); } } else { if(GET_LAYER(mapserv->map, i)->group) { snprintf(substr, PROCESSLINE_BUFLEN, "[%s_select]", GET_LAYER(mapserv->map, i)->group); outstr = msReplaceSubstring(outstr, substr, ""); snprintf(substr, PROCESSLINE_BUFLEN, "[%s_check]", GET_LAYER(mapserv->map, i)->group); outstr = msReplaceSubstring(outstr, substr, ""); } if(GET_LAYER(mapserv->map, i)->name) { snprintf(substr, PROCESSLINE_BUFLEN, "[%s_select]", GET_LAYER(mapserv->map, i)->name); outstr = msReplaceSubstring(outstr, substr, ""); snprintf(substr, PROCESSLINE_BUFLEN, "[%s_check]", GET_LAYER(mapserv->map, i)->name); outstr = msReplaceSubstring(outstr, substr, ""); } } } for(i=-1; i<=1; i++) { /* make zoom direction persistant */ if(mapserv->ZoomDirection == i) { snprintf(substr, sizeof(substr), "[zoomdir_%d_select]", i); outstr = msReplaceSubstring(outstr, substr, "selected=\"selected\""); snprintf(substr, sizeof(substr), "[zoomdir_%d_check]", i); outstr = msReplaceSubstring(outstr, substr, "checked=\"checked\""); } else { snprintf(substr, sizeof(substr), "[zoomdir_%d_select]", i); outstr = msReplaceSubstring(outstr, substr, ""); snprintf(substr, sizeof(substr), "[zoomdir_%d_check]", i); outstr = msReplaceSubstring(outstr, substr, ""); } } for(i=MINZOOM; i<=MAXZOOM; i++) { /* make zoom persistant */ if(mapserv->Zoom == i) { snprintf(substr, sizeof(substr), "[zoom_%d_select]", i); outstr = msReplaceSubstring(outstr, substr, "selected=\"selected\""); snprintf(substr, sizeof(substr), "[zoom_%d_check]", i); outstr = msReplaceSubstring(outstr, substr, "checked=\"checked\""); } else { snprintf(substr, sizeof(substr), "[zoom_%d_select]", i); outstr = msReplaceSubstring(outstr, substr, ""); snprintf(substr, sizeof(substr), "[zoom_%d_check]", i); outstr = msReplaceSubstring(outstr, substr, ""); } } /* allow web object metadata access in template */ /* * reworked by SG to use HashTable methods */ if(&(mapserv->map->web.metadata) && strstr(outstr, "web_")) { for (j=0; jmap->web.metadata.items[j] != NULL) { for(tp=mapserv->map->web.metadata.items[j]; tp!=NULL; tp=tp->next) { snprintf(substr, PROCESSLINE_BUFLEN, "[web_%s]", tp->key); outstr = msReplaceSubstring(outstr, substr, tp->data); snprintf(substr, PROCESSLINE_BUFLEN, "[web_%s_esc]", tp->key); encodedstr = msEncodeUrl(tp->data); outstr = msReplaceSubstring(outstr, substr, encodedstr); free(encodedstr); } } } } /* allow layer metadata access in template */ for(i=0; imap->numlayers; i++) { if(&(GET_LAYER(mapserv->map, i)->metadata) && GET_LAYER(mapserv->map, i)->name && strstr(outstr, GET_LAYER(mapserv->map, i)->name)) { for(j=0; jmap, i)->metadata.items[j] != NULL) { for(tp=GET_LAYER(mapserv->map, i)->metadata.items[j]; tp!=NULL; tp=tp->next) { snprintf(substr, PROCESSLINE_BUFLEN, "[%s_%s]", GET_LAYER(mapserv->map, i)->name, tp->key); if(GET_LAYER(mapserv->map, i)->status == MS_ON) outstr = msReplaceSubstring(outstr, substr, tp->data); else outstr = msReplaceSubstring(outstr, substr, ""); snprintf(substr, PROCESSLINE_BUFLEN, "[%s_%s_esc]", GET_LAYER(mapserv->map, i)->name, tp->key); if(GET_LAYER(mapserv->map, i)->status == MS_ON) { encodedstr = msEncodeUrl(tp->data); outstr = msReplaceSubstring(outstr, substr, encodedstr); free(encodedstr); } else outstr = msReplaceSubstring(outstr, substr, ""); } } } } } snprintf(repstr, sizeof(repstr), "%f", mapserv->mappnt.x); outstr = msReplaceSubstring(outstr, "[mapx]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->mappnt.y); outstr = msReplaceSubstring(outstr, "[mapy]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->map->extent.minx); /* Individual mapextent elements for spatial query building, deprecated. */ outstr = msReplaceSubstring(outstr, "[minx]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->map->extent.maxx); outstr = msReplaceSubstring(outstr, "[maxx]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->map->extent.miny); outstr = msReplaceSubstring(outstr, "[miny]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->map->extent.maxy); outstr = msReplaceSubstring(outstr, "[maxy]", repstr); if(processDateTag( &outstr ) != MS_SUCCESS) return(NULL); if(processExtentTag(mapserv, &outstr, "mapext", &(mapserv->map->extent), &(mapserv->map->projection)) != MS_SUCCESS) return(NULL); if(processExtentTag(mapserv, &outstr, "mapext_esc", &(mapserv->map->extent), &(mapserv->map->projection)) != MS_SUCCESS) /* depricated */ return(NULL); snprintf(repstr, sizeof(repstr), "%f", (mapserv->map->extent.maxx-mapserv->map->extent.minx)); /* useful for creating cachable extents (i.e. 0 0 dx dy) with legends and scalebars */ outstr = msReplaceSubstring(outstr, "[dx]", repstr); snprintf(repstr, sizeof(repstr), "%f", (mapserv->map->extent.maxy-mapserv->map->extent.miny)); outstr = msReplaceSubstring(outstr, "[dy]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->RawExt.minx); /* Individual raw extent elements for spatial query building, deprecated. */ outstr = msReplaceSubstring(outstr, "[rawminx]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->RawExt.maxx); outstr = msReplaceSubstring(outstr, "[rawmaxx]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->RawExt.miny); outstr = msReplaceSubstring(outstr, "[rawminy]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->RawExt.maxy); outstr = msReplaceSubstring(outstr, "[rawmaxy]", repstr); if(processExtentTag(mapserv, &outstr, "rawext", &(mapserv->RawExt), &(mapserv->map->projection)) != MS_SUCCESS) return(NULL); if(processExtentTag(mapserv, &outstr, "rawext_esc", &(mapserv->RawExt), &(mapserv->map->projection)) != MS_SUCCESS) /* depricated */ return(NULL); if((strstr(outstr, "lat]") || strstr(outstr, "lon]") || strstr(outstr, "lon_esc]")) && mapserv->map->projection.proj != NULL && !msProjIsGeographicCRS(&(mapserv->map->projection)) ) { llextent=mapserv->map->extent; llpoint=mapserv->mappnt; msProjectRect(&(mapserv->map->projection), &(mapserv->map->latlon), &llextent); msProjectPoint(&(mapserv->map->projection), &(mapserv->map->latlon), &llpoint); snprintf(repstr, sizeof(repstr), "%f", llpoint.x); outstr = msReplaceSubstring(outstr, "[maplon]", repstr); snprintf(repstr, sizeof(repstr), "%f", llpoint.y); outstr = msReplaceSubstring(outstr, "[maplat]", repstr); snprintf(repstr, sizeof(repstr), "%f", llextent.minx); /* map extent as lat/lon */ outstr = msReplaceSubstring(outstr, "[minlon]", repstr); snprintf(repstr, sizeof(repstr), "%f", llextent.maxx); outstr = msReplaceSubstring(outstr, "[maxlon]", repstr); snprintf(repstr, sizeof(repstr), "%f", llextent.miny); outstr = msReplaceSubstring(outstr, "[minlat]", repstr); snprintf(repstr, sizeof(repstr), "%f", llextent.maxy); outstr = msReplaceSubstring(outstr, "[maxlat]", repstr); if(processExtentTag(mapserv, &outstr, "mapext_latlon", &(llextent), NULL) != MS_SUCCESS) return(NULL); if(processExtentTag(mapserv, &outstr, "mapext_latlon_esc", &(llextent), NULL) != MS_SUCCESS) /* depricated */ return(NULL); } /* submitted by J.F (bug 1102) */ if(mapserv->map->reference.status == MS_ON) { snprintf(repstr, sizeof(repstr), "%f", mapserv->map->reference.extent.minx); /* Individual reference map extent elements for spatial query building, depricated. */ outstr = msReplaceSubstring(outstr, "[refminx]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->map->reference.extent.maxx); outstr = msReplaceSubstring(outstr, "[refmaxx]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->map->reference.extent.miny); outstr = msReplaceSubstring(outstr, "[refminy]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->map->reference.extent.maxy); outstr = msReplaceSubstring(outstr, "[refmaxy]", repstr); if(processExtentTag(mapserv, &outstr, "refext", &(mapserv->map->reference.extent), &(mapserv->map->projection)) != MS_SUCCESS) return(NULL); if(processExtentTag(mapserv, &outstr, "refext_esc", &(mapserv->map->reference.extent), &(mapserv->map->projection)) != MS_SUCCESS) /* depricated */ return(NULL); } snprintf(repstr, sizeof(repstr), "%d %d", mapserv->map->width, mapserv->map->height); outstr = msReplaceSubstring(outstr, "[mapsize]", repstr); encodedstr = msEncodeUrl(repstr); outstr = msReplaceSubstring(outstr, "[mapsize_esc]", encodedstr); free(encodedstr); snprintf(repstr, sizeof(repstr), "%d", mapserv->map->width); outstr = msReplaceSubstring(outstr, "[mapwidth]", repstr); snprintf(repstr, sizeof(repstr), "%d", mapserv->map->height); outstr = msReplaceSubstring(outstr, "[mapheight]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->map->scaledenom); outstr = msReplaceSubstring(outstr, "[scale]", repstr); outstr = msReplaceSubstring(outstr, "[scaledenom]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->map->cellsize); outstr = msReplaceSubstring(outstr, "[cellsize]", repstr); snprintf(repstr, sizeof(repstr), "%.1f %.1f", (mapserv->map->width)/2.0, (mapserv->map->height)/2.0); /* not subtracting 1 from image dimensions (see bug 633) */ outstr = msReplaceSubstring(outstr, "[center]", repstr); snprintf(repstr, sizeof(repstr), "%.1f", (mapserv->map->width)/2.0); outstr = msReplaceSubstring(outstr, "[center_x]", repstr); snprintf(repstr, sizeof(repstr), "%.1f", (mapserv->map->height)/2.0); outstr = msReplaceSubstring(outstr, "[center_y]", repstr); /* These are really for situations with multiple result sets only, but often used in header/footer */ snprintf(repstr, sizeof(repstr), "%d", mapserv->NR); /* total number of results */ outstr = msReplaceSubstring(outstr, "[nr]", repstr); snprintf(repstr, sizeof(repstr), "%d", mapserv->NL); /* total number of layers with results */ outstr = msReplaceSubstring(outstr, "[nl]", repstr); if(mapserv->resultlayer) { if(strstr(outstr, "[items]") != NULL) { char *itemstr=NULL; itemstr = msJoinStrings(mapserv->resultlayer->items, mapserv->resultlayer->numitems, ","); outstr = msReplaceSubstring(outstr, "[items]", itemstr); free(itemstr); } snprintf(repstr, sizeof(repstr), "%d", mapserv->NLR); /* total number of results within this layer */ outstr = msReplaceSubstring(outstr, "[nlr]", repstr); snprintf(repstr, sizeof(repstr), "%d", mapserv->RN); /* sequential (eg. 1..n) result number within all layers */ outstr = msReplaceSubstring(outstr, "[rn]", repstr); snprintf(repstr, sizeof(repstr), "%d", mapserv->LRN); /* sequential (eg. 1..n) result number within this layer */ outstr = msReplaceSubstring(outstr, "[lrn]", repstr); outstr = msReplaceSubstring(outstr, "[cl]", mapserv->resultlayer->name); /* current layer name */ /* if(resultlayer->description) outstr = msReplaceSubstring(outstr, "[cd]", resultlayer->description); */ /* current layer description */ /* allow layer metadata access when there is a current result layer (implicitly a query template) */ if(&(mapserv->resultlayer->metadata) && strstr(outstr, "[metadata_")) { for(i=0; iresultlayer->metadata.items[i] != NULL) { for(tp=mapserv->resultlayer->metadata.items[i]; tp!=NULL; tp=tp->next) { snprintf(substr, PROCESSLINE_BUFLEN, "[metadata_%s]", tp->key); outstr = msReplaceSubstring(outstr, substr, tp->data); snprintf(substr, PROCESSLINE_BUFLEN, "[metadata_%s_esc]", tp->key); encodedstr = msEncodeUrl(tp->data); outstr = msReplaceSubstring(outstr, substr, encodedstr); free(encodedstr); } } } } } if(mode != QUERY) { if(processResultSetTag(mapserv, &outstr, stream) != MS_SUCCESS) { msFree(outstr); return(NULL); } } else { /* return shape and/or values */ snprintf(repstr, sizeof(repstr), "%f %f", (mapserv->resultshape.bounds.maxx + mapserv->resultshape.bounds.minx)/2, (mapserv->resultshape.bounds.maxy + mapserv->resultshape.bounds.miny)/2); outstr = msReplaceSubstring(outstr, "[shpmid]", repstr); snprintf(repstr, sizeof(repstr), "%f", (mapserv->resultshape.bounds.maxx + mapserv->resultshape.bounds.minx)/2); outstr = msReplaceSubstring(outstr, "[shpmidx]", repstr); snprintf(repstr, sizeof(repstr), "%f", (mapserv->resultshape.bounds.maxy + mapserv->resultshape.bounds.miny)/2); outstr = msReplaceSubstring(outstr, "[shpmidy]", repstr); if(processExtentTag(mapserv, &outstr, "shpext", &(mapserv->resultshape.bounds), &(mapserv->resultlayer->projection)) != MS_SUCCESS) return(NULL); if(processExtentTag(mapserv, &outstr, "shpext_esc", &(mapserv->resultshape.bounds), &(mapserv->resultlayer->projection)) != MS_SUCCESS) /* depricated */ return(NULL); snprintf(repstr, sizeof(repstr), "%d", mapserv->resultshape.classindex); outstr = msReplaceSubstring(outstr, "[shpclass]", repstr); if(processShpxyTag(mapserv->resultlayer, &outstr, &mapserv->resultshape) != MS_SUCCESS) return(NULL); if(processShplabelTag(mapserv->resultlayer, &outstr, &mapserv->resultshape) != MS_SUCCESS) return(NULL); snprintf(repstr, sizeof(repstr), "%f", mapserv->resultshape.bounds.minx); outstr = msReplaceSubstring(outstr, "[shpminx]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->resultshape.bounds.miny); outstr = msReplaceSubstring(outstr, "[shpminy]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->resultshape.bounds.maxx); outstr = msReplaceSubstring(outstr, "[shpmaxx]", repstr); snprintf(repstr, sizeof(repstr), "%f", mapserv->resultshape.bounds.maxy); outstr = msReplaceSubstring(outstr, "[shpmaxy]", repstr); snprintf(repstr, sizeof(repstr), "%ld", mapserv->resultshape.index); outstr = msReplaceSubstring(outstr, "[shpidx]", repstr); snprintf(repstr, sizeof(repstr), "%d", mapserv->resultshape.tileindex); outstr = msReplaceSubstring(outstr, "[tileidx]", repstr); /* return ALL attributes in one delimeted list */ if(strstr(outstr, "[values]") != NULL) { char *valuestr=NULL; valuestr = msJoinStrings(mapserv->resultshape.values, mapserv->resultlayer->numitems, ","); outstr = msReplaceSubstring(outstr, "[values]", valuestr); free(valuestr); } for(i=0; iresultlayer->numitems; i++) { /* by default let's encode attributes for HTML presentation */ snprintf(substr, PROCESSLINE_BUFLEN, "[%s]", mapserv->resultlayer->items[i]); if(strstr(outstr, substr) != NULL) { encodedstr = msEncodeHTMLEntities(mapserv->resultshape.values[i]); outstr = msReplaceSubstring(outstr, substr, encodedstr); free(encodedstr); } /* of course you might want to embed that data in URLs */ snprintf(substr, PROCESSLINE_BUFLEN, "[%s_esc]", mapserv->resultlayer->items[i]); if(strstr(outstr, substr) != NULL) { encodedstr = msEncodeUrl(mapserv->resultshape.values[i]); outstr = msReplaceSubstring(outstr, substr, encodedstr); free(encodedstr); } /* or you might want to access the attributes unaltered */ snprintf(substr, PROCESSLINE_BUFLEN, "[%s_raw]", mapserv->resultlayer->items[i]); if(strstr(outstr, substr) != NULL) outstr = msReplaceSubstring(outstr, substr, mapserv->resultshape.values[i]); } if(processItemTag(mapserv->resultlayer, &outstr, &mapserv->resultshape) != MS_SUCCESS) return(NULL); /* handle joins in this next section */ for(i=0; iresultlayer->numjoins; i++) { if(mapserv->resultlayer->joins[i].values) { /* join has data */ for(j=0; jresultlayer->joins[i].numitems; j++) { /* by default let's encode attributes for HTML presentation */ snprintf(substr, PROCESSLINE_BUFLEN, "[%s_%s]", mapserv->resultlayer->joins[i].name, mapserv->resultlayer->joins[i].items[j]); if(strstr(outstr, substr) != NULL) { encodedstr = msEncodeHTMLEntities(mapserv->resultlayer->joins[i].values[j]); outstr = msReplaceSubstring(outstr, substr, encodedstr); free(encodedstr); } /* of course you might want to embed that data in URLs */ snprintf(substr, PROCESSLINE_BUFLEN, "[%s_%s_esc]", mapserv->resultlayer->joins[i].name, mapserv->resultlayer->joins[i].items[j]); if(strstr(outstr, substr) != NULL) { encodedstr = msEncodeUrl(mapserv->resultlayer->joins[i].values[j]); outstr = msReplaceSubstring(outstr, substr, encodedstr); free(encodedstr); } /* or you might want to access the attributes unaltered */ snprintf(substr, PROCESSLINE_BUFLEN, "[%s_%s_raw]", mapserv->resultlayer->joins[i].name, mapserv->resultlayer->joins[i].items[j]); if(strstr(outstr, substr) != NULL) outstr = msReplaceSubstring(outstr, substr, mapserv->resultlayer->joins[i].values[j]); } } else if(mapserv->resultlayer->joins[i].type == MS_JOIN_ONE_TO_MANY) { /* one-to-many join */ char *joinTemplate=NULL; snprintf(substr, PROCESSLINE_BUFLEN, "[join_%s]", mapserv->resultlayer->joins[i].name); if(strstr(outstr, substr) != NULL) { joinTemplate = processOneToManyJoin(mapserv, &(mapserv->resultlayer->joins[i])); if(joinTemplate) { outstr = msReplaceSubstring(outstr, substr, joinTemplate); free(joinTemplate); } else return NULL; } } } /* next join */ } /* end query mode specific substitutions */ if(processIncludeTag(mapserv, &outstr, stream, mode) != MS_SUCCESS) return(NULL); for(i=0; irequest->NumParams; i++) { /* Replace [variable] tags using values from URL. We cannot offer a * [variable_raw] option here due to the risk of XSS. * * Replacement is case-insensitive. (#4511) */ snprintf(substr, PROCESSLINE_BUFLEN, "[%s]", mapserv->request->ParamNames[i]); encodedstr = msEncodeHTMLEntities(mapserv->request->ParamValues[i]); outstr = msCaseReplaceSubstring(outstr, substr, encodedstr); free(encodedstr); snprintf(substr, PROCESSLINE_BUFLEN, "[%s_esc]", mapserv->request->ParamNames[i]); encodedstr = msEncodeUrl(mapserv->request->ParamValues[i]); outstr = msCaseReplaceSubstring(outstr, substr, encodedstr); free(encodedstr); } return(outstr); } #define MS_TEMPLATE_BUFFER 1024 /* 1k */ int msReturnPage(mapservObj *mapserv, char *html, int mode, char **papszBuffer) { FILE *stream; char line[MS_BUFFER_LENGTH], *tmpline; int nBufferSize = 0; int nCurrentSize = 0; int nExpandBuffer = 0; ms_regex_t re; /* compiled regular expression to be matched */ char szPath[MS_MAXPATHLEN]; if(!html) { msSetError(MS_WEBERR, "No template specified", "msReturnPage()"); return MS_FAILURE; } if(ms_regcomp(&re, MS_TEMPLATE_EXPR, MS_REG_EXTENDED|MS_REG_NOSUB|MS_REG_ICASE) != 0) { msSetError(MS_REGEXERR, NULL, "msReturnPage()"); return MS_FAILURE; } if(ms_regexec(&re, html, 0, NULL, 0) != 0) { /* no match */ ms_regfree(&re); msSetError(MS_WEBERR, "Malformed template name (%s).", "msReturnPage()", html); return MS_FAILURE; } ms_regfree(&re); if((stream = fopen(msBuildPath(szPath, mapserv->map->mappath, html), "r")) == NULL) { msSetError(MS_IOERR, "%s", "msReturnPage()", html); return MS_FAILURE; } if(isValidTemplate(stream, html) != MS_TRUE) { fclose(stream); return MS_FAILURE; } if(papszBuffer) { if((*papszBuffer) == NULL) { (*papszBuffer) = (char *)msSmallMalloc(MS_TEMPLATE_BUFFER); (*papszBuffer)[0] = '\0'; nBufferSize = MS_TEMPLATE_BUFFER; nCurrentSize = 0; nExpandBuffer = 1; } else { nCurrentSize = strlen((*papszBuffer)); nBufferSize = nCurrentSize; nExpandBuffer = (nCurrentSize/MS_TEMPLATE_BUFFER) + 1; } } while(fgets(line, MS_BUFFER_LENGTH, stream) != NULL) { /* now on to the end of the file */ if(strchr(line, '[') != NULL) { tmpline = processLine(mapserv, line, stream, mode); if(!tmpline) { fclose(stream); return MS_FAILURE; } if(papszBuffer) { if(nBufferSize <= (int)(nCurrentSize + strlen(tmpline) + 1)) { nExpandBuffer = (strlen(tmpline) / MS_TEMPLATE_BUFFER) + 1; nBufferSize = MS_TEMPLATE_BUFFER*nExpandBuffer + strlen((*papszBuffer)); (*papszBuffer) = (char *) msSmallRealloc((*papszBuffer),sizeof(char)*nBufferSize); } strcat((*papszBuffer), tmpline); nCurrentSize += strlen(tmpline); } else msIO_fwrite(tmpline, strlen(tmpline), 1, stdout); free(tmpline); } else { if(papszBuffer) { if(nBufferSize <= (int)(nCurrentSize + strlen(line))) { nExpandBuffer = (strlen(line) / MS_TEMPLATE_BUFFER) + 1; nBufferSize = MS_TEMPLATE_BUFFER*nExpandBuffer + strlen((*papszBuffer)); (*papszBuffer) = (char *)msSmallRealloc((*papszBuffer),sizeof(char)*nBufferSize); } strcat((*papszBuffer), line); nCurrentSize += strlen(line); } else msIO_fwrite(line, strlen(line), 1, stdout); } if(!papszBuffer) fflush(stdout); } /* next line */ fclose(stream); return MS_SUCCESS; } int msReturnURL(mapservObj* ms, char* url, int mode) { char *tmpurl; if(url == NULL) { msSetError(MS_WEBERR, "Empty URL.", "msReturnURL()"); return MS_FAILURE; } tmpurl = processLine(ms, url, NULL, mode); /* URL templates can't handle multi-line tags, hence the NULL file pointer */ if(!tmpurl) return MS_FAILURE; msRedirect(tmpurl); free(tmpurl); return MS_SUCCESS; } /* ** Legacy query template parsing where you use headers, footers and such... */ int msReturnNestedTemplateQuery(mapservObj* mapserv, char* pszMimeType, char **papszBuffer) { int status; int i,j,k; char buffer[1024]; int nBufferSize =0; int nCurrentSize = 0; int nExpandBuffer = 0; char *template; layerObj *lp=NULL; if(papszBuffer) { (*papszBuffer) = (char *)msSmallMalloc(MS_TEMPLATE_BUFFER); (*papszBuffer)[0] = '\0'; nBufferSize = MS_TEMPLATE_BUFFER; nCurrentSize = 0; nExpandBuffer = 1; } msInitShape(&(mapserv->resultshape)); if((mapserv->Mode == ITEMQUERY) || (mapserv->Mode == QUERY)) { /* may need to handle a URL result set since these modes return exactly 1 result */ for(i=(mapserv->map->numlayers-1); i>=0; i--) { lp = (GET_LAYER(mapserv->map, i)); if(!lp->resultcache) continue; if(lp->resultcache->numresults > 0) break; } if(i >= 0) { /* at least if no result found, mapserver will display an empty template. */ if(lp->resultcache->results[0].classindex >= 0 && lp->class[(int)(lp->resultcache->results[0].classindex)]->template) template = lp->class[(int)(lp->resultcache->results[0].classindex)]->template; else template = lp->template; if( template == NULL ) { msSetError(MS_WEBERR, "No template for layer %s or it's classes.", "msReturnNestedTemplateQuery()", lp->name ); return MS_FAILURE; } if(TEMPLATE_TYPE(template) == MS_URL) { mapserv->resultlayer = lp; #if 0 status = msLayerOpen(lp); if(status != MS_SUCCESS) return status; status = msLayerGetItems(lp); /* retrieve all the item names */ if(status != MS_SUCCESS) return status; #endif status = msLayerGetShape(lp, &(mapserv->resultshape), &(lp->resultcache->results[0])); if(status != MS_SUCCESS) return status; if(lp->numjoins > 0) { for(k=0; knumjoins; k++) { status = msJoinConnect(lp, &(lp->joins[k])); if(status != MS_SUCCESS) return status; msJoinPrepare(&(lp->joins[k]), &(mapserv->resultshape)); msJoinNext(&(lp->joins[k])); /* fetch the first row */ } } if(papszBuffer == NULL) { if(msReturnURL(mapserv, template, QUERY) != MS_SUCCESS) return MS_FAILURE; } msFreeShape(&(mapserv->resultshape)); /* msLayerClose(lp); */ mapserv->resultlayer = NULL; return MS_SUCCESS; } } } /* ** Now we know we're making a template sandwich */ mapserv->NR = mapserv->NL = 0; for(i=0; imap->numlayers; i++) { /* compute some totals */ lp = (GET_LAYER(mapserv->map, i)); if(!lp->resultcache) continue; if(lp->resultcache->numresults > 0) { mapserv->NL++; mapserv->NR += lp->resultcache->numresults; } } /* ** Is this step really necessary for buffered output? Legend and browse templates don't deal with mime-types ** so why should this. Note that new-style templates don't buffer the mime-type either. */ if(papszBuffer && mapserv->sendheaders) { snprintf(buffer, sizeof(buffer), "Content-Type: %s%c%c", pszMimeType, 10, 10); if(nBufferSize <= (int)(nCurrentSize + strlen(buffer) + 1)) { nExpandBuffer++; (*papszBuffer) = (char *)msSmallRealloc((*papszBuffer), MS_TEMPLATE_BUFFER*nExpandBuffer); nBufferSize = MS_TEMPLATE_BUFFER*nExpandBuffer; } strcat((*papszBuffer), buffer); nCurrentSize += strlen(buffer); } else if(mapserv->sendheaders) { msIO_setHeader("Content-Type","%s",pszMimeType); msIO_sendHeaders(); } if(mapserv->map->web.header) { if(msReturnPage(mapserv, mapserv->map->web.header, BROWSE, papszBuffer) != MS_SUCCESS) return MS_FAILURE; } mapserv->RN = 1; /* overall result number */ for(i=0; imap->numlayers; i++) { mapserv->resultlayer = lp = (GET_LAYER(mapserv->map, mapserv->map->layerorder[i])); if(!lp->resultcache) continue; if(lp->resultcache->numresults <= 0) continue; mapserv->NLR = lp->resultcache->numresults; #if 0 status = msLayerOpen(lp); /* open this layer */ if(status != MS_SUCCESS) return status; status = msLayerGetItems(lp); /* retrieve all the item names */ if(status != MS_SUCCESS) return status; #endif if(lp->numjoins > 0) { /* open any necessary JOINs here */ for(k=0; knumjoins; k++) { status = msJoinConnect(lp, &(lp->joins[k])); if(status != MS_SUCCESS) return status; } } if(lp->header) { if(msReturnPage(mapserv, lp->header, BROWSE, papszBuffer) != MS_SUCCESS) return MS_FAILURE; } mapserv->LRN = 1; /* layer result number */ for(j=0; jresultcache->numresults; j++) { status = msLayerGetShape(lp, &(mapserv->resultshape), &(lp->resultcache->results[j])); if(status != MS_SUCCESS) return status; /* prepare any necessary JOINs here (one-to-one only) */ if(lp->numjoins > 0) { for(k=0; knumjoins; k++) { if(lp->joins[k].type == MS_JOIN_ONE_TO_ONE) { msJoinPrepare(&(lp->joins[k]), &(mapserv->resultshape)); msJoinNext(&(lp->joins[k])); /* fetch the first row */ } } } if(lp->resultcache->results[j].classindex >= 0 && lp->class[(int)(lp->resultcache->results[j].classindex)]->template) template = lp->class[(int)(lp->resultcache->results[j].classindex)]->template; else template = lp->template; if(msReturnPage(mapserv, template, QUERY, papszBuffer) != MS_SUCCESS) { msFreeShape(&(mapserv->resultshape)); return MS_FAILURE; } msFreeShape(&(mapserv->resultshape)); /* init too */ mapserv->RN++; /* increment counters */ mapserv->LRN++; } if(lp->footer) { if(msReturnPage(mapserv, lp->footer, BROWSE, papszBuffer) != MS_SUCCESS) return MS_FAILURE; } /* msLayerClose(lp); */ mapserv->resultlayer = NULL; } if(mapserv->map->web.footer) return msReturnPage(mapserv, mapserv->map->web.footer, BROWSE, papszBuffer); return MS_SUCCESS; } int msReturnOpenLayersPage(mapservObj *mapserv) { int i; char *buffer = NULL, *layer = NULL; const char *tmpUrl = NULL; char *openlayersUrl = olUrl; char *projection = NULL; char *format = NULL; /* 2 CGI parameters are used in the template. we need to transform them * to be sure the case match during the template processing. We also * need to search the SRS/CRS parameter to get the projection info. OGC * services version >= 1.3.0 uses CRS rather than SRS */ for( i=0; irequest->NumParams; i++) { if( (strcasecmp(mapserv->request->ParamNames[i], "SRS") == 0) || (strcasecmp(mapserv->request->ParamNames[i], "CRS") == 0) ) { projection = mapserv->request->ParamValues[i]; } else if(strcasecmp(mapserv->request->ParamNames[i], "LAYERS") == 0) { free(mapserv->request->ParamNames[i]); mapserv->request->ParamNames[i] = msStrdup("LAYERS"); } else if(strcasecmp(mapserv->request->ParamNames[i], "VERSION") == 0) { free(mapserv->request->ParamNames[i]); mapserv->request->ParamNames[i] = msStrdup("VERSION"); } } if(mapserv->map->outputformat->mimetype && *mapserv->map->outputformat->mimetype) { format = mapserv->map->outputformat->mimetype; } /* check if the environment variable or config MS_OPENLAYERS_JS_URL is set */ tmpUrl = msGetConfigOption(mapserv->map, "MS_OPENLAYERS_JS_URL"); if (tmpUrl) openlayersUrl = (char*)tmpUrl; else if (getenv("MS_OPENLAYERS_JS_URL")) openlayersUrl = getenv("MS_OPENLAYERS_JS_URL"); if (mapserv->Mode == BROWSE) { msSetError(MS_WMSERR, "At least one layer name required in LAYERS.", "msWMSLoadGetMapParams()"); layer = processLine(mapserv, olLayerMapServerTag, NULL, BROWSE); } else layer = processLine(mapserv, olLayerWMSTag, NULL, BROWSE); buffer = processLine(mapserv, olTemplate, NULL, BROWSE); buffer = msReplaceSubstring(buffer, "[openlayers_js_url]", openlayersUrl); buffer = msReplaceSubstring(buffer, "[openlayers_layer]", layer); if (projection) buffer = msReplaceSubstring(buffer, "[openlayers_projection]", projection); if (format) buffer = msReplaceSubstring(buffer, "[openlayers_format]", format); else buffer = msReplaceSubstring(buffer, "[openlayers_format]", "image/jpeg"); msIO_fwrite(buffer, strlen(buffer), 1, stdout); free(layer); free(buffer); return MS_SUCCESS; } mapservObj *msAllocMapServObj() { mapservObj *mapserv = msSmallMalloc(sizeof(mapservObj)); mapserv->savemap=MS_FALSE; mapserv->savequery=MS_FALSE; /* should the query and/or map be saved */ mapserv->sendheaders = MS_TRUE; mapserv->request = msAllocCgiObj(); mapserv->map=NULL; mapserv->NumLayers=0; /* number of layers specfied by a user */ mapserv->MaxLayers=0; /* allocated size of Layers[] array */ mapserv->Layers = NULL; mapserv->icon = NULL; mapserv->RawExt.minx=-1; mapserv->RawExt.miny=-1; mapserv->RawExt.maxx=-1; mapserv->RawExt.maxy=-1; mapserv->fZoom=1; mapserv->Zoom=1; /* default for browsing */ mapserv->resultlayer=NULL; mapserv->UseShapes=MS_FALSE; mapserv->mappnt.x=-1; mapserv->mappnt.y=-1; mapserv->ZoomDirection=0; /* whether zooming in or out, default is pan or 0 */ mapserv->Mode=BROWSE; /* can be BROWSE, QUERY, etc. */ sprintf(mapserv->Id, "%ld%d", (long)time(NULL), (int)getpid()); mapserv->CoordSource=NONE; mapserv->ScaleDenom=0; mapserv->ImgRows=-1; mapserv->ImgCols=-1; mapserv->ImgExt.minx=-1; mapserv->ImgExt.miny=-1; mapserv->ImgExt.maxx=-1; mapserv->ImgExt.maxy=-1; mapserv->ImgBox.minx=-1; mapserv->ImgBox.miny=-1; mapserv->ImgBox.maxx=-1; mapserv->ImgBox.maxy=-1; mapserv->RefPnt.x=-1; mapserv->RefPnt.y=-1; mapserv->ImgPnt.x=-1; mapserv->ImgPnt.y=-1; mapserv->Buffer=0; /* ** variables for multiple query results processing */ mapserv->RN=0; /* overall result number */ mapserv->LRN=0; /* result number within a layer */ mapserv->NL=0; /* total number of layers with results */ mapserv->NR=0; /* total number or results */ mapserv->NLR=0; /* number of results in a layer */ mapserv->SearchMap=MS_FALSE; /* apply pan/zoom BEFORE doing the query (e.g. query the output image rather than the input image) */ mapserv->QueryFile=NULL; mapserv->QueryLayer=NULL; mapserv->SelectLayer=NULL; mapserv->QueryLayerIndex=-1; mapserv->SelectLayerIndex=-1; mapserv->QueryItem=NULL; mapserv->QueryString=NULL; mapserv->ShapeIndex=-1; mapserv->TileIndex=-1; mapserv->TileMode=TILE_GMAP; mapserv->TileCoords=NULL; mapserv->QueryCoordSource=NONE; mapserv->ZoomSize=0; /* zoom absolute magnitude (i.e. > 0) */ mapserv->hittest = NULL; return mapserv; } void msFreeMapServObj(mapservObj* mapserv) { int i; if(mapserv) { if( mapserv->map ) { if(mapserv->hittest) { freeMapHitTests(mapserv->map,mapserv->hittest); free(mapserv->hittest); } msFreeMap(mapserv->map); mapserv->map = NULL; } if( mapserv->request ) { msFreeCgiObj(mapserv->request); mapserv->request = NULL; } for(i=0; iNumLayers; i++) msFree(mapserv->Layers[i]); msFree(mapserv->Layers); msFree(mapserv->icon); msFree(mapserv->QueryItem); msFree(mapserv->QueryString); msFree(mapserv->QueryLayer); msFree(mapserv->SelectLayer); msFree(mapserv->QueryFile); msFree(mapserv->TileCoords); msFree(mapserv); } } /* ** Ensure there is at least one free entry in the Layers array. ** ** This function is safe to use for the initial allocation of the Layers[] ** array as well (i.e. when MaxLayers==0 and Layers==NULL) ** ** Returns MS_SUCCESS/MS_FAILURE */ int msGrowMapservLayers( mapservObj* mapserv ) { /* Do we need to increase the size of Layers[] by MS_LAYER_ALLOCSIZE? */ if(mapserv->NumLayers == mapserv->MaxLayers) { int i; if(mapserv->MaxLayers == 0) { /* initial allocation of array */ mapserv->MaxLayers += MS_LAYER_ALLOCSIZE; mapserv->NumLayers = 0; mapserv->Layers = (char**)msSmallMalloc(mapserv->MaxLayers*sizeof(char*)); } else { /* realloc existing array */ mapserv->MaxLayers += MS_LAYER_ALLOCSIZE; mapserv->Layers = (char**)msSmallRealloc(mapserv->Layers, mapserv->MaxLayers*sizeof(char*)); } if(mapserv->Layers == NULL) { msSetError(MS_MEMERR, "Failed to allocate memory for Layers array.", "msGrowMappservLayers()"); return MS_FAILURE; } for(i=mapserv->NumLayers; iMaxLayers; i++) { mapserv->Layers[i] = NULL; } } return MS_SUCCESS; } /* ** Utility function to generate map, legend, scalebar and reference images. ** ** Parameters: ** - mapserv: mapserv object (used to extract the map object). ** - bQueryMap: if set to TRUE a query map will be created instead of a regular map. ** - bReturnOnError: if set to TRUE, the function will return on the first error, else it will try to generate all the images. */ int msGenerateImages(mapservObj *mapserv, int bQueryMap, int bReturnOnError) { char buffer[1024]; if(mapserv) { /* render the map OR query map */ if((!bQueryMap && mapserv->map->status == MS_ON) || (bQueryMap && mapserv->map->querymap.status == MS_ON)) { imageObj *image = NULL; image = msDrawMap(mapserv->map, bQueryMap); if(image) { snprintf(buffer, sizeof(buffer), "%s%s%s.%s", mapserv->map->web.imagepath, mapserv->map->name, mapserv->Id, MS_IMAGE_EXTENSION(mapserv->map->outputformat)); if(msSaveImage(mapserv->map, image, buffer) != MS_SUCCESS && bReturnOnError) { msFreeImage(image); return MS_FAILURE; } msFreeImage(image); } else if(bReturnOnError) return MS_FAILURE; } /* render the legend */ if(mapserv->map->legend.status == MS_ON) { imageObj *image = NULL; image = msDrawLegend(mapserv->map, MS_FALSE, NULL); if(image) { snprintf(buffer, sizeof(buffer), "%s%sleg%s.%s", mapserv->map->web.imagepath, mapserv->map->name, mapserv->Id, MS_IMAGE_EXTENSION(mapserv->map->outputformat)); if(msSaveImage(mapserv->map, image, buffer) != MS_SUCCESS && bReturnOnError) { msFreeImage(image); return MS_FAILURE; } msFreeImage(image); } else if(bReturnOnError) return MS_FAILURE; } /* render the scalebar */ if(mapserv->map->scalebar.status == MS_ON) { imageObj *image = NULL; image = msDrawScalebar(mapserv->map); if(image) { snprintf(buffer, sizeof(buffer), "%s%ssb%s.%s", mapserv->map->web.imagepath, mapserv->map->name, mapserv->Id, MS_IMAGE_EXTENSION(mapserv->map->outputformat)); if(msSaveImage(mapserv->map, image, buffer) != MS_SUCCESS && bReturnOnError) { msFreeImage(image); return MS_FAILURE; } msFreeImage(image); } else if(bReturnOnError) return MS_FAILURE; } /* render the reference map */ if(mapserv->map->reference.status == MS_ON) { imageObj *image; image = msDrawReferenceMap(mapserv->map); if(image) { snprintf(buffer, sizeof(buffer), "%s%sref%s.%s", mapserv->map->web.imagepath, mapserv->map->name, mapserv->Id, MS_IMAGE_EXTENSION(mapserv->map->outputformat)); if(msSaveImage(mapserv->map, image, buffer) != MS_SUCCESS && bReturnOnError) { msFreeImage(image); return MS_FAILURE; } msFreeImage(image); } else if(bReturnOnError) return MS_FAILURE; } } return MS_SUCCESS; } /* ** Utility function to open a template file, process it and ** and return into a buffer the processed template. Uses the ** template file from the web object. Returns NULL if there is ** an error. */ char *msProcessTemplate(mapObj *map, int bGenerateImages, char **names, char **values, int numentries) { char *pszBuffer = NULL; if(map) { /* Initialize object and set appropriate defaults. */ mapservObj *mapserv = NULL; mapserv = msAllocMapServObj(); mapserv->map = map; mapserv->Mode = BROWSE; if(names && values && numentries > 0) { msFreeCharArray(mapserv->request->ParamNames, mapserv->request->NumParams); msFreeCharArray(mapserv->request->ParamValues, mapserv->request->NumParams); mapserv->request->ParamNames = names; mapserv->request->ParamValues = values; mapserv->request->NumParams = numentries; } /* ** ISSUE/TODO : some of the name/values should be extracted and ** processed (ex imgext, layers, ...) as it is done in function ** loadform. */ if(bGenerateImages) msGenerateImages(mapserv, MS_FALSE, MS_FALSE); /* ** Process the template. ** ** TODO : use web minscaledenom/maxscaledenom depending on the scale. */ if(msReturnPage(mapserv, mapserv->map->web.template, BROWSE, &pszBuffer) != MS_SUCCESS) { msFree(pszBuffer); pszBuffer = NULL; } /* Don't free the map and names and values arrays since they were passed by reference. */ mapserv->map = NULL; mapserv->request->ParamNames = mapserv->request->ParamValues = NULL; mapserv->request->NumParams = 0; msFreeMapServObj(mapserv); } return pszBuffer; } /* ** Utility method to process the legend template. */ char *msProcessLegendTemplate(mapObj *map, char **names, char **values, int numentries) { char *pszOutBuf = NULL; if(map && map->legend.template) { /* Initialize object and set appropriate defaults. */ mapservObj *mapserv = NULL; mapserv = msAllocMapServObj(); mapserv->map = map; mapserv->Mode = BROWSE; if(names && values && numentries > 0) { msFreeCharArray(mapserv->request->ParamNames, mapserv->request->NumParams); msFreeCharArray(mapserv->request->ParamValues, mapserv->request->NumParams); mapserv->request->ParamNames = names; mapserv->request->ParamValues = values; mapserv->request->NumParams = numentries; } pszOutBuf = generateLegendTemplate(mapserv); /* Don't free the map and names and values arrays since they were passed by reference. */ mapserv->map = NULL; mapserv->request->ParamNames = mapserv->request->ParamValues = NULL; mapserv->request->NumParams = 0; msFreeMapServObj(mapserv); } return pszOutBuf; } /* ** Utility function that process a template file(s) used in the ** query and return the processed template(s) in a buffer. */ char *msProcessQueryTemplate(mapObj *map, int bGenerateImages, char **names, char **values, int numentries) { char *pszBuffer = NULL; if(map) { /* Initialize object and set appropriate defaults. */ mapservObj *mapserv = NULL; mapserv = msAllocMapServObj(); mapserv->map = map; mapserv->Mode = QUERY; if(names && values && numentries > 0) { msFreeCharArray(mapserv->request->ParamNames, mapserv->request->NumParams); msFreeCharArray(mapserv->request->ParamValues, mapserv->request->NumParams); mapserv->request->ParamNames = names; mapserv->request->ParamValues = values; mapserv->request->NumParams = numentries; } if(bGenerateImages) msGenerateImages(mapserv, MS_TRUE, MS_FALSE); mapserv->sendheaders = MS_FALSE; msReturnTemplateQuery(mapserv, mapserv->map->web.queryformat, &pszBuffer); mapserv->map = NULL; mapserv->request->ParamNames = mapserv->request->ParamValues = NULL; mapserv->request->NumParams = 0; msFreeMapServObj(mapserv); } return pszBuffer; } mapserver-7.6.4/maptemplate.h000066400000000000000000000141261407312142500162210ustar00rootroot00000000000000/****************************************************************************** * $Id$ * * Project: MapServer * Purpose: Template processing related declarations. * Author: Steve Lime and the MapServer team. * ****************************************************************************** * Copyright (c) 1996-2005 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. ****************************************************************************/ #ifndef MAPTEMPLATE_H #define MAPTEMPLATE_H #include "mapserver.h" #include "maphash.h" #define IDPATTERN "^[0-9A-Za-z]{1,63}$" #define IDSIZE 64 #define TEMPLATE_TYPE(s) (((strncmp("http://", s, 7) == 0) || (strncmp("https://", s, 8) == 0) || (strncmp("ftp://", s, 6)) == 0) ? MS_URL : MS_FILE) #define MAXZOOM 25 #define MINZOOM -25 #define DEFAULT_DATE_FORMAT "%d/%b/%Y:%H:%M:%S %z" enum coordSources {NONE, FROMIMGPNT, FROMIMGBOX, FROMIMGSHAPE, FROMREFPNT, FROMUSERPNT, FROMUSERBOX, FROMUSERSHAPE, FROMBUF, FROMSCALE, FROMTILE}; enum modes {BROWSE, ZOOMIN, ZOOMOUT, MAP, LEGEND, LEGENDICON, REFERENCE, SCALEBAR, COORDINATE, QUERY, NQUERY, ITEMQUERY, ITEMNQUERY, FEATUREQUERY, FEATURENQUERY, ITEMFEATUREQUERY, ITEMFEATURENQUERY, INDEXQUERY, TILE, OWS, WFS, MAPLEGEND, MAPLEGENDICON }; /* struct mapservObj * Global structure used by templates and mapserver CGI interface. * * This structur was created to seperate template functionality * from the main mapserv file. Instead of moving all template * related functions in a new file (maptemplate.c) and change * their signatures to pass all global variables, we created this * structure with all global variables needed by template. */ typedef struct { /* should the query and/or map be saved */ int savemap, savequery; cgiRequestObj *request; int sendheaders; /* should mime-type header be output, default will be MS_TRUE */ mapObj *map; char **Layers; char *icon; /* layer:class combination that defines a legend icon */ int NumLayers; /* number of layers specfied by a use */ int MaxLayers; /* Allocated size of Layers[] array */ layerObj *resultlayer; int UseShapes; /* are results of a query to be used in calculating an extent of some sort */ shapeObj resultshape; rectObj RawExt; pointObj mappnt; double fZoom, Zoom; int ZoomDirection; /* whether zooming in or out, default is pan or 0 */ int Mode; /* can be BROWSE, QUERY, etc. */ int TileMode; /* can be GMAP, VE */ char *TileCoords; /* for GMAP: 0 0 1; for VE: 013021023 */ char Id[IDSIZE]; /* big enough for time + pid */ int CoordSource; double ScaleDenom; /* used to create a map extent around a point */ int ImgRows, ImgCols; rectObj ImgExt; /* Existing image's mapextent */ rectObj ImgBox; pointObj RefPnt; pointObj ImgPnt; double Buffer; int SearchMap; /* apply pan/zoom BEFORE doing the query (e.g. query the output image rather than the input image) */ char *QueryFile; char *QueryLayer; char *SelectLayer; int QueryLayerIndex; int SelectLayerIndex; char *QueryItem; char *QueryString; int ShapeIndex; int TileIndex; int QueryCoordSource; int ZoomSize; /* zoom absolute magnitude (i.e. > 0) */ /* ** variables for multiple query results processing */ int RN; /* overall result number */ int LRN; /* result number within a layer */ int NL; /* total number of layers with results */ int NR; /* total number or results */ int NLR; /* number of results in a layer */ map_hittest *hittest; } mapservObj; /*! \fn msAllocMapServObj * Allocate memory for all variables in strusture * and initiate default values */ MS_DLL_EXPORT mapservObj* msAllocMapServObj(void); /*! \fn msFreeMapServObj * free all variables in structure */ MS_DLL_EXPORT void msFreeMapServObj(mapservObj* msObj); /* For Mapserv.c */ MS_DLL_EXPORT int isOn(mapservObj* msObj, char *name, char *group); MS_DLL_EXPORT int checkWebScale(mapservObj *msObj); MS_DLL_EXPORT int setExtent(mapservObj *msObj); MS_DLL_EXPORT int msReturnPage(mapservObj* msObj, char* , int, char **); MS_DLL_EXPORT int msReturnURL(mapservObj* msObj, char*, int); MS_DLL_EXPORT int msReturnNestedTemplateQuery(mapservObj* msObj, char* pszMimeType, char **papszBuffer); MS_DLL_EXPORT int msReturnTemplateQuery(mapservObj *msObj, char* pszMimeType, char **papszBuffer); MS_DLL_EXPORT int msReturnOpenLayersPage(mapservObj *mapserv); MS_DLL_EXPORT int msRedirect(char* url); MS_DLL_EXPORT char *generateLegendTemplate(mapservObj *msObj); MS_DLL_EXPORT int msGenerateImages(mapservObj *msObj, int bQueryMap, int bReturnOnError); MS_DLL_EXPORT char *msProcessTemplate(mapObj *map, int bGenerateImages, char **names, char **values, int numentries); MS_DLL_EXPORT char *msProcessLegendTemplate(mapObj *map, char **names, char **values, int numentries); MS_DLL_EXPORT char *msProcessQueryTemplate(mapObj *map, int bGenerateImages, char **names, char **values, int numentries); MS_DLL_EXPORT int msGrowMapservLayers( mapservObj* msObj ); #endif mapserver-7.6.4/mapthread.c000066400000000000000000000264531407312142500156560ustar00rootroot00000000000000/****************************************************************************** * $Id$ * * Project: UMN MapServer * Purpose: Support code for abstracting thread issues. * Author: Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 1996-2005 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. ****************************************************************************/ /****************************************************************************** THREAD-SAFE SUPPORT IN MAPSERVER ================================ If thread safety is enabled the USE_THREAD macro will be defined. Thread API (mapthread.h/c) -------------------------- This API is made available to avoid having dependencies on different thread libraries in lots of places in MapServer. It is intended to provide minimal services required by mapserver and isn't intended to be broadly useful. It should be available for Win32 and pthreads environments. It should be possible to implement for other thread libraries if needed. int msGetThreadId(): Returns the current threads integer id. This can be used for making some information thread specific, as has been done for the global error context in maperror.c. void msAcquireLock(int): Acquires the indicated Mutex. If it is already held by another thread then this thread will block till the other thread releases it. If this thread already holds the mutex then behaviour is undefined. If the mutex id is not valid (not in the range 0 to TLOCK_STATIC_MAX) then results are undefined. void msReleaseLock(int): Releases the indicated mutex. If the lock id is invalid, or if the mutex is not currently held by this thread then results are undefined. It is incredibly important to ensure that any mutex that is acquired is released as soon as possible. Any flow of control that could result in a mutex not being release is going to be a disaster. The mutex numbers are defined in mapthread.h with the TLOCK_* codes. If you need a new mutex, add a #define in mapthread.h for it. Currently there is no "dynamic" mutex allocation, but this could be added. Making Things Thread-safe ------------------------- Generally, to make MapServer thread-safe it is necessary to ensure that different threads aren't read and updating common datastructures at the same time and that all appropriate state be kept thread specific. Generally this will mean: o The previously global error status (errorObj ms_error) is now thread specific. Use msGetErrorObj() to get the current threads error state. o Use of subcomponents that are not thread safe need to be protected by a Mutex (lock). Currently a mutex is used for the entire map file parsing operation (msLoadMap() in mapfile.c) since the yacc parser uses a number of global variables. It is also done with pj_init() from PROJ.4 since this does not appear to be thread safe. It isn't yet clear if pj_transform() is thread safe. It is expected that mutexes will need to be employed in a variety of other places to ensure serialized access to risky functionality. This may apply to sublibraries like GDAL for instance. If a new section that is not thread-safe is identified (and assuming it can't be internally modified to make it thread-safe easily), it is necessary to define a new mutex (#define a TLOCK code in mapthread.h), and then surround the resource with acquire and release lock calls. eg. msAcquireLock( TLOCK_PROJ ); if( !(p->proj = pj_init(p->numargs, p->args)) ) { msReleaseLock( TLOCK_PROJ ); msSetError(MS_PROJERR, pj_strerrno(pj_errno), "msProcessProjection()"); return(-1); } msReleaseLock( TLOCK_PROJ ); It is imperative that any acquired locks be released on all possible control paths or else the MapServer will lock up as other thread try to acquire the lock and block forever. Other Thread-safe Issues ------------------------ Some issues are not easily corrected with Mutexes or other similar mechanisms. The following restrictions currently apply to MapServer when trying to use it in thread-safe mode. Note that failure to adhere to these constraints will not usually generate nice error messages, instead operation will just fail sometimes. 1) It is currently assumed that a mapObj belongs only to one thread at a time. That is, there is no effort to syncronize access to a mapObj itself. 2) Stuff that results in a chdir() call are problematic. In particular, the .map file SHAPEPATH directive should not be used. Use full paths to data files instead. ******************************************************************************/ #include #include "mapserver.h" #include "mapthread.h" #if defined(USE_THREAD) static int thread_debug = 0; static char *lock_names[] = { NULL, "PARSER", "GDAL", "ERROROBJ", "PROJ", "TTF", "POOL", "SDE", "ORACLE", "OWS", "LAYER_VTABLE", "IOCONTEXT", "TMPFILE", "DEBUGOBJ", "OGR", "TIME", "FRIBIDI", "WXS", "GEOS", NULL }; #endif /************************************************************************/ /* ==================================================================== */ /* PTHREADS */ /* ==================================================================== */ /************************************************************************/ #if defined(USE_THREAD) && !defined(_WIN32) #include "pthread.h" static int mutexes_initialized = 0; static pthread_mutex_t mutex_locks[TLOCK_MAX]; /************************************************************************/ /* msThreadInit() */ /************************************************************************/ void msThreadInit() { static pthread_mutex_t core_lock = PTHREAD_MUTEX_INITIALIZER; if( thread_debug ) fprintf( stderr, "msThreadInit() (posix)\n" ); pthread_mutex_lock( &core_lock ); for( ; mutexes_initialized < TLOCK_STATIC_MAX; mutexes_initialized++ ) pthread_mutex_init( mutex_locks + mutexes_initialized, NULL ); pthread_mutex_unlock( &core_lock ); } /************************************************************************/ /* msGetThreadId() */ /************************************************************************/ void* msGetThreadId() { return (void*) pthread_self(); } /************************************************************************/ /* msAcquireLock() */ /************************************************************************/ void msAcquireLock( int nLockId ) { if( mutexes_initialized == 0 ) msThreadInit(); assert( nLockId >= 0 && nLockId < mutexes_initialized ); if( thread_debug ) fprintf( stderr, "msAcquireLock(%d/%s) (posix)\n", nLockId, lock_names[nLockId] ); pthread_mutex_lock( mutex_locks + nLockId ); } /************************************************************************/ /* msReleaseLock() */ /************************************************************************/ void msReleaseLock( int nLockId ) { assert( mutexes_initialized > 0 ); assert( nLockId >= 0 && nLockId < mutexes_initialized ); if( thread_debug ) fprintf( stderr, "msReleaseLock(%d/%s) (posix)\n", nLockId, lock_names[nLockId] ); pthread_mutex_unlock( mutex_locks + nLockId ); } #endif /* defined(USE_THREAD) && !defined(_WIN32) */ /************************************************************************/ /* ==================================================================== */ /* WIN32 THREADS */ /* ==================================================================== */ /************************************************************************/ #if defined(USE_THREAD) && defined(_WIN32) #include static int mutexes_initialized = 0; static HANDLE mutex_locks[TLOCK_MAX]; /************************************************************************/ /* msThreadInit() */ /************************************************************************/ void msThreadInit() { /* static pthread_mutex_t core_lock = PTHREAD_MUTEX_INITIALIZER; */ static HANDLE core_lock = NULL; if( mutexes_initialized >= TLOCK_STATIC_MAX ) return; if( thread_debug ) fprintf( stderr, "msThreadInit() (win32)\n" ); if( core_lock == NULL ) core_lock = CreateMutex( NULL, TRUE, NULL ); else WaitForSingleObject( core_lock, INFINITE ); for( ; mutexes_initialized < TLOCK_STATIC_MAX; mutexes_initialized++ ) mutex_locks[mutexes_initialized] = CreateMutex( NULL, FALSE, NULL ); ReleaseMutex( core_lock ); } /************************************************************************/ /* msGetThreadId() */ /************************************************************************/ void* msGetThreadId() { return (void*) (size_t) GetCurrentThreadId(); } /************************************************************************/ /* msAcquireLock() */ /************************************************************************/ void msAcquireLock( int nLockId ) { if( mutexes_initialized == 0 ) msThreadInit(); assert( nLockId >= 0 && nLockId < mutexes_initialized ); if( thread_debug ) fprintf( stderr, "msAcquireLock(%d/%s) (win32)\n", nLockId, lock_names[nLockId] ); WaitForSingleObject( mutex_locks[nLockId], INFINITE ); } /************************************************************************/ /* msReleaseLock() */ /************************************************************************/ void msReleaseLock( int nLockId ) { assert( mutexes_initialized > 0 ); assert( nLockId >= 0 && nLockId < mutexes_initialized ); if( thread_debug ) fprintf( stderr, "msReleaseLock(%d/%s) (win32)\n", nLockId, lock_names[nLockId] ); ReleaseMutex( mutex_locks[nLockId] ); } #endif /* defined(USE_THREAD) && defined(_WIN32) */ mapserver-7.6.4/mapthread.h000066400000000000000000000050601407312142500156520ustar00rootroot00000000000000/****************************************************************************** * $Id$ * * Project: MapServer * Purpose: Multithreading / locking related declarations. * Author: Frank Warmerdam * ****************************************************************************** * Copyright (c) 1996-2005 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. ****************************************************************************/ #ifndef MAPTHREAD_H #define MAPTHREAD_H #ifdef __cplusplus extern "C" { #endif #ifdef USE_THREAD void msThreadInit(void); void* msGetThreadId(void); void msAcquireLock(int); void msReleaseLock(int); #else #define msThreadInit() #define msGetThreadId() (0) #define msAcquireLock(x) #define msReleaseLock(x) #endif /* ** lock ids - note there is a corresponding lock_names[] array in ** mapthread.c that needs to be extended when new ids are added. */ #define TLOCK_PARSER 1 #define TLOCK_GDAL 2 #define TLOCK_ERROROBJ 3 #define TLOCK_PROJ 4 #define TLOCK_TTF 5 #define TLOCK_POOL 6 #define TLOCK_SDE 7 #define TLOCK_ORACLE 8 #define TLOCK_OWS 9 #define TLOCK_LAYER_VTABLE 10 #define TLOCK_IOCONTEXT 11 #define TLOCK_TMPFILE 12 #define TLOCK_DEBUGOBJ 13 #define TLOCK_OGR 14 #define TLOCK_TIME 15 #define TLOCK_FRIBIDI 16 #define TLOCK_WxS 17 #define TLOCK_GEOS 18 #define TLOCK_STATIC_MAX 20 #define TLOCK_MAX 100 #ifdef __cplusplus } #endif #endif /* MAPTHREAD_H */ mapserver-7.6.4/maptile.c000066400000000000000000000416531407312142500153430ustar00rootroot00000000000000/****************************************************************************** * $Id$ * * Project: MapServer * Purpose: MapServer Tile Access API * Author: Paul Ramsey * ****************************************************************************** * Copyright (c) 2008, Paul Ramsey * * 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 "maptile.h" #include "mapproject.h" #ifdef USE_TILE_API static void msTileResetMetatileLevel(mapObj *map) { hashTableObj *meta = &(map->web.metadata); const char *zero = "0"; const char *value = NULL; /* Is the tile_metatile_levetl set... */ if((value = msLookupHashTable(meta, "tile_metatile_level")) != NULL) { msRemoveHashTable(meta, "tile_metatile_level"); msInsertHashTable(meta, "tile_metatile_level", zero); } /* No tile_metatile_level value. */ else { msInsertHashTable(meta, "tile_metatile_level", zero); } } #endif /************************************************************************ * msTileGetGMapCoords * ************************************************************************/ static int msTileGetGMapCoords(const char *coordstring, int *x, int *y, int *zoom) { int num_coords = 0; char **coords = NULL; if( coordstring ) { coords = msStringSplit(coordstring, ' ', &(num_coords)); if( num_coords != 3 ) { msFreeCharArray(coords, num_coords); msSetError(MS_WEBERR, "Invalid number of tile coordinates (should be three).", "msTileSetup()"); return MS_FAILURE; } } else { msSetError(MS_WEBERR, "Tile parameter not set.", "msTileSetup()"); return MS_FAILURE; } if( x ) *x = strtol(coords[0], NULL, 10); if( y ) *y = strtol(coords[1], NULL, 10); if( zoom ) *zoom = strtol(coords[2], NULL, 10); msFreeCharArray(coords, 3); return MS_SUCCESS; } /************************************************************************ * msTileSetParams * ************************************************************************/ static void msTileGetParams(mapObj *map, tileParams *params) { const char *value = NULL; hashTableObj *meta = &(map->web.metadata); params->tile_size = SPHEREMERC_IMAGE_SIZE; /* Check for tile buffer, set to buffer==0 as default */ if((value = msLookupHashTable(meta, "tile_map_edge_buffer")) != NULL) { params->map_edge_buffer = atoi(value); if(map->debug) msDebug("msTileSetParams(): tile_map_edge_buffer = %d\n", params->map_edge_buffer); } else params->map_edge_buffer = 0; /* Check for metatile size, set to tile==metatile as default */ if((value = msLookupHashTable(meta, "tile_metatile_level")) != NULL) { params->metatile_level = atoi(value); /* Quietly force metatile_level to be sane */ if( params->metatile_level < 0 ) params->metatile_level = 0; if( params->metatile_level > 2 ) params->metatile_level = 2; if(map->debug) msDebug("msTileSetParams(): tile_metatile_level = %d\n", params->metatile_level); } else params->metatile_level = 0; } /************************************************************************ * msTileExtractSubTile * * * ************************************************************************/ static imageObj* msTileExtractSubTile(const mapservObj *msObj, const imageObj *img) { int width, mini, minj; int zoom = 2; imageObj* imgOut = NULL; tileParams params; rendererVTableObj *renderer; rasterBufferObj imgBuffer; if( !MS_RENDERER_PLUGIN(msObj->map->outputformat) || msObj->map->outputformat->renderer != img->format->renderer || ! MS_MAP_RENDERER(msObj->map)->supports_pixel_buffer ) { msSetError(MS_MISCERR,"unsupported or mixed renderers","msTileExtractSubTile()"); return NULL; } renderer = MS_MAP_RENDERER(msObj->map); if (renderer->getRasterBufferHandle((imageObj*)img,&imgBuffer) != MS_SUCCESS) { return NULL; } /* ** Load the metatiling information from the map file. */ msTileGetParams(msObj->map, ¶ms); /* ** Initialize values for the metatile clip area. */ width = img->width - 2*params.map_edge_buffer; mini = params.map_edge_buffer; minj = params.map_edge_buffer; if( msObj->TileMode == TILE_GMAP ) { int x, y, zoom; if( msObj->TileCoords ) { if( msTileGetGMapCoords(msObj->TileCoords, &x, &y, &zoom) == MS_FAILURE ) return NULL; } else { msSetError(MS_WEBERR, "Tile parameter not set.", "msTileSetup()"); return NULL; } if(msObj->map->debug) msDebug("msTileExtractSubTile(): gmaps coords (x: %d, y: %d)\n",x,y); /* ** The bottom N bits of the coordinates give us the subtile ** location relative to the metatile. */ x = (0xffff ^ (0xffff << params.metatile_level)) & x; y = (0xffff ^ (0xffff << params.metatile_level)) & y; if(msObj->map->debug) msDebug("msTileExtractSubTile(): gmaps image coords (x: %d, y: %d)\n",x,y); mini = mini + x * params.tile_size; minj = minj + y * params.tile_size; } else if( msObj->TileMode == TILE_VE ) { int tsize; int i = 0; char j = 0; if( (int)strlen( msObj->TileCoords ) - params.metatile_level < 0 ) { return(NULL); } /* ** Process the last elements of the VE coordinate string to place the ** requested tile in the context of the metatile */ for( i = strlen( msObj->TileCoords ) - params.metatile_level; i < strlen( msObj->TileCoords ); i++ ) { j = msObj->TileCoords[i]; tsize = width / zoom; if( j == '1' || j == '3' ) mini += tsize; if( j == '2' || j == '3' ) minj += tsize; zoom *= 2; } } else { return(NULL); /* Huh? Should have a mode. */ } imgOut = msImageCreate(params.tile_size, params.tile_size, msObj->map->outputformat, NULL, NULL, msObj->map->resolution, msObj->map->defresolution, NULL); if( imgOut == NULL ) { return NULL; } if(msObj->map->debug) msDebug("msTileExtractSubTile(): extracting (%d x %d) tile, top corner (%d, %d)\n",params.tile_size,params.tile_size,mini,minj); if(UNLIKELY(MS_FAILURE == renderer->mergeRasterBuffer(imgOut,&imgBuffer,1.0,mini, minj,0, 0,params.tile_size, params.tile_size))) { msFreeImage(imgOut); return NULL; } return imgOut; } /************************************************************************ * msTileSetup * * * * Called from mapserv.c, this is where the fun begins * * Set up projections and test the parameters for legality. * ************************************************************************/ int msTileSetup(mapservObj* msObj) { #ifdef USE_TILE_API char *outProjStr = NULL; tileParams params; /* ** Load the metatiling information from the map file. */ msTileGetParams(msObj->map, ¶ms); /* ** Ensure all the LAYERs have a projection. */ if( msMapSetLayerProjections(msObj->map) != 0 ) { return(MS_FAILURE); } /* ** Set the projection string for this mode. */ if( msObj->TileMode == TILE_GMAP || msObj->TileMode == TILE_VE ) { outProjStr = SPHEREMERC_PROJ4; } else { return MS_FAILURE; /* Huh? No mode? */ } if( msLoadProjectionString(&(msObj->map->projection), outProjStr) != 0 ) { msSetError(MS_CGIERR, "Unable to load projection string.", "msTileSetup()"); return MS_FAILURE; } /* ** Set up the output extents for this tilemode and tile coordinates */ if( msObj->TileMode == TILE_GMAP ) { int x, y, zoom; double zoomfactor; if( msObj->TileCoords ) { if( msTileGetGMapCoords(msObj->TileCoords, &x, &y, &zoom) == MS_FAILURE ) return MS_FAILURE; } else { msSetError(MS_WEBERR, "Tile parameter not set.", "msTileSetup()"); return MS_FAILURE; } if( params.metatile_level >= zoom ) { msTileResetMetatileLevel(msObj->map); } zoomfactor = pow(2.0, (double)zoom); /* ** Check the input request for sanity. */ if( x >= zoomfactor || y >= zoomfactor ) { msSetError(MS_CGIERR, "GMap tile coordinates are too large for supplied zoom.", "msTileSetup()"); return(MS_FAILURE); } if( x < 0 || y < 0 ) { msSetError(MS_CGIERR, "GMap tile coordinates should not be less than zero.", "msTileSetup()"); return(MS_FAILURE); } } else if ( msObj->TileMode == TILE_VE ) { if( strspn( msObj->TileCoords, "0123" ) < strlen( msObj->TileCoords ) ) { msSetError(MS_CGIERR, "VE tile name should only include characters 0, 1, 2 and 3.", "msTileSetup()"); return(MS_FAILURE); } if( params.metatile_level >= strlen(msObj->TileCoords) ) { msTileResetMetatileLevel(msObj->map); } } else { return(MS_FAILURE); /* Huh? Should have a mode. */ } return MS_SUCCESS; #else msSetError(MS_CGIERR, "Tile API is not available.", "msTileSetup()"); return(MS_FAILURE); #endif } /************************************************************************ * msTileSetExtent * * * * Based on the input parameters, set the output extent for this * * tile. * ************************************************************************/ int msTileSetExtent(mapservObj* msObj) { #ifdef USE_TILE_API mapObj *map = msObj->map; double dx, dy, buffer; tileParams params; /* Read the tile-mode map file parameters */ msTileGetParams(msObj->map, ¶ms); if( msObj->TileMode == TILE_GMAP ) { int x, y, zoom; double zoomfactor, tilesize, xmin, xmax, ymin, ymax; if( msObj->TileCoords ) { if( msTileGetGMapCoords(msObj->TileCoords, &x, &y, &zoom) == MS_FAILURE ) return MS_FAILURE; } else { msSetError(MS_WEBERR, "Tile parameter not set.", "msTileSetup()"); return MS_FAILURE; } if(map->debug) msDebug("msTileSetExtent(): gmaps coords (x: %d, y: %d, z: %d)\n",x,y,zoom); /* ** If we are metatiling, adjust the zoom level appropriately, ** then scale back the x/y coordinates to match the new level. */ if( params.metatile_level > 0 ) { zoom = zoom - params.metatile_level; x = x >> params.metatile_level; y = y >> params.metatile_level; } if(map->debug) msDebug("msTileSetExtent(): gmaps metacoords (x: %d, y: %d, z: %d)\n",x,y,zoom); zoomfactor = pow(2.0, (double)zoom); /* ** Calculate the ground extents of the tile request. */ /* printf("X: %i Y: %i Z: %i\n",x,y,zoom); */ tilesize = SPHEREMERC_GROUND_SIZE / zoomfactor; xmin = (x * tilesize) - (SPHEREMERC_GROUND_SIZE / 2.0); xmax = ((x + 1) * tilesize) - (SPHEREMERC_GROUND_SIZE / 2.0); ymin = (SPHEREMERC_GROUND_SIZE / 2.0) - ((y + 1) * tilesize); ymax = (SPHEREMERC_GROUND_SIZE / 2.0) - (y * tilesize); map->extent.minx = xmin; map->extent.maxx = xmax; map->extent.miny = ymin; map->extent.maxy = ymax; } else if( msObj->TileMode == TILE_VE ) { double minx = SPHEREMERC_GROUND_SIZE / -2.0; double miny = SPHEREMERC_GROUND_SIZE / -2.0; double maxx = SPHEREMERC_GROUND_SIZE / 2.0; double maxy = SPHEREMERC_GROUND_SIZE / 2.0; double zoom = 2.0; double tsize; int i = 0; char j = 0; /* ** Walk down the VE URL string, adjusting the extent each time. ** For meta-tiling cases, we stop early, to draw a larger image. */ for( i = 0; i < strlen( msObj->TileCoords ) - params.metatile_level; i++ ) { j = msObj->TileCoords[i]; tsize = SPHEREMERC_GROUND_SIZE / zoom; if( j == '1' || j == '3' ) minx += tsize; if( j == '0' || j == '2' ) maxx -= tsize; if( j == '2' || j == '3' ) maxy -= tsize; if( j == '0' || j == '1' ) miny += tsize; zoom *= 2.0; } map->extent.minx = minx; map->extent.maxx = maxx; map->extent.miny = miny; map->extent.maxy = maxy; } else { return(MS_FAILURE); /* Huh? Should have a mode. */ } /* ** Set the output tile size. */ msObj->ImgCols = SPHEREMERC_IMAGE_SIZE << params.metatile_level; msObj->ImgRows = SPHEREMERC_IMAGE_SIZE << params.metatile_level; map->width = SPHEREMERC_IMAGE_SIZE << params.metatile_level; map->height = SPHEREMERC_IMAGE_SIZE << params.metatile_level; if(map->debug) msDebug("msTileSetExtent(): base image size (%d x %d)\n",map->width,map->height); /* ** Add the gutters ** First calculate ground units in the buffer at current extent */ buffer = params.map_edge_buffer * (map->extent.maxx - map->extent.minx) / (double)map->width; /* ** Then adjust the map extents out by that amount */ map->extent.minx -= buffer; map->extent.maxx += buffer; map->extent.miny -= buffer; map->extent.maxy += buffer; /* ** Finally adjust the map image size by the pixel buffer */ map->width += 2 * params.map_edge_buffer; map->height += 2 * params.map_edge_buffer; msObj->ImgCols += 2 * params.map_edge_buffer; msObj->ImgRows += 2 * params.map_edge_buffer; if(map->debug) msDebug("msTileSetExtent(): buffered image size (%d x %d)\n",map->width,map->height); /* ** Adjust the extents inwards by 1/2 pixel so they are from ** center-of-pixel to center-of-pixel, instead of edge-to-edge. ** This is the way mapserver does it. */ dx = (map->extent.maxx - map->extent.minx) / map->width; map->extent.minx += dx*0.5; map->extent.maxx -= dx*0.5; dy = (map->extent.maxy - map->extent.miny) / map->height; map->extent.miny += dy*0.5; map->extent.maxy -= dy*0.5; /* ** Ensure the labelcache buffer is greater than the tile buffer. */ if( params.map_edge_buffer > 0 ) { const char *value; hashTableObj *meta = &(map->web.metadata); char tilebufferstr[64]; /* Write the tile buffer to a string */ snprintf(tilebufferstr, sizeof(tilebufferstr), "-%d", params.map_edge_buffer); /* Hm, the labelcache buffer is set... */ if((value = msLookupHashTable(meta, "labelcache_map_edge_buffer")) != NULL) { /* If it's too small, replace with a bigger one */ if( params.map_edge_buffer > abs(atoi(value)) ) { msRemoveHashTable(meta, "labelcache_map_edge_buffer"); msInsertHashTable(meta, "labelcache_map_edge_buffer", tilebufferstr); } } /* No labelcache buffer value? Then we use the tile buffer. */ else { msInsertHashTable(meta, "labelcache_map_edge_buffer", tilebufferstr); } } if(map->debug) { msDebug( "msTileSetExtent (%f, %f) (%f, %f)\n", map->extent.minx, map->extent.miny, map->extent.maxx, map->extent.maxy); } return MS_SUCCESS; #else msSetError(MS_CGIERR, "Tile API is not available.", "msTileSetExtent()"); return(MS_FAILURE); #endif } /************************************************************************ * msDrawTile * * * * Draw the tile once with gutters, metatiling and buffers, then * * clip out the final tile. * * WARNING: Call msTileSetExtent() first or this will be a pointless * * fucnction call. * ************************************************************************/ imageObj* msTileDraw(mapservObj *msObj) { imageObj *img; tileParams params; msTileGetParams(msObj->map, ¶ms); img = msDrawMap(msObj->map, MS_FALSE); if( img == NULL ) return NULL; if( params.metatile_level > 0 || params.map_edge_buffer > 0 ) { imageObj *tmp = msTileExtractSubTile(msObj, img); msFreeImage(img); if( tmp == NULL ) return NULL; img = tmp; } return img; } mapserver-7.6.4/maptile.h000066400000000000000000000042601407312142500153410ustar00rootroot00000000000000/****************************************************************************** * $Id$ * * Project: MapServer * Purpose: MapServer Tile Access API * Author: Paul Ramsey * ****************************************************************************** * Copyright (c) 2008, Paul Ramsey * * 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" #include "maptemplate.h" #define USE_TILE_API 1 #define SPHEREMERC_PROJ4 "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +units=m +k=1.0 +nadgrids=@null" #define SPHEREMERC_GROUND_SIZE (20037508.34*2) #define SPHEREMERC_IMAGE_SIZE 0x0100 enum tileModes { TILE_GMAP, TILE_VE }; MS_DLL_EXPORT int msTileSetup(mapservObj *msObj); MS_DLL_EXPORT int msTileSetExtent(mapservObj *msObj); MS_DLL_EXPORT int msTileSetProjections(mapObj *map); MS_DLL_EXPORT imageObj* msTileDraw(mapservObj *msObj); typedef struct { int metatile_level; /* In zoom levels above tile request: best bet is 0, 1 or 2 */ int tile_size; /* In pixels */ int map_edge_buffer; /* In pixels */ } tileParams; mapserver-7.6.4/maptime.c000066400000000000000000000363651407312142500153500ustar00rootroot00000000000000/****************************************************************************** * $id$ * * Project: MapServer * Purpose: Date/Time utility functions. * Author: Steve Lime and the MapServer team. * ****************************************************************************** * Copyright (c) 1996-2005 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. ****************************************************************************/ #define _GNU_SOURCE /* glibc2 needs this for strptime() */ #include #include #include #include "mapserver.h" #include "maptime.h" #include "maperror.h" #include "mapthread.h" typedef struct { char pattern[64]; ms_regex_t *regex; char format[32]; char userformat[32]; MS_TIME_RESOLUTION resolution; } timeFormatObj; static timeFormatObj ms_timeFormats[] = { {"^[0-9]{8}", NULL, "%Y%m%d","YYYYMMDD",TIME_RESOLUTION_DAY}, {"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z", NULL, "%Y-%m-%dT%H:%M:%SZ","YYYY-MM-DDTHH:MM:SSZ",TIME_RESOLUTION_SECOND}, {"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}", NULL, "%Y-%m-%dT%H:%M:%S", "YYYY-MM-DDTHH:MM:SS",TIME_RESOLUTION_SECOND}, {"^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}", NULL, "%Y-%m-%d %H:%M:%S", "YYYY-MM-DD HH:MM:SS", TIME_RESOLUTION_SECOND}, {"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}", NULL, "%Y-%m-%dT%H:%M", "YYYY-MM-DDTHH:MM",TIME_RESOLUTION_MINUTE}, {"^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}", NULL, "%Y-%m-%d %H:%M", "YYYY-MM-DD HH:MM",TIME_RESOLUTION_MINUTE}, {"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}", NULL, "%Y-%m-%dT%H", "YYYY-MM-DDTHH",TIME_RESOLUTION_HOUR}, {"^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}", NULL, "%Y-%m-%d %H", "YYYY-MM-DD HH",TIME_RESOLUTION_HOUR}, {"^[0-9]{4}-[0-9]{2}-[0-9]{2}", NULL, "%Y-%m-%d", "YYYY-MM-DD", TIME_RESOLUTION_DAY}, {"^[0-9]{4}-[0-9]{2}", NULL, "%Y-%m", "YYYY-MM",TIME_RESOLUTION_MONTH}, {"^[0-9]{4}", NULL, "%Y", "YYYY",TIME_RESOLUTION_YEAR}, {"^T[0-9]{2}:[0-9]{2}:[0-9]{2}Z", NULL, "T%H:%M:%SZ", "THH:MM:SSZ",TIME_RESOLUTION_SECOND}, {"^T[0-9]{2}:[0-9]{2}:[0-9]{2}", NULL, "T%H:%M:%S", "THH:MM:SS", TIME_RESOLUTION_SECOND}, {"^[0-9]{2}:[0-9]{2}:[0-9]{2}Z", NULL, "%H:%M:%SZ", "HH:MM:SSZ", TIME_RESOLUTION_SECOND}, {"^[0-9]{2}:[0-9]{2}:[0-9]{2}", NULL, "%H:%M:%S", "HH:MM:SS", TIME_RESOLUTION_SECOND} }; #define MS_NUMTIMEFORMATS (int)(sizeof(ms_timeFormats)/sizeof(ms_timeFormats[0])) int *ms_limited_pattern = NULL; int ms_num_limited_pattern; int ms_time_inited = 0; int msTimeSetup() { if(!ms_time_inited) { msAcquireLock(TLOCK_TIME); if(!ms_time_inited) { int i; for(i=0;itm_sec = 0; /* set all members to zero */ time->tm_min = 0; time->tm_hour = 0; time->tm_mday = 0; time->tm_mon = 0; time->tm_year = 0; time->tm_wday = 0; time->tm_yday = 0; time->tm_isdst = 0; return; } static int compareIntVals(int a, int b) { if(ab) return 1; else return 0; } int msDateCompare(struct tm *time1, struct tm *time2) { int result; if((result = compareIntVals(time1->tm_year, time2->tm_year)) != 0) return result; /* not equal based on year */ else if((result = compareIntVals(time1->tm_mon, time2->tm_mon)) != 0) return result; /* not equal based on month */ else if((result = compareIntVals(time1->tm_mday, time2->tm_mday)) != 0) return result; /* not equal based on day of month */ return(0); /* must be equal */ } int msTimeCompare(struct tm *time1, struct tm *time2) { int result; // fprintf(stderr, "in msTimeCompare()...\n"); // fprintf(stderr, "time1: %d %d %d %d %d %d\n", time1->tm_year, time1->tm_mon, time1->tm_mday, time1->tm_hour, time1->tm_min, time1->tm_sec); // fprintf(stderr, "time2: %d %d %d %d %d %d\n", time2->tm_year, time2->tm_mon, time2->tm_mday, time2->tm_hour, time2->tm_min, time2->tm_sec); if((result = compareIntVals(time1->tm_year, time2->tm_year)) != 0) return result; /* not equal based on year */ else if((result = compareIntVals(time1->tm_mon, time2->tm_mon)) != 0) return result; /* not equal based on month */ else if((result = compareIntVals(time1->tm_mday, time2->tm_mday)) != 0) return result; /* not equal based on day of month */ else if((result = compareIntVals(time1->tm_hour, time2->tm_hour)) != 0) return result; /* not equal based on hour */ else if((result = compareIntVals(time1->tm_min, time2->tm_min)) != 0) return result; /* not equal based on minute */ else if((result = compareIntVals(time1->tm_sec, time2->tm_sec)) != 0) return result; /* not equal based on second */ return(0); /* must be equal */ } #if defined(_WIN32) && !defined(__CYGWIN__) #include void msGettimeofday(struct mstimeval* tp, void* tzp) { struct _timeb theTime; _ftime(&theTime); tp->tv_sec = theTime.time; tp->tv_usec = theTime.millitm * 1000; } #endif #if defined(_WIN32) && !defined(__CYGWIN__) /* we need to provide our own prototype on windows. */ char *strptime( const char *buf, const char *format, struct tm *timeptr ); #endif char *msStrptime(const char *s, const char *format, struct tm *tm) { memset(tm, 0, sizeof(struct tm)); return strptime(s, format, tm); } /** return MS_TRUE if the time string matchs the timeformat. else return MS_FALSE. */ int msTimeMatchPattern(const char *timestring, const char *timeformat) { int i =-1; if(msTimeSetup() != MS_SUCCESS) { return MS_FALSE; } /* match the pattern format first and then check if the time string */ /* matchs the pattern. If it is the case retrurn the MS_TRUE */ for (i=0; i= 0 && i < MS_NUMTIMEFORMATS) { int match = ms_regexec(ms_timeFormats[i].regex, timestring, 0, NULL, 0); if(match == 0) return MS_TRUE; } return MS_FALSE; } void msUnsetLimitedPatternToUse() { msTimeSetup(); ms_num_limited_pattern = 0; } void msSetLimitedPatternsToUse(const char *patternstring) { int *limitedpatternindice = NULL; int numpatterns=0, i=0, j=0, ntmp=0; char **patterns = NULL; msTimeSetup(); limitedpatternindice = (int *)msSmallMalloc(sizeof(int)*MS_NUMTIMEFORMATS); /* free previous setting */ msUnsetLimitedPatternToUse(); if (patternstring) { patterns = msStringSplit(patternstring, ',', &ntmp); if (patterns && ntmp >= 1) { for (i=0; i 0) { for (i=0; i 0) num_patterns = ms_num_limited_pattern; else num_patterns = MS_NUMTIMEFORMATS; for(i=0; i 0) indice = ms_limited_pattern[i]; else indice = i; match = ms_regexec(ms_timeFormats[indice].regex, string, 0,NULL, 0); /* test the expression against the string */ if(match == 0) { /* match */ msStrptime(string, ms_timeFormats[indice].format, tm); return(MS_TRUE); } } msSetError(MS_REGEXERR, "Unrecognized date or time format (%s).", "msParseTime()", string); return(MS_FALSE); } /** * Parse the time string and return the reslution */ int msTimeGetResolution(const char *timestring) { int i=0; if (!timestring) return -1; for(i=0; i=2) { /*range */ if (msParseTime(atimeelements[0], &tmtimestart) != MS_TRUE) { msFreeCharArray(atimeelements, numelements); return MS_FALSE; } if (msParseTime(atimeelements[1], &tmtimeend) != MS_TRUE) { msFreeCharArray(atimeelements, numelements); return MS_FALSE; } } msFreeCharArray(atimeelements, numelements); /* Now parse the time extent. Extents can be - one range (2004-09-21/2004-09-25/resolution) - multiple rages 2004-09-21/2004-09-25/res1,2004-09-21/2004-09-25/res2 - one value 2004-09-21 - mutiple values 2004-09-21,2004-09-22,2004-09-23 */ numextents = 0; atimeextents = msStringSplit (timeextent, ',', &numextents); if (numextents <= 0) { msFreeCharArray(atimeextents, numextents); return MS_FALSE; } /*the time timestring should at be valid in one of the extents defined */ for (i=0; i= 0) { msFreeCharArray(atimerange, numranges); msFreeCharArray(atimeextents, numextents); return MS_TRUE; } } /*2004-09-21/2004-09-25/res1*/ else if (numranges >= 2) { if (msParseTime(atimerange[0], &tmstart) == MS_TRUE && msParseTime(atimerange[1], &tmend) == MS_TRUE && msTimeCompare(&tmstart, &tmtimestart) <= 0 && msTimeCompare(&tmend, &tmtimeend) >= 0) { msFreeCharArray(atimerange, numranges); msFreeCharArray(atimeextents, numextents); return MS_TRUE; } } msFreeCharArray(atimerange, numranges); } msFreeCharArray(atimeextents, numextents); return MS_FALSE; } int msValidateTimeValue(const char *timestring, const char *timeextent) { char **atimes = NULL; int i, numtimes=0; /* we need to validate the time passsed in the request */ /* against the time extent defined */ if (!timestring || !timeextent) return MS_FALSE; /* To avoid SQL injections */ if (strchr(timestring, '\'')) return MS_FALSE; /* parse the time string. We support descrete times (eg 2004-09-21), */ /* multiple times (2004-09-21, 2004-09-22, ...) */ /* and range(s) (2004-09-21/2004-09-25, 2004-09-27/2004-09-29) */ if (strstr(timestring, ",") == NULL && strstr(timestring, "/") == NULL) { /* discrete time */ return _msValidateTime(timestring, timeextent); } else { atimes = msStringSplit(timestring, ',', &numtimes); if (numtimes >=1) { /* multiple times */ if (strstr(atimes[0], "/") == NULL) { /* multiple descrete times */ for (i=0; i /* for gettimeofday() */ # define mstimeval timeval # define msGettimeofday(t,u) gettimeofday(t,u) #endif typedef enum { TIME_RESOLUTION_UNDEFINED = -1, TIME_RESOLUTION_MICROSECOND =0, TIME_RESOLUTION_MILLISECOND =1, TIME_RESOLUTION_SECOND =2, TIME_RESOLUTION_MINUTE =3, TIME_RESOLUTION_HOUR =4, TIME_RESOLUTION_DAY =5, TIME_RESOLUTION_MONTH =6, TIME_RESOLUTION_YEAR =7 } MS_TIME_RESOLUTION; /* function prototypes */ void msTimeInit(struct tm *time); int msDateCompare(struct tm *time1, struct tm *time2); int msTimeCompare(struct tm *time1, struct tm *time2); char *msStrptime(const char *s, const char *format, struct tm *tm); int msParseTime(const char *string, struct tm *tm); int msTimeMatchPattern(const char *timestring, const char *pattern); void msSetLimitedPatternsToUse(const char *patternstring); void msUnsetLimitedPatternToUse(void); MS_DLL_EXPORT int msTimeGetResolution(const char *timestring); void msTimeCleanup(); int msValidateTimeValue(const char *timestring, const char *timeextent); #endif /* MAPTIME_H */ mapserver-7.6.4/maptree.c000066400000000000000000000642011407312142500153370ustar00rootroot00000000000000/****************************************************************************** * $Id$ * * Project: MapServer * Purpose: .qix spatial index implementation. Derived from shapelib, and * relicensed with permission of Frank Warmerdam (shapelib author). * Author: Steve Lime * ****************************************************************************** * Copyright (c) 1996-2005 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" #include "maptree.h" /* -------------------------------------------------------------------- */ /* If the following is 0.5, nodes will be split in half. If it */ /* is 0.6 then each subnode will contain 60% of the parent */ /* node, with 20% representing overlap. This can be help to */ /* prevent small objects on a boundary from shifting too high */ /* up the tree. */ /* -------------------------------------------------------------------- */ #define SPLITRATIO 0.55 static int treeAddShapeId(treeObj *tree, int id, rectObj rect); static void SwapWord( int length, void * wordP ) { int i; uchar temp; for( i=0; i < length/2; i++ ) { temp = ((uchar *) wordP)[i]; ((uchar *)wordP)[i] = ((uchar *) wordP)[length-i-1]; ((uchar *) wordP)[length-i-1] = temp; } } static void * SfRealloc( void * pMem, int nNewSize ) { if( pMem == NULL ) return( (void *) malloc(nNewSize) ); else return( (void *) realloc(pMem,nNewSize) ); } static treeNodeObj *treeNodeCreate(rectObj rect) { treeNodeObj *node; node = (treeNodeObj *) msSmallMalloc(sizeof(treeNodeObj)); node->numshapes = 0; node->ids = NULL; node->numsubnodes = 0; memcpy(&(node->rect), &(rect), sizeof(rectObj)); return node; } SHPTreeHandle msSHPDiskTreeOpen(const char * pszTree, int debug) { char *pszFullname, *pszBasename; SHPTreeHandle psTree; char pabyBuf[16]; int i; char bBigEndian; /* -------------------------------------------------------------------- */ /* Establish the byte order on this machine. */ /* -------------------------------------------------------------------- */ i = 1; if( *((uchar *) &i) == 1 ) bBigEndian = MS_FALSE; else bBigEndian = MS_TRUE; /* -------------------------------------------------------------------- */ /* Initialize the info structure. */ /* -------------------------------------------------------------------- */ psTree = (SHPTreeHandle) msSmallMalloc(sizeof(SHPTreeInfo)); /* -------------------------------------------------------------------- */ /* Compute the base (layer) name. If there is any extension */ /* on the passed in filename we will strip it off. */ /* -------------------------------------------------------------------- */ pszBasename = (char *) msSmallMalloc(strlen(pszTree)+5); strcpy( pszBasename, pszTree ); for( i = strlen(pszBasename)-1; i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/' && pszBasename[i] != '\\'; i-- ) {} if( pszBasename[i] == '.' ) pszBasename[i] = '\0'; /* -------------------------------------------------------------------- */ /* Open the .shp and .shx files. Note that files pulled from */ /* a PC to Unix with upper case filenames won't work! */ /* -------------------------------------------------------------------- */ pszFullname = (char *) msSmallMalloc(strlen(pszBasename) + 5); sprintf( pszFullname, "%s%s", pszBasename, MS_INDEX_EXTENSION); psTree->fp = fopen(pszFullname, "rb" ); if( psTree->fp == NULL ) { sprintf( pszFullname, "%s.QIX", pszBasename); psTree->fp = fopen(pszFullname, "rb" ); } msFree(pszBasename); /* don't need these any more */ msFree(pszFullname); if( psTree->fp == NULL ) { msFree(psTree); return( NULL ); } if( fread( pabyBuf, 8, 1, psTree->fp ) != 1 ) { msFree(psTree); return( NULL ); } memcpy( &psTree->signature, pabyBuf, 3 ); if( strncmp(psTree->signature,"SQT",3) ) { /* ---------------------------------------------------------------------- */ /* must check if the 2 first bytes equal 0 of max depth that cannot */ /* be more than 65535. If yes, we must swap all value. The problem */ /* here is if there's no Depth (bytea 5,6,7,8 in the file) all bytes */ /* will be set to 0. So,we will test with the number of shapes (bytes */ /* 1,2,3,4) that cannot be more than 65535 too. */ /* ---------------------------------------------------------------------- */ if (debug) { msDebug("WARNING in msSHPDiskTreeOpen(): %s is in old index format " "which has been deprecated. It is strongly recommended to " "regenerate it in new format.\n", pszTree); } if((pabyBuf[4] == 0 && pabyBuf[5] == 0 && pabyBuf[6] == 0 && pabyBuf[7] == 0)) { psTree->LSB_order = !(pabyBuf[0] == 0 && pabyBuf[1] == 0); } else { psTree->LSB_order = !(pabyBuf[4] == 0 && pabyBuf[5] == 0); } psTree->needswap = ((psTree->LSB_order) != (!bBigEndian)); /* ---------------------------------------------------------------------- */ /* poor hack to see if this quadtree was created by a computer with a */ /* different Endian */ /* ---------------------------------------------------------------------- */ psTree->version = 0; } else { psTree->needswap = (( pabyBuf[3] == MS_NEW_MSB_ORDER ) ^ ( bBigEndian )); psTree->LSB_order = ( pabyBuf[3] == MS_NEW_LSB_ORDER ); memcpy( &psTree->version, pabyBuf+4, 1 ); memcpy( &psTree->flags, pabyBuf+5, 3 ); if( fread( pabyBuf, 8, 1, psTree->fp ) != 1 ) { msFree(psTree); return( NULL ); } } if( psTree->needswap ) SwapWord( 4, pabyBuf ); memcpy( &psTree->nShapes, pabyBuf, 4 ); if( psTree->needswap ) SwapWord( 4, pabyBuf+4 ); memcpy( &psTree->nDepth, pabyBuf+4, 4 ); return( psTree ); } void msSHPDiskTreeClose(SHPTreeHandle disktree) { fclose( disktree->fp ); free( disktree ); } treeObj *msCreateTree(shapefileObj *shapefile, int maxdepth) { int i; treeObj *tree; rectObj bounds; if(!shapefile) return NULL; /* -------------------------------------------------------------------- */ /* Allocate the tree object */ /* -------------------------------------------------------------------- */ tree = (treeObj *) msSmallMalloc(sizeof(treeObj)); tree->numshapes = shapefile->numshapes; tree->maxdepth = maxdepth; /* -------------------------------------------------------------------- */ /* If no max depth was defined, try to select a reasonable one */ /* that implies approximately 8 shapes per node. */ /* -------------------------------------------------------------------- */ if( tree->maxdepth == 0 ) { int numnodes = 1; while(numnodes*4 < shapefile->numshapes) { tree->maxdepth += 1; numnodes = numnodes * 2; } } /* -------------------------------------------------------------------- */ /* Allocate the root node. */ /* -------------------------------------------------------------------- */ tree->root = treeNodeCreate(shapefile->bounds); for(i=0; inumshapes; i++) { if(msSHPReadBounds(shapefile->hSHP, i, &bounds) == MS_SUCCESS) treeAddShapeId(tree, i, bounds); } return tree; } static void destroyTreeNode(treeNodeObj *node) { int i; for(i=0; inumsubnodes; i++ ) { if(node->subnode[i]) destroyTreeNode(node->subnode[i]); } if(node->ids) free(node->ids); free(node); } void msDestroyTree(treeObj *tree) { destroyTreeNode(tree->root); free(tree); } static void treeSplitBounds( rectObj *in, rectObj *out1, rectObj *out2) { double range; /* -------------------------------------------------------------------- */ /* The output bounds will be very similar to the input bounds, */ /* so just copy over to start. */ /* -------------------------------------------------------------------- */ memcpy(out1, in, sizeof(rectObj)); memcpy(out2, in, sizeof(rectObj)); /* -------------------------------------------------------------------- */ /* Split in X direction. */ /* -------------------------------------------------------------------- */ if((in->maxx - in->minx) > (in->maxy - in->miny)) { range = in->maxx - in->minx; out1->maxx = in->minx + range * SPLITRATIO; out2->minx = in->maxx - range * SPLITRATIO; } /* -------------------------------------------------------------------- */ /* Otherwise split in Y direction. */ /* -------------------------------------------------------------------- */ else { range = in->maxy - in->miny; out1->maxy = in->miny + range * SPLITRATIO; out2->miny = in->maxy - range * SPLITRATIO; } } static int treeNodeAddShapeId( treeNodeObj *node, int id, rectObj rect, int maxdepth) { int i; /* -------------------------------------------------------------------- */ /* If there are subnodes, then consider whether this object */ /* will fit in them. */ /* -------------------------------------------------------------------- */ if( maxdepth > 1 && node->numsubnodes > 0 ) { for(i=0; inumsubnodes; i++ ) { if( msRectContained(&rect, &node->subnode[i]->rect)) { return treeNodeAddShapeId( node->subnode[i], id, rect, maxdepth-1); } } } /* -------------------------------------------------------------------- */ /* Otherwise, consider creating four subnodes if could fit into */ /* them, and adding to the appropriate subnode. */ /* -------------------------------------------------------------------- */ #if MAX_SUBNODES == 4 else if( maxdepth > 1 && node->numsubnodes == 0 ) { rectObj half1, half2, quad1, quad2, quad3, quad4; treeSplitBounds(&node->rect, &half1, &half2); treeSplitBounds(&half1, &quad1, &quad2); treeSplitBounds(&half2, &quad3, &quad4); if(msRectContained(&rect, &quad1) || msRectContained(&rect, &quad2) || msRectContained(&rect, &quad3) || msRectContained(&rect, &quad4)) { node->numsubnodes = 4; node->subnode[0] = treeNodeCreate(quad1); node->subnode[1] = treeNodeCreate(quad2); node->subnode[2] = treeNodeCreate(quad3); node->subnode[3] = treeNodeCreate(quad4); /* recurse back on this node now that it has subnodes */ return(treeNodeAddShapeId(node, id, rect, maxdepth)); } } #endif /* -------------------------------------------------------------------- */ /* Otherwise, consider creating two subnodes if could fit into */ /* them, and adding to the appropriate subnode. */ /* -------------------------------------------------------------------- */ #if MAX_SUBNODE == 2 else if( maxdepth > 1 && node->numsubnodes == 0 ) { rectObj half1, half2; treeSplitBounds(&node->rect, &half1, &half2); if( msRectContained(&rect, &half1)) { node->numsubnodes = 2; node->subnode[0] = treeNodeCreate(half1); node->subnode[1] = treeNodeCreate(half2); return(treeNodeAddShapeId(node->subnode[0], id, rect, maxdepth-1)); } else if(msRectContained(&rect, &half2)) { node->numsubnodes = 2; node->subnode[0] = treeNodeCreate(&half1); node->subnode[1] = treeNodeCreate(&half2); return(treeNodeAddShapeId(node->subnode[1], id, rect, maxdepth-1)); } } #endif /* MAX_SUBNODE == 2 */ /* -------------------------------------------------------------------- */ /* If none of that worked, just add it to this nodes list. */ /* -------------------------------------------------------------------- */ node->numshapes++; node->ids = SfRealloc( node->ids, sizeof(ms_int32) * node->numshapes ); node->ids[node->numshapes-1] = id; return MS_TRUE; } static int treeAddShapeId(treeObj *tree, int id, rectObj rect) { return(treeNodeAddShapeId(tree->root, id, rect, tree->maxdepth)); } static void treeCollectShapeIds(treeNodeObj *node, rectObj aoi, ms_bitarray status) { int i; /* -------------------------------------------------------------------- */ /* Does this node overlap the area of interest at all? If not, */ /* return without adding to the list at all. */ /* -------------------------------------------------------------------- */ if(!msRectOverlap(&node->rect, &aoi)) return; /* -------------------------------------------------------------------- */ /* Add the local nodes shapeids to the list. */ /* -------------------------------------------------------------------- */ for(i=0; inumshapes; i++) msSetBit(status, node->ids[i], 1); /* -------------------------------------------------------------------- */ /* Recurse to subnodes if they exist. */ /* -------------------------------------------------------------------- */ for(i=0; inumsubnodes; i++) { if(node->subnode[i]) treeCollectShapeIds(node->subnode[i], aoi, status); } } ms_bitarray msSearchTree(const treeObj *tree, rectObj aoi) { ms_bitarray status=NULL; status = msAllocBitArray(tree->numshapes); if(!status) { msSetError(MS_MEMERR, NULL, "msSearchTree()"); return(NULL); } treeCollectShapeIds(tree->root, aoi, status); return(status); } static int treeNodeTrim( treeNodeObj *node ) { int i; /* -------------------------------------------------------------------- */ /* Trim subtrees, and free subnodes that come back empty. */ /* -------------------------------------------------------------------- */ for(i=0; inumsubnodes; i++ ) { if(treeNodeTrim(node->subnode[i])) { destroyTreeNode(node->subnode[i]); node->subnode[i] = node->subnode[node->numsubnodes-1]; node->numsubnodes--; i--; /* process the new occupant of this subnode entry */ } } /* -------------------------------------------------------------------- */ /* If the current node has 1 subnode and no shapes, promote that */ /* subnode to the current node position. */ /* -------------------------------------------------------------------- */ if( node->numsubnodes == 1 && node->numshapes == 0) { treeNodeObj* psSubNode = node->subnode[0]; memcpy(&node->rect, &psSubNode->rect, sizeof(psSubNode->rect)); node->numshapes = psSubNode->numshapes; assert(node->ids == NULL); node->ids = psSubNode->ids; node->numsubnodes = psSubNode->numsubnodes; for( i = 0; i < psSubNode->numsubnodes; i++ ) node->subnode[i] = psSubNode->subnode[i]; free(psSubNode); } /* -------------------------------------------------------------------- */ /* We should be trimmed if we have no subnodes, and no shapes. */ /* -------------------------------------------------------------------- */ return(node->numsubnodes == 0 && node->numshapes == 0); } void msTreeTrim(treeObj *tree) { treeNodeTrim(tree->root); } static void searchDiskTreeNode(SHPTreeHandle disktree, rectObj aoi, ms_bitarray status) { int i; ms_int32 offset; ms_int32 numshapes, numsubnodes; rectObj rect; int *ids=NULL; if( fread( &offset, 4, 1, disktree->fp ) != 1 ) goto error; if ( disktree->needswap ) SwapWord ( 4, &offset ); if( fread( &rect, sizeof(rectObj), 1, disktree->fp ) != 1 ) goto error; if ( disktree->needswap ) SwapWord ( 8, &rect.minx ); if ( disktree->needswap ) SwapWord ( 8, &rect.miny ); if ( disktree->needswap ) SwapWord ( 8, &rect.maxx ); if ( disktree->needswap ) SwapWord ( 8, &rect.maxy ); if( fread( &numshapes, 4, 1, disktree->fp ) != 1 ) goto error; if ( disktree->needswap ) SwapWord ( 4, &numshapes ); if(!msRectOverlap(&rect, &aoi)) { /* skip rest of this node and sub-nodes */ offset += numshapes*sizeof(ms_int32) + sizeof(ms_int32); fseek(disktree->fp, offset, SEEK_CUR); return; } if(numshapes > 0) { ids = (int *)msSmallMalloc(numshapes*sizeof(ms_int32)); if( fread( ids, numshapes*sizeof(ms_int32), 1, disktree->fp ) != 1 ) goto error; if (disktree->needswap ) { for( i=0; ifp ) != 1 ) goto error; if ( disktree->needswap ) SwapWord ( 4, &numsubnodes ); for(i=0; inShapes != numshapes) { msSetError(MS_SHPERR, "The spatial index file %s is corrupt.", "msSearchDiskTree()", filename); msSHPDiskTreeClose(disktree); return(NULL); } status = msAllocBitArray(disktree->nShapes); if(!status) { msSetError(MS_MEMERR, NULL, "msSearchDiskTree()"); msSHPDiskTreeClose( disktree ); return(NULL); } searchDiskTreeNode(disktree, aoi, status); msSHPDiskTreeClose( disktree ); return(status); } treeNodeObj *readTreeNode( SHPTreeHandle disktree ) { int i,res; ms_int32 offset; treeNodeObj *node; node = (treeNodeObj *) msSmallMalloc(sizeof(treeNodeObj)); node->ids = NULL; res = fread( &offset, 4, 1, disktree->fp ); if ( !res ) { free(node); return NULL; } if ( disktree->needswap ) SwapWord ( 4, &offset ); res = fread( &node->rect, sizeof(rectObj), 1, disktree->fp ); if ( !res ) { free(node); return NULL; } if ( disktree->needswap ) SwapWord ( 8, &node->rect.minx ); if ( disktree->needswap ) SwapWord ( 8, &node->rect.miny ); if ( disktree->needswap ) SwapWord ( 8, &node->rect.maxx ); if ( disktree->needswap ) SwapWord ( 8, &node->rect.maxy ); res = fread( &node->numshapes, 4, 1, disktree->fp ); if ( !res ) { free(node); return NULL; } if ( disktree->needswap ) SwapWord ( 4, &node->numshapes ); if( node->numshapes > 0 ) node->ids = (ms_int32 *)msSmallMalloc(sizeof(ms_int32)*node->numshapes); res = fread( node->ids, node->numshapes*4, 1, disktree->fp ); if ( !res ) { free(node->ids); free(node); return NULL; } for( i=0; i < node->numshapes; i++ ) { if ( disktree->needswap ) SwapWord ( 4, &node->ids[i] ); } res = fread( &node->numsubnodes, 4, 1, disktree->fp ); if ( !res ) { free(node->ids); free(node); return NULL; } if ( disktree->needswap ) SwapWord ( 4, &node->numsubnodes ); return node; } treeObj *msReadTree(char *filename, int debug) { treeObj *tree=NULL; SHPTreeHandle disktree; disktree = msSHPDiskTreeOpen( filename, debug ); if(!disktree) { msSetError(MS_IOERR, NULL, "msReadTree()"); return(NULL); } tree = (treeObj *) malloc(sizeof(treeObj)); MS_CHECK_ALLOC(tree, sizeof(treeObj), NULL); tree->numshapes = disktree->nShapes; tree->maxdepth = disktree->nDepth; tree->root = readTreeNode( disktree ); return(tree); } static ms_int32 getSubNodeOffset(treeNodeObj *node) { int i; ms_int32 offset=0; for(i=0; inumsubnodes; i++ ) { if(node->subnode[i]) { offset += sizeof(rectObj) + (node->subnode[i]->numshapes+3)*sizeof(int); offset += getSubNodeOffset(node->subnode[i]); } } /* offset is the disk offset in the index file on disk */ /* that format is (per node) */ /* int offset 4 bytes */ /* rectObj rect 4 * 8 bytes */ /* int numShapes 4 bytes */ /* int ids[numShapes] 4 * numShapes bytes */ /* int numSubNodes 4 bytes */ /* */ return(offset); } static void writeTreeNode(SHPTreeHandle disktree, treeNodeObj *node) { int i,j; ms_int32 offset; char *pabyRec = NULL; offset = getSubNodeOffset(node); pabyRec = msSmallMalloc(sizeof(rectObj) + (3 * sizeof(ms_int32)) + (node->numshapes * sizeof(ms_int32)) ); memcpy( pabyRec, &offset, 4); if( disktree->needswap ) SwapWord( 4, pabyRec ); memcpy( pabyRec+4, &node->rect, sizeof(rectObj)); for (i=0; i < 4; i++) if( disktree->needswap ) SwapWord( 8, pabyRec+4+(8*i) ); memcpy( pabyRec+36, &node->numshapes, 4); if( disktree->needswap ) SwapWord( 4, pabyRec+36 ); j = node->numshapes*sizeof(ms_int32); memcpy( pabyRec+40, node->ids, j); for (i=0; inumshapes; i++) if( disktree->needswap ) SwapWord( 4, pabyRec+40+(4*i)); memcpy( pabyRec+j+40, &node->numsubnodes, 4); if( disktree->needswap ) SwapWord( 4, pabyRec+40+j ); fwrite( pabyRec, 44+j, 1, disktree->fp); free (pabyRec); for(i=0; inumsubnodes; i++ ) { if(node->subnode[i]) writeTreeNode(disktree, node->subnode[i]); } return; } int msWriteTree(treeObj *tree, char *filename, int B_order) { char signature[3] = "SQT"; char version = 1; char reserved[3] = {0,0,0}; SHPTreeHandle disktree; int i; char mtBigEndian; char pabyBuf[32]; char *pszBasename, *pszFullname; disktree = (SHPTreeHandle) malloc(sizeof(SHPTreeInfo)); MS_CHECK_ALLOC(disktree, sizeof(SHPTreeInfo), MS_FALSE); /* -------------------------------------------------------------------- */ /* Compute the base (layer) name. If there is any extension */ /* on the passed in filename we will strip it off. */ /* -------------------------------------------------------------------- */ pszBasename = (char *) msSmallMalloc(strlen(filename)+5); strcpy( pszBasename, filename ); for( i = strlen(pszBasename)-1; i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/' && pszBasename[i] != '\\'; i-- ) {} if( pszBasename[i] == '.' ) pszBasename[i] = '\0'; /* -------------------------------------------------------------------- */ /* Open the .shp and .shx files. Note that files pulled from */ /* a PC to Unix with upper case filenames won't work! */ /* -------------------------------------------------------------------- */ pszFullname = (char *) msSmallMalloc(strlen(pszBasename) + 5); sprintf( pszFullname, "%s%s", pszBasename, MS_INDEX_EXTENSION); disktree->fp = fopen(pszFullname, "wb"); msFree(pszBasename); /* not needed */ msFree(pszFullname); if(!disktree->fp) { msFree(disktree); msSetError(MS_IOERR, NULL, "msWriteTree()"); return(MS_FALSE); } /* for efficiency, trim the tree */ msTreeTrim(tree); /* -------------------------------------------------------------------- */ /* Establish the byte order on this machine. */ /* -------------------------------------------------------------------- */ i = 1; if( *((uchar *) &i) == 1 ) mtBigEndian = MS_FALSE; else mtBigEndian = MS_TRUE; if( !(mtBigEndian ^ ( B_order == MS_LSB_ORDER || B_order == MS_NEW_LSB_ORDER )) ) disktree->needswap = 1; else disktree->needswap = 0; if( B_order == MS_NATIVE_ORDER ) disktree->needswap = 0; /* write the header */ if ( B_order > 0 ) { memcpy( pabyBuf, &signature, 3 ); memcpy (&disktree->signature, &signature, 3); pabyBuf[3] = B_order; memcpy( pabyBuf+4, &version, 1); memcpy( pabyBuf+5, &reserved, 3); memcpy( &disktree->version, &version, 1); memcpy( &disktree->flags, &reserved, 3); fwrite( pabyBuf, 8, 1, disktree->fp ); } memcpy( pabyBuf, &tree->numshapes, 4 ); if( disktree->needswap ) SwapWord( 4, pabyBuf ); memcpy( pabyBuf+4, &tree->maxdepth, 4 ); if( disktree->needswap ) SwapWord( 4, pabyBuf+4 ); i = fwrite( pabyBuf, 8, 1, disktree->fp ); if( !i ) { fprintf (stderr, "unable to write to index file ... exiting \n"); msSHPDiskTreeClose( disktree ); return (MS_FALSE); } writeTreeNode(disktree, tree->root); msSHPDiskTreeClose( disktree ); return(MS_TRUE); } /* Function to filter search results further against feature bboxes */ void msFilterTreeSearch(shapefileObj *shp, ms_bitarray status, rectObj search_rect) { int i; rectObj shape_rect; i = msGetNextBit(status, 0, shp->numshapes); while(i >= 0) { if(msSHPReadBounds(shp->hSHP, i, &shape_rect) == MS_SUCCESS) { if(msRectOverlap(&shape_rect, &search_rect) != MS_TRUE) { msSetBit(status, i, 0); } } i = msGetNextBit(status, i+1, shp->numshapes); } } mapserver-7.6.4/maptree.h000066400000000000000000000064021407312142500153430ustar00rootroot00000000000000/****************************************************************************** * $Id$ * * Project: MapServer * Purpose: .qix spatial index declarations. * Author: Steve Lime and the MapServer team. * ****************************************************************************** * Copyright (c) 1996-2005 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. ****************************************************************************/ #ifndef MAPTREE_H #define MAPTREE_H #ifdef __cplusplus extern "C" { #endif /* this can be 2 or 4 for binary or quad tree */ #define MAX_SUBNODES 4 typedef struct shape_tree_node { /* area covered by this node */ rectObj rect; /* list of shapes stored at this node. */ ms_int32 numshapes; ms_int32 *ids; int numsubnodes; struct shape_tree_node *subnode[MAX_SUBNODES]; } treeNodeObj; typedef struct { ms_int32 numshapes; ms_int32 maxdepth; treeNodeObj *root; } treeObj; typedef struct { FILE *fp; char signature[3]; char LSB_order; char needswap; char version; char flags[3]; ms_int32 nShapes; ms_int32 nDepth; } SHPTreeInfo; typedef SHPTreeInfo * SHPTreeHandle; #define MS_LSB_ORDER -1 #define MS_MSB_ORDER -2 #define MS_NATIVE_ORDER 0 #define MS_NEW_LSB_ORDER 1 #define MS_NEW_MSB_ORDER 2 MS_DLL_EXPORT SHPTreeHandle msSHPDiskTreeOpen(const char * pszTree, int debug); MS_DLL_EXPORT void msSHPDiskTreeClose(SHPTreeHandle disktree); MS_DLL_EXPORT treeNodeObj *readTreeNode( SHPTreeHandle disktree ); MS_DLL_EXPORT treeObj *msCreateTree(shapefileObj *shapefile, int maxdepth); MS_DLL_EXPORT void msTreeTrim(treeObj *tree); MS_DLL_EXPORT void msDestroyTree(treeObj *tree); MS_DLL_EXPORT ms_bitarray msSearchTree(const treeObj *tree, rectObj aoi); MS_DLL_EXPORT ms_bitarray msSearchDiskTree(const char *filename, rectObj aoi, int debug, int numshapes); MS_DLL_EXPORT treeObj *msReadTree(char *filename, int debug); MS_DLL_EXPORT int msWriteTree(treeObj *tree, char *filename, int LSB_order); MS_DLL_EXPORT void msFilterTreeSearch(shapefileObj *shp, ms_bitarray status, rectObj search_rect); #ifdef __cplusplus } #endif #endif /* MAPTREE_H */ mapserver-7.6.4/mapunion.c000066400000000000000000000605061407312142500155340ustar00rootroot00000000000000/****************************************************************************** * $Id$ * * Project: MapServer * Purpose: Implementation of the union layer data provider (RFC-68). * Author: Tamas Szekeres (szekerest@gmail.com). * ****************************************************************************** * Copyright (c) 1996-2005 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. ****************************************************************************/ #define _CRT_SECURE_NO_WARNINGS 1 /* $Id$ */ #include #include "mapserver.h" #define MSUNION_NUMITEMS 3 #define MSUNION_SOURCELAYERNAME "Union_SourceLayerName" #define MSUNION_SOURCELAYERNAMEINDEX -100 #define MSUNION_SOURCELAYERGROUP "Union_SourceLayerGroup" #define MSUNION_SOURCELAYERGROUPINDEX -101 #define MSUNION_SOURCELAYERVISIBLE "Union_SourceLayerVisible" #define MSUNION_SOURCELAYERVISIBLEINDEX -102 typedef struct { int layerIndex; /* current source layer index */ int classIndex; /* current class index */ char* classText; /* current class text (autostyle) */ int layerCount; /* number of the source layers */ layerObj* layers; /* structure to the source layers */ int *status; /* the layer status */ int *classgroup; /* current array of the valid classes */ int nclasses; /* number of the valid classes */ reprojectionObj* reprojectorSrcLayerToLayer; int reprojectorCurSrcLayer; } msUnionLayerInfo; /* Close the the combined layer */ int msUnionLayerClose(layerObj *layer) { int i; msUnionLayerInfo* layerinfo = (msUnionLayerInfo*)layer->layerinfo; if (!layerinfo) return MS_SUCCESS; if (!layer->map) return MS_FAILURE; msProjectDestroyReprojector(layerinfo->reprojectorSrcLayerToLayer); for (i = 0; i < layerinfo->layerCount; i++) { msLayerClose(&layerinfo->layers[i]); freeLayer(&layerinfo->layers[i]); } msFree(layerinfo->layers); msFree(layerinfo->status); msFree(layerinfo->classgroup); msFree(layerinfo->classText); msFree(layerinfo); layer->layerinfo = NULL; return MS_SUCCESS; } int isScaleInRange(mapObj* map, layerObj *layer) { if(map->scaledenom > 0) { int i; /* layer scale boundaries should be checked first */ if((layer->maxscaledenom > 0) && (map->scaledenom > layer->maxscaledenom)) return MS_FALSE; if((layer->minscaledenom > 0) && (map->scaledenom <= layer->minscaledenom)) return MS_FALSE; /* now check class scale boundaries (all layers *must* pass these tests) */ if(layer->numclasses > 0) { for(i=0; inumclasses; i++) { if((layer->class[i]->maxscaledenom > 0) && (map->scaledenom > layer->class[i]->maxscaledenom)) continue; /* can skip this one, next class */ if((layer->class[i]->minscaledenom > 0) && (map->scaledenom <= layer->class[i]->minscaledenom)) continue; /* can skip this one, next class */ break; /* can't skip this class (or layer for that matter) */ } if(i == layer->numclasses) return MS_FALSE; } if (layer->maxscaledenom <= 0 && layer->minscaledenom <= 0) { if((layer->maxgeowidth > 0) && ((map->extent.maxx - map->extent.minx) > layer->maxgeowidth)) return MS_FALSE; if((layer->mingeowidth > 0) && ((map->extent.maxx - map->extent.minx) < layer->mingeowidth)) return MS_FALSE; } } return MS_TRUE; } int msUnionLayerOpen(layerObj *layer) { msUnionLayerInfo *layerinfo; char **layerNames; mapObj* map; int i; int layerCount; const char* pkey; int status_check; int scale_check; if (layer->layerinfo != NULL) { return MS_SUCCESS; /* Nothing to do... layer is already opened */ } if (!layer->connection) { msSetError(MS_MISCERR, "The CONNECTION option is not specified for layer: %s", "msUnionLayerOpen()", layer->name); return MS_FAILURE; } if (!layer->map) { msSetError(MS_MISCERR, "No map assigned to this layer: %s", "msUnionLayerOpen()", layer->name); return MS_FAILURE; } map = layer->map; layerinfo =(msUnionLayerInfo*)calloc(1, sizeof(msUnionLayerInfo)); MS_CHECK_ALLOC(layerinfo, sizeof(msUnionLayerInfo), MS_FAILURE); layer->layerinfo = layerinfo; layerinfo->layerIndex = 0; layerinfo->classgroup = NULL; layerinfo->nclasses = 0; layerinfo->layerCount = 0; layerinfo->classText = NULL; layerinfo->reprojectorCurSrcLayer = -1; pkey = msLayerGetProcessingKey(layer, "UNION_STATUS_CHECK"); if(pkey && strcasecmp(pkey, "true") == 0) status_check = MS_TRUE; else status_check = MS_FALSE; pkey = msLayerGetProcessingKey(layer, "UNION_SCALE_CHECK"); if(pkey && strcasecmp(pkey, "false") == 0) scale_check = MS_FALSE; else scale_check = MS_TRUE; pkey = msLayerGetProcessingKey(layer, "UNION_SRCLAYER_CLOSE_CONNECTION"); layerNames = msStringSplit(layer->connection, ',', &layerCount); if (layerCount == 0) { msSetError(MS_MISCERR, "No source layers specified in layer: %s", "msUnionLayerOpen()", layer->name); if(layerNames) msFreeCharArray(layerNames, layerinfo->layerCount); msUnionLayerClose(layer); return MS_FAILURE; } layerinfo->layers =(layerObj*)malloc(layerCount * sizeof(layerObj)); MS_CHECK_ALLOC(layerinfo->layers, layerCount * sizeof(layerObj), MS_FAILURE); layerinfo->status =(int*)malloc(layerCount * sizeof(int)); MS_CHECK_ALLOC(layerinfo->status, layerCount * sizeof(int), MS_FAILURE); for(i=0; i < layerCount; i++) { int layerindex = msGetLayerIndex(map, layerNames[i]); if (layerindex >= 0 && layerindex < map->numlayers) { layerObj* srclayer = map->layers[layerindex]; if (srclayer->type != layer->type) { msSetError(MS_MISCERR, "The type of the source layer doesn't match with the union layer: %s", "msUnionLayerOpen()", srclayer->name); if(layerNames) msFreeCharArray(layerNames, layerinfo->layerCount); msUnionLayerClose(layer); return MS_FAILURE; } /* we need to create a new layer in order make the singlepass query to work */ if(initLayer(&layerinfo->layers[i], map) == -1) { msSetError(MS_MISCERR, "Cannot initialize source layer: %s", "msUnionLayerOpen()", srclayer->name); if(layerNames) msFreeCharArray(layerNames, layerinfo->layerCount); msUnionLayerClose(layer); return MS_FAILURE; } ++layerinfo->layerCount; if (msCopyLayer(&layerinfo->layers[i], srclayer) != MS_SUCCESS) { msSetError(MS_MISCERR, "Cannot copy source layer: %s", "msUnionLayerOpen()", srclayer->name); if(layerNames) msFreeCharArray(layerNames, layerinfo->layerCount); msUnionLayerClose(layer); return MS_FAILURE; } if (pkey) { /* override connection flag */ msLayerSetProcessingKey(&layerinfo->layers[i], "CLOSE_CONNECTION", pkey); } /* check is we should skip this source (status check) */ if (status_check && layerinfo->layers[i].status == MS_OFF) { layerinfo->status[i] = MS_DONE; continue; } /* check is we should skip this source (scale check) */ if (scale_check && isScaleInRange(map, &layerinfo->layers[i]) == MS_FALSE) { layerinfo->status[i] = MS_DONE; continue; } layerinfo->status[i] = msLayerOpen(&layerinfo->layers[i]); if (layerinfo->status[i] != MS_SUCCESS) { if(layerNames) msFreeCharArray(layerNames, layerinfo->layerCount); msUnionLayerClose(layer); return MS_FAILURE; } } else { msSetError(MS_MISCERR, "Invalid layer: %s", "msUnionLayerOpen()", layerNames[i]); if(layerNames) msFreeCharArray(layerNames, layerinfo->layerCount); msUnionLayerClose(layer); return MS_FAILURE; } } if(layerNames) msFreeCharArray(layerNames, layerinfo->layerCount); return MS_SUCCESS; } /* Return MS_TRUE if layer is open, MS_FALSE otherwise. */ int msUnionLayerIsOpen(layerObj *layer) { if (layer->layerinfo) return(MS_TRUE); else return(MS_FALSE); } /* Free the itemindexes array in a layer. */ void msUnionLayerFreeItemInfo(layerObj *layer) { int i; msUnionLayerInfo* layerinfo = (msUnionLayerInfo*)layer->layerinfo; if (!layerinfo || !layer->map) return; msFree(layer->iteminfo); layer->iteminfo = NULL; for (i = 0; i < layerinfo->layerCount; i++) { msLayerFreeItemInfo(&layerinfo->layers[i]); if(layerinfo->layers[i].items) { /* need to remove the source layer items */ msFreeCharArray(layerinfo->layers[i].items, layerinfo->layers[i].numitems); layerinfo->layers[i].items = NULL; layerinfo->layers[i].numitems = 0; } } } /* clean up expression tokens */ void msUnionLayerFreeExpressionTokens(layerObj *layer) { int i,j; msFreeExpressionTokens(&(layer->filter)); msFreeExpressionTokens(&(layer->cluster.group)); msFreeExpressionTokens(&(layer->cluster.filter)); for(i=0; inumclasses; i++) { msFreeExpressionTokens(&(layer->class[i]->expression)); msFreeExpressionTokens(&(layer->class[i]->text)); for(j=0; jclass[i]->numstyles; j++) msFreeExpressionTokens(&(layer->class[i]->styles[j]->_geomtransform)); } } /* allocate the iteminfo index array - same order as the item list */ int msUnionLayerInitItemInfo(layerObj *layer) { int i, numitems; int *itemindexes; char* itemlist = NULL; msUnionLayerInfo* layerinfo = (msUnionLayerInfo*)layer->layerinfo; if(layer->numitems == 0) { return MS_SUCCESS; } if (!layerinfo || !layer->map) return MS_FAILURE; /* Cleanup any previous item selection */ msUnionLayerFreeItemInfo(layer); layer->iteminfo = (int *) malloc(sizeof(int) * layer->numitems); MS_CHECK_ALLOC(layer->iteminfo, sizeof(int) * layer->numitems, MS_FAILURE); itemindexes = (int*)layer->iteminfo; /* check whether we require attributes from the source layers also */ numitems = 0; for (i = 0; i < layer->numitems; i++) { if (EQUAL(layer->items[i], MSUNION_SOURCELAYERNAME)) itemindexes[i] = MSUNION_SOURCELAYERNAMEINDEX; else if (EQUAL(layer->items[i], MSUNION_SOURCELAYERGROUP)) itemindexes[i] = MSUNION_SOURCELAYERGROUPINDEX; else if (EQUAL(layer->items[i], MSUNION_SOURCELAYERVISIBLE)) itemindexes[i] = MSUNION_SOURCELAYERVISIBLEINDEX; else { itemindexes[i] = numitems++; if (itemlist) { itemlist = msStringConcatenate(itemlist, ","); itemlist = msStringConcatenate(itemlist, layer->items[i]); } else { itemlist = msStrdup(layer->items[i]); } } } for (i = 0; i < layerinfo->layerCount; i++) { layerObj* srclayer = &layerinfo->layers[i]; if (layerinfo->status[i] != MS_SUCCESS) continue; /* skip empty layers */ msUnionLayerFreeExpressionTokens(srclayer); if (itemlist) { /* get items requested by the union layer plus the required items */ msLayerSetProcessingKey(srclayer, "ITEMS", itemlist); if (msLayerWhichItems(srclayer, MS_TRUE, NULL) != MS_SUCCESS) { msFree(itemlist); return MS_FAILURE; } } else { /* get only the required items */ if (msLayerWhichItems(srclayer, MS_FALSE, NULL) != MS_SUCCESS) return MS_FAILURE; } } msFree(itemlist); return MS_SUCCESS; } int msUnionLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) { int i; layerObj* srclayer; rectObj srcRect; msUnionLayerInfo* layerinfo = (msUnionLayerInfo*)layer->layerinfo; if (!layerinfo || !layer->map) return MS_FAILURE; for (i = 0; i < layerinfo->layerCount; i++) { layerObj* srclayer = &layerinfo->layers[i]; if (layerinfo->status[i] != MS_SUCCESS) continue; /* skip empty layers */ if (layer->styleitem && layer->numitems == 0) { /* need to initialize items */ msUnionLayerFreeExpressionTokens(srclayer); /* get only the required items */ if (msLayerWhichItems(srclayer, MS_FALSE, NULL) != MS_SUCCESS) return MS_FAILURE; } srcRect = rect; if(srclayer->transform == MS_TRUE && srclayer->project && layer->transform == MS_TRUE && layer->project &&msProjectionsDiffer(&(srclayer->projection), &(layer->projection))) msProjectRect(&layer->projection, &srclayer->projection, &srcRect); /* project the searchrect to source coords */ layerinfo->status[i] = msLayerWhichShapes(srclayer, srcRect, isQuery); if (layerinfo->status[i] == MS_FAILURE) return MS_FAILURE; } layerinfo->layerIndex = 0; srclayer = &layerinfo->layers[0]; msFree(layerinfo->classgroup); layerinfo->classgroup = NULL; layerinfo->nclasses = 0; if (srclayer->classgroup && srclayer->numclasses > 0) layerinfo->classgroup = msAllocateValidClassGroups(srclayer, &layerinfo->nclasses); return MS_SUCCESS; } static int BuildFeatureAttributes(layerObj *layer, layerObj* srclayer, shapeObj *shape) { int i; char **values; int* itemindexes = layer->iteminfo; values = malloc(sizeof(char*) * (layer->numitems)); MS_CHECK_ALLOC(values, layer->numitems * sizeof(char*), MS_FAILURE);; for (i = 0; i < layer->numitems; i++) { if (itemindexes[i] == MSUNION_SOURCELAYERNAMEINDEX) values[i] = msStrdup(srclayer->name); else if (itemindexes[i] == MSUNION_SOURCELAYERGROUPINDEX) values[i] = msStrdup(srclayer->group); else if (itemindexes[i] == MSUNION_SOURCELAYERVISIBLEINDEX) { if (srclayer->status == MS_OFF) values[i] = msStrdup("0"); else values[i] = msStrdup("1"); } else if (shape->values[itemindexes[i]]) values[i] = msStrdup(shape->values[itemindexes[i]]); else values[i] = msStrdup(""); } if (shape->values) msFreeCharArray(shape->values, shape->numvalues); shape->values = values; shape->numvalues = layer->numitems; return MS_SUCCESS; } /* find the next shape with the appropriate shape type */ /* also, load in the attribute data */ /* MS_DONE => no more data */ int msUnionLayerNextShape(layerObj *layer, shapeObj *shape) { int rv; layerObj* srclayer; msUnionLayerInfo* layerinfo = (msUnionLayerInfo*)layer->layerinfo; if (!layerinfo || !layer->map) return MS_FAILURE; if (layerinfo->layerIndex < 0 || layerinfo->layerIndex >= layerinfo->layerCount) return MS_FAILURE; rv = MS_DONE; while (layerinfo->layerIndex < layerinfo->layerCount) { srclayer = &layerinfo->layers[layerinfo->layerIndex]; if (layerinfo->status[layerinfo->layerIndex] == MS_SUCCESS) { while ((rv = srclayer->vtable->LayerNextShape(srclayer, shape)) == MS_SUCCESS) { if(layer->styleitem) { /* need to retrieve the source layer classindex if styleitem AUTO is set */ layerinfo->classIndex = msShapeGetClass(srclayer, layer->map, shape, layerinfo->classgroup, layerinfo->nclasses); if(layerinfo->classIndex < 0 || layerinfo->classIndex >= srclayer->numclasses) { /* this shape is not visible, skip it */ msFreeShape(shape); if (rv == MS_SUCCESS) continue; else break; } if(srclayer->styleitem && strcasecmp(srclayer->styleitem, "AUTO") != 0) { /* Generic feature style handling as per RFC-61 */ msLayerGetFeatureStyle(layer->map, srclayer, srclayer->class[layerinfo->classIndex], shape); } /* set up annotation */ msFree(layerinfo->classText); layerinfo->classText = NULL; if(srclayer->class[layerinfo->classIndex]->numlabels > 0) { /* pull text from the first label only */ if(msGetLabelStatus(layer->map,layer,shape,srclayer->class[layerinfo->classIndex]->labels[0]) == MS_ON) { layerinfo->classText = msShapeGetLabelAnnotation(layer,shape,srclayer->class[layerinfo->classIndex]->labels[0]); } } } /* reproject to the target layer */ if( layerinfo->reprojectorCurSrcLayer != layerinfo->layerIndex ) { msProjectDestroyReprojector(layerinfo->reprojectorSrcLayerToLayer); layerinfo->reprojectorSrcLayerToLayer = NULL; layerinfo->reprojectorCurSrcLayer = layerinfo->layerIndex; if(srclayer->project && msProjectionsDiffer(&(srclayer->projection), &(layer->projection))) layerinfo->reprojectorSrcLayerToLayer = msProjectCreateReprojector(&(srclayer->projection), &(layer->projection)); else srclayer->project = MS_FALSE; } if(layerinfo->reprojectorSrcLayerToLayer) msProjectShapeEx(layerinfo->reprojectorSrcLayerToLayer, shape); /* update the layer styles with the bound values */ if(msBindLayerToShape(srclayer, shape, MS_FALSE) != MS_SUCCESS) return MS_FAILURE; shape->tileindex = layerinfo->layerIndex; /* construct the item array */ if (layer->iteminfo) rv = BuildFeatureAttributes(layer, srclayer, shape); /* check the layer filter condition */ if(layer->filter.string != NULL && layer->numitems > 0 && layer->iteminfo) { if (layer->filter.type == MS_EXPRESSION && layer->filter.tokens == NULL) msTokenizeExpression(&(layer->filter), layer->items, &(layer->numitems)); if (!msEvalExpression(layer, shape, &(layer->filter), layer->filteritemindex)) { /* this shape is filtered */ msFreeShape(shape); continue; } } return rv; } } ++layerinfo->layerIndex; if (layerinfo->layerIndex == layerinfo->layerCount) { layerinfo->layerIndex = 0; return MS_DONE; } /* allocate the classgroups for the next layer */ msFree(layerinfo->classgroup); layerinfo->classgroup = NULL; layerinfo->nclasses = 0; if (srclayer->classgroup && srclayer->numclasses > 0) layerinfo->classgroup = msAllocateValidClassGroups(srclayer, &layerinfo->nclasses); } return rv; } /* Random access of the feature. */ int msUnionLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) { int rv; layerObj* srclayer; long tile = record->tileindex; msUnionLayerInfo* layerinfo = (msUnionLayerInfo*)layer->layerinfo; if (!layerinfo || !layer->map) return MS_FAILURE; if (tile < 0 || tile >= layerinfo->layerCount) { msSetError(MS_MISCERR, "Invalid tile index: %s", "msUnionLayerGetShape()", layer->name); return MS_FAILURE; } srclayer = &layerinfo->layers[tile]; record->tileindex = 0; rv = srclayer->vtable->LayerGetShape(srclayer, shape, record); record->tileindex = tile; if (rv == MS_SUCCESS) { /* reproject to the target layer */ if( layerinfo->reprojectorCurSrcLayer != tile ) { msProjectDestroyReprojector(layerinfo->reprojectorSrcLayerToLayer); layerinfo->reprojectorSrcLayerToLayer = NULL; layerinfo->reprojectorCurSrcLayer = tile; if(srclayer->project && msProjectionsDiffer(&(srclayer->projection), &(layer->projection))) layerinfo->reprojectorSrcLayerToLayer = msProjectCreateReprojector(&(srclayer->projection), &(layer->projection)); else srclayer->project = MS_FALSE; } if(layerinfo->reprojectorSrcLayerToLayer) msProjectShapeEx(layerinfo->reprojectorSrcLayerToLayer, shape); shape->tileindex = tile; /* construct the item array */ if (layer->iteminfo) rv = BuildFeatureAttributes(layer, srclayer, shape); } return rv; } /* Query for the items collection */ int msUnionLayerGetItems(layerObj *layer) { /* we support certain built in attributes */ layer->numitems = 2; layer->items = malloc(sizeof(char*) * (layer->numitems)); MS_CHECK_ALLOC(layer->items, layer->numitems * sizeof(char*), MS_FAILURE); layer->items[0] = msStrdup(MSUNION_SOURCELAYERNAME); layer->items[1] = msStrdup(MSUNION_SOURCELAYERGROUP); return msUnionLayerInitItemInfo(layer); } int msUnionLayerGetNumFeatures(layerObj *layer) { int i, c, numFeatures; msUnionLayerInfo* layerinfo = (msUnionLayerInfo*)layer->layerinfo; if (!layerinfo || !layer->map) return 0; numFeatures = 0; for (i = 0; i < layerinfo->layerCount; i++) { if (layerinfo->status[i] != MS_SUCCESS) continue; /* skip empty layers */ c = msLayerGetNumFeatures(&layerinfo->layers[i]); if (c > 0) numFeatures += c; } return numFeatures; } static int msUnionLayerGetAutoStyle(mapObj *map, layerObj *layer, classObj *c, shapeObj* shape) { layerObj* srclayer; msUnionLayerInfo* layerinfo = (msUnionLayerInfo*)layer->layerinfo; if (!layerinfo || !layer->map) return MS_FAILURE; if (shape->tileindex < 0 || shape->tileindex >= layerinfo->layerCount) { msSetError(MS_MISCERR, "Invalid tile index: %s", "msUnionLayerGetAutoStyle()", layer->name); return MS_FAILURE; } srclayer = &layerinfo->layers[shape->tileindex]; if(srclayer->styleitem && strcasecmp(srclayer->styleitem, "AUTO") == 0) { int rv; int tileindex = shape->tileindex; shape->tileindex = 0; rv = msLayerGetAutoStyle(map, srclayer, c, shape); shape->tileindex = tileindex; return rv; } else { int i,j; classObj* src = srclayer->class[layerinfo->classIndex]; /* copy the style from the current class index */ /* free any previous styles on the dst layer */ resetClassStyle(c); for (i = 0; i < src->numstyles; i++) { if (msMaybeAllocateClassStyle(c, i)) return MS_FAILURE; if (msCopyStyle(c->styles[i], src->styles[i]) != MS_SUCCESS) { msSetError(MS_MEMERR, "Failed to copy style.", "msUnionLayerGetAutoStyle()"); return MS_FAILURE; } /* remove the bindings on the style */ for(j=0; jstyles[i]->bindings[j].item); c->styles[i]->bindings[j].item = NULL; } c->styles[i]->numbindings = 0; } for (i = 0; i < src->numlabels; i++) { // RFC77 TODO: allocation need to be done, but is the right way (from mapcopy.c)? if (msGrowClassLabels(c) == NULL) return MS_FAILURE; initLabel(c->labels[i]); if (msCopyLabel(c->labels[i], src->labels[i]) != MS_SUCCESS) { msSetError(MS_MEMERR, "Failed to copy label.", "msUnionLayerGetAutoStyle()"); return MS_FAILURE; } /* remove the bindings on the label */ for(j=0; jlabels[i]->bindings[j].item); c->labels[i]->bindings[j].item = NULL; } c->labels[i]->numbindings = 0; } c->numlabels = src->numlabels; c->layer = layer; c->text.string = layerinfo->classText; layerinfo->classText = NULL; } return MS_SUCCESS; } int msUnionLayerCopyVirtualTable(layerVTableObj* vtable) { vtable->LayerInitItemInfo = msUnionLayerInitItemInfo; vtable->LayerFreeItemInfo = msUnionLayerFreeItemInfo; vtable->LayerOpen = msUnionLayerOpen; vtable->LayerIsOpen = msUnionLayerIsOpen; vtable->LayerWhichShapes = msUnionLayerWhichShapes; vtable->LayerNextShape = msUnionLayerNextShape; vtable->LayerGetShape = msUnionLayerGetShape; /* layer->vtable->LayerGetShapeCount, use default */ vtable->LayerClose = msUnionLayerClose; vtable->LayerGetItems = msUnionLayerGetItems; vtable->LayerCloseConnection = msUnionLayerClose; vtable->LayerGetAutoStyle = msUnionLayerGetAutoStyle; vtable->LayerGetNumFeatures = msUnionLayerGetNumFeatures; return MS_SUCCESS; } int msUnionLayerInitializeVirtualTable(layerObj *layer) { assert(layer != NULL); assert(layer->vtable != NULL); return msUnionLayerCopyVirtualTable(layer->vtable); } mapserver-7.6.4/maputfgrid.cpp000066400000000000000000000540241407312142500164060ustar00rootroot00000000000000/****************************************************************************** * $Id$ * * Project: MapServer * Purpose: UTFGrid rendering functions (using AGG) * Author: Francois Desjarlais * ****************************************************************************** * Copyright (c) 1996-2007 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" #include "maputfgrid.h" #include "mapagg.h" #include "renderers/agg/include/agg_rasterizer_scanline_aa.h" #include "renderers/agg/include/agg_basics.h" #include "renderers/agg/include/agg_renderer_scanline.h" #include "renderers/agg/include/agg_scanline_bin.h" #include "renderers/agg/include/agg_gamma_functions.h" #include "renderers/agg/include/agg_conv_stroke.h" #include "renderers/agg/include/agg_ellipse.h" typedef mapserver::int32u band_type; typedef mapserver::row_ptr_cache rendering_buffer; typedef pixfmt_utf pixfmt_utf32; typedef mapserver::renderer_base renderer_base; typedef mapserver::rasterizer_scanline_aa<> rasterizer_scanline; typedef mapserver::renderer_scanline_bin_solid renderer_scanline; static utfpix32 UTF_WATER = utfpix32(32); #define utfitem(c) utfpix32(c) struct shapeData { char *datavalues; char *itemvalue; band_type utfvalue; int serialid; }; class lookupTable { public: lookupTable() { table = (shapeData*) msSmallMalloc(sizeof(shapeData)); table->datavalues = NULL; table->itemvalue = NULL; table->utfvalue = 0; table->serialid = 0; size = 1; counter = 0; } ~lookupTable() { int i; for(i=0; ipoint; *x = m_point->x/utfresolution; *y = m_point->y/utfresolution; m_point++; return first ? mapserver::path_cmd_move_to : mapserver::path_cmd_line_to; } *x = *y = 0.0; if(!m_stop) { m_line++; if(m_line>=m_lend) { m_stop=true; return mapserver::path_cmd_end_poly; } m_point=m_line->point; m_pend=&(m_line->point[m_line->numpoints]); return mapserver::path_cmd_end_poly; } return mapserver::path_cmd_stop; } private: int utfresolution; }; /* * UTFGrid specific line adaptor. */ class line_adaptor_utf:public line_adaptor { public: line_adaptor_utf(shapeObj *shape,int utfres_in):line_adaptor(shape) { utfresolution = utfres_in; } virtual unsigned vertex(double* x, double* y) { if(m_point < m_pend) { bool first = m_point == m_line->point; *x = m_point->x/utfresolution; *y = m_point->y/utfresolution; m_point++; return first ? mapserver::path_cmd_move_to : mapserver::path_cmd_line_to; } m_line++; *x = *y = 0.0; if(m_line>=m_lend) return mapserver::path_cmd_stop; m_point=m_line->point; m_pend=&(m_line->point[m_line->numpoints]); return vertex(x,y); } private: int utfresolution; }; class UTFGridRenderer { public: UTFGridRenderer() { stroke = NULL; } ~UTFGridRenderer() { if(stroke) delete stroke; delete data; } lookupTable *data; int utfresolution; int layerwatch; int renderlayer; int useutfitem; int useutfdata; int duplicates; band_type utfvalue; layerObj *utflayer; band_type *buffer; rendering_buffer m_rendering_buffer; pixfmt_utf32 m_pixel_format; renderer_base m_renderer_base; rasterizer_scanline m_rasterizer; renderer_scanline m_renderer_scanline; mapserver::scanline_bin sl_utf; mapserver::conv_stroke *stroke; }; #define UTFGRID_RENDERER(image) ((UTFGridRenderer*) (image)->img.plugin) /* * Encode to avoid unavailable char in the JSON */ unsigned int encodeForRendering(unsigned int toencode) { unsigned int encoded; encoded = toencode + 32; /* 34 => " */ if(encoded >= 34) { encoded = encoded +1; } /* 92 => \ */ if (encoded >= 92) { encoded = encoded +1; } return encoded; } /* * Decode value to have the initial one */ unsigned int decodeRendered(unsigned int todecode) { unsigned int decoded; if(todecode >= 92) todecode --; if(todecode >= 34) todecode --; decoded = todecode-32; return decoded; } /* * Allocate more memory to the table if necessary. */ int growTable(lookupTable *data) { int i; data->table = (shapeData*) msSmallRealloc(data->table,sizeof(*data->table)*data->size*2); data->size = data->size*2; for(i=data->counter; isize; i++) { data->table[i].datavalues = NULL; data->table[i].itemvalue = NULL; data->table[i].utfvalue = 0; data->table[i].serialid = 0; } return MS_SUCCESS; } /* * Add the shapeObj UTFDATA and UTFITEM to the lookup table. */ band_type addToTable(UTFGridRenderer *r, shapeObj *p) { band_type utfvalue; /* Looks for duplicates. */ if(r->duplicates==0 && r->useutfitem==1) { int i; for(i=0; idata->counter; i++) { if(!strcmp(p->values[r->utflayer->utfitemindex],r->data->table[i].itemvalue)) { /* Found a copy of the values in the table. */ utfvalue = r->data->table[i].utfvalue; return utfvalue; } } } /* Grow size of table if necessary */ if(r->data->size == r->data->counter) growTable(r->data); utfvalue = (r->data->counter+1); /* Simple operation so we don't have unavailable char in the JSON */ utfvalue = encodeForRendering(utfvalue); /* Data added to the table */ r->data->table[r->data->counter].datavalues = msEvalTextExpressionJSonEscape(&r->utflayer->utfdata, p); /* If UTFITEM is set in the mapfile we add its value to the table */ if(r->useutfitem) r->data->table[r->data->counter].itemvalue = msStrdup(p->values[r->utflayer->utfitemindex]); r->data->table[r->data->counter].serialid = r->data->counter+1; r->data->table[r->data->counter].utfvalue = utfvalue; r->data->counter++; return utfvalue; } /* * Use AGG to render any path. */ template int utfgridRenderPath(imageObj *img, vertex_source &path) { UTFGridRenderer *r = UTFGRID_RENDERER(img); r->m_rasterizer.reset(); r->m_rasterizer.filling_rule(mapserver::fill_even_odd); r->m_rasterizer.add_path(path); r->m_renderer_scanline.color(utfitem(r->utfvalue)); mapserver::render_scanlines(r->m_rasterizer, r->sl_utf, r->m_renderer_scanline); return MS_SUCCESS; } /* * Initialize the renderer, create buffer, allocate memory. */ imageObj *utfgridCreateImage(int width, int height, outputFormatObj *format, colorObj * bg) { UTFGridRenderer *r; r = new UTFGridRenderer; r->data = new lookupTable; r->utfresolution = atof(msGetOutputFormatOption(format, "UTFRESOLUTION", "4")); if(r->utfresolution < 1) { msSetError(MS_MISCERR, "UTFRESOLUTION smaller that 1 in the mapfile.", "utfgridCreateImage()"); return NULL; } r->layerwatch = 0; r->renderlayer = 0; r->useutfitem = 0; r->useutfdata = 0; r->duplicates = EQUAL("true", msGetOutputFormatOption(format, "DUPLICATES", "true")); r->utfvalue = 0; r->buffer = (band_type*)msSmallMalloc(width/r->utfresolution * height/r->utfresolution * sizeof(band_type)); /* AGG specific operations */ r->m_rendering_buffer.attach(r->buffer, width/r->utfresolution, height/r->utfresolution, width/r->utfresolution); r->m_pixel_format.attach(r->m_rendering_buffer); r->m_renderer_base.attach(r->m_pixel_format); r->m_renderer_scanline.attach(r->m_renderer_base); r->m_renderer_base.clear(UTF_WATER); r->m_rasterizer.gamma(mapserver::gamma_none()); r->utflayer = NULL; imageObj *image = NULL; image = (imageObj *) msSmallCalloc(1,sizeof(imageObj)); image->img.plugin = (void*) r; return image; } /* * Free all the memory used by the renderer. */ int utfgridFreeImage(imageObj *img) { UTFGridRenderer *r = UTFGRID_RENDERER(img); msFree(r->buffer); delete r; img->img.plugin = NULL; return MS_SUCCESS; } /* * Update a character in the utfgrid. */ int utfgridUpdateChar(imageObj *img, band_type oldChar, band_type newChar) { UTFGridRenderer *r = UTFGRID_RENDERER(img); int i,bufferLength; bufferLength = (img->height/r->utfresolution) * (img->width/r->utfresolution); for(i=0;ibuffer[i] == oldChar) r->buffer[i] = newChar; } return MS_SUCCESS; } /* * Remove unnecessary data that didn't made it to the final grid. */ int utfgridCleanData(imageObj *img) { UTFGridRenderer *r = UTFGRID_RENDERER(img); unsigned char* usedChar; int i,bufferLength,itemFound,dataCounter; shapeData* updatedData; band_type utfvalue; bufferLength = (img->height/r->utfresolution) * (img->width/r->utfresolution); usedChar =(unsigned char*) msSmallMalloc(r->data->counter*sizeof(unsigned char)); for(i=0;idata->counter;i++){ usedChar[i]=0; } itemFound=0; for(i=0;ibuffer[i]) != 0 && usedChar[decodeRendered(r->buffer[i])-1]==0) { itemFound++; usedChar[decodeRendered(r->buffer[i])-1] = 1; } } updatedData = (shapeData*) msSmallMalloc(itemFound * sizeof(shapeData)); dataCounter = 0; for(i=0; i< r->data->counter; i++){ if(usedChar[decodeRendered(r->data->table[i].utfvalue)-1]==1){ updatedData[dataCounter] = r->data->table[i]; updatedData[dataCounter].serialid=dataCounter+1; utfvalue=encodeForRendering(dataCounter+1); utfgridUpdateChar(img,updatedData[dataCounter].utfvalue,utfvalue); updatedData[dataCounter].utfvalue = utfvalue; dataCounter++; } else { if(r->data->table[i].datavalues) msFree(r->data->table[i].datavalues); if(r->data->table[i].itemvalue) msFree(r->data->table[i].itemvalue); } } msFree(usedChar); msFree(r->data->table); r->data->table = updatedData; r->data->counter = dataCounter; r->data->size = dataCounter; return MS_SUCCESS; } /* * Print the renderer data as JSON. */ int utfgridSaveImage(imageObj *img, mapObj *map, FILE *fp, outputFormatObj *format) { int row, col, i, imgheight, imgwidth; band_type pixelid; char* pszEscaped; utfgridCleanData(img); UTFGridRenderer *renderer = UTFGRID_RENDERER(img); if(renderer->layerwatch>1) return MS_FAILURE; imgheight = img->height/renderer->utfresolution; imgwidth = img->width/renderer->utfresolution; msIO_fprintf(fp,"{\"grid\":["); /* Print the buffer */ for(row=0; rowwidth/renderer->utfresolution; col++) { /* Get the data from buffer. */ pixelid = renderer->buffer[(row*imgwidth)+col]; *stringptr = pixelid; stringptr++; } /* Conversion to UTF-8 encoding */ *stringptr = '\0'; char * utf8; #if defined(_WIN32) && !defined(__CYGWIN__) const char* encoding = "UCS-2LE"; #else const char* encoding = "UCS-4LE"; #endif utf8 = msConvertWideStringToUTF8(string, encoding); msIO_fprintf(fp,"%s", utf8); msFree(utf8); msFree(string); msIO_fprintf(fp,"\""); } msIO_fprintf(fp,"],\"keys\":[\"\""); /* Print the specified key */ for(i=0;idata->counter;i++) { msIO_fprintf(fp,","); if(renderer->useutfitem) { pszEscaped = msEscapeJSonString(renderer->data->table[i].itemvalue); msIO_fprintf(fp,"\"%s\"", pszEscaped); msFree(pszEscaped); } /* If no UTFITEM specified use the serial ID as the key */ else msIO_fprintf(fp,"\"%i\"", renderer->data->table[i].serialid); } msIO_fprintf(fp,"],\"data\":{"); /* Print the data */ if(renderer->useutfdata) { for(i=0;idata->counter;i++) { if(i!=0) msIO_fprintf(fp,","); if(renderer->useutfitem) { pszEscaped = msEscapeJSonString(renderer->data->table[i].itemvalue); msIO_fprintf(fp,"\"%s\":", pszEscaped); msFree(pszEscaped); } /* If no UTFITEM specified use the serial ID as the key */ else msIO_fprintf(fp,"\"%i\":", renderer->data->table[i].serialid); msIO_fprintf(fp,"%s", renderer->data->table[i].datavalues); } } msIO_fprintf(fp,"}}"); return MS_SUCCESS; } /* * Starts a layer for UTFGrid renderer. */ int utfgridStartLayer(imageObj *img, mapObj *map, layerObj *layer) { UTFGridRenderer *r = UTFGRID_RENDERER(img); /* Look if the layer uses the UTFGrid output format */ if(layer->utfdata.string!=0) { r->useutfdata = 1; } /* layerwatch is set to 1 on first layer treated. Doesn't allow multiple layers. */ if(!r->layerwatch) { r->layerwatch++; r->renderlayer = 1; r->utflayer = layer; layer->refcount++; /* Verify if renderer needs to use UTFITEM */ if(r->utflayer->utfitem) r->useutfitem = 1; } /* If multiple layers, send error */ else { r->layerwatch++; msSetError(MS_MISCERR, "MapServer does not support multiple UTFGrid layers rendering simultaneously.", "utfgridStartLayer()"); return MS_FAILURE; } return MS_SUCCESS; } /* * Tell renderer the layer is done. */ int utfgridEndLayer(imageObj *img, mapObj *map, layerObj *layer) { UTFGridRenderer *r = UTFGRID_RENDERER(img); /* Look if the layer was rendered, if it was then turn off rendering. */ if(r->renderlayer) { r->utflayer = NULL; layer->refcount--; r->renderlayer = 0; } return MS_SUCCESS; } /* * Do the table operations on the shapes. Allow multiple types of data to be rendered. */ int utfgridStartShape(imageObj *img, shapeObj *shape) { UTFGridRenderer *r = UTFGRID_RENDERER(img); if(!r->renderlayer) return MS_FAILURE; /* Table operations */ r->utfvalue = addToTable(r, shape); return MS_SUCCESS; } /* * Tells the renderer that the shape's rendering is done. */ int utfgridEndShape(imageObj *img, shapeObj *shape) { UTFGridRenderer *r = UTFGRID_RENDERER(img); r->utfvalue = 0; return MS_SUCCESS; } /* * Function that renders polygons into UTFGrid. */ int utfgridRenderPolygon(imageObj *img, shapeObj *polygonshape, colorObj *color) { UTFGridRenderer *r = UTFGRID_RENDERER(img); /* utfvalue is set to 0 if the shape isn't in the table. */ if(r->utfvalue == 0) { return MS_FAILURE; } /* Render the polygon */ polygon_adaptor_utf polygons(polygonshape, r->utfresolution); utfgridRenderPath(img, polygons); return MS_SUCCESS; } /* * Function that renders lines into UTFGrid. Starts by looking if the line is a polygon * outline, draw it if it's not. */ int utfgridRenderLine(imageObj *img, shapeObj *lineshape, strokeStyleObj *linestyle) { UTFGridRenderer *r = UTFGRID_RENDERER(img); /* utfvalue is set to 0 if the shape isn't in the table. */ if(r->utfvalue == 0) { return MS_SUCCESS; /* If we dont get a caracter to draw we just skip execution * instead of failing */ } /* Render the line */ line_adaptor_utf lines(lineshape, r->utfresolution); if(!r->stroke) { r->stroke = new mapserver::conv_stroke(lines); } else { r->stroke->attach(lines); } r->stroke->width(linestyle->width/r->utfresolution); utfgridRenderPath(img, *r->stroke); return MS_SUCCESS; } /* * Function that render vector type symbols into UTFGrid. */ int utfgridRenderVectorSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj * style) { UTFGridRenderer *r = UTFGRID_RENDERER(img); double ox = symbol->sizex * 0.5; double oy = symbol->sizey * 0.5; /* utfvalue is set to 0 if the shape isn't in the table. */ if(r->utfvalue == 0) { return MS_FAILURE; } /* Pathing the symbol */ mapserver::path_storage path = imageVectorSymbol(symbol); /* Transformation to the right size/scale. */ mapserver::trans_affine mtx; mtx *= mapserver::trans_affine_translation(-ox,-oy); mtx *= mapserver::trans_affine_scaling(style->scale/r->utfresolution); mtx *= mapserver::trans_affine_rotation(-style->rotation); mtx *= mapserver::trans_affine_translation(x/r->utfresolution, y/r->utfresolution); path.transform(mtx); /* Rendering the symbol. */ utfgridRenderPath(img, path); return MS_SUCCESS; } /* * Function that renders Pixmap type symbols into UTFGrid. */ int utfgridRenderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj * style) { UTFGridRenderer *r = UTFGRID_RENDERER(img); rasterBufferObj *pixmap = symbol->pixmap_buffer; /* utfvalue is set to 0 if the shape isn't in the table. */ if(r->utfvalue == 0) { return MS_FAILURE; } /* Pathing the symbol BBox */ mapserver::path_storage pixmap_bbox; double w, h; w = pixmap->width*style->scale/(2.0); h= pixmap->height*style->scale/(2.0); pixmap_bbox.move_to((x-w)/r->utfresolution,(y-h)/r->utfresolution); pixmap_bbox.line_to((x+w)/r->utfresolution,(y-h)/r->utfresolution); pixmap_bbox.line_to((x+w)/r->utfresolution,(y+h)/r->utfresolution); pixmap_bbox.line_to((x-w)/r->utfresolution,(y+h)/r->utfresolution); /* Rendering the symbol */ utfgridRenderPath(img, pixmap_bbox); return MS_SUCCESS; } /* * Function that render ellipse type symbols into UTFGrid. */ int utfgridRenderEllipseSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj * style) { UTFGridRenderer *r = UTFGRID_RENDERER(img); /* utfvalue is set to 0 if the shape isn't in the table. */ if(r->utfvalue == 0) { return MS_FAILURE; } /* Pathing the symbol. */ mapserver::path_storage path; mapserver::ellipse ellipse(x/r->utfresolution,y/r->utfresolution,symbol->sizex*style->scale/2/r->utfresolution,symbol->sizey*style->scale/2/r->utfresolution); path.concat_path(ellipse); /* Rotation if necessary. */ if( style->rotation != 0) { mapserver::trans_affine mtx; mtx *= mapserver::trans_affine_translation(-x/r->utfresolution,-y/r->utfresolution); mtx *= mapserver::trans_affine_rotation(-style->rotation); mtx *= mapserver::trans_affine_translation(x/r->utfresolution,y/r->utfresolution); path.transform(mtx); } /* Rendering the symbol. */ utfgridRenderPath(img, path); return MS_SUCCESS; } int utfgridRenderGlyphs(imageObj *img, textPathObj *tp, colorObj *c, colorObj *oc, int ow, int isMarker) { UTFGridRenderer *r = UTFGRID_RENDERER(img); /* If it's not a marker then it's a label or other thing and we dont * want to draw it on the map */ if(!isMarker) { return MS_SUCCESS; //Stop the rendering with no errors } /* utfvalue is set to 0 if the shape isn't in the table. */ if(r->utfvalue == 0) { return MS_SUCCESS; //Stop the rendering with no errors } /* Pathing the symbol BBox */ mapserver::path_storage box; double size, x, y; size = tp->glyph_size;; x = tp->glyphs->pnt.x; y = tp->glyphs->pnt.y; box.move_to((x)/r->utfresolution,(y)/r->utfresolution); box.line_to((x+size)/r->utfresolution,(y)/r->utfresolution); box.line_to((x+size)/r->utfresolution,(y-size)/r->utfresolution); box.line_to((x)/r->utfresolution,(y-size)/r->utfresolution); /* Rotation if necessary. */ if( tp->glyphs->rot != 0) { mapserver::trans_affine mtx; mtx *= mapserver::trans_affine_translation(-x/r->utfresolution,-y/r->utfresolution); mtx *= mapserver::trans_affine_rotation(-tp->glyphs->rot); mtx *= mapserver::trans_affine_translation(x/r->utfresolution,y/r->utfresolution); box.transform(mtx); } /* Rendering the symbol */ utfgridRenderPath(img, box); return MS_SUCCESS; } int utfgridFreeSymbol(symbolObj * symbol) { return MS_SUCCESS; } /* * Add the necessary functions for UTFGrid to the renderer VTable. */ int msPopulateRendererVTableUTFGrid( rendererVTableObj *renderer ) { renderer->default_transform_mode = MS_TRANSFORM_SIMPLIFY; renderer->createImage = &utfgridCreateImage; renderer->freeImage = &utfgridFreeImage; renderer->saveImage = &utfgridSaveImage; renderer->startLayer = &utfgridStartLayer; renderer->endLayer = &utfgridEndLayer; renderer->startShape = &utfgridStartShape; renderer->endShape = &utfgridEndShape; renderer->renderPolygon = &utfgridRenderPolygon; renderer->renderGlyphs = &utfgridRenderGlyphs; renderer->renderLine = &utfgridRenderLine; renderer->renderVectorSymbol = &utfgridRenderVectorSymbol; renderer->renderPixmapSymbol = &utfgridRenderPixmapSymbol; renderer->renderEllipseSymbol = &utfgridRenderEllipseSymbol; renderer->freeSymbol = &utfgridFreeSymbol; renderer->loadImageFromFile = msLoadMSRasterBufferFromFile; return MS_SUCCESS; } mapserver-7.6.4/maputfgrid.h000066400000000000000000000166551407312142500160630ustar00rootroot00000000000000/****************************************************************************** * $Id$ * * Project: MapServer * Purpose: UTFGrid rendering functions (using AGG) * Author: Francois Desjarlais * ****************************************************************************** * Copyright (c) 1996-2007 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 "renderers/agg/include/agg_renderer_base.h" #include "renderers/agg/include/agg_rendering_buffer.h" /* * Using AGG templates to create UTFGrid pixel. */ //==================================================================utfpix32 struct utfpix32 { typedef mapserver::int32u value_type; typedef mapserver::int64u calc_type; typedef mapserver::int64 long_type; typedef utfpix32 self_type; value_type v; //-------------------------------------------------------------------- utfpix32() {} //-------------------------------------------------------------------- utfpix32(unsigned v_) : v(mapserver::int32u(v_)) {} //-------------------------------------------------------------------- utfpix32(const self_type& c) : v(c.v) {} //-------------------------------------------------------------------- void clear() { v = 0; } //-------------------------------------------------------------------- AGG_INLINE void add(const self_type& c, unsigned cover) { *this = c; } }; //=================================================pixfmt_utf template class pixfmt_utf { public: typedef RenBuf rbuf_type; typedef typename rbuf_type::row_data row_data; typedef ColorT color_type; typedef typename color_type::value_type value_type; typedef typename color_type::calc_type calc_type; enum base_scale_e { pix_width = sizeof(value_type), pix_step = Step, pix_offset = Offset }; private: //-------------------------------------------------------------------- static AGG_INLINE void copy_or_blend_pix(value_type* p, const color_type& c, unsigned cover) { *p = c.v; } static AGG_INLINE void copy_or_blend_pix(value_type* p, const color_type& c) { *p = c.v; } public: pixfmt_utf() : m_rbuf(0) {} //-------------------------------------------------------------------- explicit pixfmt_utf(rbuf_type& rb) : m_rbuf(&rb) {} void attach(rbuf_type& rb) { m_rbuf = &rb; } //-------------------------------------------------------------------- template bool attach(PixFmt& pixf, int x1, int y1, int x2, int y2) { mapserver::rect_i r(x1, y1, x2, y2); if(r.clip(mapserver::rect_i(0, 0, pixf.width()-1, pixf.height()-1))) { int stride = pixf.stride(); m_rbuf->attach(pixf.pix_ptr(r.x1, stride < 0 ? r.y2 : r.y1), (r.x2 - r.x1) + 1, (r.y2 - r.y1) + 1, stride); return true; } return false; } //-------------------------------------------------------------------- AGG_INLINE unsigned width() const { return m_rbuf->width(); } AGG_INLINE unsigned height() const { return m_rbuf->height(); } AGG_INLINE int stride() const { return m_rbuf->stride(); } //-------------------------------------------------------------------- mapserver::int8u* row_ptr(int y) { return m_rbuf->row_ptr(y); } const mapserver::int8u* row_ptr(int y) const { return m_rbuf->row_ptr(y); } row_data row(int y) const { return m_rbuf->row(y); } const mapserver::int8u* pix_ptr(int x, int y) const { return m_rbuf->row_ptr(y) + x * Step + Offset+1213; } mapserver::int8u* pix_ptr(int x, int y) { return m_rbuf->row_ptr(y) + x * Step + Offset +1213; } //-------------------------------------------------------------------- AGG_INLINE static void make_pix(mapserver::int8u* p, const color_type& c) { *(value_type*)p = c.v; } //-------------------------------------------------------------------- AGG_INLINE color_type pixel(int x, int y) const { value_type* p = (value_type*)m_rbuf->row_ptr(y) + x * Step + Offset; return color_type(*p); } //-------------------------------------------------------------------- AGG_INLINE void copy_pixel(int x, int y, const color_type& c) { *((value_type*)m_rbuf->row_ptr(x, y, 1) + x * Step + Offset) = c.v; } //-------------------------------------------------------------------- AGG_INLINE void blend_pixel(int x, int y, const color_type& c, mapserver::int8u cover) { copy_or_blend_pix((value_type*) m_rbuf->row_ptr(x, y, 1) + x * Step + Offset, c); } //-------------------------------------------------------------------- AGG_INLINE void copy_hline(int x, int y, unsigned len, const color_type& c) { value_type* p = (value_type*) m_rbuf->row_ptr(x, y, len) + x * Step + Offset; do { *p = c.v; p += Step; } while(--len); } //-------------------------------------------------------------------- AGG_INLINE void copy_vline(int x, int y, unsigned len, const color_type& c) { do { value_type* p = (value_type*) m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; *p = c.v; } while(--len); } //-------------------------------------------------------------------- void blend_hline(int x, int y, unsigned len, const color_type& c, mapserver::int8u cover) { value_type* p = (value_type*) m_rbuf->row_ptr(x, y, len) + x * Step + Offset; do { *p = c.v; p += Step; } while(--len); } //-------------------------------------------------------------------- void blend_vline(int x, int y, unsigned len, const color_type& c, mapserver::int8u cover) { do { value_type* p = (value_type*) m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset; *p = c.v; } while(--len); } private: rbuf_type* m_rbuf; }; mapserver-7.6.4/maputil.c000066400000000000000000002703131407312142500153600ustar00rootroot00000000000000/****************************************************************************** * $Id$ * * Project: MapServer * Purpose: Various utility functions ... a real hodgepodge. * Author: Steve Lime and the MapServer team. * * Notes: Some code (notably msAlphaBlend()) are directly derived from GD. See * the mapserver/GD-COPYING file for the GD license. Use of this code in this * manner is compatible with the MapServer license. * ****************************************************************************** * Copyright (c) 1996-2005 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 #include "mapserver.h" #include "maptime.h" #include "mapthread.h" #include "mapcopy.h" #include "mapows.h" #include "gdal.h" #if defined(_WIN32) && !defined(__CYGWIN__) # include # include # include # include #include #endif #ifdef USE_RSVG #include #endif #ifdef USE_GEOS #include #endif extern char *msyystring_buffer; extern int msyylex_destroy(void); extern int yyparse(parseObj *); int msScaleInBounds(double scale, double minscale, double maxscale) { if(scale > 0) { if(maxscale != -1 && scale >= maxscale) return MS_FALSE; if(minscale != -1 && scale < minscale) return MS_FALSE; } return MS_TRUE; } /* ** Helper functions to convert from strings to other types or objects. */ static int bindIntegerAttribute(int *attribute, const char *value) { if(!value || strlen(value) == 0) return MS_FAILURE; *attribute = MS_NINT(atof(value)); /*use atof instead of atoi as a fix for bug 2394*/ return MS_SUCCESS; } static int bindDoubleAttribute(double *attribute, const char *value) { if(!value || strlen(value) == 0) return MS_FAILURE; *attribute = atof(value); return MS_SUCCESS; } static int bindColorAttribute(colorObj *attribute, const char *value) { int len; if(!value || ((len = strlen(value)) == 0)) return MS_FAILURE; if(value[0] == '#' && (len == 7 || len == 9)) { /* got a hex color */ char hex[2]; hex[0] = value[1]; hex[1] = value[2]; attribute->red = msHexToInt(hex); hex[0] = value[3]; hex[1] = value[4]; attribute->green = msHexToInt(hex); hex[0] = value[5]; hex[1] = value[6]; attribute->blue = msHexToInt(hex); if(len == 9) { hex[0] = value[7]; hex[1] = value[8]; attribute->alpha = msHexToInt(hex); } return MS_SUCCESS; } else { /* try a space delimited string */ char **tokens=NULL; int numtokens=0; tokens = msStringSplit(value, ' ', &numtokens); if(tokens==NULL || numtokens != 3) { msFreeCharArray(tokens, numtokens); return MS_FAILURE; /* punt */ } attribute->red = atoi(tokens[0]); attribute->green = atoi(tokens[1]); attribute->blue = atoi(tokens[2]); msFreeCharArray(tokens, numtokens); return MS_SUCCESS; } return MS_FAILURE; /* shouldn't get here */ } static void bindStyle(layerObj *layer, shapeObj *shape, styleObj *style, int drawmode) { int applyOpacity = MS_FALSE; assert(MS_DRAW_FEATURES(drawmode)); if(style->numbindings > 0) { applyOpacity = MS_TRUE; if(style->bindings[MS_STYLE_BINDING_SYMBOL].index != -1) { style->symbol = msGetSymbolIndex(&(layer->map->symbolset), shape->values[style->bindings[MS_STYLE_BINDING_SYMBOL].index], MS_TRUE); if(style->symbol == -1) style->symbol = 0; /* a reasonable default (perhaps should throw an error?) */ } if(style->bindings[MS_STYLE_BINDING_ANGLE].index != -1) { style->angle = 360.0; bindDoubleAttribute(&style->angle, shape->values[style->bindings[MS_STYLE_BINDING_ANGLE].index]); } if(style->bindings[MS_STYLE_BINDING_SIZE].index != -1) { style->size = 1; bindDoubleAttribute(&style->size, shape->values[style->bindings[MS_STYLE_BINDING_SIZE].index]); } if(style->bindings[MS_STYLE_BINDING_WIDTH].index != -1) { style->width = 1; bindDoubleAttribute(&style->width, shape->values[style->bindings[MS_STYLE_BINDING_WIDTH].index]); } if(style->bindings[MS_STYLE_BINDING_COLOR].index != -1 && !MS_DRAW_QUERY(drawmode)) { MS_INIT_COLOR(style->color, -1,-1,-1,255); bindColorAttribute(&style->color, shape->values[style->bindings[MS_STYLE_BINDING_COLOR].index]); } if(style->bindings[MS_STYLE_BINDING_OUTLINECOLOR].index != -1 && !MS_DRAW_QUERY(drawmode)) { MS_INIT_COLOR(style->outlinecolor, -1,-1,-1,255); bindColorAttribute(&style->outlinecolor, shape->values[style->bindings[MS_STYLE_BINDING_OUTLINECOLOR].index]); } if(style->bindings[MS_STYLE_BINDING_OUTLINEWIDTH].index != -1) { style->outlinewidth = 1; bindDoubleAttribute(&style->outlinewidth, shape->values[style->bindings[MS_STYLE_BINDING_OUTLINEWIDTH].index]); } if(style->bindings[MS_STYLE_BINDING_OPACITY].index != -1) { style->opacity = 100; bindIntegerAttribute(&style->opacity, shape->values[style->bindings[MS_STYLE_BINDING_OPACITY].index]); } if(style->bindings[MS_STYLE_BINDING_OFFSET_X].index != -1) { style->offsetx = 0; bindDoubleAttribute(&style->offsetx, shape->values[style->bindings[MS_STYLE_BINDING_OFFSET_X].index]); } if(style->bindings[MS_STYLE_BINDING_OFFSET_Y].index != -1) { style->offsety = 0; bindDoubleAttribute(&style->offsety, shape->values[style->bindings[MS_STYLE_BINDING_OFFSET_Y].index]); } if(style->bindings[MS_STYLE_BINDING_POLAROFFSET_PIXEL].index != -1) { style->polaroffsetpixel = 0; bindDoubleAttribute(&style->polaroffsetpixel, shape->values[style->bindings[MS_STYLE_BINDING_POLAROFFSET_PIXEL].index]); } if(style->bindings[MS_STYLE_BINDING_POLAROFFSET_ANGLE].index != -1) { style->polaroffsetangle = 0; bindDoubleAttribute(&style->polaroffsetangle, shape->values[style->bindings[MS_STYLE_BINDING_POLAROFFSET_ANGLE].index]); } } if (style->nexprbindings > 0) { applyOpacity = MS_TRUE; if (style->exprBindings[MS_STYLE_BINDING_OFFSET_X].type == MS_EXPRESSION) { style->offsetx = msEvalDoubleExpression( &(style->exprBindings[MS_STYLE_BINDING_OFFSET_X]), shape); } if (style->exprBindings[MS_STYLE_BINDING_OFFSET_Y].type == MS_EXPRESSION) { style->offsety = msEvalDoubleExpression( &(style->exprBindings[MS_STYLE_BINDING_OFFSET_Y]), shape); } if (style->exprBindings[MS_STYLE_BINDING_ANGLE].type == MS_EXPRESSION) { style->angle = msEvalDoubleExpression( &(style->exprBindings[MS_STYLE_BINDING_ANGLE]), shape); } if (style->exprBindings[MS_STYLE_BINDING_SIZE].type == MS_EXPRESSION) { style->size = msEvalDoubleExpression( &(style->exprBindings[MS_STYLE_BINDING_SIZE]), shape); } if (style->exprBindings[MS_STYLE_BINDING_WIDTH].type == MS_EXPRESSION) { style->width = msEvalDoubleExpression( &(style->exprBindings[MS_STYLE_BINDING_WIDTH]), shape); } if (style->exprBindings[MS_STYLE_BINDING_OPACITY].type == MS_EXPRESSION) { style->opacity = 100 * msEvalDoubleExpression( &(style->exprBindings[MS_STYLE_BINDING_OPACITY]), shape); } if (style->exprBindings[MS_STYLE_BINDING_OUTLINECOLOR].type == MS_EXPRESSION) { char* txt = msEvalTextExpression( &(style->exprBindings[MS_STYLE_BINDING_OUTLINECOLOR]), shape); bindColorAttribute(&style->outlinecolor, txt); msFree(txt); } if (style->exprBindings[MS_STYLE_BINDING_COLOR].type == MS_EXPRESSION) { char* txt = msEvalTextExpression( &(style->exprBindings[MS_STYLE_BINDING_COLOR]), shape); bindColorAttribute(&style->color, txt); msFree(txt); } } if(applyOpacity == MS_TRUE && (style->opacity < 100 || style->color.alpha != 255) ) { int alpha; alpha = MS_NINT(style->opacity*2.55); style->color.alpha = alpha; style->outlinecolor.alpha = alpha; style->backgroundcolor.alpha = alpha; style->mincolor.alpha = alpha; style->maxcolor.alpha = alpha; } } static void bindLabel(layerObj *layer, shapeObj *shape, labelObj *label, int drawmode) { int i; assert(MS_DRAW_LABELS(drawmode)); /* check the label styleObj's (TODO: do we need to use querymapMode here? */ for(i=0; inumstyles; i++) { /* force MS_DRAWMODE_FEATURES for label styles */ bindStyle(layer, shape, label->styles[i], drawmode|MS_DRAWMODE_FEATURES); } if(label->numbindings > 0) { if(label->bindings[MS_LABEL_BINDING_ANGLE].index != -1) { label->angle = 0.0; bindDoubleAttribute(&label->angle, shape->values[label->bindings[MS_LABEL_BINDING_ANGLE].index]); } if(label->bindings[MS_LABEL_BINDING_SIZE].index != -1) { label->size = 1; bindIntegerAttribute(&label->size, shape->values[label->bindings[MS_LABEL_BINDING_SIZE].index]); } if(label->bindings[MS_LABEL_BINDING_COLOR].index != -1) { MS_INIT_COLOR(label->color, -1,-1,-1,255); bindColorAttribute(&label->color, shape->values[label->bindings[MS_LABEL_BINDING_COLOR].index]); } if(label->bindings[MS_LABEL_BINDING_OUTLINECOLOR].index != -1) { MS_INIT_COLOR(label->outlinecolor, -1,-1,-1,255); bindColorAttribute(&label->outlinecolor, shape->values[label->bindings[MS_LABEL_BINDING_OUTLINECOLOR].index]); } if(label->bindings[MS_LABEL_BINDING_FONT].index != -1) { msFree(label->font); label->font = msStrdup(shape->values[label->bindings[MS_LABEL_BINDING_FONT].index]); } if(label->bindings[MS_LABEL_BINDING_PRIORITY].index != -1) { label->priority = MS_DEFAULT_LABEL_PRIORITY; bindIntegerAttribute(&label->priority, shape->values[label->bindings[MS_LABEL_BINDING_PRIORITY].index]); } if(label->bindings[MS_LABEL_BINDING_SHADOWSIZEX].index != -1) { label->shadowsizex = 1; bindIntegerAttribute(&label->shadowsizex, shape->values[label->bindings[MS_LABEL_BINDING_SHADOWSIZEX].index]); } if(label->bindings[MS_LABEL_BINDING_SHADOWSIZEY].index != -1) { label->shadowsizey = 1; bindIntegerAttribute(&label->shadowsizey, shape->values[label->bindings[MS_LABEL_BINDING_SHADOWSIZEY].index]); } if(label->bindings[MS_LABEL_BINDING_OFFSET_X].index != -1) { label->offsetx = 0; bindIntegerAttribute(&label->offsetx, shape->values[label->bindings[MS_LABEL_BINDING_OFFSET_X].index]); } if(label->bindings[MS_LABEL_BINDING_OFFSET_Y].index != -1) { label->offsety = 0; bindIntegerAttribute(&label->offsety, shape->values[label->bindings[MS_LABEL_BINDING_OFFSET_Y].index]); } if(label->bindings[MS_LABEL_BINDING_ALIGN].index != -1) { int tmpAlign = 0; bindIntegerAttribute(&tmpAlign, shape->values[label->bindings[MS_LABEL_BINDING_ALIGN].index]); if(tmpAlign != 0) { /* is this test sufficient? */ label->align = tmpAlign; } else { /* Integer binding failed, look for strings like cc, ul, lr, etc... */ if(strlen(shape->values[label->bindings[MS_LABEL_BINDING_ALIGN].index]) >= 4) { char *va = shape->values[label->bindings[MS_LABEL_BINDING_ALIGN].index]; if(!strncasecmp(va,"center",5)) label->align = MS_ALIGN_CENTER; else if(!strncasecmp(va,"left",4)) label->align = MS_ALIGN_LEFT; else if(!strncasecmp(va,"right",5)) label->align = MS_ALIGN_RIGHT; } } } if(label->bindings[MS_LABEL_BINDING_POSITION].index != -1) { int tmpPosition = 0; bindIntegerAttribute(&tmpPosition, shape->values[label->bindings[MS_LABEL_BINDING_POSITION].index]); if(tmpPosition != 0) { /* is this test sufficient? */ label->position = tmpPosition; } else { /* Integer binding failed, look for strings like cc, ul, lr, etc... */ if(strlen(shape->values[label->bindings[MS_LABEL_BINDING_POSITION].index]) == 2) { char *vp = shape->values[label->bindings[MS_LABEL_BINDING_POSITION].index]; if(!strncasecmp(vp,"ul",2)) label->position = MS_UL; else if(!strncasecmp(vp,"lr",2)) label->position = MS_LR; else if(!strncasecmp(vp,"ur",2)) label->position = MS_UR; else if(!strncasecmp(vp,"ll",2)) label->position = MS_LL; else if(!strncasecmp(vp,"cr",2)) label->position = MS_CR; else if(!strncasecmp(vp,"cl",2)) label->position = MS_CL; else if(!strncasecmp(vp,"uc",2)) label->position = MS_UC; else if(!strncasecmp(vp,"lc",2)) label->position = MS_LC; else if(!strncasecmp(vp,"cc",2)) label->position = MS_CC; } } } } if (label->nexprbindings > 0) { if (label->exprBindings[MS_LABEL_BINDING_ANGLE].type == MS_EXPRESSION) { label->angle = msEvalDoubleExpression( &(label->exprBindings[MS_LABEL_BINDING_ANGLE]), shape); } if (label->exprBindings[MS_LABEL_BINDING_SIZE].type == MS_EXPRESSION) { label->size = msEvalDoubleExpression( &(label->exprBindings[MS_LABEL_BINDING_SIZE]), shape); } if (label->exprBindings[MS_LABEL_BINDING_COLOR].type == MS_EXPRESSION) { char* txt = msEvalTextExpression( &(label->exprBindings[MS_LABEL_BINDING_COLOR]), shape); bindColorAttribute(&label->color, txt); msFree(txt); } if (label->exprBindings[MS_LABEL_BINDING_OUTLINECOLOR].type == MS_EXPRESSION) { char* txt = msEvalTextExpression( &(label->exprBindings[MS_LABEL_BINDING_OUTLINECOLOR]), shape); bindColorAttribute(&label->outlinecolor, txt); msFree(txt); } } } /* ** Function to bind various layer properties to shape attributes. */ int msBindLayerToShape(layerObj *layer, shapeObj *shape, int drawmode) { int i, j; if(!layer || !shape) return MS_FAILURE; for(i=0; inumclasses; i++) { /* check the styleObj's */ if(MS_DRAW_FEATURES(drawmode)) { for(j=0; jclass[i]->numstyles; j++) { bindStyle(layer, shape, layer->class[i]->styles[j], drawmode); } } /* check the labelObj's */ if(MS_DRAW_LABELS(drawmode)) { for(j=0; jclass[i]->numlabels; j++) { bindLabel(layer, shape, layer->class[i]->labels[j], drawmode); } } } /* next classObj */ return MS_SUCCESS; } /* * Used to get red, green, blue integers separately based upon the color index */ int getRgbColor(mapObj *map,int i,int *r,int *g,int *b) { /* check index range */ int status=1; *r=*g=*b=-1; if ((i > 0 ) && (i <= map->palette.numcolors) ) { *r=map->palette.colors[i-1].red; *g=map->palette.colors[i-1].green; *b=map->palette.colors[i-1].blue; status=0; } return status; } static int searchContextForTag(mapObj *map, char **ltags, char *tag, char *context, int requires) { int i; if(!context) return MS_FAILURE; /* printf("\tin searchContextForTag, searching %s for %s\n", context, tag); */ if(strstr(context, tag) != NULL) return MS_SUCCESS; /* found the tag */ /* check referenced layers for the tag too */ for(i=0; inumlayers; i++) { if(strstr(context, ltags[i]) != NULL) { /* need to check this layer */ if(requires == MS_TRUE) { if(searchContextForTag(map, ltags, tag, GET_LAYER(map, i)->requires, MS_TRUE) == MS_SUCCESS) return MS_SUCCESS; } else { if(searchContextForTag(map, ltags, tag, GET_LAYER(map, i)->labelrequires, MS_FALSE) == MS_SUCCESS) return MS_SUCCESS; } } } return MS_FAILURE; } /* ** Function to take a look at all layers with REQUIRES/LABELREQUIRES set to make sure there are no ** recursive context requirements set (e.g. layer1 requires layer2 and layer2 requires layer1). This ** is bug 1059. */ int msValidateContexts(mapObj *map) { int i; char **ltags; int status = MS_SUCCESS; ltags = (char **) msSmallMalloc(map->numlayers*sizeof(char *)); for(i=0; inumlayers; i++) { if(GET_LAYER(map, i)->name == NULL) { ltags[i] = msStrdup("[NULL]"); } else { ltags[i] = (char *) msSmallMalloc(sizeof(char)*strlen(GET_LAYER(map, i)->name) + 3); sprintf(ltags[i], "[%s]", GET_LAYER(map, i)->name); } } /* check each layer's REQUIRES and LABELREQUIRES parameters */ for(i=0; inumlayers; i++) { /* printf("working on layer %s, looking for references to %s\n", GET_LAYER(map, i)->name, ltags[i]); */ if(searchContextForTag(map, ltags, ltags[i], GET_LAYER(map, i)->requires, MS_TRUE) == MS_SUCCESS) { msSetError(MS_PARSEERR, "Recursion error found for REQUIRES parameter for layer %s.", "msValidateContexts", GET_LAYER(map, i)->name); status = MS_FAILURE; break; } if(searchContextForTag(map, ltags, ltags[i], GET_LAYER(map, i)->labelrequires, MS_FALSE) == MS_SUCCESS) { msSetError(MS_PARSEERR, "Recursion error found for LABELREQUIRES parameter for layer %s.", "msValidateContexts", GET_LAYER(map, i)->name); status = MS_FAILURE; break; } /* printf("done layer %s\n", GET_LAYER(map, i)->name); */ } /* clean up */ msFreeCharArray(ltags, map->numlayers); return status; } int msEvalContext(mapObj *map, layerObj *layer, char *context) { int i, status; char *tag=NULL; expressionObj e; parseObj p; if(!context) return(MS_TRUE); /* initialize a temporary expression (e) */ msInitExpression(&e); e.string = msStrdup(context); e.type = MS_EXPRESSION; /* todo */ for(i=0; inumlayers; i++) { /* step through all the layers */ if(layer->index == i) continue; /* skip the layer in question */ if (GET_LAYER(map, i)->name == NULL) continue; /* Layer without name cannot be used in contexts */ tag = (char *)msSmallMalloc(sizeof(char)*strlen(GET_LAYER(map, i)->name) + 3); sprintf(tag, "[%s]", GET_LAYER(map, i)->name); if(strstr(e.string, tag)) { if(msLayerIsVisible(map, (GET_LAYER(map, i)))) e.string = msReplaceSubstring(e.string, tag, "1"); else e.string = msReplaceSubstring(e.string, tag, "0"); } free(tag); } msTokenizeExpression(&e, NULL, NULL); p.shape = NULL; p.expr = &e; p.expr->curtoken = p.expr->tokens; /* reset */ p.type = MS_PARSE_TYPE_BOOLEAN; status = yyparse(&p); msFreeExpression(&e); if (status != 0) { msSetError(MS_PARSEERR, "Failed to parse context", "msEvalContext"); return MS_FALSE; /* error in parse */ } return p.result.intval; } /* msEvalExpression() * * Evaluates a mapserver expression for a given set of attribute values and * returns the result of the expression (MS_TRUE or MS_FALSE) * May also return MS_FALSE in case of parsing errors or invalid expressions * (check the error stack if you care) * */ int msEvalExpression(layerObj *layer, shapeObj *shape, expressionObj *expression, int itemindex) { if(MS_STRING_IS_NULL_OR_EMPTY(expression->string)) return MS_TRUE; /* NULL or empty expressions are ALWAYS true */ if(expression->native_string != NULL) return MS_TRUE; /* expressions that are evaluated natively are ALWAYS true */ switch(expression->type) { case(MS_STRING): if(itemindex == -1) { msSetError(MS_MISCERR, "Cannot evaluate expression, no item index defined.", "msEvalExpression()"); return MS_FALSE; } if(itemindex >= layer->numitems || itemindex >= shape->numvalues) { msSetError(MS_MISCERR, "Invalid item index.", "msEvalExpression()"); return MS_FALSE; } if(expression->flags & MS_EXP_INSENSITIVE) { if(strcasecmp(expression->string, shape->values[itemindex]) == 0) return MS_TRUE; /* got a match */ } else { if(strcmp(expression->string, shape->values[itemindex]) == 0) return MS_TRUE; /* got a match */ } break; case(MS_LIST): if(itemindex == -1) { msSetError(MS_MISCERR, "Cannot evaluate expression, no item index defined.", "msEvalExpression()"); return MS_FALSE; } if(itemindex >= layer->numitems || itemindex >= shape->numvalues) { msSetError(MS_MISCERR, "Invalid item index.", "msEvalExpression()"); return MS_FALSE; } { char *start,*end; int value_len = strlen(shape->values[itemindex]); start = expression->string; while((end = strchr(start,',')) != NULL) { if(value_len == end-start && !strncmp(start,shape->values[itemindex],end-start)) return MS_TRUE; start = end+1; } if(!strcmp(start,shape->values[itemindex])) return MS_TRUE; } break; case(MS_EXPRESSION): { int status; parseObj p; p.shape = shape; p.expr = expression; p.expr->curtoken = p.expr->tokens; /* reset */ p.type = MS_PARSE_TYPE_BOOLEAN; status = yyparse(&p); if (status != 0) { msSetError(MS_PARSEERR, "Failed to parse expression: %s", "msEvalExpression", expression->string); return MS_FALSE; } return p.result.intval; break; } case(MS_REGEX): if(itemindex == -1) { msSetError(MS_MISCERR, "Cannot evaluate expression, no item index defined.", "msEvalExpression()"); return MS_FALSE; } if(itemindex >= layer->numitems || itemindex >= shape->numvalues) { msSetError(MS_MISCERR, "Invalid item index.", "msEvalExpression()"); return MS_FALSE; } if(MS_STRING_IS_NULL_OR_EMPTY(shape->values[itemindex]) == MS_TRUE) return MS_FALSE; if(!expression->compiled) { if(expression->flags & MS_EXP_INSENSITIVE) { if(ms_regcomp(&(expression->regex), expression->string, MS_REG_EXTENDED|MS_REG_NOSUB|MS_REG_ICASE) != 0) { /* compile the expression */ msSetError(MS_REGEXERR, "Invalid regular expression.", "msEvalExpression()"); return MS_FALSE; } } else { if(ms_regcomp(&(expression->regex), expression->string, MS_REG_EXTENDED|MS_REG_NOSUB) != 0) { /* compile the expression */ msSetError(MS_REGEXERR, "Invalid regular expression.", "msEvalExpression()"); return MS_FALSE; } } expression->compiled = MS_TRUE; } if(ms_regexec(&(expression->regex), shape->values[itemindex], 0, NULL, 0) == 0) return MS_TRUE; /* got a match */ break; } return MS_FALSE; } int *msAllocateValidClassGroups(layerObj *lp, int *nclasses) { int *classgroup = NULL; int nvalidclass = 0, i=0; if (!lp || !lp->classgroup || lp->numclasses <=0 || !nclasses) return NULL; classgroup = (int *)msSmallMalloc(sizeof(int)*lp->numclasses); nvalidclass = 0; for (i=0; inumclasses; i++) { if (lp->class[i]->group && strcasecmp(lp->class[i]->group, lp->classgroup) == 0) { classgroup[nvalidclass] = i; nvalidclass++; } } if (nvalidclass > 0) { classgroup = (int *)msSmallRealloc(classgroup, sizeof(int)*nvalidclass); *nclasses = nvalidclass; return classgroup; } if (classgroup) msFree(classgroup); return NULL; } int msShapeGetClass(layerObj *layer, mapObj *map, shapeObj *shape, int *classgroup, int numclasses) { return msShapeGetNextClass(-1, layer, map, shape, classgroup, numclasses); } int msShapeGetNextClass(int currentclass, layerObj *layer, mapObj *map, shapeObj *shape, int *classgroup, int numclasses) { int i, iclass; if (currentclass < 0) currentclass = -1; if (layer->numclasses > 0) { if (classgroup == NULL || numclasses <=0) numclasses = layer->numclasses; for(i=currentclass+1; i= layer->numclasses) continue; /* this should never happen but just in case */ if(map->scaledenom > 0) { /* verify scaledenom here */ if((layer->class[iclass]->maxscaledenom > 0) && (map->scaledenom > layer->class[iclass]->maxscaledenom)) continue; /* can skip this one, next class */ if((layer->class[iclass]->minscaledenom > 0) && (map->scaledenom <= layer->class[iclass]->minscaledenom)) continue; /* can skip this one, next class */ } /* verify the minfeaturesize */ if ((shape->type == MS_SHAPE_LINE || shape->type == MS_SHAPE_POLYGON) && (layer->class[iclass]->minfeaturesize > 0)) { double minfeaturesize = Pix2LayerGeoref(map, layer, layer->class[iclass]->minfeaturesize); if (msShapeCheckSize(shape, minfeaturesize) == MS_FALSE) continue; /* skip this one, next class */ } if(layer->class[iclass]->status != MS_DELETE && msEvalExpression(layer, shape, &(layer->class[iclass]->expression), layer->classitemindex) == MS_TRUE) { if (layer->class[iclass]->isfallback && currentclass != -1) { // Class is not applicable if it is flagged as fallback ( tag in SLD) // but other classes have been applied before. return -1; } else { return(iclass); } } } } return(-1); /* no match */ } static char *msEvalTextExpressionInternal(expressionObj *expr, shapeObj *shape, int bJSonEscape) { char *result=NULL; if(!expr->string) return result; /* nothing to do */ switch(expr->type) { case(MS_STRING): { char *target=NULL; char *pszEscaped; tokenListNodeObjPtr node=NULL; tokenListNodeObjPtr nextNode=NULL; result = msStrdup(expr->string); node = expr->tokens; if(node) { while(node != NULL) { nextNode = node->next; if(node->token == MS_TOKEN_BINDING_DOUBLE || node->token == MS_TOKEN_BINDING_INTEGER || node->token == MS_TOKEN_BINDING_STRING || node->token == MS_TOKEN_BINDING_TIME) { target = (char *) msSmallMalloc(strlen(node->tokenval.bindval.item) + 3); sprintf(target, "[%s]", node->tokenval.bindval.item); if( bJSonEscape ) pszEscaped = msEscapeJSonString(shape->values[node->tokenval.bindval.index]); else pszEscaped = msStrdup(shape->values[node->tokenval.bindval.index]); result = msReplaceSubstring(result, target, pszEscaped); msFree(pszEscaped); msFree(target); } node = nextNode; } } if(!strlen(result)) { msFree(result); result = NULL; } } break; case(MS_EXPRESSION): { int status; parseObj p; p.shape = shape; p.expr = expr; p.expr->curtoken = p.expr->tokens; /* reset */ p.type = MS_PARSE_TYPE_STRING; status = yyparse(&p); if (status != 0) { msSetError(MS_PARSEERR, "Failed to process text expression: %s", "msEvalTextExpression", expr->string); return NULL; } result = p.result.strval; break; } default: break; } if(result && !strlen(result)) { msFree(result); result = NULL; } return result; } char *msEvalTextExpressionJSonEscape(expressionObj *expr, shapeObj *shape) { return msEvalTextExpressionInternal(expr, shape, MS_TRUE); } char *msEvalTextExpression(expressionObj *expr, shapeObj *shape) { return msEvalTextExpressionInternal(expr, shape, MS_FALSE); } double msEvalDoubleExpression(expressionObj *expression, shapeObj *shape) { double value; int status; parseObj p; p.shape = shape; p.expr = expression; p.expr->curtoken = p.expr->tokens; /* reset */ p.type = MS_PARSE_TYPE_STRING; status = yyparse(&p); if (status != 0) { msSetError(MS_PARSEERR, "Failed to parse expression: %s", "bindStyle", expression->string); value = 0.0; } else { value = atof(p.result.strval); msFree(p.result.strval); } return value; } char* msShapeGetLabelAnnotation(layerObj *layer, shapeObj *shape, labelObj *lbl) { assert(shape && lbl); if(lbl->text.string) { return msEvalTextExpression(&(lbl->text), shape); } else if(layer->class[shape->classindex]->text.string) { return msEvalTextExpression(&(layer->class[shape->classindex]->text), shape); } else { if (shape->values && layer->labelitemindex >= 0 && shape->values[layer->labelitemindex] && strlen(shape->values[layer->labelitemindex]) ) return msStrdup(shape->values[layer->labelitemindex]); else if(shape->text) return msStrdup(shape->text); /* last resort but common with iniline features */ } return NULL; } int msGetLabelStatus(mapObj *map, layerObj *layer, shapeObj *shape, labelObj *lbl) { assert(layer && lbl); if(!msScaleInBounds(map->scaledenom,lbl->minscaledenom,lbl->maxscaledenom)) return MS_OFF; if(msEvalExpression(layer, shape, &(lbl->expression), layer->labelitemindex) != MS_TRUE) return MS_OFF; /* TODO: check for minfeaturesize here ? */ return MS_ON; } /* Check if the shape is enough big to be drawn with the layer::minfeaturesize setting. The minfeaturesize parameter should be the value in geo ref (not in pixel) and should have been multiplied by the resolution factor. */ int msShapeCheckSize(shapeObj *shape, double minfeaturesize) { double dx = (shape->bounds.maxx-shape->bounds.minx); double dy = (shape->bounds.maxy-shape->bounds.miny); if (pow(minfeaturesize,2.0) > (pow(dx,2.0)+pow(dy,2.0))) return MS_FALSE; return MS_TRUE; } /* ** Adjusts an image size in one direction to fit an extent. */ int msAdjustImage(rectObj rect, int *width, int *height) { if(*width == -1 && *height == -1) { msSetError(MS_MISCERR, "Cannot calculate both image height and width.", "msAdjustImage()"); return(-1); } if(*width > 0) *height = MS_NINT((rect.maxy - rect.miny)/((rect.maxx - rect.minx)/(*width))); else *width = MS_NINT((rect.maxx - rect.minx)/((rect.maxy - rect.miny)/(*height))); return(0); } /* ** Make sure extent fits image window to be created. Returns cellsize of output image. */ double msAdjustExtent(rectObj *rect, int width, int height) { double cellsize, ox, oy; if(width == 1 || height == 1) return 0; cellsize = MS_MAX(MS_CELLSIZE(rect->minx, rect->maxx, width), MS_CELLSIZE(rect->miny, rect->maxy, height)); if(cellsize <= 0) /* avoid division by zero errors */ return(0); ox = MS_MAX(((width-1) - (rect->maxx - rect->minx)/cellsize)/2,0); /* these were width-1 and height-1 */ oy = MS_MAX(((height-1) - (rect->maxy - rect->miny)/cellsize)/2,0); rect->minx = rect->minx - ox*cellsize; rect->miny = rect->miny - oy*cellsize; rect->maxx = rect->maxx + ox*cellsize; rect->maxy = rect->maxy + oy*cellsize; return(cellsize); } /* ** Rect must always contain a portion of bounds. If not, rect is ** shifted to overlap by overlay percent. The dimensions of rect do ** not change but placement relative to bounds can. */ int msConstrainExtent(rectObj *bounds, rectObj *rect, double overlay) { double offset=0; /* check left edge, and if necessary the right edge of bounds */ if(rect->maxx <= bounds->minx) { offset = overlay*(rect->maxx - rect->minx); rect->minx += offset; /* shift right */ rect->maxx += offset; } else if(rect->minx >= bounds->maxx) { offset = overlay*(rect->maxx - rect->minx); rect->minx -= offset; /* shift left */ rect->maxx -= offset; } /* check top edge, and if necessary the bottom edge of bounds */ if(rect->maxy <= bounds->miny) { offset = overlay*(rect->maxy - rect->miny); rect->miny -= offset; /* shift down */ rect->maxy -= offset; } else if(rect->miny >= bounds->maxy) { offset = overlay*(rect->maxy - rect->miny); rect->miny += offset; /* shift up */ rect->maxy += offset; } return(MS_SUCCESS); } /* ** Generic function to save an image to a file. ** ** Note that map may be NULL. If it is set, then it is used for two things: ** - Deal with relative imagepaths (compute absolute path relative to map path) ** - Extract the georeferenced extents and coordinate system ** of the map for writing out with the image when appropriate ** (primarily this means via msSaveImageGDAL() to something like GeoTIFF). ** ** The filename is NULL when the image is supposed to be written to stdout. */ int msSaveImage(mapObj *map, imageObj *img, const char *filename) { int nReturnVal = MS_FAILURE; char szPath[MS_MAXPATHLEN]; struct mstimeval starttime={0}, endtime={0}; if(map && map->debug >= MS_DEBUGLEVEL_TUNING) { msGettimeofday(&starttime, NULL); } if (img) { if( MS_DRIVER_GDAL(img->format) ) { if (map != NULL && filename != NULL ) nReturnVal = msSaveImageGDAL(map, img, msBuildPath(szPath, map->mappath, filename)); else nReturnVal = msSaveImageGDAL(map, img, filename); } else if (MS_RENDERER_PLUGIN(img->format)) { rendererVTableObj *renderer = img->format->vtable; FILE *stream = NULL; if(filename) { if(map) stream = fopen(msBuildPath(szPath, map->mappath, filename),"wb"); else stream = fopen(filename,"wb"); if(!stream) { msSetError(MS_IOERR, "Failed to create output file (%s).", "msSaveImage()", (map?szPath:filename) ); return MS_FAILURE; } } else { if ( msIO_needBinaryStdout() == MS_FAILURE ) return MS_FAILURE; stream = stdout; } if(renderer->supports_pixel_buffer) { rasterBufferObj data; if(renderer->getRasterBufferHandle(img,&data) != MS_SUCCESS) { if( stream != stdout ) fclose(stream); return MS_FAILURE; } nReturnVal = msSaveRasterBuffer(map,&data,stream,img->format ); } else { nReturnVal = renderer->saveImage(img, map, stream, img->format); } if( stream != stdout ) fclose(stream); } else if( MS_DRIVER_IMAGEMAP(img->format) ) nReturnVal = msSaveImageIM(img, filename, img->format); else msSetError(MS_MISCERR, "Unknown image type", "msSaveImage()"); } if(map && map->debug >= MS_DEBUGLEVEL_TUNING) { msGettimeofday(&endtime, NULL); msDebug("msSaveImage(%s) total time: %.3fs\n", (filename ? filename : "stdout"), (endtime.tv_sec+endtime.tv_usec/1.0e6)- (starttime.tv_sec+starttime.tv_usec/1.0e6) ); } return nReturnVal; } /* ** Generic function to save an image to a byte array. ** - the return value is the pointer to the byte array ** - size_ptr contains the number of bytes returned ** - format: the desired output format ** ** The caller is responsible to free the returned array ** The function returns NULL if the output format is not supported. */ unsigned char *msSaveImageBuffer(imageObj* image, int *size_ptr, outputFormatObj *format) { int status = MS_SUCCESS; *size_ptr = 0; if( MS_RENDERER_PLUGIN(image->format)) { rasterBufferObj data; rendererVTableObj *renderer = image->format->vtable; if(renderer->supports_pixel_buffer) { bufferObj buffer; msBufferInit(&buffer); status = renderer->getRasterBufferHandle(image,&data); if(UNLIKELY(status == MS_FAILURE)) { return NULL; } msSaveRasterBufferToBuffer(&data,&buffer,format); *size_ptr = buffer.size; return buffer.data; /* don't free the bufferObj as we don't own the bytes anymore */ } else { /* check if the renderer supports native buffer output */ if (renderer->saveImageBuffer) return renderer->saveImageBuffer(image, size_ptr, format); msSetError(MS_MISCERR, "Unsupported image type", "msSaveImageBuffer()"); return NULL; } } msSetError(MS_MISCERR, "Unsupported image type", "msSaveImage()"); return NULL; } /** * Generic function to free the imageObj */ void msFreeImage(imageObj *image) { if (image) { if(MS_RENDERER_PLUGIN(image->format)) { rendererVTableObj *renderer = image->format->vtable; tileCacheObj *next,*cur = image->tilecache; while(cur) { msFreeImage(cur->image); next = cur->next; free(cur); cur = next; } image->ntiles = 0; renderer->freeImage(image); } else if( MS_RENDERER_IMAGEMAP(image->format) ) msFreeImageIM(image); else if( MS_RENDERER_RAWDATA(image->format) ) msFree(image->img.raw_16bit); else msSetError(MS_MISCERR, "Unknown image type", "msFreeImage()"); if (image->imagepath) free(image->imagepath); if (image->imageurl) free(image->imageurl); if( --image->format->refcount < 1 ) msFreeOutputFormat( image->format ); image->imagepath = NULL; image->imageurl = NULL; msFree( image->img_mask ); image->img_mask= NULL; msFree( image ); } } /* ** Return an array containing all the layer's index given a group name. ** If nothing is found, NULL is returned. The nCount is initalized ** to the number of elements in the returned array. ** Note : the caller of the function should free the array. */ int *msGetLayersIndexByGroup(mapObj *map, char *groupname, int *pnCount) { int i; int iLayer = 0; int *aiIndex; if(!groupname || !map || !pnCount) { return NULL; } aiIndex = (int *)msSmallMalloc(sizeof(int) * map->numlayers); for(i=0; inumlayers; i++) { if(!GET_LAYER(map, i)->group) /* skip it */ continue; if(strcmp(groupname, GET_LAYER(map, i)->group) == 0) { aiIndex[iLayer] = i; iLayer++; } } if (iLayer == 0) { free(aiIndex); aiIndex = NULL; *pnCount = 0; } else { aiIndex = (int *)msSmallRealloc(aiIndex, sizeof(int)* iLayer); *pnCount = iLayer; } return aiIndex; } /* ==================================================================== */ /* Measured shape utility functions. */ /* ==================================================================== */ /************************************************************************/ /* pointObj *msGetPointUsingMeasure(shapeObj *shape, double m) */ /* */ /* Using a measured value get the XY location it corresonds */ /* to. */ /* */ /************************************************************************/ pointObj *msGetPointUsingMeasure(shapeObj *shape, double m) { #ifdef USE_POINT_Z_M pointObj *point = NULL; lineObj line; double dfMin = 0; double dfMax = 0; int i,j = 0; int bFound = 0; double dfFirstPointX = 0; double dfFirstPointY = 0; double dfFirstPointM = 0; double dfSecondPointX = 0; double dfSecondPointY = 0; double dfSecondPointM = 0; double dfCurrentM = 0; double dfFactor = 0; if (shape && shape->numlines > 0) { /* -------------------------------------------------------------------- */ /* check fir the first value (min) and the last value(max) to */ /* see if the m is contained between these min and max. */ /* -------------------------------------------------------------------- */ line = shape->line[0]; dfMin = line.point[0].m; line = shape->line[shape->numlines-1]; dfMax = line.point[line.numpoints-1].m; if (m >= dfMin && m <= dfMax) { for (i=0; inumlines; i++) { line = shape->line[i]; for (j=0; j m) { bFound = 1; dfSecondPointX = line.point[j].x; dfSecondPointY = line.point[j].y; dfSecondPointM = line.point[j].m; /* -------------------------------------------------------------------- */ /* get the previous node xy values. */ /* -------------------------------------------------------------------- */ if (j > 0) { /* not the first point of the line */ dfFirstPointX = line.point[j-1].x; dfFirstPointY = line.point[j-1].y; dfFirstPointM = line.point[j-1].m; } else { /* get last point of previous line */ dfFirstPointX = shape->line[i-1].point[0].x; dfFirstPointY = shape->line[i-1].point[0].y; dfFirstPointM = shape->line[i-1].point[0].m; } break; } } } } if (!bFound) return NULL; /* -------------------------------------------------------------------- */ /* extrapolate the m value to get t he xy coordinate. */ /* -------------------------------------------------------------------- */ if (dfFirstPointM != dfSecondPointM) dfFactor = (m-dfFirstPointM)/(dfSecondPointM - dfFirstPointM); else dfFactor = 0; point = (pointObj *)msSmallMalloc(sizeof(pointObj)); point->x = dfFirstPointX + (dfFactor * (dfSecondPointX - dfFirstPointX)); point->y = dfFirstPointY + (dfFactor * (dfSecondPointY - dfFirstPointY)); point->m = dfFirstPointM + (dfFactor * (dfSecondPointM - dfFirstPointM)); return point; } return NULL; #else msSetError(MS_MISCERR, "The \"m\" parameter for points is unavailable in your build.", "msGetPointUsingMeasure()"); return NULL; #endif /* USE_POINT_Z_M */ } /************************************************************************/ /* IntersectionPointLinepointObj *p, pointObj *a, pointObj *b) */ /* */ /* Retunrs a point object corresponding to the intersection of */ /* point p and a line formed of 2 points : a and b. */ /* */ /* Alorith base on : */ /* http://www.faqs.org/faqs/graphics/algorithms-faq/ */ /* */ /* Subject 1.02:How do I find the distance from a point to a line? */ /* */ /* Let the point be C (Cx,Cy) and the line be AB (Ax,Ay) to (Bx,By).*/ /* Let P be the point of perpendicular projection of C on AB. The parameter*/ /* r, which indicates P's position along AB, is computed by the dot product */ /* of AC and AB divided by the square of the length of AB: */ /* */ /* (1) AC dot AB */ /* r = --------- */ /* ||AB||^2 */ /* */ /* r has the following meaning: */ /* */ /* r=0 P = A */ /* r=1 P = B */ /* r<0 P is on the backward extension of AB */ /* r>1 P is on the forward extension of AB */ /* 00 C is right of AB */ /* s=0 C is on AB */ /* */ /* Compute s as follows: */ /* */ /* (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay) */ /* s = ----------------------------- */ /* L^2 */ /* */ /* */ /* Then the distance from C to P = |s|*L. */ /* */ /************************************************************************/ pointObj *msIntersectionPointLine(pointObj *p, pointObj *a, pointObj *b) { double r = 0; double L = 0; pointObj *result = NULL; if (p && a && b) { L = sqrt(((b->x - a->x)*(b->x - a->x)) + ((b->y - a->y)*(b->y - a->y))); if (L != 0) r = ((p->x - a->x)*(b->x - a->x) + (p->y - a->y)*(b->y - a->y))/(L*L); else r = 0; result = (pointObj *)msSmallMalloc(sizeof(pointObj)); /* -------------------------------------------------------------------- */ /* We want to make sure that the point returned is on the line */ /* */ /* r=0 P = A */ /* r=1 P = B */ /* r<0 P is on the backward extension of AB */ /* r>1 P is on the forward extension of AB */ /* 0x = a->x; result->y = a->y; } else if (r > 1) { result->x = b->x; result->y = b->y; } else { result->x = a->x + r*(b->x - a->x); result->y = a->y + r*(b->y - a->y); } #ifdef USE_POINT_Z_M result->m = 0; #endif } return result; } /************************************************************************/ /* pointObj *msGetMeasureUsingPoint(shapeObj *shape, pointObj */ /* *point) */ /* */ /* Calculate the intersection point betwwen the point and the */ /* shape and return the Measured value at the intersection. */ /************************************************************************/ pointObj *msGetMeasureUsingPoint(shapeObj *shape, pointObj *point) { double dfMinDist = 1e35; double dfDist = 0; pointObj oFirst; pointObj oSecond; int i, j = 0; lineObj line; pointObj *poIntersectionPt = NULL; #ifdef USE_POINT_Z_M double dfFactor = 0; double dfDistTotal, dfDistToIntersection = 0; #endif if (shape && point) { for (i=0; inumlines; i++) { line = shape->line[i]; /* -------------------------------------------------------------------- */ /* for each line (2 consecutive lines) get the distance between */ /* the line and the point and determine which line segment is */ /* the closeset to the point. */ /* -------------------------------------------------------------------- */ for (j=0; jx - oFirst.x)* (poIntersectionPt->x - oFirst.x)) + ((poIntersectionPt->y - oFirst.y)* (poIntersectionPt->y - oFirst.y))); dfFactor = dfDistToIntersection / dfDistTotal; poIntersectionPt->m = oFirst.m + (oSecond.m - oFirst.m)*dfFactor; #endif return poIntersectionPt; } } return NULL; } /* ==================================================================== */ /* End Measured shape utility functions. */ /* ==================================================================== */ char **msGetAllGroupNames(mapObj *map, int *numTok) { char **papszGroups = NULL; int bFound = 0; int nCount = 0; int i = 0, j = 0; assert(map); *numTok = 0; if (!map->layerorder) { map->layerorder = (int*)msSmallMalloc(map->numlayers * sizeof(int)); /* * Initiate to default order */ for (i=0; inumlayers; i++) map->layerorder[i] = i; } if (map->numlayers > 0) { nCount = map->numlayers; papszGroups = (char **)msSmallMalloc(sizeof(char *)*nCount); for (i=0; ilayerorder[i])); bFound = 0; if (lp->group && lp->status != MS_DELETE) { for (j=0; j<*numTok; j++) { if (papszGroups[j] && strcmp(lp->group, papszGroups[j]) == 0) { bFound = 1; break; } } if (!bFound) { /* New group... add to the list of groups found */ papszGroups[(*numTok)] = msStrdup(lp->group); (*numTok)++; } } } } return papszGroups; } /************************************************************************/ /* msForceTmpFileBase() */ /************************************************************************/ static int tmpCount = 0; static char *ForcedTmpBase = NULL; void msForceTmpFileBase( const char *new_base ) { /* -------------------------------------------------------------------- */ /* Clear previous setting, if any. */ /* -------------------------------------------------------------------- */ if( ForcedTmpBase != NULL ) { free( ForcedTmpBase ); ForcedTmpBase = NULL; } tmpCount = -1; if( new_base == NULL ) return; /* -------------------------------------------------------------------- */ /* Record new base. */ /* -------------------------------------------------------------------- */ ForcedTmpBase = msStrdup( new_base ); tmpCount = 0; } /********************************************************************** * msTmpFile() * * Generate a Unique temporary file. * * Returns char* which must be freed by caller. **********************************************************************/ char *msTmpFile(mapObj *map, const char *mappath, const char *tmppath, const char *ext) { char szPath[MS_MAXPATHLEN]; const char *fullFname; char *tmpFileName; /* big enough for time + pid + ext */ char *tmpBase = NULL; tmpBase = msTmpPath(map, mappath, tmppath); tmpFileName = msTmpFilename(ext); fullFname = msBuildPath(szPath, tmpBase, tmpFileName); free(tmpFileName); free(tmpBase); if (fullFname) return msStrdup(fullFname); return NULL; } /********************************************************************** * msTmpPath() * * Return the temporary path based on the platform. * * Returns char* which must be freed by caller. **********************************************************************/ char *msTmpPath(mapObj *map, const char *mappath, const char *tmppath) { char szPath[MS_MAXPATHLEN]; const char *fullPath; const char *tmpBase; #ifdef _WIN32 DWORD dwRetVal = 0; TCHAR lpTempPathBuffer[MAX_PATH]; #endif if( ForcedTmpBase != NULL ) tmpBase = ForcedTmpBase; else if (tmppath != NULL) tmpBase = tmppath; else if (getenv("MS_TEMPPATH")) tmpBase = getenv("MS_TEMPPATH"); else if (map && map->web.temppath) tmpBase = map->web.temppath; else { /* default paths */ #ifndef _WIN32 tmpBase = "/tmp/"; #else dwRetVal = GetTempPath(MAX_PATH, /* length of the buffer */ lpTempPathBuffer); /* buffer for path */ if (dwRetVal > MAX_PATH || (dwRetVal == 0)) { tmpBase = "C:\\"; } else { tmpBase = (char*)lpTempPathBuffer; } #endif } fullPath = msBuildPath(szPath, mappath, tmpBase); return msStrdup(fullPath); } /********************************************************************** * msTmpFilename() * * Generate a Unique temporary filename. * * Returns char* which must be freed by caller. **********************************************************************/ char *msTmpFilename(const char *ext) { char *tmpFname; int tmpFnameBufsize; char *fullFname; char tmpId[128]; /* big enough for time + pid + ext */ snprintf(tmpId, sizeof(tmpId), "%lx_%x",(long)time(NULL),(int)getpid()); if (ext == NULL) ext = ""; tmpFnameBufsize = strlen(tmpId) + 10 + strlen(ext) + 1; tmpFname = (char*)msSmallMalloc(tmpFnameBufsize); msAcquireLock( TLOCK_TMPFILE ); snprintf(tmpFname, tmpFnameBufsize, "%s_%x.%s", tmpId, tmpCount++, ext); msReleaseLock( TLOCK_TMPFILE ); fullFname = msStrdup(tmpFname); free(tmpFname); return fullFname; } /** * Generic function to Initalize an image object. */ imageObj *msImageCreate(int width, int height, outputFormatObj *format, char *imagepath, char *imageurl, double resolution, double defresolution, colorObj *bg) { imageObj *image = NULL; if(MS_RENDERER_PLUGIN(format)) { image = format->vtable->createImage(width,height,format,bg); if (image == NULL) { msSetError(MS_MEMERR, "Unable to create new image object.", "msImageCreate()"); return NULL; } image->format = format; format->refcount++; image->width = width; image->height = height; image->imagepath = NULL; image->imageurl = NULL; image->tilecache = NULL; image->ntiles = 0; image->resolution = resolution; image->resolutionfactor = resolution/defresolution; if (imagepath) image->imagepath = msStrdup(imagepath); if (imageurl) image->imageurl = msStrdup(imageurl); } else if( MS_RENDERER_RAWDATA(format) ) { if( format->imagemode != MS_IMAGEMODE_INT16 && format->imagemode != MS_IMAGEMODE_FLOAT32 && format->imagemode != MS_IMAGEMODE_BYTE ) { msSetError(MS_IMGERR, "Attempt to use illegal imagemode with rawdata renderer.", "msImageCreate()" ); return NULL; } image = (imageObj *)calloc(1,sizeof(imageObj)); if (image == NULL) { msSetError(MS_MEMERR, "Unable to create new image object.", "msImageCreate()"); return NULL; } if( format->imagemode == MS_IMAGEMODE_INT16 ) image->img.raw_16bit = (short *) msSmallCalloc(sizeof(short),width*height*format->bands); else if( format->imagemode == MS_IMAGEMODE_FLOAT32 ) image->img.raw_float = (float *) msSmallCalloc(sizeof(float),width*height*format->bands); else if( format->imagemode == MS_IMAGEMODE_BYTE ) image->img.raw_byte = (unsigned char *) msSmallCalloc(sizeof(unsigned char),width*height*format->bands); if( image->img.raw_16bit == NULL ) { msFree( image ); msSetError(MS_IMGERR, "Attempt to allocate raw image failed, out of memory.", "msImageCreate()" ); return NULL; } image->img_mask = msAllocBitArray( width*height ); image->format = format; format->refcount++; image->width = width; image->height = height; image->imagepath = NULL; image->imageurl = NULL; image->resolution = resolution; image->resolutionfactor = resolution/defresolution; if (imagepath) image->imagepath = msStrdup(imagepath); if (imageurl) image->imageurl = msStrdup(imageurl); /* initialize to requested nullvalue if there is one */ if( msGetOutputFormatOption(image->format,"NULLVALUE",NULL) != NULL ) { int i = image->width * image->height * format->bands; const char *nullvalue = msGetOutputFormatOption(image->format, "NULLVALUE",NULL); if( atof(nullvalue) == 0.0 ) /* nothing to do */; else if( format->imagemode == MS_IMAGEMODE_INT16 ) { short nv = atoi(nullvalue); for( ; i > 0; ) image->img.raw_16bit[--i] = nv; } else if( format->imagemode == MS_IMAGEMODE_FLOAT32 ) { float nv = atof(nullvalue); for( ; i > 0; ) image->img.raw_float[--i] = nv; } else if( format->imagemode == MS_IMAGEMODE_BYTE ) { unsigned char nv = (unsigned char) atoi(nullvalue); memset( image->img.raw_byte, nv, i ); } } } else if( MS_RENDERER_IMAGEMAP(format) ) { image = msImageCreateIM(width, height, format, imagepath, imageurl, resolution, defresolution); } else { msSetError(MS_MISCERR, "Unsupported renderer requested, unable to initialize image.", "msImageCreate()"); return NULL; } if(!image) msSetError(MS_IMGERR, "Unable to initialize image.", "msImageCreate()"); image->refpt.x = image->refpt.y = 0; return image; } /** * Generic function to transorm a point. * */ void msTransformPoint(pointObj *point, rectObj *extent, double cellsize, imageObj *image) { double invcellsize; /*We should probabaly have a function defined at all the renders*/ if (image != NULL && MS_RENDERER_PLUGIN(image->format)) { if(image->format->renderer == MS_RENDER_WITH_KML) { return; } } invcellsize = 1.0/cellsize; point->x = MS_MAP2IMAGE_X_IC_DBL(point->x, extent->minx, invcellsize); point->y = MS_MAP2IMAGE_Y_IC_DBL(point->y, extent->maxy, invcellsize); } /* ** Helper functions supplied as part of bug #2868 solution. Consider moving these to ** mapprimitive.c for more general use. */ /* vector difference */ static pointObj point_diff(const pointObj a, const pointObj b) { pointObj retv; retv.x = a.x-b.x; retv.y = a.y-b.y; #ifdef USE_POINT_Z_M retv.z = a.z-b.z; retv.m = a.m-b.m; #endif return retv; } /* vector sum */ static pointObj point_sum(const pointObj a, const pointObj b) { pointObj retv; retv.x = a.x+b.x; retv.y = a.y+b.y; #ifdef USE_POINT_Z_M retv.z = a.z+b.z; retv.m = a.m+b.m; #endif return retv; } /* vector multiply */ static pointObj point_mul(const pointObj a, double b) { pointObj retv; retv.x = a.x*b; retv.y = a.y*b; #ifdef USE_POINT_Z_M retv.z = a.z*b; retv.m = a.m*b; #endif return retv; } /* vector ??? */ static double point_abs2(const pointObj a) { #ifdef USE_POINT_Z_M return a.x*a.x+a.y*a.y+a.z*a.z+a.m*a.m; #else return a.x*a.x+a.y*a.y; #endif } /* vector normal */ static pointObj point_norm(const pointObj a) { double lenmul; pointObj retv; int norm_vector; norm_vector = a.x==0 && a.y==0; #ifdef USE_POINT_Z_M norm_vector = norm_vector && a.z==0 && a.m==0; #endif if (norm_vector) return a; lenmul=1.0/sqrt(point_abs2(a)); /* this seems to be the costly operation */ retv.x = a.x*lenmul; retv.y = a.y*lenmul; #ifdef USE_POINT_Z_M retv.z = a.z*lenmul; retv.m = a.m*lenmul; #endif return retv; } /* rotate a vector 90 degrees */ static pointObj point_rotz90(const pointObj a) { double nx=-1.0*a.y, ny=a.x; pointObj retv=a; retv.x=nx; retv.y=ny; return retv; } /* vector cross product (warning: z and m dimensions are ignored!) */ static double point_cross(const pointObj a, const pointObj b) { return a.x*b.y-a.y*b.x; } shapeObj *msOffsetCurve(shapeObj *p, double offset) { shapeObj *ret; int i, j, first,idx,ok=0; #if defined USE_GEOS && (GEOS_VERSION_MAJOR > 3 || (GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR >= 3)) ret = msGEOSOffsetCurve(p,offset); /* GEOS curve offsetting can fail sometimes, we continue with our own implementation if that is the case.*/ if(ret) return ret; /* clear error raised by geos in this case */ msResetErrorList(); #endif /* ** For offset corner point calculation 1/sin() is used ** to avoid 1/0 division (and long spikes) we define a ** limit for sin(). */ #define CURVE_SIN_LIMIT 0.3 ret = (shapeObj*)msSmallMalloc(sizeof(shapeObj)); msInitShape(ret); ret->numlines = p->numlines; ret->line=(lineObj*)msSmallMalloc(sizeof(lineObj)*ret->numlines); for(i=0; inumlines; i++) { ret->line[i].numpoints=p->line[i].numpoints; ret->line[i].point=(pointObj*)msSmallMalloc(sizeof(pointObj)*ret->line[i].numpoints); } for (i = 0; i < p->numlines; i++) { pointObj old_pt = {0}, old_diffdir, old_offdir; if(p->line[i].numpoints<2) { ret->line[i].numpoints = 0; continue; /* skip degenerate points */ } ok = 1; /* initialize old_offdir and old_diffdir, as gcc isn't smart enough to see that it * is not an error to do so, and prints a warning */ old_offdir.x=old_offdir.y=old_diffdir.x=old_diffdir.y = 0; idx=0; first = 1; /* saved metrics of the last processed point */ if (p->line[i].numpoints>0) old_pt=p->line[i].point[0]; for(j=1; jline[i].numpoints; j++) { const pointObj pt = p->line[i].point[j]; /* place of the point */ const pointObj diffdir = point_norm(point_diff(pt,old_pt)); /* direction of the line */ const pointObj offdir = point_rotz90(diffdir); /* direction where the distance between the line and the offset is measured */ pointObj offpt; /* this will be the corner point of the offset line */ /* offset line points computation */ if(first == 1) { /* first point */ first = 0; offpt = point_sum(old_pt,point_mul(offdir,offset)); } else { /* middle points */ /* curve is the angle of the last and the current line's direction (supplementary angle of the shape's inner angle) */ double sin_curve = point_cross(diffdir,old_diffdir); double cos_curve = point_cross(old_offdir,diffdir); if ((-1.0)*CURVE_SIN_LIMIT < sin_curve && sin_curve < CURVE_SIN_LIMIT) { /* do not calculate 1/sin, instead use a corner point approximation: average of the last and current offset direction and length */ /* ** TODO: fair for obtuse inner angles, however, positive and negative ** acute inner angles would need special handling - similar to LINECAP ** to avoid drawing of long spikes */ offpt = point_sum(old_pt, point_mul(point_sum(offdir, old_offdir),0.5*offset)); } else { double base_shift = -1.0*(1.0+cos_curve)/sin_curve; offpt = point_sum(old_pt, point_mul(point_sum(point_mul(diffdir,base_shift),offdir), offset)); } } ret->line[i].point[idx]=offpt; idx++; old_pt=pt; old_diffdir=diffdir; old_offdir=offdir; } /* last point */ if(first == 0) { pointObj offpt=point_sum(old_pt,point_mul(old_offdir,offset)); ret->line[i].point[idx]=offpt; idx++; } if(idx != p->line[i].numpoints) { /* printf("shouldn't happen :(\n"); */ ret->line[i].numpoints=idx; ret->line=msSmallRealloc(ret->line,ret->line[i].numpoints*sizeof(pointObj)); } } if(!ok) ret->numlines = 0; /* all lines where degenerate */ return ret; } shapeObj *msOffsetPolyline(shapeObj *p, double offsetx, double offsety) { int i, j; shapeObj *ret; if(offsety == MS_STYLE_SINGLE_SIDED_OFFSET) { /* complex calculations */ return msOffsetCurve(p,offsetx); } else if(offsety == MS_STYLE_DOUBLE_SIDED_OFFSET) { shapeObj *tmp1; ret = msOffsetCurve(p,offsetx/2.0); tmp1 = msOffsetCurve(p, -offsetx/2.0); for(i=0;inumlines; i++) { msAddLineDirectly(ret,tmp1->line + i); } msFreeShape(tmp1); free(tmp1); return ret; } ret = (shapeObj*)msSmallMalloc(sizeof(shapeObj)); msInitShape(ret); ret->numlines = p->numlines; ret->line=(lineObj*)msSmallMalloc(sizeof(lineObj)*ret->numlines); for(i=0; inumlines; i++) { ret->line[i].numpoints=p->line[i].numpoints; ret->line[i].point=(pointObj*)msSmallMalloc(sizeof(pointObj)*ret->line[i].numpoints); } for (i = 0; i < p->numlines; i++) { for(j=0; jline[i].numpoints; j++) { ret->line[i].point[j].x=p->line[i].point[j].x+offsetx; ret->line[i].point[j].y=p->line[i].point[j].y+offsety; } } return ret; } /* ------------------------------------------------------------------------------- msSetup() Contributed by Jerry Pisk in bug 1203. Heads off potential race condition in initializing GD font cache with multiple threads. Should be called from mapscript module initialization code. ------------------------------------------------------------------------------- */ int msSetup() { #ifdef _WIN32 char* maxfiles = getenv("MS_MAX_OPEN_FILES"); if (maxfiles) { int res = _getmaxstdio(); if (res < 2048) { res = _setmaxstdio(atoi(maxfiles)); assert(res != -1); } } #endif #ifdef USE_THREAD msThreadInit(); #endif /* Use PROJ_LIB env vars if set */ msProjLibInitFromEnv(); /* Use MS_ERRORFILE and MS_DEBUGLEVEL env vars if set */ if (msDebugInitFromEnv() != MS_SUCCESS) return MS_FAILURE; #ifdef USE_GEOS msGEOSSetup(); #endif #ifdef USE_RSVG #if !GLIB_CHECK_VERSION(2, 35, 0) g_type_init(); #endif #endif msFontCacheSetup(); return MS_SUCCESS; } /* This is intended to be a function to cleanup anything that "hangs around" when all maps are destroyed, like Registered GDAL drivers, and so forth. */ #ifndef NDEBUG #if defined(USE_LIBXML2) #include "maplibxml2.h" #endif #endif void msCleanup() { msForceTmpFileBase( NULL ); msConnPoolFinalCleanup(); /* Lexer string parsing variable */ if (msyystring_buffer != NULL) { msFree(msyystring_buffer); msyystring_buffer = NULL; } msyylex_destroy(); msOGRCleanup(); msGDALCleanup(); /* Release both GDAL and OGR resources */ msAcquireLock( TLOCK_GDAL ); #if GDAL_VERSION_MAJOR >= 3 || (GDAL_VERSION_MAJOR == 2 && GDAL_VERSION_MINOR == 4) /* Cleanup some GDAL global resources in particular */ GDALDestroy(); #else GDALDestroyDriverManager(); #endif msReleaseLock( TLOCK_GDAL ); #if PROJ_VERSION_MAJOR < 6 # if PJ_VERSION >= 480 pj_clear_initcache(); # endif pj_deallocate_grids(); #endif msSetPROJ_LIB( NULL, NULL ); msProjectionContextPoolCleanup(); #if defined(USE_CURL) msHTTPCleanup(); #endif #ifdef USE_GEOS msGEOSCleanup(); #endif /* make valgrind happy on debug code */ #ifndef NDEBUG #ifdef USE_CAIRO msCairoCleanup(); #endif #if defined(USE_LIBXML2) xmlCleanupParser(); #endif #endif msFontCacheCleanup(); msTimeCleanup(); msIO_Cleanup(); msResetErrorList(); /* Close/cleanup log/debug output. Keep this at the very end. */ msDebugCleanup(); /* Clean up the vtable factory */ msPluginFreeVirtualTableFactory(); } /************************************************************************/ /* msAlphaBlend() */ /* */ /* Function to overlay/blend an RGBA value into an existing */ /* RGBA value using the Porter-Duff "over" operator. */ /* Primarily intended for use with rasterBufferObj */ /* raster rendering. The "src" is the overlay value, and "dst" */ /* is the existing value being overlaid. dst is expected to be */ /* premultiplied, but the source should not be. */ /* */ /* NOTE: alpha_dst may be NULL. */ /************************************************************************/ void msAlphaBlend( unsigned char red_src, unsigned char green_src, unsigned char blue_src, unsigned char alpha_src, unsigned char *red_dst, unsigned char *green_dst, unsigned char *blue_dst, unsigned char *alpha_dst ) { /* -------------------------------------------------------------------- */ /* Simple cases we want to handle fast. */ /* -------------------------------------------------------------------- */ if( alpha_src == 0 ) return; if( alpha_src == 255 ) { *red_dst = red_src; *green_dst = green_src; *blue_dst = blue_src; if( alpha_dst ) *alpha_dst = 255; return; } /* -------------------------------------------------------------------- */ /* Premultiple alpha for source values now. */ /* -------------------------------------------------------------------- */ red_src = red_src * alpha_src / 255; green_src = green_src * alpha_src / 255; blue_src = blue_src * alpha_src / 255; /* -------------------------------------------------------------------- */ /* Another pretty fast case if there is nothing in the */ /* destination to mix with. */ /* -------------------------------------------------------------------- */ if( alpha_dst && *alpha_dst == 0) { *red_dst = red_src; *green_dst = green_src; *blue_dst = blue_src; *alpha_dst = alpha_src; return; } /* -------------------------------------------------------------------- */ /* Cases with actual blending. */ /* -------------------------------------------------------------------- */ if(!alpha_dst || *alpha_dst == 255) { int weight_dst = 256 - alpha_src; *red_dst = (256 * red_src + *red_dst * weight_dst) >> 8; *green_dst = (256 * green_src + *green_dst * weight_dst) >> 8; *blue_dst = (256 * blue_src + *blue_dst * weight_dst) >> 8; } else { int weight_dst = (256 - alpha_src); *red_dst = (256 * red_src + *red_dst * weight_dst) >> 8; *green_dst = (256 * green_src + *green_dst * weight_dst) >> 8; *blue_dst = (256 * blue_src + *blue_dst * weight_dst) >> 8; *alpha_dst = (256 * alpha_src + *alpha_dst * weight_dst) >> 8; } } /************************************************************************/ /* msAlphaBlendPM() */ /* */ /* Same as msAlphaBlend() except that the source RGBA is */ /* assumed to already be premultiplied. */ /************************************************************************/ void msAlphaBlendPM( unsigned char red_src, unsigned char green_src, unsigned char blue_src, unsigned char alpha_src, unsigned char *red_dst, unsigned char *green_dst, unsigned char *blue_dst, unsigned char *alpha_dst ) { /* -------------------------------------------------------------------- */ /* Simple cases we want to handle fast. */ /* -------------------------------------------------------------------- */ if( alpha_src == 0 ) return; if( alpha_src == 255 ) { *red_dst = red_src; *green_dst = green_src; *blue_dst = blue_src; if( alpha_dst ) *alpha_dst = 255; return; } /* -------------------------------------------------------------------- */ /* Another pretty fast case if there is nothing in the */ /* destination to mix with. */ /* -------------------------------------------------------------------- */ if( alpha_dst && *alpha_dst == 0) { *red_dst = red_src; *green_dst = green_src; *blue_dst = blue_src; *alpha_dst = alpha_src; return; } /* -------------------------------------------------------------------- */ /* Cases with actual blending. */ /* -------------------------------------------------------------------- */ if(!alpha_dst || *alpha_dst == 255) { int weight_dst = 255 - alpha_src; *red_dst = (alpha_src * red_src + *red_dst * weight_dst) >> 8; *green_dst = (alpha_src * green_src + *green_dst * weight_dst) >> 8; *blue_dst = (alpha_src * blue_src + *blue_dst * weight_dst) >> 8; } else { int weight_dst = (255 - alpha_src); *red_dst = (alpha_src * red_src + *red_dst * weight_dst) >> 8; *green_dst = (alpha_src * green_src + *green_dst * weight_dst) >> 8; *blue_dst = (alpha_src * blue_src + *blue_dst * weight_dst) >> 8; *alpha_dst = (255 * alpha_src + *alpha_dst * weight_dst) >> 8; } } void msRGBtoHSL(colorObj *rgb, double *h, double *s, double *l) { double r = rgb->red/255.0, g = rgb->green/255.0, b = rgb->blue/255.0; double maxv = MS_MAX(MS_MAX(r, g), b), minv = MS_MIN(MS_MIN(r, g), b); double d = maxv - minv; *h = 0, *s = 0; *l = (maxv + minv) / 2; if (maxv != minv) { *s = *l > 0.5 ? d / (2 - maxv - minv) : d / (maxv + minv); if (maxv == r) { *h = (g - b) / d + (g < b ? 6 : 0); } else if (maxv == g) { *h = (b - r) / d + 2; } else if (maxv == b) { *h = (r - g) / d + 4; } *h /= 6; } } static double hue_to_rgb(double p, double q, double t) { if(t < 0) t += 1; if(t > 1) t -= 1; if(t < 0.1666666666666666) return p + (q - p) * 6 * t; if(t < 0.5) return q; if(t < 0.6666666666666666) return p + (q - p) * (0.666666666666 - t) * 6; return p; } void msHSLtoRGB(double h, double s, double l, colorObj *rgb) { double r, g, b; if(s == 0){ r = g = b = l; } else { double q = l < 0.5 ? l * (1 + s) : l + s - l * s; double p = 2 * l - q; r = hue_to_rgb(p, q, h + 0.33333333333333333); g = hue_to_rgb(p, q, h); b = hue_to_rgb(p, q, h - 0.33333333333333333); } rgb->red = r * 255; rgb->green = g * 255; rgb->blue = b * 255; } /* RFC 24: check if the parent pointer is NULL and raise an error otherwise */ int msCheckParentPointer(void* p, char *objname) { char* msg=NULL; if (p == NULL) { if(objname != NULL) { msSetError(MS_NULLPARENTERR, "The %s parent object is null", "msCheckParentPointer()", msg); } else { msSetError(MS_NULLPARENTERR, "The parent object is null", "msCheckParentPointer()"); } return MS_FAILURE; } return MS_SUCCESS; } void msBufferInit(bufferObj *buffer) { buffer->data=NULL; buffer->size=0; buffer->available=0; buffer->_next_allocation_size = MS_DEFAULT_BUFFER_ALLOC; } void msBufferResize(bufferObj *buffer, size_t target_size) { while(buffer->available <= target_size) { buffer->data = msSmallRealloc(buffer->data,buffer->available+buffer->_next_allocation_size); buffer->available += buffer->_next_allocation_size; buffer->_next_allocation_size *= 2; } } void msBufferAppend(bufferObj *buffer, void *data, size_t length) { if(buffer->available < buffer->size+length) { msBufferResize(buffer,buffer->size+length); } memcpy(&(buffer->data[buffer->size]),data,length); buffer->size += length; } void msBufferFree(bufferObj *buffer) { if(buffer->available>0) free(buffer->data); } void msFreeRasterBuffer(rasterBufferObj *b) { switch(b->type) { case MS_BUFFER_BYTE_RGBA: msFree(b->data.rgba.pixels); b->data.rgba.pixels = NULL; break; case MS_BUFFER_BYTE_PALETTE: msFree(b->data.palette.pixels); msFree(b->data.palette.palette); b->data.palette.pixels = NULL; b->data.palette.palette = NULL; break; } } /* ** Issue #3043: Layer extent comparison short circuit. ** ** msExtentsOverlap() ** ** Returns MS_TRUE if map extent and layer extent overlap, ** MS_FALSE if they are disjoint, and MS_UNKNOWN if there is ** not enough info to calculate a deterministic answer. ** */ int msExtentsOverlap(mapObj *map, layerObj *layer) { rectObj map_extent; rectObj layer_extent; /* No extent info? Nothing we can do, return MS_UNKNOWN. */ if( (map->extent.minx == -1) && (map->extent.miny == -1) && (map->extent.maxx == -1 ) && (map->extent.maxy == -1) ) return MS_UNKNOWN; if( (layer->extent.minx == -1) && (layer->extent.miny == -1) && (layer->extent.maxx == -1 ) && (layer->extent.maxy == -1) ) return MS_UNKNOWN; /* No map projection? Let someone else sort this out. */ if( ! (map->projection.numargs > 0) ) return MS_UNKNOWN; /* No layer projection? Perform naive comparison, because they are ** in the same projection. */ if( ! (layer->projection.numargs > 0) ) return msRectOverlap( &(map->extent), &(layer->extent) ); /* In the case where map and layer projections are identical, and the */ /* bounding boxes don't cross the dateline, do simple rectangle comparison */ if( map->extent.minx < map->extent.maxx && layer->extent.minx < layer->extent.maxx && !msProjectionsDiffer(&(map->projection), &(layer->projection)) ) { return msRectOverlap( &(map->extent), &(layer->extent) ); } /* We need to transform our rectangles for comparison, ** so we will work with copies and leave the originals intact. */ MS_COPYRECT(&map_extent, &(map->extent) ); MS_COPYRECT(&layer_extent, &(layer->extent) ); /* Transform map extents into geographics for comparison. */ if( msProjectRect(&(map->projection), &(map->latlon), &map_extent) ) return MS_UNKNOWN; /* Transform layer extents into geographics for comparison. */ if( msProjectRect(&(layer->projection), &(map->latlon), &layer_extent) ) return MS_UNKNOWN; /* Simple case? Return simple answer. */ if ( map_extent.minx < map_extent.maxx && layer_extent.minx < layer_extent.maxx ) return msRectOverlap( &(map_extent), &(layer_extent) ); /* Uh oh, one of the rects crosses the dateline! ** Let someone else handle it. */ return MS_UNKNOWN; } /************************************************************************/ /* msSmallMalloc() */ /************************************************************************/ /* Safe version of malloc(). This function is taken from gdal/cpl. */ void *msSmallMalloc( size_t nSize ) { void *pReturn; if( UNLIKELY(nSize == 0) ) return NULL; pReturn = malloc( nSize ); if( UNLIKELY(pReturn == NULL) ) { msIO_fprintf(stderr, "msSmallMalloc(): Out of memory allocating %ld bytes.\n", (long) nSize ); exit(1); } return pReturn; } /************************************************************************/ /* msSmallRealloc() */ /************************************************************************/ /* Safe version of realloc(). This function is taken from gdal/cpl. */ void * msSmallRealloc( void * pData, size_t nNewSize ) { void *pReturn; if ( UNLIKELY(nNewSize == 0) ) return NULL; pReturn = realloc( pData, nNewSize ); if( UNLIKELY(pReturn == NULL) ) { msIO_fprintf(stderr, "msSmallRealloc(): Out of memory allocating %ld bytes.\n", (long)nNewSize ); exit(1); } return pReturn; } /************************************************************************/ /* msSmallCalloc() */ /************************************************************************/ /* Safe version of calloc(). This function is taken from gdal/cpl. */ void *msSmallCalloc( size_t nCount, size_t nSize ) { void *pReturn; if( UNLIKELY(nSize * nCount == 0) ) return NULL; pReturn = calloc( nCount, nSize ); if( UNLIKELY(pReturn == NULL) ) { msIO_fprintf(stderr, "msSmallCalloc(): Out of memory allocating %ld bytes.\n", (long)(nCount*nSize)); exit(1); } return pReturn; } /* ** msBuildOnlineResource() ** ** Try to build the online resource (mapserv URL) for this service. ** "http://$(SERVER_NAME):$(SERVER_PORT)$(SCRIPT_NAME)?" ** (+append the map=... param if it was explicitly passed in QUERY_STRING) ** ** Returns a newly allocated string that should be freed by the caller or ** NULL in case of error. */ char *msBuildOnlineResource(mapObj *map, cgiRequestObj *req) { char *online_resource = NULL; const char *value, *hostname, *port, *script, *protocol="http", *mapparam=NULL; char **hostname_array = NULL; int mapparam_len = 0, hostname_array_len = 0; hostname = getenv("HTTP_X_FORWARDED_HOST"); if(!hostname) hostname = getenv("SERVER_NAME"); else { if(strchr(hostname,',')) { hostname_array = msStringSplit(hostname,',', &hostname_array_len); hostname = hostname_array[0]; } } port = getenv("HTTP_X_FORWARDED_PORT"); if(!port) port = getenv("SERVER_PORT"); script = getenv("SCRIPT_NAME"); /* HTTPS is set by Apache to "on" in an HTTPS server ... if not set */ /* then check SERVER_PORT: 443 is the default https port. */ if ( ((value=getenv("HTTPS")) && strcasecmp(value, "on") == 0) || ((value=getenv("SERVER_PORT")) && atoi(value) == 443) ) { protocol = "https"; } if ( (value=getenv("HTTP_X_FORWARDED_PROTO")) ) { protocol = value; } /* If map=.. was explicitly set then we'll include it in onlineresource */ if (req->type == MS_GET_REQUEST) { int i; for(i=0; iNumParams; i++) { if (strcasecmp(req->ParamNames[i], "map") == 0) { mapparam = req->ParamValues[i]; mapparam_len = strlen(mapparam)+5; /* +5 for "map="+"&" */ break; } } } if (hostname && port && script) { size_t buffer_size; buffer_size = strlen(hostname)+strlen(port)+strlen(script)+mapparam_len+11; /* 11 comes from https://[host]:[port][scriptname]?[map]\0, i.e. "https://:?\0" */ online_resource = (char*)msSmallMalloc(buffer_size); if ((atoi(port) == 80 && strcmp(protocol, "http") == 0) || (atoi(port) == 443 && strcmp(protocol, "https") == 0) ) snprintf(online_resource, buffer_size, "%s://%s%s?", protocol, hostname, script); else snprintf(online_resource, buffer_size, "%s://%s:%s%s?", protocol, hostname, port, script); if (mapparam) { int baselen; baselen = strlen(online_resource); snprintf(online_resource+baselen, buffer_size-baselen, "map=%s&", mapparam); } } else { msSetError(MS_CGIERR, "Impossible to establish server URL.", "msBuildOnlineResource()"); return NULL; } if(hostname_array) { msFreeCharArray(hostname_array, hostname_array_len); } return online_resource; } /************************************************************************/ /* msIntegerInArray() */ /************************************************************************/ /* Check if a integer is in a array */ int msIntegerInArray(const int value, int *array, int numelements) { int i; for (i=0; iprojection.numargs <= 0) { msSetError(MS_WMSERR, "Cannot set new SRS on a map that doesn't " "have any projection set. Please make sure your mapfile " "has a PROJECTION defined at the top level.", "msTileSetProjectionst()"); return(MS_FAILURE); } for(i=0; inumlayers; i++) { layerObj *lp = GET_LAYER(map,i); /* This layer is turned on and needs a projection? */ if (lp->projection.numargs <= 0 && lp->status != MS_OFF && lp->transform == MS_TRUE) { /* Fetch main map projection string only now that we need it */ if (mapProjStr == NULL) mapProjStr = msGetProjectionString(&(map->projection)); /* Set the projection to the map file projection */ if (msLoadProjectionString(&(lp->projection), mapProjStr) != 0) { msSetError(MS_CGIERR, "Unable to set projection on layer.", "msMapSetLayerProjections()"); return(MS_FAILURE); } lp->project = MS_TRUE; if(lp->connection && IS_THIRDPARTY_LAYER_CONNECTIONTYPE(lp->connectiontype)) { char **reflayers; int numreflayers,j; reflayers = msStringSplit(lp->connection,',',&numreflayers); for(j=0; jprojection.numargs <= 0 && glp->transform == MS_TRUE) { /* Set the projection to the map file projection */ if (msLoadProjectionString(&(glp->projection), mapProjStr) != 0) { msSetError(MS_CGIERR, "Unable to set projection on layer.", "msMapSetLayerProjections()"); return(MS_FAILURE); } glp->project = MS_TRUE; } } free(lidx); } else { /* group name did not match, check by layer name */ int layer_idx = msGetLayerIndex(map,lp->connection); layerObj *glp = GET_LAYER(map,layer_idx); if (glp->projection.numargs <= 0 && glp->transform == MS_TRUE) { /* Set the projection to the map file projection */ if (msLoadProjectionString(&(glp->projection), mapProjStr) != 0) { msSetError(MS_CGIERR, "Unable to set projection on layer.", "msMapSetLayerProjections()"); return(MS_FAILURE); } glp->project = MS_TRUE; } } } msFreeCharArray(reflayers, numreflayers); } } } msFree(mapProjStr); return(MS_SUCCESS); } /************************************************************************ * msMapSetLanguageSpecificConnection * * * * Override DATA and CONNECTION of each layer with their specific * * variant for the specified language. * ************************************************************************/ void msMapSetLanguageSpecificConnection(mapObj* map, const char* validated_language) { int i; for(i=0; inumlayers; i++) { layerObj *layer = GET_LAYER(map, i); if(layer->data) layer->data = msCaseReplaceSubstring(layer->data, "%language%", validated_language); if(layer->connection) layer->connection = msCaseReplaceSubstring(layer->connection, "%language%", validated_language); } } /* Generalize a shape based of the tolerance. Ref: http://trac.osgeo.org/gdal/ticket/966 */ shapeObj* msGeneralize(shapeObj *shape, double tolerance) { lineObj newLine = {0,NULL}; const double sqTolerance = tolerance*tolerance; shapeObj* newShape = (shapeObj*)msSmallMalloc(sizeof(shapeObj)); msInitShape(newShape); msCopyShape(shape, newShape); if (shape->numlines<1) return newShape; /* Clean shape */ for (int i=0; i < newShape->numlines; i++) free(newShape->line[i].point); newShape->numlines = 0; if (newShape->line) free(newShape->line); msAddLine(newShape, &newLine); if (shape->line[0].numpoints==0) { return newShape; } msAddPointToLine(&newShape->line[0], &shape->line[0].point[0]); double dX0 = shape->line[0].point[0].x; double dY0 = shape->line[0].point[0].y; for(int i=1; iline[0].numpoints; i++) { double dX1 = shape->line[0].point[i].x; double dY1 = shape->line[0].point[i].y; const double dX = dX1-dX0; const double dY = dY1-dY0; const double dSqDist = dX*dX + dY*dY; if (i == shape->line[0].numpoints-1 || dSqDist >= sqTolerance) { pointObj p; p.x = dX1; p.y = dY1; /* Keep this point (always keep the last point) */ msAddPointToLine(&newShape->line[0], &p); dX0 = dX1; dY0 = dY1; } } return newShape; } void msSetLayerOpacity(layerObj *layer, int opacity) { if(!layer->compositer) { layer->compositer = msSmallMalloc(sizeof(LayerCompositer)); initLayerCompositer(layer->compositer); } layer->compositer->opacity = opacity; } mapserver-7.6.4/mapuvraster.c000066400000000000000000001150401407312142500162510ustar00rootroot00000000000000/********************************************************************** * $Id: mapuv.c 12629 2011-10-06 18:06:34Z aboudreault $ * * Project: MapServer * Purpose: UV Layer * Author: Alan Boudreault (aboudreault@mapgears.com) * ********************************************************************** * Copyright (c) 2011, Alan Boudreault, MapGears * * 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" #include #include #include "mapows.h" #include "mapresample.h" #include "mapthread.h" #define MSUVRASTER_NUMITEMS 6 #define MSUVRASTER_ANGLE "uv_angle" #define MSUVRASTER_ANGLEINDEX -100 #define MSUVRASTER_MINUS_ANGLE "uv_minus_angle" #define MSUVRASTER_MINUSANGLEINDEX -101 #define MSUVRASTER_LENGTH "uv_length" #define MSUVRASTER_LENGTHINDEX -102 #define MSUVRASTER_LENGTH_2 "uv_length_2" #define MSUVRASTER_LENGTH2INDEX -103 #define MSUVRASTER_U "u" #define MSUVRASTER_UINDEX -104 #define MSUVRASTER_V "v" #define MSUVRASTER_VINDEX -105 #define RQM_UNKNOWN 0 #define RQM_ENTRY_PER_PIXEL 1 #define RQM_HIST_ON_CLASS 2 #define RQM_HIST_ON_VALUE 3 typedef struct { /* query cache results */ int query_results; /* int query_alloc_max; int query_request_max; int query_result_hard_max; int raster_query_mode; */ int band_count; int refcount; /* query bound in force shapeObj *searchshape;*/ /* Only nearest result to this point. int range_mode; MS_QUERY_SINGLE, MS_QUERY_MULTIPLE or -1 (skip test) double range_dist; pointObj target_point;*/ /* double shape_tolerance; */ float **u; /* u values */ float **v; /* v values */ int width; int height; rectObj extent; int next_shape; int x, y; /* used internally in msUVRasterLayerNextShape() */ mapObj* mapToUseForWhichShapes; /* set if the map->extent and map->projection are valid in msUVRASTERLayerWhichShapes() */ } uvRasterLayerInfo; void msUVRASTERLayerUseMapExtentAndProjectionForNextWhichShapes(layerObj* layer, mapObj* map) { uvRasterLayerInfo *uvlinfo = (uvRasterLayerInfo *) layer->layerinfo; uvlinfo->mapToUseForWhichShapes = map; } static int msUVRASTERLayerInitItemInfo(layerObj *layer) { uvRasterLayerInfo *uvlinfo = (uvRasterLayerInfo *) layer->layerinfo; int i; int *itemindexes; int failed=0; if (layer->numitems == 0) return MS_SUCCESS; if( uvlinfo == NULL ) { msSetError(MS_MISCERR, "Assertion failed: GDAL layer not opened!!!", "msUVRASTERLayerInitItemInfo()"); return(MS_FAILURE); } if (layer->iteminfo) free(layer->iteminfo); if((layer->iteminfo = (int *)malloc(sizeof(int)*layer->numitems))== NULL) { msSetError(MS_MEMERR, NULL, "msUVRASTERLayerInitItemInfo()"); return(MS_FAILURE); } itemindexes = (int*)layer->iteminfo; for(i=0; inumitems; i++) { /* Special case for handling text string and angle coming from */ /* OGR style strings. We use special attribute snames. */ if (EQUAL(layer->items[i], MSUVRASTER_ANGLE)) itemindexes[i] = MSUVRASTER_ANGLEINDEX; else if (EQUAL(layer->items[i], MSUVRASTER_MINUS_ANGLE)) itemindexes[i] = MSUVRASTER_MINUSANGLEINDEX; else if (EQUAL(layer->items[i], MSUVRASTER_LENGTH)) itemindexes[i] = MSUVRASTER_LENGTHINDEX; else if (EQUAL(layer->items[i], MSUVRASTER_LENGTH_2)) itemindexes[i] = MSUVRASTER_LENGTH2INDEX; else if (EQUAL(layer->items[i], MSUVRASTER_U)) itemindexes[i] = MSUVRASTER_UINDEX; else if (EQUAL(layer->items[i], MSUVRASTER_V)) itemindexes[i] = MSUVRASTER_VINDEX; else { itemindexes[i] = -1; msSetError(MS_OGRERR, "Invalid Field name: %s", "msUVRASTERLayerInitItemInfo()", layer->items[i]); failed=1; } } return failed ? (MS_FAILURE) : (MS_SUCCESS); } void msUVRASTERLayerFreeItemInfo(layerObj *layer) { if (layer->iteminfo) free(layer->iteminfo); layer->iteminfo = NULL; } static void msUVRasterLayerInfoInitialize(layerObj *layer) { uvRasterLayerInfo *uvlinfo = (uvRasterLayerInfo *) layer->layerinfo; if( uvlinfo != NULL ) return; uvlinfo = (uvRasterLayerInfo *) msSmallCalloc(1,sizeof(uvRasterLayerInfo)); layer->layerinfo = uvlinfo; uvlinfo->band_count = -1; /* uvlinfo->raster_query_mode = RQM_ENTRY_PER_PIXEL; */ /* uvlinfo->range_mode = -1; /\* inactive *\/ */ /* uvlinfo->refcount = 0; */ /* uvlinfo->shape_tolerance = 0.0; */ uvlinfo->u = NULL; uvlinfo->v = NULL; uvlinfo->width = 0; uvlinfo->height = 0; /* Set attribute type to Real, unless the user has explicitly set */ /* something else. */ { const char* const items[] = { MSUVRASTER_ANGLE, MSUVRASTER_MINUS_ANGLE, MSUVRASTER_LENGTH, MSUVRASTER_LENGTH_2, MSUVRASTER_U, MSUVRASTER_V, }; size_t i; for( i = 0; i < sizeof(items)/sizeof(items[0]); ++i ) { char szTmp[100]; snprintf(szTmp, sizeof(szTmp), "%s_type", items[i]); if (msOWSLookupMetadata(&(layer->metadata), "OFG", szTmp) == NULL) { snprintf(szTmp, sizeof(szTmp), "gml_%s_type", items[i]); msInsertHashTable(&(layer->metadata), szTmp, "Real"); } } } /* uvlinfo->query_result_hard_max = 1000000; */ /* if( CSLFetchNameValue( layer->processing, "RASTER_QUERY_MAX_RESULT" ) */ /* != NULL ) */ /* { */ /* uvlinfo->query_result_hard_max = */ /* atoi(CSLFetchNameValue( layer->processing, "RASTER_QUERY_MAX_RESULT" )); */ /* } */ } static void msUVRasterLayerInfoFree( layerObj *layer ) { uvRasterLayerInfo *uvlinfo = (uvRasterLayerInfo *) layer->layerinfo; int i; if( uvlinfo == NULL ) return; if (uvlinfo->u) { for (i=0; iwidth; ++i) { free(uvlinfo->u[i]); } free(uvlinfo->u); } if (uvlinfo->v) { for (i=0; iwidth; ++i) { free(uvlinfo->v[i]); } free(uvlinfo->v); } free( uvlinfo ); layer->layerinfo = NULL; } int msUVRASTERLayerOpen(layerObj *layer) { uvRasterLayerInfo *uvlinfo; /* If we don't have info, initialize an empty one now */ if( layer->layerinfo == NULL ) msUVRasterLayerInfoInitialize( layer ); uvlinfo = (uvRasterLayerInfo *) layer->layerinfo; uvlinfo->refcount = uvlinfo->refcount + 1; return MS_SUCCESS; } int msUVRASTERLayerIsOpen(layerObj *layer) { if (layer->layerinfo) return MS_TRUE; return MS_FALSE; } int msUVRASTERLayerClose(layerObj *layer) { uvRasterLayerInfo *uvlinfo = (uvRasterLayerInfo *) layer->layerinfo; if( uvlinfo != NULL ) { uvlinfo->refcount--; if( uvlinfo->refcount < 1 ) msUVRasterLayerInfoFree( layer ); } return MS_SUCCESS; } int msUVRASTERLayerGetItems(layerObj *layer) { uvRasterLayerInfo *uvlinfo = (uvRasterLayerInfo *) layer->layerinfo; if( uvlinfo == NULL ) return MS_FAILURE; layer->numitems = 0; layer->items = (char **) msSmallCalloc(sizeof(char *),10);; layer->items[layer->numitems++] = msStrdup(MSUVRASTER_ANGLE); layer->items[layer->numitems++] = msStrdup(MSUVRASTER_MINUS_ANGLE); layer->items[layer->numitems++] = msStrdup(MSUVRASTER_LENGTH); layer->items[layer->numitems++] = msStrdup(MSUVRASTER_LENGTH_2); layer->items[layer->numitems++] = msStrdup(MSUVRASTER_U); layer->items[layer->numitems++] = msStrdup(MSUVRASTER_V); layer->items[layer->numitems] = NULL; return msUVRASTERLayerInitItemInfo(layer); } /********************************************************************** * msUVRASTERGetValues() * * Special attribute names are used to return some UV params: uv_angle, * uv_length, u and v. **********************************************************************/ static char **msUVRASTERGetValues(layerObj *layer, float *u, float *v) { char **values; int i = 0; char tmp[100]; float size_scale; int *itemindexes = (int*)layer->iteminfo; if(layer->numitems == 0) return(NULL); if(!layer->iteminfo) { /* Should not happen... but just in case! */ if (msUVRASTERLayerInitItemInfo(layer) != MS_SUCCESS) return NULL; itemindexes = (int*)layer->iteminfo; /* reassign after malloc */ } if((values = (char **)malloc(sizeof(char *)*layer->numitems)) == NULL) { msSetError(MS_MEMERR, NULL, "msUVRASTERGetValues()"); return(NULL); } /* -------------------------------------------------------------------- */ /* Determine desired size_scale. Default to 1 if not otherwise set */ /* -------------------------------------------------------------------- */ size_scale = 1; if( CSLFetchNameValue( layer->processing, "UV_SIZE_SCALE" ) != NULL ) { size_scale = atof(CSLFetchNameValue( layer->processing, "UV_SIZE_SCALE" )); } for(i=0; inumitems; i++) { if (itemindexes[i] == MSUVRASTER_ANGLEINDEX) { snprintf(tmp, 100, "%f", (atan2((double)*v, (double)*u) * 180 / MS_PI)); values[i] = msStrdup(tmp); } else if (itemindexes[i] == MSUVRASTER_MINUSANGLEINDEX) { double minus_angle; minus_angle = (atan2((double)*v, (double)*u) * 180 / MS_PI)+180; if (minus_angle >= 360) minus_angle -= 360; snprintf(tmp, 100, "%f", minus_angle); values[i] = msStrdup(tmp); } else if ( (itemindexes[i] == MSUVRASTER_LENGTHINDEX) || (itemindexes[i] == MSUVRASTER_LENGTH2INDEX) ) { float length = sqrt((*u**u)+(*v**v))*size_scale; if (itemindexes[i] == MSUVRASTER_LENGTHINDEX) snprintf(tmp, 100, "%f", length); else snprintf(tmp, 100, "%f", length/2); values[i] = msStrdup(tmp); } else if (itemindexes[i] == MSUVRASTER_UINDEX) { snprintf(tmp, 100, "%f",*u); values[i] = msStrdup(tmp); } else if (itemindexes[i] == MSUVRASTER_VINDEX) { snprintf(tmp, 100, "%f",*v); values[i] = msStrdup(tmp); } else { values[i] = NULL; } } return values; } rectObj msUVRASTERGetSearchRect( layerObj* layer, mapObj* map ) { rectObj searchrect = map->extent; int bDone = MS_FALSE; /* For UVRaster, it is important that the searchrect is not too large */ /* to avoid insufficient intermediate raster resolution, which could */ /* happen if we use the default code path, given potential reprojection */ /* issues when using a map extent that is not in the validity area of */ /* the layer projection. */ if( !layer->projection.gt.need_geotransform && !(msProjIsGeographicCRS(&(map->projection)) && msProjIsGeographicCRS(&(layer->projection))) ) { rectObj layer_ori_extent; if( msLayerGetExtent(layer, &layer_ori_extent) == MS_SUCCESS ) { projectionObj map_proj; double map_extent_minx = map->extent.minx; double map_extent_miny = map->extent.miny; double map_extent_maxx = map->extent.maxx; double map_extent_maxy = map->extent.maxy; rectObj layer_extent = layer_ori_extent; /* Create a variant of map->projection without geotransform for */ /* conveniency */ msInitProjection(&map_proj); msCopyProjection(&map_proj, &map->projection); map_proj.gt.need_geotransform = MS_FALSE; if( map->projection.gt.need_geotransform ) { map_extent_minx = map->projection.gt.geotransform[0] + map->projection.gt.geotransform[1] * map->extent.minx + map->projection.gt.geotransform[2] * map->extent.miny; map_extent_miny = map->projection.gt.geotransform[3] + map->projection.gt.geotransform[4] * map->extent.minx + map->projection.gt.geotransform[5] * map->extent.miny; map_extent_maxx = map->projection.gt.geotransform[0] + map->projection.gt.geotransform[1] * map->extent.maxx + map->projection.gt.geotransform[2] * map->extent.maxy; map_extent_maxy = map->projection.gt.geotransform[3] + map->projection.gt.geotransform[4] * map->extent.maxx + map->projection.gt.geotransform[5] * map->extent.maxy; } /* Reproject layer extent to map projection */ msProjectRect(&layer->projection, &map_proj, &layer_extent); if( layer_extent.minx <= map_extent_minx && layer_extent.miny <= map_extent_miny && layer_extent.maxx >= map_extent_maxx && layer_extent.maxy >= map_extent_maxy ) { /* do nothing special if area to map is inside layer extent */ } else { if( layer_extent.minx >= map_extent_minx && layer_extent.maxx <= map_extent_maxx && layer_extent.miny >= map_extent_miny && layer_extent.maxy <= map_extent_maxy ) { /* if the area to map is larger than the layer extent, then */ /* use full layer extent and add some margin to reflect the */ /* proportion of the useful area over the requested bbox */ double extra_x = (map_extent_maxx - map_extent_minx) / (layer_extent.maxx - layer_extent.minx) * (layer_ori_extent.maxx - layer_ori_extent.minx); double extra_y = (map_extent_maxy - map_extent_miny) / (layer_extent.maxy - layer_extent.miny) * (layer_ori_extent.maxy - layer_ori_extent.miny); searchrect.minx = layer_ori_extent.minx - extra_x / 2; searchrect.maxx = layer_ori_extent.maxx + extra_x / 2; searchrect.miny = layer_ori_extent.miny - extra_y / 2; searchrect.maxy = layer_ori_extent.maxy + extra_y / 2; } else { /* otherwise clip the map extent with the reprojected layer */ /* extent */ searchrect.minx = MS_MAX( map_extent_minx, layer_extent.minx ); searchrect.maxx = MS_MIN( map_extent_maxx, layer_extent.maxx ); searchrect.miny = MS_MAX( map_extent_miny, layer_extent.miny ); searchrect.maxy = MS_MIN( map_extent_maxy, layer_extent.maxy ); /* and reproject into the layer projection */ msProjectRect(&map_proj, &layer->projection, &searchrect); } bDone = MS_TRUE; } msFreeProjection(&map_proj); } } if( !bDone ) msProjectRect(&map->projection, &layer->projection, &searchrect); /* project the searchrect to source coords */ return searchrect; } int msUVRASTERLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) { uvRasterLayerInfo *uvlinfo = (uvRasterLayerInfo *) layer->layerinfo; imageObj *image_tmp; outputFormatObj *outputformat = NULL; mapObj *map_tmp; double map_cellsize; unsigned int spacing; int width, height, u_src_off, v_src_off, i, x, y; char **alteredProcessing = NULL, *saved_layer_mask; char **savedProcessing = NULL; int bHasLonWrap = MS_FALSE; double dfLonWrap = 0.0; rectObj oldLayerExtent = {0}; char* oldLayerData = NULL; projectionObj oldLayerProjection={0}; int ret; if (layer->debug) msDebug("Entering msUVRASTERLayerWhichShapes().\n"); if( uvlinfo == NULL ) return MS_FAILURE; if( CSLFetchNameValue( layer->processing, "BANDS" ) == NULL ) { msSetError( MS_MISCERR, "BANDS processing option is required for UV layer. You have to specified 2 bands.", "msUVRASTERLayerWhichShapes()" ); return MS_FAILURE; } /* ** Allocate mapObj structure */ map_tmp = (mapObj *)msSmallCalloc(sizeof(mapObj),1); if(initMap(map_tmp) == -1) { /* initialize this map */ msFree(map_tmp); return(MS_FAILURE); } /* -------------------------------------------------------------------- */ /* Determine desired spacing. Default to 32 if not otherwise set */ /* -------------------------------------------------------------------- */ spacing = 32; if( CSLFetchNameValue( layer->processing, "UV_SPACING" ) != NULL ) { spacing = atoi(CSLFetchNameValue( layer->processing, "UV_SPACING" )); } width = (int)ceil(layer->map->width/spacing); height = (int)ceil(layer->map->height/spacing); /* Initialize our dummy map */ MS_INIT_COLOR(map_tmp->imagecolor, 255,255,255,255); map_tmp->resolution = layer->map->resolution; map_tmp->defresolution = layer->map->defresolution; outputformat = (outputFormatObj *) msSmallCalloc(1,sizeof(outputFormatObj)); outputformat->bands = uvlinfo->band_count = 2; outputformat->name = NULL; outputformat->driver = NULL; outputformat->refcount = 0; outputformat->vtable = NULL; outputformat->device = NULL; outputformat->renderer = MS_RENDER_WITH_RAWDATA; outputformat->imagemode = MS_IMAGEMODE_FLOAT32; msAppendOutputFormat(map_tmp, outputformat); msCopyHashTable(&map_tmp->configoptions, &layer->map->configoptions); map_tmp->mappath = msStrdup(layer->map->mappath); map_tmp->shapepath = msStrdup(layer->map->shapepath); map_tmp->gt.rotation_angle = 0.0; /* Custom msCopyProjection() that removes lon_wrap parameter */ { int i; map_tmp->projection.numargs = 0; map_tmp->projection.gt = layer->projection.gt; map_tmp->projection.automatic = layer->projection.automatic; for (i = 0; i < layer->projection.numargs; i++) { if( strncmp(layer->projection.args[i], "lon_wrap=", strlen("lon_wrap=")) == 0 ) { bHasLonWrap = MS_TRUE; dfLonWrap = atof( layer->projection.args[i] + strlen("lon_wrap=") ); } else { map_tmp->projection.args[map_tmp->projection.numargs ++] = msStrdup(layer->projection.args[i]); } } if (map_tmp->projection.numargs != 0) { msProcessProjection(&(map_tmp->projection)); } map_tmp->projection.wellknownprojection = layer->projection.wellknownprojection; } /* Very special case to improve quality for rasters referenced from lon=0 to 360 */ /* We create a temporary VRT that swiches the 2 hemispheres, and then we */ /* modify the georeferncing to be in the more standard [-180, 180] range */ /* and we adjust the layer->data, extent and projection accordingly */ if( layer->tileindex == NULL && uvlinfo->mapToUseForWhichShapes && bHasLonWrap && dfLonWrap == 180.0 ) { rectObj layerExtent; msLayerGetExtent(layer, &layerExtent); if( layerExtent.minx == 0 && layerExtent.maxx == 360 ) { GDALDatasetH hDS = NULL; char* decrypted_path; if( strncmp(layer->data, "data); } else { char szPath[MS_MAXPATHLEN]; msTryBuildPath3(szPath, layer->map->mappath, layer->map->shapepath, layer->data); decrypted_path = msDecryptStringTokens( layer->map, szPath ); } if( decrypted_path ) { char** connectionoptions; GDALAllRegister(); connectionoptions = msGetStringListFromHashTable(&(layer->connectionoptions)); hDS = GDALOpenEx(decrypted_path, GDAL_OF_RASTER, NULL, (const char* const*)connectionoptions, NULL); CSLDestroy(connectionoptions); } if( hDS != NULL ) { int iBand; int nXSize = GDALGetRasterXSize( hDS ); int nYSize = GDALGetRasterYSize( hDS ); int nBands = GDALGetRasterCount( hDS ); int nMaxLen = 100 + nBands * (800 + 2 * strlen(decrypted_path)); int nOffset = 0; char* pszInlineVRT = msSmallMalloc( nMaxLen ); snprintf(pszInlineVRT, nMaxLen, "", nXSize, nYSize); nOffset = strlen(pszInlineVRT); for( iBand = 1; iBand <= nBands; iBand++ ) { const char* pszDataType = "Byte"; switch( GDALGetRasterDataType(GDALGetRasterBand(hDS, iBand)) ) { case GDT_Byte: pszDataType = "Byte"; break; case GDT_Int16: pszDataType = "Int16"; break; case GDT_UInt16: pszDataType = "UInt16"; break; case GDT_Int32: pszDataType = "Int32"; break; case GDT_UInt32: pszDataType = "UInt32"; break; case GDT_Float32: pszDataType = "Float32"; break; case GDT_Float64: pszDataType = "Float64"; break; default: break; } snprintf( pszInlineVRT + nOffset, nMaxLen - nOffset, " " " " " " " %d" " " " " " " " " " " " %d" " " " " " " " ", pszDataType, iBand, decrypted_path, iBand, nXSize / 2, 0, nXSize - nXSize / 2, nYSize, 0, 0, nXSize - nXSize / 2, nYSize, decrypted_path, iBand, 0, 0, nXSize / 2, nYSize, nXSize - nXSize / 2, 0, nXSize / 2, nYSize ); nOffset += strlen(pszInlineVRT + nOffset); } snprintf(pszInlineVRT + nOffset, nMaxLen - nOffset, ""); oldLayerExtent = layer->extent; oldLayerData = layer->data; oldLayerProjection = layer->projection; layer->extent.minx = -180; layer->extent.maxx = 180; layer->data = pszInlineVRT; layer->projection = map_tmp->projection; /* map_tmp->projection is actually layer->projection without lon_wrap */ rect = uvlinfo->mapToUseForWhichShapes->extent; msProjectRect(&uvlinfo->mapToUseForWhichShapes->projection, &map_tmp->projection, &rect); bHasLonWrap = MS_FALSE; GDALClose(hDS); } msFree( decrypted_path ); } } if( isQuery ) { /* For query mode, use layer->map->extent reprojected rather than */ /* the provided rect. Generic query code will filter returned features. */ rect = msUVRASTERGetSearchRect(layer, layer->map); } map_cellsize = MS_MAX(MS_CELLSIZE(rect.minx, rect.maxx,layer->map->width), MS_CELLSIZE(rect.miny,rect.maxy,layer->map->height)); map_tmp->cellsize = map_cellsize*spacing; map_tmp->extent.minx = rect.minx-(0.5*map_cellsize)+(0.5*map_tmp->cellsize); map_tmp->extent.miny = rect.miny-(0.5*map_cellsize)+(0.5*map_tmp->cellsize); map_tmp->extent.maxx = map_tmp->extent.minx+((width-1)*map_tmp->cellsize); map_tmp->extent.maxy = map_tmp->extent.miny+((height-1)*map_tmp->cellsize); if( bHasLonWrap && dfLonWrap == 180.0) { if( map_tmp->extent.minx >= 180 ) { /* Request on the right half of the shifted raster (= western hemisphere) */ map_tmp->extent.minx -= 360; map_tmp->extent.maxx -= 360; } else if( map_tmp->extent.maxx >= 180.0 ) { /* Request spanning on the 2 hemispheres => drawing whole planet */ /* Take only into account vertical resolution, as horizontal one */ /* will be unreliable (assuming square pixels...) */ map_cellsize = MS_CELLSIZE(rect.miny,rect.maxy,layer->map->height); map_tmp->cellsize = map_cellsize*spacing; width = 360.0 / map_tmp->cellsize; map_tmp->extent.minx = -180.0+(0.5*map_tmp->cellsize); map_tmp->extent.maxx = 180.0-(0.5*map_tmp->cellsize); } } if (layer->debug) msDebug("msUVRASTERLayerWhichShapes(): width: %d, height: %d, cellsize: %g\n", width, height, map_tmp->cellsize); if (layer->debug == 5) msDebug("msUVRASTERLayerWhichShapes(): extent: %g %g %g %g\n", map_tmp->extent.minx, map_tmp->extent.miny, map_tmp->extent.maxx, map_tmp->extent.maxy); /* important to use that function, to compute map geotransform, used by the resampling*/ msMapSetSize(map_tmp, width, height); if (layer->debug == 5) msDebug("msUVRASTERLayerWhichShapes(): geotransform: %g %g %g %g %g %g\n", map_tmp->gt.geotransform[0], map_tmp->gt.geotransform[1], map_tmp->gt.geotransform[2], map_tmp->gt.geotransform[3], map_tmp->gt.geotransform[4], map_tmp->gt.geotransform[5]); uvlinfo->extent = map_tmp->extent; image_tmp = msImageCreate(width, height, map_tmp->outputformatlist[0], NULL, NULL, map_tmp->resolution, map_tmp->defresolution, &(map_tmp->imagecolor)); /* Default set to AVERAGE resampling */ if( CSLFetchNameValue( layer->processing, "RESAMPLE" ) == NULL ) { alteredProcessing = CSLDuplicate( layer->processing ); alteredProcessing = CSLSetNameValue( alteredProcessing, "RESAMPLE", "AVERAGE"); savedProcessing = layer->processing; layer->processing = alteredProcessing; } /* disable masking at this level: we don't want to apply the mask at the raster level, * it will be applied with the correct cellsize and image size in the vector rendering * phase. */ saved_layer_mask = layer->mask; layer->mask = NULL; ret = msDrawRasterLayerLow(map_tmp, layer, image_tmp, NULL ); /* restore layer attributes if we went through the above on-the-fly VRT */ if( oldLayerData ) { msFree(layer->data); layer->data = oldLayerData; layer->extent = oldLayerExtent; layer->projection = oldLayerProjection; } /* restore layer mask */ layer->mask = saved_layer_mask; /* restore the saved processing */ if (alteredProcessing != NULL) { layer->processing = savedProcessing; CSLDestroy(alteredProcessing); } if( ret == MS_FAILURE) { msSetError(MS_MISCERR, "Unable to draw raster data.", "msUVRASTERLayerWhichShapes()"); msFreeMap(map_tmp); msFreeImage(image_tmp); return MS_FAILURE; } /* free old query arrays */ if (uvlinfo->u) { for (i=0; iwidth; ++i) { free(uvlinfo->u[i]); } free(uvlinfo->u); } if (uvlinfo->v) { for (i=0; iwidth; ++i) { free(uvlinfo->v[i]); } free(uvlinfo->v); } /* Update our uv layer structure */ uvlinfo->width = width; uvlinfo->height = height; uvlinfo->query_results = width*height; uvlinfo->u = (float **)msSmallMalloc(sizeof(float *)*width); uvlinfo->v = (float **)msSmallMalloc(sizeof(float *)*width); for (x = 0; x < width; ++x) { uvlinfo->u[x] = (float *)msSmallMalloc(height * sizeof(float)); uvlinfo->v[x] = (float *)msSmallMalloc(height * sizeof(float)); for (y = 0; y < height; ++y) { u_src_off = v_src_off = x + y * width; v_src_off += width*height; uvlinfo->u[x][y] = image_tmp->img.raw_float[u_src_off]; uvlinfo->v[x][y] = image_tmp->img.raw_float[v_src_off]; /* null vector? update the number of results */ if (uvlinfo->u[x][y] == 0 && uvlinfo->v[x][y] == 0) --uvlinfo->query_results; } } msFreeImage(image_tmp); /* we do not need the imageObj anymore */ msFreeMap(map_tmp); uvlinfo->next_shape = 0; return MS_SUCCESS; } int msUVRASTERLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) { uvRasterLayerInfo *uvlinfo = (uvRasterLayerInfo *) layer->layerinfo; lineObj line ; pointObj point; int i, j, k, x=0, y=0; long shapeindex = record->shapeindex; msFreeShape(shape); shape->type = MS_SHAPE_NULL; if( shapeindex < 0 || shapeindex >= uvlinfo->query_results ) { msSetError(MS_MISCERR, "Out of range shape index requested. Requested %ld\n" "but only %d shapes available.", "msUVRASTERLayerGetShape()", shapeindex, uvlinfo->query_results ); return MS_FAILURE; } /* loop to the next non null vector */ k = 0; for (i=0, x=-1; iwidth && k<=shapeindex; ++i, ++x) { for (j=0, y=-1; jheight && k<=shapeindex; ++j, ++k, ++y) { if (uvlinfo->u[i][j] == 0 && uvlinfo->v[i][j] == 0) --k; } } point.x = Pix2Georef(x, 0, uvlinfo->width-1, uvlinfo->extent.minx, uvlinfo->extent.maxx, MS_FALSE); point.y = Pix2Georef(y, 0, uvlinfo->height-1, uvlinfo->extent.miny, uvlinfo->extent.maxy, MS_TRUE); if (layer->debug == 5) msDebug("msUVRASTERLayerWhichShapes(): shapeindex: %ld, x: %g, y: %g\n", shapeindex, point.x, point.y); #ifdef USE_POINT_Z_M point.m = 0.0; #endif shape->type = MS_SHAPE_POINT; line.numpoints = 1; line.point = &point; msAddLine( shape, &line ); msComputeBounds( shape ); shape->numvalues = layer->numitems; shape->values = msUVRASTERGetValues(layer, &uvlinfo->u[x][y], &uvlinfo->v[x][y]); shape->index = shapeindex; shape->resultindex = shapeindex; return MS_SUCCESS; } int msUVRASTERLayerNextShape(layerObj *layer, shapeObj *shape) { uvRasterLayerInfo *uvlinfo = (uvRasterLayerInfo *) layer->layerinfo; if( uvlinfo->next_shape < 0 || uvlinfo->next_shape >= uvlinfo->query_results ) { msFreeShape(shape); shape->type = MS_SHAPE_NULL; return MS_DONE; } else { resultObj record; record.shapeindex = uvlinfo->next_shape++; record.tileindex = 0; record.classindex = record.resultindex = -1; return msUVRASTERLayerGetShape( layer, shape, &record); } } /************************************************************************/ /* msUVRASTERLayerGetExtent() */ /* Simple copy of the maprasterquery.c file. might change in the future */ /************************************************************************/ int msUVRASTERLayerGetExtent(layerObj *layer, rectObj *extent) { char szPath[MS_MAXPATHLEN]; mapObj *map = layer->map; shapefileObj *tileshpfile; int tilelayerindex = -1; if( (!layer->data || strlen(layer->data) == 0) && layer->tileindex == NULL) { /* should we be issuing a specific error about not supporting extents for tileindexed raster layers? */ return MS_FAILURE; } if( map == NULL ) return MS_FAILURE; /* If the layer use a tileindex, return the extent of the tileindex shapefile/referenced layer */ if (layer->tileindex) { tilelayerindex = msGetLayerIndex(map, layer->tileindex); if(tilelayerindex != -1) /* does the tileindex reference another layer */ return msLayerGetExtent(GET_LAYER(map, tilelayerindex), extent); else { tileshpfile = (shapefileObj *) malloc(sizeof(shapefileObj)); MS_CHECK_ALLOC(tileshpfile, sizeof(shapefileObj), MS_FAILURE); if(msShapefileOpen(tileshpfile, "rb", msBuildPath3(szPath, map->mappath, map->shapepath, layer->tileindex), MS_TRUE) == -1) if(msShapefileOpen(tileshpfile, "rb", msBuildPath(szPath, map->mappath, layer->tileindex), MS_TRUE) == -1) return MS_FAILURE; *extent = tileshpfile->bounds; msShapefileClose(tileshpfile); free(tileshpfile); return MS_SUCCESS; } } msTryBuildPath3(szPath, map->mappath, map->shapepath, layer->data); char* decrypted_path = msDecryptStringTokens( map, szPath ); if( !decrypted_path ) return MS_FAILURE; GDALAllRegister(); char** connectionoptions = msGetStringListFromHashTable(&(layer->connectionoptions)); GDALDatasetH hDS = GDALOpenEx(decrypted_path, GDAL_OF_RASTER, NULL, (const char* const*)connectionoptions, NULL); CSLDestroy(connectionoptions); msFree( decrypted_path ); if( hDS == NULL ) { return MS_FAILURE; } const int nXSize = GDALGetRasterXSize( hDS ); const int nYSize = GDALGetRasterYSize( hDS ); double adfGeoTransform[6] = {0}; const CPLErr eErr = GDALGetGeoTransform( hDS, adfGeoTransform ); if( eErr != CE_None ) { GDALClose( hDS ); return MS_FAILURE; } /* If this appears to be an ungeoreferenced raster than flip it for mapservers purposes. */ if( adfGeoTransform[5] == 1.0 && adfGeoTransform[3] == 0.0 ) { adfGeoTransform[5] = -1.0; adfGeoTransform[3] = nYSize; } extent->minx = adfGeoTransform[0]; extent->maxy = adfGeoTransform[3]; extent->maxx = adfGeoTransform[0] + nXSize * adfGeoTransform[1]; extent->miny = adfGeoTransform[3] + nYSize * adfGeoTransform[5]; return MS_SUCCESS; } /************************************************************************/ /* msUVRASTERLayerSetTimeFilter() */ /* */ /* This function is actually just used in the context of */ /* setting a filter on the tileindex for time based queries. */ /* For instance via WMS requests. So it isn't really related */ /* to the "raster query" support at all. */ /* */ /* If a local shapefile tileindex is in use, we will set a */ /* backtics filter (shapefile compatible). If another layer is */ /* being used as the tileindex then we will forward the */ /* SetTimeFilter call to it. If there is no tileindex in */ /* place, we do nothing. */ /************************************************************************/ int msUVRASTERLayerSetTimeFilter(layerObj *layer, const char *timestring, const char *timefield) { int tilelayerindex; /* -------------------------------------------------------------------- */ /* If we don't have a tileindex the time filter has no effect. */ /* -------------------------------------------------------------------- */ if( layer->tileindex == NULL ) return MS_SUCCESS; /* -------------------------------------------------------------------- */ /* Find the tileindex layer. */ /* -------------------------------------------------------------------- */ tilelayerindex = msGetLayerIndex(layer->map, layer->tileindex); /* -------------------------------------------------------------------- */ /* If we are using a local shapefile as our tileindex (that is */ /* to say, the tileindex name is not of another layer), then we */ /* just install a backtics style filter on the raster layer. */ /* This is propogated to the "working layer" created for the */ /* tileindex by code in mapraster.c. */ /* -------------------------------------------------------------------- */ if( tilelayerindex == -1 ) return msLayerMakeBackticsTimeFilter( layer, timestring, timefield ); /* -------------------------------------------------------------------- */ /* Otherwise we invoke the tileindex layers SetTimeFilter */ /* method. */ /* -------------------------------------------------------------------- */ if ( msCheckParentPointer(layer->map,"map")==MS_FAILURE ) return MS_FAILURE; return msLayerSetTimeFilter( layer->GET_LAYER(map,tilelayerindex), timestring, timefield ); } /************************************************************************/ /* msRASTERLayerInitializeVirtualTable() */ /************************************************************************/ int msUVRASTERLayerInitializeVirtualTable(layerObj *layer) { assert(layer != NULL); assert(layer->vtable != NULL); layer->vtable->LayerInitItemInfo = msUVRASTERLayerInitItemInfo; layer->vtable->LayerFreeItemInfo = msUVRASTERLayerFreeItemInfo; layer->vtable->LayerOpen = msUVRASTERLayerOpen; layer->vtable->LayerIsOpen = msUVRASTERLayerIsOpen; layer->vtable->LayerWhichShapes = msUVRASTERLayerWhichShapes; layer->vtable->LayerNextShape = msUVRASTERLayerNextShape; layer->vtable->LayerGetShape = msUVRASTERLayerGetShape; /* layer->vtable->LayerGetShapeCount, use default */ layer->vtable->LayerClose = msUVRASTERLayerClose; layer->vtable->LayerGetItems = msUVRASTERLayerGetItems; layer->vtable->LayerGetExtent = msUVRASTERLayerGetExtent; /* layer->vtable->LayerGetAutoStyle, use default */ /* layer->vtable->LayerApplyFilterToLayer, use default */ /* layer->vtable->LayerCloseConnection = msUVRASTERLayerClose; */ /* we use backtics for proper tileindex shapefile functioning */ layer->vtable->LayerSetTimeFilter = msUVRASTERLayerSetTimeFilter; /* layer->vtable->LayerCreateItems, use default */ /* layer->vtable->LayerGetNumFeatures, use default */ return MS_SUCCESS; } mapserver-7.6.4/mapv8.cpp000066400000000000000000000300651407312142500152760ustar00rootroot00000000000000/********************************************************************** * * Project: MapServer * Purpose: V8 JavaScript Engine Support * Author: Alan Boudreault (aboudreault@mapgears.com) * ********************************************************************** * Copyright (c) 2013, Alan Boudreault, MapGears * * 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-config.h" #ifdef USE_V8_MAPSCRIPT #include "mapserver.h" #include "v8_mapscript.h" /* This file could be refactored in the future to encapsulate the global functions and internal use functions in a class. */ /* Handler for Javascript Exceptions. Not exposed to JavaScript, used internally. Most of the code from v8 shell example. */ void msV8ReportException(TryCatch* try_catch, const char *msg = "") { HandleScope handle_scope; if (!try_catch || !try_catch->HasCaught()) { msSetError(MS_V8ERR, "%s.", "msV8ReportException()", msg); return; } String::Utf8Value exception(try_catch->Exception()); const char* exception_string = *exception; Handle message = try_catch->Message(); if (message.IsEmpty()) { msSetError(MS_V8ERR, "Javascript Exception: %s.", "msV8ReportException()", exception_string); } else { String::Utf8Value filename(message->GetScriptResourceName()); const char* filename_string = *filename; int linenum = message->GetLineNumber(); msSetError(MS_V8ERR, "Javascript Exception: %s:%i: %s", "msV8ReportException()", filename_string, linenum, exception_string); String::Utf8Value sourceline(message->GetSourceLine()); const char* sourceline_string = *sourceline; msSetError(MS_V8ERR, "Exception source line: %s", "msV8ReportException()", sourceline_string); String::Utf8Value stack_trace(try_catch->StackTrace()); if (stack_trace.length() > 0) { const char* stack_trace_string = *stack_trace; msSetError(MS_V8ERR, "Exception StackTrace: %s", "msV8ReportException()", stack_trace_string); } } } /* This function load a javascript file in memory. */ static Handle msV8ReadFile(V8Context *v8context, const char *path) { FILE* file = fopen(path, "rb"); if (file == NULL) { char err[MS_MAXPATHLEN+21]; sprintf(err, "Error opening file: %s", path); msV8ReportException(NULL, err); return Handle(String::New("")); } fseek(file, 0, SEEK_END); int size = ftell(file); rewind(file); char* chars = new char[size + 1]; chars[size] = '\0'; for (int i = 0; i < size;) { int read = static_cast(fread(&chars[i], 1, size - i, file)); if (read == 0) { delete [] chars; fclose(file); msDebug("msV8ReadFile: error while reading file '%s'\n", path); return Undefined(); } i += read; } fclose(file); Handle result = String::New(chars, size); delete[] chars; return result; } /* Returns a compiled javascript script. */ static Handle