make shape_io work with geometry_container concept

This commit is contained in:
Artem Pavlenko 2011-12-09 12:25:13 +00:00
parent 9d5d52a48f
commit 02dce6a756
4 changed files with 24 additions and 311 deletions

View file

@ -248,49 +248,19 @@ feature_ptr shape_featureset<filterT>::next()
} }
case shape_io::shape_polyline: case shape_io::shape_polyline:
{
geometry_type* line = shape_.read_polyline();
feature->add_geometry(line);
++count_;
break;
}
case shape_io::shape_polylinem: case shape_io::shape_polylinem:
{
geometry_type* line = shape_.read_polylinem();
feature->add_geometry(line);
++count_;
break;
}
case shape_io::shape_polylinez: case shape_io::shape_polylinez:
{ {
geometry_type* line = shape_.read_polylinez(); shape_.read_polyline(feature->paths());
feature->add_geometry(line);
++count_; ++count_;
break; break;
} }
case shape_io::shape_polygon: case shape_io::shape_polygon:
{
geometry_type* poly = shape_.read_polygon();
feature->add_geometry(poly);
++count_;
break;
}
case shape_io::shape_polygonm: case shape_io::shape_polygonm:
{
geometry_type* poly = shape_.read_polygonm();
feature->add_geometry(poly);
++count_;
break;
}
case shape_io::shape_polygonz: case shape_io::shape_polygonz:
{ {
geometry_type* poly = shape_.read_polygonz(); shape_.read_polygon(feature->paths());
feature->add_geometry(poly);
++count_; ++count_;
break; break;
} }

View file

@ -193,49 +193,18 @@ feature_ptr shape_index_featureset<filterT>::next()
} }
case shape_io::shape_polyline: case shape_io::shape_polyline:
{
geometry_type* line = shape_.read_polyline();
feature->add_geometry(line);
++count_;
break;
}
case shape_io::shape_polylinem: case shape_io::shape_polylinem:
{
geometry_type* line = shape_.read_polylinem();
feature->add_geometry(line);
++count_;
break;
}
case shape_io::shape_polylinez: case shape_io::shape_polylinez:
{ {
geometry_type* line = shape_.read_polylinez(); shape_.read_polyline(feature->paths());
feature->add_geometry(line);
++count_; ++count_;
break; break;
} }
case shape_io::shape_polygon: case shape_io::shape_polygon:
{
geometry_type* poly = shape_.read_polygon();
feature->add_geometry(poly);
++count_;
break;
}
case shape_io::shape_polygonm: case shape_io::shape_polygonm:
{
geometry_type* poly = shape_.read_polygonm();
feature->add_geometry(poly);
++count_;
break;
}
case shape_io::shape_polygonz: case shape_io::shape_polygonz:
{ {
geometry_type* poly = shape_.read_polygonz(); shape_.read_polygon(feature->paths());
feature->add_geometry(poly);
++count_; ++count_;
break; break;
} }

View file

@ -106,18 +106,16 @@ dbf_file& shape_io::dbf()
return dbf_; return dbf_;
} }
geometry_type* shape_io::read_polyline() void shape_io::read_polyline(mapnik::geometry_container & geom)
{ {
shape_file::record_type record(reclength_ * 2 - 36); shape_file::record_type record(reclength_ * 2 - 36);
shp_.read_record(record); shp_.read_record(record);
int num_parts = record.read_ndr_integer(); int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer(); int num_points = record.read_ndr_integer();
geometry_type* line = new geometry_type(mapnik::LineString);
line->set_capacity(num_points + num_parts);
if (num_parts == 1) if (num_parts == 1)
{ {
line->set_capacity(num_points + 1); geometry_type* line = new geometry_type(mapnik::LineString);
record.skip(4); record.skip(4);
double x = record.read_double(); double x = record.read_double();
double y = record.read_double(); double y = record.read_double();
@ -128,6 +126,7 @@ geometry_type* shape_io::read_polyline()
y = record.read_double(); y = record.read_double();
line->line_to(x, y); line->line_to(x, y);
} }
geom.push_back(line);
} }
else else
{ {
@ -140,6 +139,7 @@ geometry_type* shape_io::read_polyline()
int start, end; int start, end;
for (int k = 0; k < num_parts; ++k) for (int k = 0; k < num_parts; ++k)
{ {
geometry_type* line = new geometry_type(mapnik::LineString);
start = parts[k]; start = parts[k];
if (k == num_parts - 1) if (k == num_parts - 1)
{ {
@ -160,135 +160,9 @@ geometry_type* shape_io::read_polyline()
y = record.read_double(); y = record.read_double();
line->line_to(x, y); line->line_to(x, y);
} }
geom.push_back(line);
} }
} }
return line;
}
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);
line->set_capacity(num_points + num_parts);
if (num_parts == 1)
{
record.skip(4);
double x = record.read_double();
double y = record.read_double();
line->move_to(x, y);
for (int i = 1; i < num_points; ++i)
{
x = record.read_double();
y = record.read_double();
line->line_to(x, y);
}
}
else
{
std::vector<int> parts(num_parts);
for (int i = 0; i < num_parts; ++i)
{
parts[i] = record.read_ndr_integer();
}
int start, end;
for (int k = 0; k < num_parts; ++k)
{
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();
line->move_to(x, y);
for (int j = start + 1; j < end; ++j)
{
x = record.read_double();
y = record.read_double();
line->line_to(x, y);
}
}
}
// m-range
//double m0=record.read_double();
//double m1=record.read_double();
//for (int i=0;i<num_points;++i)
//{
// double m=record.read_double();
//}
return line;
}
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);
line->set_capacity(num_points + num_parts);
if (num_parts == 1)
{
record.skip(4);
double x = record.read_double();
double y = record.read_double();
line->move_to(x, y);
for (int i = 1; i < num_points; ++i)
{
x = record.read_double();
y = record.read_double();
line->line_to(x, y);
}
}
else
{
std::vector<int> parts(num_parts);
for (int i = 0; i < num_parts; ++i)
{
parts[i] = record.read_ndr_integer();
}
int start, end;
for (int k = 0; k < num_parts; ++k)
{
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();
line->move_to(x, y);
for (int j = start + 1; j < end; ++j)
{
x = record.read_double();
y = record.read_double();
line->line_to(x, y);
}
}
}
// z-range // z-range
//double z0=record.read_double(); //double z0=record.read_double();
//double z1=record.read_double(); //double z1=record.read_double();
@ -306,10 +180,9 @@ geometry_type* shape_io::read_polylinez()
// double m=record.read_double(); // double m=record.read_double();
//} //}
return line;
} }
geometry_type* shape_io::read_polygon() void shape_io::read_polygon(mapnik::geometry_container & geom)
{ {
shape_file::record_type record(reclength_ * 2 - 36); shape_file::record_type record(reclength_ * 2 - 36);
shp_.read_record(record); shp_.read_record(record);
@ -317,8 +190,7 @@ geometry_type* shape_io::read_polygon()
int num_parts = record.read_ndr_integer(); int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer(); int num_points = record.read_ndr_integer();
std::vector<int> parts(num_parts); std::vector<int> parts(num_parts);
geometry_type* poly = new geometry_type(mapnik::Polygon);
poly->set_capacity(num_points + num_parts);
for (int i = 0; i < num_parts; ++i) for (int i = 0; i < num_parts; ++i)
{ {
parts[i] = record.read_ndr_integer(); parts[i] = record.read_ndr_integer();
@ -326,6 +198,7 @@ geometry_type* shape_io::read_polygon()
for (int k = 0; k < num_parts; k++) for (int k = 0; k < num_parts; k++)
{ {
geometry_type* poly = new geometry_type(mapnik::Polygon);
int start = parts[k]; int start = parts[k];
int end; int end;
if (k == num_parts - 1) if (k == num_parts - 1)
@ -347,101 +220,8 @@ geometry_type* shape_io::read_polygon()
y = record.read_double(); y = record.read_double();
poly->line_to(x, y); poly->line_to(x, y);
} }
geom.push_back(poly);
} }
return poly;
}
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);
geometry_type* poly = new geometry_type(mapnik::Polygon);
poly->set_capacity(num_points + num_parts);
for (int i = 0; i < num_parts; ++i)
{
parts[i] = record.read_ndr_integer();
}
for (int k = 0; k < num_parts; k++)
{
int start = parts[k];
int end;
if (k == num_parts - 1)
{
end = num_points;
}
else
{
end = parts[k + 1];
}
double x = record.read_double();
double y = record.read_double();
poly->move_to(x, y);
for (int j = start + 1; j < end; j++)
{
x = record.read_double();
y = record.read_double();
poly->line_to(x, y);
}
}
// m-range
//double m0=record.read_double();
//double m1=record.read_double();
//for (int i=0;i<num_points;++i)
//{
// double m=record.read_double();
//}
return poly;
}
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);
geometry_type* poly = new geometry_type(mapnik::Polygon);
poly->set_capacity(num_points + num_parts);
for (int i = 0; i < num_parts; ++i)
{
parts[i] = record.read_ndr_integer();
}
for (int k = 0; k < num_parts; k++)
{
int start = parts[k];
int end;
if (k == num_parts - 1)
{
end = num_points;
}
else
{
end = parts[k + 1];
}
double x = record.read_double();
double y = record.read_double();
poly->move_to(x, y);
for (int j = start + 1; j < end; j++)
{
x = record.read_double();
y = record.read_double();
poly->line_to(x, y);
}
}
// z-range // z-range
//double z0=record.read_double(); //double z0=record.read_double();
//double z1=record.read_double(); //double z1=record.read_double();
@ -458,6 +238,6 @@ geometry_type* shape_io::read_polygonz()
//{ //{
// double m=record.read_double(); // double m=record.read_double();
//} //}
return poly;
} }

View file

@ -23,6 +23,8 @@
#ifndef SHAPE_IO_HPP #ifndef SHAPE_IO_HPP
#define SHAPE_IO_HPP #define SHAPE_IO_HPP
// mapnik
#include <mapnik/geometry.hpp>
// boost // boost
#include <boost/utility.hpp> #include <boost/utility.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
@ -56,7 +58,6 @@ public:
~shape_io(); ~shape_io();
shape_file& shp(); shape_file& shp();
//shape_file& shx();
dbf_file& dbf(); dbf_file& dbf();
inline boost::shared_ptr<shape_file>& index() inline boost::shared_ptr<shape_file>& index()
@ -72,16 +73,10 @@ public:
void move_to(int id); void move_to(int id);
int type() const; int type() const;
const box2d<double>& current_extent() const; const box2d<double>& current_extent() const;
mapnik::geometry_type* read_polyline(); void read_polyline(mapnik::geometry_container & geom);
mapnik::geometry_type* read_polylinem(); void read_polygon(mapnik::geometry_container & geom);
mapnik::geometry_type* read_polylinez();
mapnik::geometry_type* read_polygon();
mapnik::geometry_type* read_polygonm();
mapnik::geometry_type* read_polygonz();
unsigned type_; unsigned type_;
shape_file shp_; shape_file shp_;
//shape_file shx_;
dbf_file dbf_; dbf_file dbf_;
boost::shared_ptr<shape_file> index_; boost::shared_ptr<shape_file> index_;
unsigned reclength_; unsigned reclength_;
@ -89,7 +84,6 @@ public:
box2d<double> cur_extent_; box2d<double> cur_extent_;
static const std::string SHP; static const std::string SHP;
//static const std::string SHX;
static const std::string DBF; static const std::string DBF;
static const std::string INDEX; static const std::string INDEX;
}; };