Skip to content

Commit

Permalink
rename to map2img
Browse files Browse the repository at this point in the history
  • Loading branch information
jmckenna committed Sep 14, 2021
1 parent 17d8fa9 commit ecc2a6e
Show file tree
Hide file tree
Showing 135 changed files with 816 additions and 489 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Please create a .zip file that contains:
- small .map file
- data
- commands.txt (containing commands to reproduce your problem such as
shp2img, mapserv, etc.
map2img, mapserv, etc.

## Operating system

Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ endif(BUILD_STATIC)

add_executable(mapserv mapserv.c)
target_link_libraries(mapserv ${MAPSERVER_LIBMAPSERVER})
add_executable(shp2img shp2img.c)
target_link_libraries(shp2img ${MAPSERVER_LIBMAPSERVER})
add_executable(map2img map2img.c)
target_link_libraries(map2img ${MAPSERVER_LIBMAPSERVER})
add_executable(shptree shptree.c)
target_link_libraries(shptree ${MAPSERVER_LIBMAPSERVER})
add_executable(shptreevis shptreevis.c)
Expand Down Expand Up @@ -980,7 +980,7 @@ if(USE_MSSQL2008)
endif(USE_MSSQL2008)


INSTALL(TARGETS sortshp shptree shptreevis msencrypt legend scalebar tile4ms shptreetst shp2img mapserv
INSTALL(TARGETS sortshp shptree shptreevis msencrypt legend scalebar tile4ms shptreetst map2img mapserv
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
)

Expand Down
2 changes: 1 addition & 1 deletion ci/travis/after_success.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ if [ "$BUILD_NAME" != "PHP_7.2_WITH_ASAN" ]; then
sh -c 'if test "$TRAVIS_SECURE_ENV_VARS" = "true" -a "$TRAVIS_BRANCH" = "master"; then echo "run coverage"; ./run_code_coverage_upload.sh; fi'
ln -s ../../../mapparser.y build/CMakeFiles/mapserver.dir/
ln -s ../../../maplexer.l build/CMakeFiles/mapserver.dir/
coveralls --exclude renderers --exclude mapscript --exclude apache --exclude build/mapscript/mapscriptJAVA_wrap.c --exclude build/mapscript/mapscriptPYTHON_wrap.c --exclude shp2img.c --exclude legend.c --exclude scalebar.c --exclude msencrypt.c --exclude sortshp.c --exclude shptreevis.c --exclude shptree.c --exclude testexpr.c --exclude sym2img.c --exclude testcopy.c --exclude shptreetst.c --exclude tile4ms.c --extension .c --extension .cpp
coveralls --exclude renderers --exclude mapscript --exclude apache --exclude build/mapscript/mapscriptJAVA_wrap.c --exclude build/mapscript/mapscriptPYTHON_wrap.c --exclude map2img.c --exclude legend.c --exclude scalebar.c --exclude msencrypt.c --exclude sortshp.c --exclude shptreevis.c --exclude shptree.c --exclude testexpr.c --exclude sym2img.c --exclude testcopy.c --exclude shptreetst.c --exclude tile4ms.c --extension .c --extension .cpp
fi
2 changes: 1 addition & 1 deletion ci/travis/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if [ "$BUILD_NAME" = "PHP_7.2_WITH_ASAN" ]; then
# -DNDEBUG to avoid issues with cairo cleanup
make cmakebuild MFLAGS="-j2" CMAKE_C_FLAGS="-g -fsanitize=address -DNDEBUG -DACCEPT_USE_OF_DEPRECATED_PROJ_API_H" CMAKE_CXX_FLAGS="-g -fsanitize=address -DNDEBUG -DACCEPT_USE_OF_DEPRECATED_PROJ_API_H" EXTRA_CMAKEFLAGS="-DCMAKE_BUILD_TYPE=None -DCMAKE_EXE_LINKER_FLAGS=-fsanitize=address"
export AUTOTEST_OPTS="--strict --run_under_asan"
# Only run tests that only involve mapserv/shp2img binaries. mspython, etc would require LD_PREOLOAD'ing the asan shared object
# Only run tests that only involve mapserv/map2img binaries. mspython, etc would require LD_PREOLOAD'ing the asan shared object
make -j4 asan_compatible_tests
elif [ "$BUILD_NAME" = "PHP_7.3_WITH_PROJ7" ]; then
make cmakebuild MFLAGS="-j2" CMAKE_C_FLAGS="-O2" CMAKE_CXX_FLAGS="-O2" LIBMAPSERVER_EXTRA_FLAGS="-Wall -Werror -Wextra"
Expand Down
327 changes: 327 additions & 0 deletions map2img.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,327 @@
/******************************************************************************
* $Id$
*
* Project: MapServer
* Purpose: Commandline .map rendering utility, mostly for testing.
* 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.
****************************************************************************/

#include "mapserver.h"
#include "maptime.h"

#include "limits.h"

int main(int argc, char *argv[])
{
int i,j,k;

mapObj *map=NULL;
imageObj *image = NULL;

char **layers=NULL;
int num_layers=0;

int layer_found=0;

char *outfile=NULL; /* no -o sends image to STDOUT */

int iterations = 1;
int draws = 0;

for(i=1; i<argc; i++) {
if (strcmp(argv[i],"-c") == 0) { /* user specified number of draws */
iterations = atoi(argv[i+1]);
if( iterations < 0 || iterations > INT_MAX - 1 )
{
printf("Invalid number of iterations");
return 1;
}
printf("We will draw %d times...\n", iterations);
continue;
}

if(i < argc-1 && strcmp(argv[i], "-all_debug") == 0) { /* global debug */
int debug_level = atoi(argv[++i]);

msSetGlobalDebugLevel(debug_level);

/* Send output to stderr by default */
if (msGetErrorFile() == NULL)
msSetErrorFile("stderr", NULL);

continue;
}

}

for(draws=0; draws<iterations; draws++) {

struct mstimeval requeststarttime, requestendtime;

if(msGetGlobalDebugLevel() >= MS_DEBUGLEVEL_TUNING)
msGettimeofday(&requeststarttime, NULL);

if(argc > 1 && strcmp(argv[1], "-v") == 0) {
printf("%s\n", msGetVersion());
exit(0);
}

/* ---- check the number of arguments, return syntax if not correct ---- */
if( argc < 3 ) {
fprintf(stdout, "\nPurpose: convert a mapfile to an image\n\n");
fprintf(stdout,
"Syntax: map2img -m mapfile [-o image] [-e minx miny maxx maxy] [-s sizex sizey]\n"
" [-l \"layer1 [layers2...]\"] [-i format]\n"
" [-all_debug n] [-map_debug n] [-layer_debug n] [-p n] [-c n] [-d layername datavalue]\n");


fprintf(stdout," -m mapfile: Map file to operate on - required\n" );
fprintf(stdout," -i format: Override the IMAGETYPE value to pick output format\n" );
fprintf(stdout," -o image: output filename (stdout if not provided)\n");
fprintf(stdout," -e minx miny maxx maxy: extents to render\n");
fprintf(stdout," -s sizex sizey: output image size\n");
fprintf(stdout," -l layers: layers / groups to enable - make sure they are quoted and space separated if more than one listed\n" );
fprintf(stdout," -all_debug n: Set debug level for map and all layers\n" );
fprintf(stdout," -map_debug n: Set map debug level\n" );
fprintf(stdout," -layer_debug layer_name n: Set layer debug level\n" );
fprintf(stdout," -c n: draw map n number of times\n" );
fprintf(stdout," -p n: pause for n seconds after reading the map\n" );
fprintf(stdout," -d layername datavalue: change DATA value for layer\n" );


exit(0);
}

if ( msSetup() != MS_SUCCESS ) {
msWriteError(stderr);
exit(1);
}

/* Use PROJ_LIB env vars if set */
msProjLibInitFromEnv();

/* Use MS_ERRORFILE and MS_DEBUGLEVEL env vars if set */
if ( msDebugInitFromEnv() != MS_SUCCESS ) {
msWriteError(stderr);
msCleanup();
exit(1);
}

for(i=1; i<argc; i++) { /* Step though the user arguments, 1st to find map file */

if(strcmp(argv[i],"-m") == 0) {
map = msLoadMap(argv[i+1], NULL);
if(!map) {
msWriteError(stderr);
msCleanup();
exit(1);
}
msApplyDefaultSubstitutions(map);
}
}

if(!map) {
fprintf(stderr, "Mapfile (-m) option not specified.\n");
msCleanup();
exit(1);
}


for(i=1; i<argc; i++) { /* Step though the user arguments */

if(strcmp(argv[i],"-m") == 0) { /* skip it */
i+=1;
}

if(strcmp(argv[i],"-p") == 0) {
int pause_length = atoi(argv[i+1]);
time_t start_time = time(NULL);

printf( "Start pause of %d seconds.\n", pause_length );
while( time(NULL) < start_time + pause_length ) {}
printf( "Done pause.\n" );

i+=1;
}

if(strcmp(argv[i],"-o") == 0) { /* load the output image filename */
outfile = argv[i+1];
i+=1;
}

if(strcmp(argv[i],"-i") == 0) {
outputFormatObj *format;

format = msSelectOutputFormat( map, argv[i+1] );

if( format == NULL )
printf( "No such OUTPUTFORMAT as %s.\n", argv[i+1] );
else {
msFree( (char *) map->imagetype );
map->imagetype = msStrdup( argv[i+1] );
msApplyOutputFormat( &(map->outputformat), format, MS_NOOVERRIDE);
}
i+=1;
}

if(strcmp(argv[i],"-d") == 0) { /* swap layer data */
for(j=0; j<map->numlayers; j++) {
if(strcmp(GET_LAYER(map, j)->name, argv[i+1]) == 0) {
free(GET_LAYER(map, j)->data);
GET_LAYER(map, j)->data = msStrdup(argv[i+2]);
break;
}
}
i+=2;
}

if(i < argc-1 && strcmp(argv[i], "-all_debug") == 0) { /* global debug */
int debug_level = atoi(argv[++i]);

/* msSetGlobalDebugLevel() already called. Just need to force debug
* level in map and all layers
*/
map->debug = debug_level;
for(j=0; j<map->numlayers; j++) {
GET_LAYER(map, j)->debug = debug_level;
}

}

if(i < argc-1 && strcmp(argv[i], "-map_debug") == 0) { /* debug */
map->debug = atoi(argv[++i]);

/* Send output to stderr by default */
if (msGetErrorFile() == NULL)
msSetErrorFile("stderr", NULL);
}

if(i < argc-1 && strcmp(argv[i], "-layer_debug") == 0) { /* debug */
const char *layer_name = argv[++i];
int debug_level = atoi(argv[++i]);
int got_layer = 0;

for(j=0; j<map->numlayers; j++) {
if(strcmp(GET_LAYER(map, j)->name,layer_name) == 0 ) {
GET_LAYER(map, j)->debug = debug_level;
got_layer = 1;
}
}
if( !got_layer )
fprintf( stderr,
" Did not find layer '%s' from -layer_debug switch.\n",
layer_name );

/* Send output to stderr by default */
if (msGetErrorFile() == NULL)
msSetErrorFile("stderr", NULL);
}

if(strcmp(argv[i],"-e") == 0) { /* change extent */
if( argc <= i+4 ) {
fprintf( stderr,
"Argument -e needs 4 space separated numbers as argument.\n" );
msCleanup();
exit(1);
}
map->extent.minx = atof(argv[i+1]);
map->extent.miny = atof(argv[i+2]);
map->extent.maxx = atof(argv[i+3]);
map->extent.maxy = atof(argv[i+4]);
i+=4;
}

if (strcmp(argv[i], "-s") == 0) {
msMapSetSize(map, atoi(argv[i+1]), atoi(argv[i+2]));
i+=2;
}

if(strcmp(argv[i],"-l") == 0) { /* load layer list */
layers = msStringSplit(argv[i+1], ' ', &(num_layers));

for(j=0; j<num_layers; j++) { /* loop over -l */
layer_found=0;
for(k=0; k<map->numlayers; k++) {
if((GET_LAYER(map, k)->name && strcasecmp(GET_LAYER(map, k)->name, layers[j]) == 0) || (GET_LAYER(map, k)->group && strcasecmp(GET_LAYER(map, k)->group, layers[j]) == 0)) {
layer_found = 1;
break;
}
}
if (layer_found==0) {
fprintf(stderr, "Layer (-l) \"%s\" not found\n", layers[j]);
msCleanup();
exit(1);
}
}

for(j=0; j<map->numlayers; j++) {
if(GET_LAYER(map, j)->status == MS_DEFAULT)
continue;
else {
GET_LAYER(map, j)->status = MS_OFF;
for(k=0; k<num_layers; k++) {
if((GET_LAYER(map, j)->name && strcasecmp(GET_LAYER(map, j)->name, layers[k]) == 0) ||
(GET_LAYER(map, j)->group && strcasecmp(GET_LAYER(map, j)->group, layers[k]) == 0)) {
GET_LAYER(map, j)->status = MS_ON;
break;
}
}
}
}

msFreeCharArray(layers, num_layers);

i+=1;
}
}

image = msDrawMap(map, MS_FALSE);

if(!image) {
msWriteError(stderr);

msFreeMap(map);
msCleanup();
exit(1);
}

if( msSaveImage(map, image, outfile) != MS_SUCCESS ) {
msWriteError(stderr);
}

msFreeImage(image);
msFreeMap(map);

if(msGetGlobalDebugLevel() >= MS_DEBUGLEVEL_TUNING) {
msGettimeofday(&requestendtime, NULL);
msDebug("map2img total time: %.3fs\n",
(requestendtime.tv_sec+requestendtime.tv_usec/1.0e6)-
(requeststarttime.tv_sec+requeststarttime.tv_usec/1.0e6) );
}

msCleanup();

} /* for(draws=0; draws<iterations; draws++) { */
return(0);
} /* ---- END Main Routine ---- */
2 changes: 1 addition & 1 deletion mapserver-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ endif()

# These are IMPORTED targets created by mapserverTargets.cmake
set(MAPSERVER_LIBRARIES mapserver)
set(MAPSERVER_EXECUTABLES sortshp shptree shptreevis msencrypt legend scalebar tile4ms shptreetst shp2img mapserv)
set(MAPSERVER_EXECUTABLES sortshp shptree shptreevis msencrypt legend scalebar tile4ms shptreetst map2img mapserv)
6 changes: 3 additions & 3 deletions msautotest/gdal/class8_range.map
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#RUN_PARMS: class8_range.png [SHP2IMG] -m [MAPFILE] -i png8_t -o [RESULT] -l grid1
#RUN_PARMS: double_range_rgb.png [SHP2IMG] -m [MAPFILE] -i png -o [RESULT] -l grid2
#RUN_PARMS: double_range_hsl.png [SHP2IMG] -m [MAPFILE] -i png -o [RESULT] -l grid3
#RUN_PARMS: class8_range.png [MAP2IMG] -m [MAPFILE] -i png8_t -o [RESULT] -l grid1
#RUN_PARMS: double_range_rgb.png [MAP2IMG] -m [MAPFILE] -i png -o [RESULT] -l grid2
#RUN_PARMS: double_range_hsl.png [MAP2IMG] -m [MAPFILE] -i png -o [RESULT] -l grid3
#
# Simple test of classification methods on a floating point input.
#
Expand Down
2 changes: 1 addition & 1 deletion msautotest/misc/attrbind.map
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# REQUIRES: INPUT=SHAPE OUTPUT=PNG
#
# RUN_PARMS: attrbind_test001.png [SHP2IMG] -m [MAPFILE] -l test001 -o [RESULT]
# RUN_PARMS: attrbind_test001.png [MAP2IMG] -m [MAPFILE] -l test001 -o [RESULT]
MAP
NAME 'attrbind'
EXTENT -1.5 0.1 -0.6 1.0
Expand Down
Loading

0 comments on commit ecc2a6e

Please sign in to comment.