- modified coding style in shape plugin
This commit is contained in:
parent
c0273234b6
commit
2a4fe24ea9
7 changed files with 656 additions and 595 deletions
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -21,15 +21,15 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
// stl
|
||||
#include <iostream>
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/feature_factory.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
// stl
|
||||
#include <iostream>
|
||||
|
||||
#include "shape_featureset.hpp"
|
||||
|
||||
using mapnik::geometry_type;
|
||||
|
@ -52,6 +52,7 @@ shape_featureset<filterT>::shape_featureset(const filterT& filter,
|
|||
row_limit_(row_limit)
|
||||
{
|
||||
shape_.shp().skip(100);
|
||||
|
||||
//attributes
|
||||
typename std::set<std::string>::const_iterator pos = attribute_names.begin();
|
||||
while (pos != attribute_names.end())
|
||||
|
@ -66,12 +67,14 @@ shape_featureset<filterT>::shape_featureset(const filterT& filter,
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! found_name)
|
||||
{
|
||||
std::ostringstream s;
|
||||
|
||||
s << "no attribute '" << *pos << "' in '"
|
||||
<< shape_name << "'. Valid attributes are: ";
|
||||
|
||||
std::vector<std::string> list;
|
||||
for (int i = 0; i < shape_.dbf().num_fields(); ++i)
|
||||
{
|
||||
|
@ -85,14 +88,16 @@ shape_featureset<filterT>::shape_featureset(const filterT& filter,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename filterT>
|
||||
feature_ptr shape_featureset<filterT>::next()
|
||||
{
|
||||
if (row_limit_ && count_ > row_limit_)
|
||||
{
|
||||
return feature_ptr();
|
||||
}
|
||||
|
||||
std::streampos pos = shape_.shp().pos();
|
||||
|
||||
// skip null shapes
|
||||
while (pos > 0 && pos < std::streampos(file_length_ * 2))
|
||||
{
|
||||
|
@ -101,7 +106,10 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
{
|
||||
pos += std::streampos(12);
|
||||
}
|
||||
else break;
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pos < std::streampos(file_length_ * 2))
|
||||
|
@ -122,7 +130,8 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
{
|
||||
double x = shape_.shp().read_double();
|
||||
double y = shape_.shp().read_double();
|
||||
shape_.shp().skip(8); //m
|
||||
// skip m
|
||||
shape_.shp().skip(8);
|
||||
geometry_type* point = new geometry_type(mapnik::Point);
|
||||
point->move_to(x, y);
|
||||
feature->add_geometry(point);
|
||||
|
@ -134,7 +143,6 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
double y = shape_.shp().read_double();
|
||||
// skip z
|
||||
shape_.shp().skip(8);
|
||||
|
||||
// skip m if exists
|
||||
if (shape_.reclength_ == 8 + 36)
|
||||
{
|
||||
|
@ -154,10 +162,18 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
if (shape_.type() == shape_io::shape_null)
|
||||
{
|
||||
pos += std::streampos(12);
|
||||
// TODO handle the shapes
|
||||
std::cerr << "NULL SHAPE len=" << shape_.reclength_ << std::endl;
|
||||
}
|
||||
else if (filter_.pass(shape_.current_extent())) break;
|
||||
else pos += std::streampos(2 * shape_.reclength_ - 36);
|
||||
else if (filter_.pass(shape_.current_extent()))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos += std::streampos(2 * shape_.reclength_ - 36);
|
||||
}
|
||||
|
||||
if (pos > 0 && pos < std::streampos(file_length_ * 2))
|
||||
{
|
||||
shape_.move_to(pos);
|
||||
|
@ -187,6 +203,7 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_multipointm:
|
||||
{
|
||||
int num_points = shape_.shp().read_ndr_integer();
|
||||
|
@ -204,10 +221,11 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_multipointz:
|
||||
{
|
||||
unsigned num_points = shape_.shp().read_ndr_integer();
|
||||
for (unsigned i=0; i< num_points;++i)
|
||||
int num_points = shape_.shp().read_ndr_integer();
|
||||
for (int i = 0; i < num_points; ++i)
|
||||
{
|
||||
double x = shape_.shp().read_double();
|
||||
double y = shape_.shp().read_double();
|
||||
|
@ -220,8 +238,7 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
shape_.shp().skip(2 * 8 + 8 * num_points);
|
||||
|
||||
// check if we have measure data
|
||||
|
||||
if ( shape_.reclength_ == num_points * 16 + 36)
|
||||
if (shape_.reclength_ == (unsigned)(num_points * 16 + 36))
|
||||
{
|
||||
// skip m
|
||||
shape_.shp().skip(2 * 8 + 8 * num_points);
|
||||
|
@ -229,6 +246,7 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polyline:
|
||||
{
|
||||
geometry_type* line = shape_.read_polyline();
|
||||
|
@ -236,6 +254,7 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polylinem:
|
||||
{
|
||||
geometry_type* line = shape_.read_polylinem();
|
||||
|
@ -243,6 +262,7 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polylinez:
|
||||
{
|
||||
geometry_type* line = shape_.read_polylinez();
|
||||
|
@ -250,6 +270,7 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polygon:
|
||||
{
|
||||
geometry_type* poly = shape_.read_polygon();
|
||||
|
@ -257,6 +278,7 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polygonm:
|
||||
{
|
||||
geometry_type* poly = shape_.read_polygonm();
|
||||
|
@ -264,6 +286,7 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polygonz:
|
||||
{
|
||||
geometry_type* poly = shape_.read_polygonz();
|
||||
|
@ -292,6 +315,7 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
std::clog << "Shape Plugin: error processing attributes " << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return feature;
|
||||
}
|
||||
else
|
||||
|
@ -308,5 +332,3 @@ shape_featureset<filterT>::~shape_featureset() {}
|
|||
|
||||
template class shape_featureset<mapnik::filter_in_box>;
|
||||
template class shape_featureset<mapnik::filter_at_point>;
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,7 +20,8 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id: shape_index_featureset.cc 36 2005-04-05 14:32:18Z pavlenko $
|
||||
// stl
|
||||
#include <fstream>
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/feature_factory.hpp>
|
||||
|
@ -29,9 +30,6 @@
|
|||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/interprocess/streams/bufferstream.hpp>
|
||||
|
||||
// stl
|
||||
#include <fstream>
|
||||
|
||||
#include "shape_index_featureset.hpp"
|
||||
|
||||
using mapnik::feature_factory;
|
||||
|
@ -50,9 +48,9 @@ shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
|
|||
tr_(new transcoder(encoding)),
|
||||
count_(0),
|
||||
row_limit_(row_limit)
|
||||
|
||||
{
|
||||
shape_.shp().skip(100);
|
||||
|
||||
boost::shared_ptr<shape_file> index = shape_.index();
|
||||
if (index)
|
||||
{
|
||||
|
@ -63,6 +61,7 @@ shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
|
|||
shp_index<filterT,std::ifstream>::query(filter, index->file(), ids_);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::sort(ids_.begin(), ids_.end());
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
|
@ -85,21 +84,23 @@ shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! found_name)
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "no attribute '" << *pos << "' in '" << shape_name << "'. Valid attributes are: ";
|
||||
|
||||
s << "no attribute '" << *pos << "' in '"
|
||||
<< shape_name << "'. Valid attributes are: ";
|
||||
std::vector<std::string> list;
|
||||
for (int i = 0; i < shape_.dbf().num_fields(); ++i)
|
||||
{
|
||||
list.push_back(shape_.dbf().descriptor(i).name_);
|
||||
}
|
||||
|
||||
s << boost::algorithm::join(list, ",") << ".";
|
||||
|
||||
throw mapnik::datasource_exception("Shape Plugin: " + s.str());
|
||||
}
|
||||
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
|
@ -108,12 +109,15 @@ template <typename filterT>
|
|||
feature_ptr shape_index_featureset<filterT>::next()
|
||||
{
|
||||
if (row_limit_ && count_ > row_limit_)
|
||||
{
|
||||
return feature_ptr();
|
||||
}
|
||||
|
||||
if (itr_ != ids_.end())
|
||||
{
|
||||
int pos = *itr_++;
|
||||
shape_.move_to(pos);
|
||||
|
||||
int type = shape_.type();
|
||||
feature_ptr feature(feature_factory::create(shape_.id_));
|
||||
if (type == shape_io::shape_point)
|
||||
|
@ -125,12 +129,12 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
feature->add_geometry(point);
|
||||
++count_;
|
||||
}
|
||||
|
||||
else if (type == shape_io::shape_pointm)
|
||||
{
|
||||
double x = shape_.shp().read_double();
|
||||
double y = shape_.shp().read_double();
|
||||
shape_.shp().skip(8);// skip m
|
||||
// skip m
|
||||
shape_.shp().skip(8);
|
||||
geometry_type* point = new geometry_type(mapnik::Point);
|
||||
point->move_to(x, y);
|
||||
feature->add_geometry(point);
|
||||
|
@ -142,7 +146,6 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
double y = shape_.shp().read_double();
|
||||
// skip z
|
||||
shape_.shp().skip(8);
|
||||
|
||||
// skip m if exists
|
||||
if (shape_.reclength_ == 8 + 36)
|
||||
{
|
||||
|
@ -188,6 +191,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polyline:
|
||||
{
|
||||
geometry_type* line = shape_.read_polyline();
|
||||
|
@ -195,6 +199,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polylinem:
|
||||
{
|
||||
geometry_type* line = shape_.read_polylinem();
|
||||
|
@ -202,6 +207,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polylinez:
|
||||
{
|
||||
geometry_type* line = shape_.read_polylinez();
|
||||
|
@ -209,6 +215,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polygon:
|
||||
{
|
||||
geometry_type* poly = shape_.read_polygon();
|
||||
|
@ -216,6 +223,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polygonm:
|
||||
{
|
||||
geometry_type* poly = shape_.read_polygonm();
|
||||
|
@ -223,6 +231,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polygonz:
|
||||
{
|
||||
geometry_type* poly = shape_.read_polygonz();
|
||||
|
@ -248,7 +257,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
}
|
||||
catch (...)
|
||||
{
|
||||
std::clog << "Shape Plugin: error processing attributes" << std::endl;
|
||||
std::cerr << "Shape Plugin: error processing attributes" << std::endl;
|
||||
}
|
||||
}
|
||||
return feature;
|
||||
|
@ -269,4 +278,3 @@ shape_index_featureset<filterT>::~shape_index_featureset() {}
|
|||
|
||||
template class shape_index_featureset<mapnik::filter_in_box>;
|
||||
template class shape_index_featureset<mapnik::filter_at_point>;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -23,13 +23,18 @@
|
|||
#ifndef SHAPE_INDEX_FEATURESET_HPP
|
||||
#define SHAPE_INDEX_FEATURESET_HPP
|
||||
|
||||
// stl
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/geom_util.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
#include "shape_datasource.hpp"
|
||||
#include "shape_io.hpp"
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
using mapnik::Featureset;
|
||||
using mapnik::box2d;
|
||||
|
@ -38,18 +43,6 @@ using mapnik::feature_ptr;
|
|||
template <typename filterT>
|
||||
class shape_index_featureset : public Featureset
|
||||
{
|
||||
filterT filter_;
|
||||
//int shape_type_;
|
||||
shape_io & shape_;
|
||||
boost::scoped_ptr<transcoder> tr_;
|
||||
std::vector<int> ids_;
|
||||
std::vector<int>::iterator itr_;
|
||||
std::set<int> attr_ids_;
|
||||
mutable box2d<double> feature_ext_;
|
||||
mutable int total_geom_size;
|
||||
mutable int count_;
|
||||
const int row_limit_;
|
||||
|
||||
public:
|
||||
shape_index_featureset(const filterT& filter,
|
||||
shape_io& shape,
|
||||
|
@ -61,6 +54,17 @@ class shape_index_featureset : public Featureset
|
|||
feature_ptr next();
|
||||
|
||||
private:
|
||||
filterT filter_;
|
||||
//int shape_type_;
|
||||
shape_io & shape_;
|
||||
boost::scoped_ptr<transcoder> tr_;
|
||||
std::vector<int> ids_;
|
||||
std::vector<int>::iterator itr_;
|
||||
std::set<int> attr_ids_;
|
||||
mutable box2d<double> feature_ext_;
|
||||
mutable int total_geom_size;
|
||||
mutable int count_;
|
||||
const int row_limit_;
|
||||
//no copying
|
||||
shape_index_featureset(const shape_index_featureset&);
|
||||
shape_index_featureset& operator=(const shape_index_featureset&);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,10 +20,9 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id: shape_io.cc 26 2005-03-29 19:18:59Z pavlenko $
|
||||
|
||||
#include "shape_io.hpp"
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/datasource.hpp>
|
||||
|
||||
// boost
|
||||
|
@ -49,11 +48,11 @@ shape_io::shape_io(const std::string& shape_name, bool open_index)
|
|||
{
|
||||
throw datasource_exception("Shape Plugin: cannot read shape file '" + shape_name + "'");
|
||||
}
|
||||
|
||||
if (open_index)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
index_= boost::make_shared<shape_file>(shape_name + INDEX);
|
||||
}
|
||||
catch (...)
|
||||
|
@ -95,11 +94,12 @@ shape_file& shape_io::shp()
|
|||
return shp_;
|
||||
}
|
||||
|
||||
/*shape_file& shape_io::shx()
|
||||
#if 0
|
||||
shape_file& shape_io::shx()
|
||||
{
|
||||
return shx_;
|
||||
}*/
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
dbf_file& shape_io::dbf()
|
||||
{
|
||||
|
@ -110,6 +110,7 @@ geometry_type * shape_io::read_polyline()
|
|||
{
|
||||
shape_file::record_type record(reclength_ * 2 - 36);
|
||||
shp_.read_record(record);
|
||||
|
||||
int num_parts = record.read_ndr_integer();
|
||||
int num_points = record.read_ndr_integer();
|
||||
geometry_type* line = new geometry_type(mapnik::LineString);
|
||||
|
@ -141,9 +142,13 @@ geometry_type * shape_io::read_polyline()
|
|||
{
|
||||
start = parts[k];
|
||||
if (k == num_parts - 1)
|
||||
{
|
||||
end = num_points;
|
||||
}
|
||||
else
|
||||
{
|
||||
end = parts[k + 1];
|
||||
}
|
||||
|
||||
double x = record.read_double();
|
||||
double y = record.read_double();
|
||||
|
@ -164,6 +169,7 @@ geometry_type * shape_io::read_polylinem()
|
|||
{
|
||||
shape_file::record_type record(reclength_ * 2 - 36);
|
||||
shp_.read_record(record);
|
||||
|
||||
int num_parts = record.read_ndr_integer();
|
||||
int num_points = record.read_ndr_integer();
|
||||
geometry_type* line = new geometry_type(mapnik::LineString);
|
||||
|
@ -194,9 +200,13 @@ geometry_type * shape_io::read_polylinem()
|
|||
{
|
||||
start = parts[k];
|
||||
if (k == num_parts - 1)
|
||||
{
|
||||
end = num_points;
|
||||
}
|
||||
else
|
||||
{
|
||||
end = parts[k + 1];
|
||||
}
|
||||
|
||||
double x = record.read_double();
|
||||
double y = record.read_double();
|
||||
|
@ -210,6 +220,7 @@ geometry_type * shape_io::read_polylinem()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// m-range
|
||||
//double m0=record.read_double();
|
||||
//double m1=record.read_double();
|
||||
|
@ -226,6 +237,7 @@ geometry_type * shape_io::read_polylinez()
|
|||
{
|
||||
shape_file::record_type record(reclength_ * 2 - 36);
|
||||
shp_.read_record(record);
|
||||
|
||||
int num_parts = record.read_ndr_integer();
|
||||
int num_points = record.read_ndr_integer();
|
||||
geometry_type* line = new geometry_type(mapnik::LineString);
|
||||
|
@ -256,9 +268,13 @@ geometry_type * shape_io::read_polylinez()
|
|||
{
|
||||
start = parts[k];
|
||||
if (k == num_parts - 1)
|
||||
{
|
||||
end = num_points;
|
||||
}
|
||||
else
|
||||
{
|
||||
end = parts[k + 1];
|
||||
}
|
||||
|
||||
double x = record.read_double();
|
||||
double y = record.read_double();
|
||||
|
@ -272,6 +288,7 @@ geometry_type * shape_io::read_polylinez()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// z-range
|
||||
//double z0=record.read_double();
|
||||
//double z1=record.read_double();
|
||||
|
@ -288,6 +305,7 @@ geometry_type * shape_io::read_polylinez()
|
|||
//{
|
||||
// double m=record.read_double();
|
||||
//}
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
|
@ -295,6 +313,7 @@ geometry_type * shape_io::read_polygon()
|
|||
{
|
||||
shape_file::record_type record(reclength_ * 2 - 36);
|
||||
shp_.read_record(record);
|
||||
|
||||
int num_parts = record.read_ndr_integer();
|
||||
int num_points = record.read_ndr_integer();
|
||||
std::vector<int> parts(num_parts);
|
||||
|
@ -317,6 +336,7 @@ geometry_type * shape_io::read_polygon()
|
|||
{
|
||||
end = parts[k + 1];
|
||||
}
|
||||
|
||||
double x = record.read_double();
|
||||
double y = record.read_double();
|
||||
poly->move_to(x, y);
|
||||
|
@ -335,6 +355,7 @@ geometry_type * shape_io::read_polygonm()
|
|||
{
|
||||
shape_file::record_type record(reclength_ * 2 - 36);
|
||||
shp_.read_record(record);
|
||||
|
||||
int num_parts = record.read_ndr_integer();
|
||||
int num_points = record.read_ndr_integer();
|
||||
std::vector<int> parts(num_parts);
|
||||
|
@ -357,6 +378,7 @@ geometry_type * shape_io::read_polygonm()
|
|||
{
|
||||
end = parts[k + 1];
|
||||
}
|
||||
|
||||
double x = record.read_double();
|
||||
double y = record.read_double();
|
||||
poly->move_to(x, y);
|
||||
|
@ -368,6 +390,7 @@ geometry_type * shape_io::read_polygonm()
|
|||
poly->line_to(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
// m-range
|
||||
//double m0=record.read_double();
|
||||
//double m1=record.read_double();
|
||||
|
@ -383,6 +406,7 @@ geometry_type * shape_io::read_polygonz()
|
|||
{
|
||||
shape_file::record_type record(reclength_ * 2 - 36);
|
||||
shp_.read_record(record);
|
||||
|
||||
int num_parts = record.read_ndr_integer();
|
||||
int num_points = record.read_ndr_integer();
|
||||
std::vector<int> parts(num_parts);
|
||||
|
@ -405,6 +429,7 @@ geometry_type * shape_io::read_polygonz()
|
|||
{
|
||||
end = parts[k + 1];
|
||||
}
|
||||
|
||||
double x = record.read_double();
|
||||
double y = record.read_double();
|
||||
poly->move_to(x, y);
|
||||
|
@ -416,6 +441,7 @@ geometry_type * shape_io::read_polygonz()
|
|||
poly->line_to(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
// z-range
|
||||
//double z0=record.read_double();
|
||||
//double z1=record.read_double();
|
||||
|
@ -432,5 +458,6 @@ geometry_type * shape_io::read_polygonz()
|
|||
//{
|
||||
// double m=record.read_double();
|
||||
//}
|
||||
|
||||
return poly;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -23,29 +23,16 @@
|
|||
#ifndef SHAPE_IO_HPP
|
||||
#define SHAPE_IO_HPP
|
||||
|
||||
// mapnik
|
||||
#include "dbfile.hpp"
|
||||
#include "shapefile.hpp"
|
||||
#include "shp_index.hpp"
|
||||
// boost
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "dbfile.hpp"
|
||||
#include "shapefile.hpp"
|
||||
#include "shp_index.hpp"
|
||||
|
||||
struct shape_io : boost::noncopyable
|
||||
{
|
||||
static const std::string SHP;
|
||||
//static const std::string SHX;
|
||||
static const std::string DBF;
|
||||
static const std::string INDEX;
|
||||
unsigned type_;
|
||||
shape_file shp_;
|
||||
//shape_file shx_;
|
||||
dbf_file dbf_;
|
||||
boost::shared_ptr<shape_file> index_;
|
||||
unsigned reclength_;
|
||||
unsigned id_;
|
||||
box2d<double> cur_extent_;
|
||||
|
||||
public:
|
||||
enum shapeType
|
||||
{
|
||||
|
@ -67,6 +54,7 @@ public:
|
|||
|
||||
shape_io(const std::string& shape_name, bool open_index=true);
|
||||
~shape_io();
|
||||
|
||||
shape_file& shp();
|
||||
//shape_file& shx();
|
||||
dbf_file& dbf();
|
||||
|
@ -90,6 +78,20 @@ public:
|
|||
mapnik::geometry_type* read_polygon();
|
||||
mapnik::geometry_type* read_polygonm();
|
||||
mapnik::geometry_type* read_polygonz();
|
||||
|
||||
unsigned type_;
|
||||
shape_file shp_;
|
||||
//shape_file shx_;
|
||||
dbf_file dbf_;
|
||||
boost::shared_ptr<shape_file> index_;
|
||||
unsigned reclength_;
|
||||
unsigned id_;
|
||||
box2d<double> cur_extent_;
|
||||
|
||||
static const std::string SHP;
|
||||
//static const std::string SHX;
|
||||
static const std::string DBF;
|
||||
static const std::string INDEX;
|
||||
};
|
||||
|
||||
#endif //SHAPE_IO_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -20,11 +20,13 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id: shapefile.hpp 33 2005-04-04 13:01:03Z pavlenko $
|
||||
|
||||
#ifndef SHAPEFILE_HPP
|
||||
#define SHAPEFILE_HPP
|
||||
|
||||
// stl
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/global.hpp>
|
||||
#include <mapnik/box2d.hpp>
|
||||
|
@ -35,10 +37,6 @@
|
|||
#include <boost/cstdint.hpp>
|
||||
#include <boost/interprocess/streams/bufferstream.hpp>
|
||||
|
||||
// stl
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
|
||||
using mapnik::box2d;
|
||||
using mapnik::read_int32_ndr;
|
||||
using mapnik::read_int32_xdr;
|
||||
|
@ -73,11 +71,17 @@ struct shape_record
|
|||
typename Tag::data_type data;
|
||||
size_t size;
|
||||
mutable size_t pos;
|
||||
|
||||
explicit shape_record(size_t size)
|
||||
:
|
||||
data(Tag::alloc(size)),
|
||||
: data(Tag::alloc(size)),
|
||||
size(size),
|
||||
pos(0) {}
|
||||
pos(0)
|
||||
{}
|
||||
|
||||
~shape_record()
|
||||
{
|
||||
Tag::dealloc(data);
|
||||
}
|
||||
|
||||
void set_data(typename Tag::data_type data_)
|
||||
{
|
||||
|
@ -117,16 +121,11 @@ struct shape_record
|
|||
pos += 8;
|
||||
return val;
|
||||
}
|
||||
|
||||
long remains()
|
||||
{
|
||||
return (size - pos);
|
||||
}
|
||||
|
||||
~shape_record()
|
||||
{
|
||||
Tag::dealloc(data);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
using namespace boost::interprocess;
|
||||
|
@ -144,10 +143,10 @@ public:
|
|||
#endif
|
||||
|
||||
file_source_type file_;
|
||||
|
||||
shape_file() {}
|
||||
|
||||
shape_file(std::string const& file_name)
|
||||
:
|
||||
shape_file(std::string const& file_name) :
|
||||
#ifdef SHAPE_MEMORY_MAPPED_FILE
|
||||
file_()
|
||||
#else
|
||||
|
@ -155,8 +154,9 @@ public:
|
|||
#endif
|
||||
{
|
||||
#ifdef SHAPE_MEMORY_MAPPED_FILE
|
||||
boost::optional<mapnik::mapped_region_ptr> memory =
|
||||
mapnik::mapped_memory_cache::find(file_name.c_str(),true);
|
||||
|
||||
boost::optional<mapnik::mapped_region_ptr> memory = mapnik::mapped_memory_cache::find(file_name.c_str(),true);
|
||||
if (memory)
|
||||
{
|
||||
file_.buffer(static_cast<char*>((*memory)->get_address()), (*memory)->get_size());
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2006 Artem Pavlenko
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -23,9 +23,10 @@
|
|||
#ifndef SHP_INDEX_HH
|
||||
#define SHP_INDEX_HH
|
||||
|
||||
// st
|
||||
// stl
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/box2d.hpp>
|
||||
#include <mapnik/query.hpp>
|
||||
|
@ -85,7 +86,6 @@ void shp_index<filterT,IStream>::query_node(const filterT& filter,IStream & file
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename filterT, typename IStream>
|
||||
int shp_index<filterT, IStream>::read_ndr_integer(IStream& file)
|
||||
{
|
||||
|
@ -94,12 +94,10 @@ int shp_index<filterT,IStream>::read_ndr_integer(IStream & file)
|
|||
return (b[0] & 0xff) | (b[1] & 0xff) << 8 | (b[2] & 0xff) << 16 | (b[3] & 0xff) << 24;
|
||||
}
|
||||
|
||||
|
||||
template <typename filterT, typename IStream>
|
||||
void shp_index<filterT, IStream>::read_envelope(IStream& file, box2d<double>& envelope)
|
||||
{
|
||||
file.read(reinterpret_cast<char*>(&envelope), sizeof(envelope));
|
||||
}
|
||||
|
||||
|
||||
#endif // SHP_INDEX_HH
|
||||
|
|
Loading…
Reference in a new issue