/* This file is part of Mapnik (c++ mapping toolkit) * Copyright (C) 2005 Artem Pavlenko * * Mapnik is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ //$Id$ #include #include #include "config.hh" #include "mapnik.hh" #include "shape.hh" #include "quadtree.hh" const int MAXDEPTH = 64; const int DEFAULT_DEPTH = 16; const double MINRATIO=0.5; const double MAXRATIO=0.8; const double DEFAULT_RATIO=0.55; const char* argp_program_version = "shapeindex utility version 0.1"; const char* argp_program_bug_address="bugs@shapeindex"; static char doc[] = "shapeindex utility to create spatial index"; static char args_doc[]="shape_file"; static struct argp_option options[] = { {"verbose",'v',0, 0,"Produce verbose output"}, {"quite", 'q',0, 0,"Don't produce any output"}, {"silent", 's',0, OPTION_ALIAS}, {0,0,0,0, "shape index options:" }, {"depth", 'd',"VALUE",0,"maximum depth of the tree (default=16)"}, {"ratio", 'r',"VALUE",0,"split ratio between 0.5-0.9 (default 0.55)"}, { 0 } }; struct arguments { char *args[2]; int silent; int verbose; int depth; double ratio; }; static error_t parse_opt ( int key,char *arg, struct argp_state *state) { struct arguments* arguments = (struct arguments*)state->input; switch (key) { case 'q': case 's': arguments->silent = 1; break; case 'v': arguments->verbose = 1; break; case 'd': arguments->depth = arg ? atoi(arg) : DEFAULT_DEPTH; break; case 'r': arguments->ratio = arg ? atof(arg) : DEFAULT_RATIO; break; case ARGP_KEY_NO_ARGS: argp_usage (state); case ARGP_KEY_ARG: if (state->arg_num>=1) //too many arguments. argp_usage (state); arguments->args[state->arg_num] = arg; break; case ARGP_KEY_END: if (state->arg_num < 1) //not enough arguments argp_usage (state); break; default: return ARGP_ERR_UNKNOWN; } return 0; } static struct argp argp = { options, parse_opt, args_doc, doc }; using namespace mapnik; int main (int argc,char** argv) { struct arguments arguments; arguments.silent = 0; arguments.verbose = 0; arguments.silent = 0; arguments.depth = DEFAULT_DEPTH; arguments.ratio = DEFAULT_RATIO; argp_parse(&argp, argc, argv, 0, 0, &arguments); std::cout<<"processing "< extent; shp.read_envelope(extent); if (!arguments.silent) { //std::cout<<"length="< tree(extent,arguments.depth,arguments.ratio); int count=0; while (true) { int offset=shp.pos(); int record_number=shp.read_xdr_integer(); int content_length=shp.read_xdr_integer(); shp.skip(4); Envelope item_ext; if (shape_type==shape_io::shape_point) { double x=shp.read_double(); double y=shp.read_double(); shp.skip(2*content_length-2*8-4); item_ext=Envelope(x,y,x,y); } else if (shape_type==shape_io::shape_pointz) { double x=shp.read_double(); double y=shp.read_double(); double z=shp.read_double(); shp.skip(2*content_length-2*8-4); item_ext=Envelope(x,y,x,y); } else { shp.read_envelope(item_ext); shp.skip(2*content_length-4*8-4); } tree.insert(offset,item_ext); if (arguments.verbose) { std::cout<<"record number "<