1.added copyright notice to SConstruct/SConscript files
2.fixed include/libs in datasources 3.revived shapeindex utility (+ boost::program_options)
This commit is contained in:
parent
84bd684f87
commit
32c76d5a5f
25 changed files with 347 additions and 281 deletions
24
SConstruct
24
SConstruct
|
@ -1,4 +1,21 @@
|
|||
#mapnik SConctruct
|
||||
# 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$
|
||||
|
||||
import os
|
||||
|
||||
|
@ -23,7 +40,7 @@ cxx = 'g++'
|
|||
|
||||
env = Environment(CXX=cxx,ENV=os.environ, options=opts)
|
||||
|
||||
cxx_debug='-Wall -ftemplate-depth-100 -O0 -fno-inline -g -pthread'
|
||||
cxx_debug='-Wall -ftemplate-depth-100 -O0 -fno-inline -g -pthread -DDEBUG'
|
||||
cxx_release='-Wall -ftemplate-depth-100 -O2 -finline-functions -Wno-inline -pthread -DNDEBUG'
|
||||
|
||||
release_env = env.Copy(CXXFLAGS = cxx_release)
|
||||
|
@ -72,6 +89,9 @@ SConscript('src/SConscript')
|
|||
#python ext
|
||||
SConscript('python/SConscript')
|
||||
|
||||
#shapeindex
|
||||
SConscript('util/shapeindex/SConscript')
|
||||
|
||||
#datasources
|
||||
for datasource in Split(env['DATASOURCES']):
|
||||
env.BuildDir('build/datasources/'+datasource,'src/datasources/'+datasource,duplicate=0)
|
||||
|
|
|
@ -1,4 +1,22 @@
|
|||
# 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$
|
||||
|
||||
import glob
|
||||
|
||||
Import('env')
|
||||
|
|
|
@ -1,4 +1,22 @@
|
|||
##
|
||||
# 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$
|
||||
|
||||
import glob
|
||||
|
||||
Import('env')
|
||||
|
|
|
@ -1,12 +1,28 @@
|
|||
#mapnik
|
||||
# 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$
|
||||
|
||||
|
||||
Import ('env')
|
||||
|
||||
prefix = env['PREFIX']
|
||||
boost_root = env['BOOST_ROOT']
|
||||
postgresql_root = env['POSTGRESQL_ROOT']
|
||||
agg_root = env['AGG_ROOT']
|
||||
agg_headers = agg_root + '/include'
|
||||
|
||||
postgresql_headers=postgresql_root+"/include"
|
||||
postgresql_libs=postgresql_root+"/lib"
|
||||
|
@ -18,7 +34,7 @@ postgis_src = Split(
|
|||
"""
|
||||
)
|
||||
|
||||
headers = ['#include',boost_root,agg_headers,postgresql_headers]
|
||||
headers = ['#include',boost_root,postgresql_headers]
|
||||
postgis_datasource = env.SharedLibrary('postgis',source=postgis_src,SHLIBPREFIX='',CPPPATH=headers,LIBS="pq",LIBPATH=postgresql_libs)
|
||||
env.Install(prefix + '/datasources',postgis_datasource)
|
||||
env.Alias("install",prefix + '/datasources')
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
|
||||
#include "libpq-fe.h"
|
||||
#include "mapnik.hpp"
|
||||
#include "resultset.hpp"
|
||||
|
||||
using namespace mapnik;
|
||||
|
|
|
@ -22,7 +22,10 @@
|
|||
#define POSTGIS_HPP
|
||||
|
||||
|
||||
#include "mapnik.hpp"
|
||||
#include "datasource.hpp"
|
||||
#include "envelope.hpp"
|
||||
#include "feature.hpp"
|
||||
|
||||
#include "connection_manager.hpp"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
|
||||
#include "postgis.hpp"
|
||||
#include "global.hpp"
|
||||
#include "wkb.hpp"
|
||||
|
||||
using boost::lexical_cast;
|
||||
using boost::bad_lexical_cast;
|
||||
|
@ -53,7 +55,7 @@ Feature* PostgisFeatureset::next()
|
|||
for (unsigned pos=0;pos<num_attrs_;++pos)
|
||||
{
|
||||
const char* buf=rs_->getValue(start + pos);
|
||||
int field_size = rs_->getFieldLength(start + pos);
|
||||
//int field_size = rs_->getFieldLength(start + pos);
|
||||
int oid = rs_->getTypeOID(start + pos);
|
||||
|
||||
if (oid==23) //int4
|
||||
|
|
|
@ -1,11 +1,26 @@
|
|||
#mapnik
|
||||
# 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$
|
||||
|
||||
Import ('env')
|
||||
|
||||
prefix = env['PREFIX']
|
||||
boost_root = env['BOOST_ROOT']
|
||||
agg_root = env['AGG_ROOT']
|
||||
agg_headers = agg_root + '/include'
|
||||
|
||||
shape_src = Split(
|
||||
"""
|
||||
|
@ -19,8 +34,8 @@ shape_src = Split(
|
|||
"""
|
||||
)
|
||||
|
||||
headers = ['#include',boost_root,agg_headers]
|
||||
headers = ['#include',boost_root]
|
||||
|
||||
shape_datasource = env.SharedLibrary('shape',source=shape_src,SHLIBPREFIX='',CPPPATH=headers)
|
||||
shape_datasource = env.SharedLibrary('shape',source=shape_src,SHLIBPREFIX='',LIBS="",CPPPATH=headers)
|
||||
env.Install(prefix+"/datasources",shape_datasource)
|
||||
|
||||
env.Alias("install",prefix + '/datasources')
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "dbffile.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <fstream>
|
||||
#include <cassert>
|
||||
|
||||
#include "mapnik.hpp"
|
||||
#include "feature.hpp"
|
||||
|
||||
using namespace mapnik;
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "shape.hpp"
|
||||
#include "shape_featureset.hpp"
|
||||
#include "shape_index_featureset.hpp"
|
||||
#include "geom_util.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
#ifndef SHAPE_HH
|
||||
#define SHAPE_HH
|
||||
|
||||
#include "mapnik.hpp"
|
||||
#include "datasource.hpp"
|
||||
#include "envelope.hpp"
|
||||
#include "shape_io.hpp"
|
||||
|
||||
using namespace mapnik;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#define SHAPE_FS_HH
|
||||
|
||||
#include "shape.hpp"
|
||||
#include "geom_util.hpp"
|
||||
|
||||
using namespace mapnik;
|
||||
|
||||
|
|
|
@ -21,9 +21,10 @@
|
|||
#ifndef SHAPEFILE_HH
|
||||
#define SHAPEFILE_HH
|
||||
|
||||
#include "mapnik.hpp"
|
||||
#include <fstream>
|
||||
|
||||
#include "envelope.hpp"
|
||||
|
||||
using namespace mapnik;
|
||||
|
||||
struct shape_record
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "shp_index.hpp"
|
||||
#include "geom_util.hpp"
|
||||
|
||||
template <typename filterT>
|
||||
void shp_index<filterT>::query(const filterT& filter,std::ifstream& file,std::set<int>& pos)
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
#ifndef SHP_INDEX_HH
|
||||
#define SHP_INDEX_HH
|
||||
|
||||
#include "mapnik.hpp"
|
||||
#include "envelope.hpp"
|
||||
#include "query.hpp"
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#ifndef GEOM_UTIL_HPP
|
||||
#define GEOM_UTIL_HPP
|
||||
|
||||
#include "geometry.hpp"
|
||||
#include <cmath>
|
||||
|
||||
namespace mapnik
|
||||
|
@ -81,7 +80,7 @@ namespace mapnik
|
|||
}
|
||||
|
||||
template <typename Iter>
|
||||
inline bool point_inside_path(Iter start,Iter end,double x,double y)
|
||||
inline bool point_inside_path(double x,double y,Iter start,Iter end)
|
||||
{
|
||||
bool inside=false;
|
||||
double x0=start->x;
|
||||
|
@ -145,57 +144,15 @@ namespace mapnik
|
|||
}
|
||||
|
||||
#undef TOL
|
||||
|
||||
inline bool point_on_path(double x,double y,const geometry<vertex2d>& geom)
|
||||
template <typename Iter>
|
||||
inline bool point_on_path(double x,double y,Iter start,Iter end)
|
||||
{
|
||||
bool on_path=false;
|
||||
if (geom.num_points()>1)
|
||||
{
|
||||
geometry<vertex2d>::path_iterator<NO_SHIFT> itr=geom.begin<NO_SHIFT>();
|
||||
geometry<vertex2d>::path_iterator<NO_SHIFT> end=geom.end<NO_SHIFT>();
|
||||
|
||||
double x0=itr->x;
|
||||
double y0=itr->y;
|
||||
|
||||
while (++itr!=end)
|
||||
{
|
||||
if (itr->cmd == SEG_MOVETO)
|
||||
{
|
||||
x0=itr->x;
|
||||
y0=itr->y;
|
||||
continue;
|
||||
}
|
||||
double x1=itr->x;
|
||||
double y1=itr->y;
|
||||
|
||||
on_path = point_on_segment(x,y,x0,y0,x1,y1);
|
||||
if (on_path)
|
||||
break;
|
||||
|
||||
x0=itr->x;
|
||||
y0=itr->y;
|
||||
}
|
||||
}
|
||||
return on_path;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool point_on_points (double x,double y,const geometry_type& geom)
|
||||
|
||||
template <typename Iter>
|
||||
inline bool point_on_points (double x,double y,Iter start,Iter end)
|
||||
{
|
||||
geometry<vertex2d>::path_iterator<NO_SHIFT> itr=geom.begin<NO_SHIFT>();
|
||||
geometry<vertex2d>::path_iterator<NO_SHIFT> end=geom.end<NO_SHIFT>();
|
||||
while (itr!=end)
|
||||
{
|
||||
double dx = x - itr->x;
|
||||
double dy = y - itr->y;
|
||||
double d = sqrt(dx*dx+dy*dy);
|
||||
|
||||
if (d < 0.02)
|
||||
{
|
||||
std::cout<<"d="<<d<<" x="<<x<<" y="<<y<<" itr->x="<<itr->x<<" itr->y="<<itr->y<<std::endl;
|
||||
return true;
|
||||
}
|
||||
++itr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -221,7 +178,6 @@ namespace mapnik
|
|||
return extent.contains(pt_);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //GEOM_UTIL_HPP
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "vertex_transform.hpp"
|
||||
#include "ctrans.hpp"
|
||||
#include "ptr.hpp"
|
||||
#include "geom_util.hpp"
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
@ -183,6 +184,7 @@ namespace mapnik
|
|||
template <typename T, template <typename> class Container=vertex_vector>
|
||||
class point : public geometry<T,Container>
|
||||
{
|
||||
typedef geometry<T,Container> geometry_base;
|
||||
typedef typename geometry<T,Container>::value_type value_type;
|
||||
using geometry<T,Container>::cont_;
|
||||
public:
|
||||
|
@ -196,7 +198,10 @@ namespace mapnik
|
|||
}
|
||||
bool hit_test(value_type x,value_type y) const
|
||||
{
|
||||
return point_on_points(x,y,*this);
|
||||
typedef typename geometry_base::template path_iterator<NO_SHIFT> path_iterator;
|
||||
path_iterator start = geometry_base::template begin<NO_SHIFT>();
|
||||
path_iterator end = geometry_base::template end<NO_SHIFT>();
|
||||
return point_on_points(x,y,start,end);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -221,13 +226,14 @@ namespace mapnik
|
|||
typedef typename geometry_base::template path_iterator<NO_SHIFT> path_iterator;
|
||||
path_iterator start = geometry_base::template begin<NO_SHIFT>();
|
||||
path_iterator end = geometry_base::template end<NO_SHIFT>();
|
||||
return point_inside_path(start,end,x,y);
|
||||
return point_inside_path(x,y, start,end);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, template <typename> class Container=vertex_vector>
|
||||
class line_string : public geometry<T,Container>
|
||||
{
|
||||
typedef geometry<T,Container> geometry_base;
|
||||
typedef typename geometry<T,Container>::value_type value_type;
|
||||
public:
|
||||
line_string(int srid)
|
||||
|
@ -241,7 +247,10 @@ namespace mapnik
|
|||
|
||||
bool hit_test(value_type x,value_type y) const
|
||||
{
|
||||
return point_on_path(x,y,*this);
|
||||
typedef typename geometry_base::template path_iterator<NO_SHIFT> path_iterator;
|
||||
path_iterator start = geometry_base::template begin<NO_SHIFT>();
|
||||
path_iterator end = geometry_base::template end<NO_SHIFT>();
|
||||
return point_on_path(x,y,start,end);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,3 +1,22 @@
|
|||
# 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$
|
||||
|
||||
import os
|
||||
import SCons.Errors
|
||||
import SCons.Defaults
|
||||
|
|
19
settings.py
19
settings.py
|
@ -1,3 +1,22 @@
|
|||
# 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$
|
||||
|
||||
#edit this file
|
||||
|
||||
PREFIX = '/opt/mapnik'
|
||||
|
|
|
@ -1,4 +1,22 @@
|
|||
##
|
||||
# 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$
|
||||
|
||||
import glob
|
||||
|
||||
Import ('env')
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
/* config.hh. Generated by configure. */
|
||||
/* config.hh.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "shapeindex"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "bugs@shapeindex"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "shapeindex"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "shapeindex 0.1"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "shapeindex"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "0.1"
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "0.1"
|
|
@ -1,21 +0,0 @@
|
|||
/* 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: quadtree.cc 17 2005-03-08 23:58:43Z pavlenko $
|
||||
|
||||
#include "quadtree.hh"
|
|
@ -21,7 +21,7 @@
|
|||
#ifndef QUADTREE_HH
|
||||
#define QUADTREE_HH
|
||||
|
||||
#include "mapnik.hh"
|
||||
#include "envelope.hpp"
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
|
||||
|
|
|
@ -18,192 +18,183 @@
|
|||
|
||||
//$Id: shapeindex.cc 27 2005-03-30 21:45:40Z pavlenko $
|
||||
|
||||
#include <iostream>
|
||||
#include <argp.h>
|
||||
#include "config.hh"
|
||||
#include "mapnik.hh"
|
||||
#include "shape.hh"
|
||||
#include "quadtree.hh"
|
||||
#include "shape.hpp"
|
||||
#include "quadtree.hpp"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
const int MAXDEPTH = 64;
|
||||
const int DEFAULT_DEPTH = 16;
|
||||
const int DEFAULT_DEPTH = 8;
|
||||
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)
|
||||
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<string> shape_files;
|
||||
|
||||
try
|
||||
{
|
||||
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;
|
||||
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<unsigned int>(), "max tree depth\n(default 8)")
|
||||
("ratio,r",po::value<double>(),"split ratio (default 0.55)")
|
||||
("shape_files",po::value<vector<string> >(),"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"))
|
||||
{
|
||||
cout<<"version 0.2.0a" <<endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (vm.count("help"))
|
||||
{
|
||||
cout << desc << "\n";
|
||||
return 1;
|
||||
}
|
||||
if (vm.count("depth"))
|
||||
{
|
||||
depth = vm["depth"].as<unsigned int>();
|
||||
}
|
||||
if (vm.count("ratio"))
|
||||
{
|
||||
ratio = vm["ratio"].as<double>();
|
||||
}
|
||||
|
||||
if (vm.count("shape_files"))
|
||||
{
|
||||
shape_files=vm["shape_files"].as< vector<string> >();
|
||||
}
|
||||
}
|
||||
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 "<<arguments.args[0]<<std::endl;
|
||||
|
||||
std::cout<<"max tree depth:"<<arguments.depth<<std::endl;
|
||||
std::cout<<"split ratio:"<<arguments.ratio<<std::endl;
|
||||
|
||||
shape_file shp;
|
||||
std::string shapename(arguments.args[0]);
|
||||
if (!shp.open(shapename+".shp")) {
|
||||
std::cerr<<"error : cannot open "<< (shapename+".shp") <<"\n";
|
||||
catch (...)
|
||||
{
|
||||
cerr << "Exception of unknown type!"<<endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int file_code=shp.read_xdr_integer();
|
||||
assert(file_code==9994);
|
||||
shp.skip(5*4);
|
||||
|
||||
std::cout<<"max tree depth:"<<depth<<std::endl;
|
||||
std::cout<<"split ratio:"<<ratio<<std::endl;
|
||||
|
||||
int file_length=shp.read_xdr_integer();
|
||||
int version=shp.read_ndr_integer();
|
||||
int shape_type=shp.read_ndr_integer();
|
||||
Envelope<double> extent;
|
||||
shp.read_envelope(extent);
|
||||
vector<string>::const_iterator itr=shape_files.begin();
|
||||
if (itr==shape_files.end())
|
||||
{
|
||||
std::cout << "no shape files to index"<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
while (itr != shape_files.end())
|
||||
{
|
||||
std::cout<<"processing "<<*itr << std::endl;
|
||||
shape_file shp;
|
||||
std::string shapename(*itr++);
|
||||
if (!shp.open(shapename+".shp")) {
|
||||
std::cerr<<"error : cannot open "<< (shapename+".shp") <<"\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!arguments.silent) {
|
||||
//std::cout<<"length="<<file_length<<std::endl;
|
||||
//std::cout<<"version="<<version<<std::endl;
|
||||
int file_code=shp.read_xdr_integer();
|
||||
assert(file_code==9994);
|
||||
shp.skip(5*4);
|
||||
|
||||
int file_length=shp.read_xdr_integer();
|
||||
int version=shp.read_ndr_integer();
|
||||
int shape_type=shp.read_ndr_integer();
|
||||
Envelope<double> extent;
|
||||
shp.read_envelope(extent);
|
||||
|
||||
|
||||
std::cout<<"length="<<file_length<<std::endl;
|
||||
std::cout<<"version="<<version<<std::endl;
|
||||
std::cout<<"type="<<shape_type<<std::endl;
|
||||
std::cout<<"extent:"<<extent<<std::endl;
|
||||
}
|
||||
|
||||
int pos=50;
|
||||
shp.seek(pos*2);
|
||||
quadtree<int> 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();
|
||||
|
||||
int pos=50;
|
||||
shp.seek(pos*2);
|
||||
quadtree<int> 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);
|
||||
Envelope<double> 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<double>(x,y,x,y);
|
||||
shp.skip(4);
|
||||
Envelope<double> 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<double>(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<double>(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.skip(2*content_length-2*8-4);
|
||||
item_ext=Envelope<double>(x,y,x,y);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
else
|
||||
{
|
||||
|
||||
shp.read_envelope(item_ext);
|
||||
shp.skip(2*content_length-4*8-4);
|
||||
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 "<<record_number<<" box="<<item_ext<<std::endl;
|
||||
}
|
||||
tree.insert(offset,item_ext);
|
||||
if (verbose) {
|
||||
std::cout<<"record number "<<record_number<<" box="<<item_ext<<std::endl;
|
||||
}
|
||||
|
||||
pos+=4+content_length;
|
||||
++count;
|
||||
pos+=4+content_length;
|
||||
++count;
|
||||
|
||||
if (pos>=file_length) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
shp.close();
|
||||
if (pos>=file_length) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
shp.close();
|
||||
|
||||
std::cout<<" number shapes="<<count<<std::endl;
|
||||
std::cout<<" number shapes="<<count<<std::endl;
|
||||
|
||||
std::fstream file((shapename+".index").c_str(),
|
||||
std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary);
|
||||
if (!file) {
|
||||
std::cerr << "cannot open index file for writing file \""
|
||||
<<(shapename+".index")<<"\""<<std::endl;
|
||||
} else {
|
||||
tree.trim();
|
||||
|
||||
std::cout<<" number nodes="<<tree.count()<<std::endl;
|
||||
|
||||
|
||||
tree.write(file);
|
||||
file.close();
|
||||
std::fstream file((shapename+".index").c_str(),
|
||||
std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary);
|
||||
if (!file) {
|
||||
std::cerr << "cannot open index file for writing file \""
|
||||
<<(shapename+".index")<<"\""<<std::endl;
|
||||
} else {
|
||||
tree.trim();
|
||||
std::cout<<" number nodes="<<tree.count()<<std::endl;
|
||||
tree.write(file);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
std::cout<<"done!"<<std::endl;
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue