/***************************************
OSM planet file splitter.
Part of the Routino routing software.
******************/ /******************
This file Copyright 2008-2015 Andrew M. Bishop
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
***************************************/
#include
#include
#include
#include
#include "types.h"
#include "ways.h"
#include "typesx.h"
#include "nodesx.h"
#include "segmentsx.h"
#include "waysx.h"
#include "relationsx.h"
#include "superx.h"
#include "prunex.h"
#include "files.h"
#include "logging.h"
#include "errorlogx.h"
#include "functions.h"
#include "osmparser.h"
#include "tagging.h"
#include "uncompress.h"
/* Global variables */
/*+ The name of the temporary directory. +*/
char *option_tmpdirname=NULL;
/*+ The amount of RAM to use for filesorting. +*/
size_t option_filesort_ramsize=0;
/*+ The number of threads to use for filesorting. +*/
int option_filesort_threads=1;
/* Local functions */
static void print_usage(int detail,const char *argerr,const char *err);
/*++++++++++++++++++++++++++++++++++++++
The main program for the planetsplitter.
++++++++++++++++++++++++++++++++++++++*/
int main(int argc,char** argv)
{
NodesX *OSMNodes;
SegmentsX *OSMSegments,*SuperSegments=NULL,*MergedSegments=NULL;
WaysX *OSMWays;
RelationsX *OSMRelations;
int iteration=0,quit=0;
int max_iterations=5;
char *dirname=NULL,*prefix=NULL,*tagging=NULL,*errorlog=NULL;
int option_parse_only=0,option_process_only=0;
int option_append=0,option_keep=0,option_changes=0;
int option_filenames=0;
int option_prune_isolated=500,option_prune_short=5,option_prune_straight=3;
int arg;
printf_program_start();
/* Parse the command line arguments */
for(arg=1;arg9?"=":"");
fflush(stdout);
if(iteration==0)
{
/* Select the super-nodes */
ChooseSuperNodes(OSMNodes,OSMSegments,OSMWays);
/* Select the super-segments */
SuperSegments=CreateSuperSegments(OSMNodes,OSMSegments,OSMWays);
nsuper=OSMSegments->number;
}
else
{
SegmentsX *SuperSegments2;
/* Index the super-segments */
IndexSegments(SuperSegments,OSMNodes,OSMWays);
/* Select the super-nodes */
ChooseSuperNodes(OSMNodes,SuperSegments,OSMWays);
/* Select the super-segments */
SuperSegments2=CreateSuperSegments(OSMNodes,SuperSegments,OSMWays);
nsuper=SuperSegments->number;
FreeSegmentList(SuperSegments);
SuperSegments=SuperSegments2;
}
/* Sort the super-segments and remove duplicates */
DeduplicateSuperSegments(SuperSegments,OSMWays);
/* Check for end condition */
if(SuperSegments->number==nsuper)
quit=1;
iteration++;
if(iteration>max_iterations)
quit=1;
}
while(!quit);
/* Combine the super-segments */
printf("\nCombine Segments and Super-Segments\n===================================\n\n");
fflush(stdout);
/* Merge the super-segments */
MergedSegments=MergeSuperSegments(OSMSegments,SuperSegments);
FreeSegmentList(OSMSegments);
FreeSegmentList(SuperSegments);
OSMSegments=MergedSegments;
/* Cross reference the nodes and segments */
printf("\nCross-Reference Nodes and Segments\n==================================\n\n");
fflush(stdout);
/* Sort the nodes and segments geographically */
SortNodeListGeographically(OSMNodes);
SortSegmentListGeographically(OSMSegments,OSMNodes);
/* Re-index the segments */
IndexSegments(OSMSegments,OSMNodes,OSMWays);
/* Sort the turn relations geographically */
SortTurnRelationListGeographically(OSMRelations,OSMNodes,OSMSegments,1);
/* Output the results */
printf("\nWrite Out Database Files\n========================\n\n");
fflush(stdout);
/* Write out the nodes */
SaveNodeList(OSMNodes,FileName(dirname,prefix,"nodes.mem"),OSMSegments);
/* Write out the segments */
SaveSegmentList(OSMSegments,FileName(dirname,prefix,"segments.mem"));
/* Write out the ways */
SaveWayList(OSMWays,FileName(dirname,prefix,"ways.mem"));
/* Write out the relations */
SaveRelationList(OSMRelations,FileName(dirname,prefix,"relations.mem"));
/* Free the memory (delete the temporary files) */
FreeSegmentList(OSMSegments);
/* Close the error log file and process the data */
if(errorlog)
{
close_errorlog();
if(option_keep)
{
ErrorLogsX *OSMErrorLogs;
printf("\nCreate Error Log\n================\n\n");
fflush(stdout);
OSMErrorLogs=NewErrorLogList();
ProcessErrorLogs(OSMErrorLogs,OSMNodes,OSMWays,OSMRelations);
SortErrorLogsGeographically(OSMErrorLogs);
SaveErrorLogs(OSMErrorLogs,FileName(dirname,prefix,"errorlogs.mem"));
FreeErrorLogList(OSMErrorLogs);
}
}
/* Free the memory (delete the temporary files) */
FreeNodeList(OSMNodes,0);
FreeWayList(OSMWays,0);
FreeRelationList(OSMRelations,0);
printf("\n");
fflush(stdout);
printf_program_end();
exit(EXIT_SUCCESS);
}
/*++++++++++++++++++++++++++++++++++++++
Print out the usage information.
int detail The level of detail to use - 0 = low, 1 = high.
const char *argerr The argument that gave the error (if there is one).
const char *err Other error message (if there is one).
++++++++++++++++++++++++++++++++++++++*/
static void print_usage(int detail,const char *argerr,const char *err)
{
fprintf(stderr,
"Usage: planetsplitter [--help]\n"
" [--dir=] [--prefix=]\n"
#if defined(USE_PTHREADS) && USE_PTHREADS
" [--sort-ram-size=] [--sort-threads=]\n"
#else
" [--sort-ram-size=]\n"
#endif
" [--tmpdir=]\n"
" [--tagging=]\n"
" [--loggable] [--logtime] [--logmemory]\n"
" [--errorlog[=]]\n"
" [--parse-only | --process-only]\n"
" [--append] [--keep] [--changes]\n"
" [--max-iterations=]\n"
" [--prune-none]\n"
" [--prune-isolated=]\n"
" [--prune-short=]\n"
" [--prune-straight=]\n"
" [ ... | ...\n"
" | ...\n"
" | ... | ..."
#if defined(USE_BZIP2) && USE_BZIP2
"\n | ..."
#endif
#if defined(USE_GZIP) && USE_GZIP
"\n | ..."
#endif
#if defined(USE_XZ) && USE_XZ
"\n | ..."
#endif
"]\n");
if(argerr)
fprintf(stderr,
"\n"
"Error with command line parameter: %s\n",argerr);
if(err)
fprintf(stderr,
"\n"
"Error: %s\n",err);
if(detail)
fprintf(stderr,
"\n"
"--help Prints this information.\n"
"\n"
"--dir= The directory containing the routing database.\n"
"--prefix= The filename prefix for the routing database.\n"
"\n"
"--sort-ram-size= The amount of RAM (in MB) to use for data sorting\n"
#if SLIM
" (defaults to 64MB otherwise.)\n"
#else
" (defaults to 256MB otherwise.)\n"
#endif
#if defined(USE_PTHREADS) && USE_PTHREADS
"--sort-threads= The number of threads to use for data sorting.\n"
#endif
"\n"
"--tmpdir= The directory name for temporary files.\n"
" (defaults to the '--dir' option directory.)\n"
"\n"
"--tagging= The name of the XML file containing the tagging rules\n"
" (defaults to 'tagging.xml' with '--dir' and\n"
" '--prefix' options or the file installed in\n"
" '" ROUTINO_DATADIR "').\n"
"\n"
"--loggable Print progress messages suitable for logging to file.\n"
"--logtime Print the elapsed time for each processing step.\n"
"--logmemory Print the max allocated/mapped memory for each step.\n"
"--errorlog[=] Log parsing errors to 'error.log' or the given name\n"
" (the '--dir' and '--prefix' options are applied).\n"
"\n"
"--parse-only Parse the OSM/OSC file(s) and store the results.\n"
"--process-only Process the stored results from previous option.\n"
"--append Parse the OSM file(s) and append to existing results.\n"
"--keep Keep the intermediate files after parsing & sorting.\n"
"--changes Parse the data as an OSC file and apply the changes.\n"
"\n"
"--max-iterations= The number of iterations for finding super-nodes\n"
" (defaults to 5).\n"
"\n"
"--prune-none Disable the prune options below, they are re-enabled\n"
" by adding them to the command line after this option.\n"
"--prune-isolated= Remove access from small disconnected segment groups\n"
" (defaults to removing groups under 500m).\n"
"--prune-short= Remove short segments (defaults to removing segments\n"
" up to a maximum length of 5m).\n"
"--prune-straight= Remove nodes in almost straight highways (defaults to\n"
" removing nodes up to 3m offset from a straight line).\n"
"\n"
", , , , \n"
" The name(s) of the file(s) to read and parse.\n"
" Filenames ending '.pbf' read as PBF, filenames ending\n"
" '.o5m' or '.o5c' read as O5M/O5C, others as XML.\n"
#if defined(USE_BZIP2) && USE_BZIP2
" Filenames ending '.bz2' will be bzip2 uncompressed.\n"
#endif
#if defined(USE_GZIP) && USE_GZIP
" Filenames ending '.gz' will be gzip uncompressed.\n"
#endif
#if defined(USE_XZ) && USE_XZ
" Filenames ending '.xz' will be xz uncompressed.\n"
#endif
"\n"
" defaults to all but can be set to:\n"
"%s"
"\n"
" can be selected from:\n"
"%s"
"\n"
" can be selected from:\n"
"%s",
TransportList(),HighwayList(),PropertyList());
exit(!detail);
}