/***************************************************************************** * * This file is part of Mapnik (c++ mapping toolkit) * * Copyright (C) 2006 Artem Pavlenko * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ //$Id: shapeindex.cc 27 2005-03-30 21:45:40Z pavlenko $ #include "shape.hpp" #include "quadtree.hpp" #include #include #include #include #include #include const int MAXDEPTH = 64; const int DEFAULT_DEPTH = 8; const double MINRATIO=0.5; const double MAXRATIO=0.8; const double DEFAULT_RATIO=0.55; int main (int argc,char** argv) { using namespace mapnik; namespace po = boost::program_options; using std::string; using std::vector; bool verbose=false; unsigned int depth=DEFAULT_DEPTH; double ratio=DEFAULT_RATIO; vector shape_files; try { po::options_description desc("shapeindex utility"); desc.add_options() ("help,h", "produce usage message") ("version,V","print version string") ("verbose,v","verbose output") ("depth,d", po::value(), "max tree depth\n(default 8)") ("ratio,r",po::value(),"split ratio (default 0.55)") ("shape_files",po::value >(),"shape files to index file1 file2 ...fileN") ; po::positional_options_description p; p.add("shape_files",-1); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); po::notify(vm); if (vm.count("version")) { clog<<"version 0.2.0a" <(); } if (vm.count("ratio")) { ratio = vm["ratio"].as(); } if (vm.count("shape_files")) { shape_files=vm["shape_files"].as< vector >(); } } catch (...) { clog << "Exception of unknown type!"<::const_iterator itr=shape_files.begin(); if (itr==shape_files.end()) { std::clog << "no shape files to index"< extent; shp.read_envelope(extent); std::clog<<"length="< tree(extent,depth,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); std::cout << "offset= "<< offset << std::endl; Envelope item_ext; if (shape_type==shape_io::shape_point) { double x=shp.read_double(); double y=shp.read_double(); item_ext=Envelope(x,y,x,y); } if (shape_type==shape_io::shape_pointm) { double x=shp.read_double(); double y=shp.read_double(); shp.read_double(); 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(); shp.read_double(); shp.read_double(); 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 (verbose) { std::clog<<"record number "<