void shape_datasource::init(shape_io& shape) { #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, "shape_datasource::init"); #endif //first read header from *.shp int file_code=shape.shp().read_xdr_integer(); if (file_code!=9994) { //invalid file code throw datasource_exception("Shape Plugin: " + (boost::format("wrong file code : %d") % file_code).str()); } shape.shp().skip(5*4); file_length_=shape.shp().read_xdr_integer(); int version=shape.shp().read_ndr_integer(); if (version!=1000) { //invalid version number throw datasource_exception("Shape Plugin: " + (boost::format("invalid version number: %d") % version).str()); } shape_type_ = static_cast<shape_io::shapeType>(shape.shp().read_ndr_integer()); if (shape_type_ == shape_io::shape_multipatch) throw datasource_exception("Shape Plugin: shapefile multipatch type is not supported"); shape.shp().read_envelope(extent_); #ifdef MAPNIK_LOG const double zmin = shape.shp().read_double(); const double zmax = shape.shp().read_double(); const double mmin = shape.shp().read_double(); const double mmax = shape.shp().read_double(); MAPNIK_LOG_DEBUG(shape) << "shape_datasource: Z min/max=" << zmin << "," << zmax; MAPNIK_LOG_DEBUG(shape) << "shape_datasource: M min/max=" << mmin << "," << mmax; #else shape.shp().skip(4*8); #endif // check if we have an index file around indexed_ = shape.has_index(); MAPNIK_LOG_DEBUG(shape) << "shape_datasource: Extent=" << extent_; MAPNIK_LOG_DEBUG(shape) << "shape_datasource: File length=" << file_length_; MAPNIK_LOG_DEBUG(shape) << "shape_datasource: Shape type=" << shape_type_; }
void shape_datasource::init(shape_io& shape) { //first read header from *.shp int file_code=shape.shp().read_xdr_integer(); if (file_code!=9994) { //invalid throw datasource_exception("wrong file code"); } shape.shp().skip(5*4); file_length_=shape.shp().read_xdr_integer(); int version=shape.shp().read_ndr_integer(); if (version!=1000) { //invalid version number throw datasource_exception("invalid version number"); } int shape_type=shape.shp().read_ndr_integer(); shape.shp().read_envelope(extent_); shape.shp().skip(4*8); // check if we have an index file around std::string index_name(shape_name_+".index"); std::ifstream file(index_name.c_str(),std::ios::in | std::ios::binary); if (file) { indexed_=true; file.close(); } std::clog << extent_ << std::endl; std::clog << "file_length=" << file_length_ << std::endl; std::clog << "shape_type=" << shape_type << std::endl; }
void setup_attributes(mapnik::context_ptr const& ctx, std::set<std::string> const& names, std::string const& shape_name, shape_io & shape, std::vector<int> & attr_ids) { std::set<std::string>::const_iterator pos = names.begin(); std::set<std::string>::const_iterator end = names.end(); for ( ;pos !=end; ++pos) { bool found_name = false; for (int i = 0; i < shape.dbf().num_fields(); ++i) { if (shape.dbf().descriptor(i).name_ == *pos) { ctx->push(*pos); attr_ids.push_back(i); found_name = true; 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) { list.push_back(shape.dbf().descriptor(i).name_); } s << boost::algorithm::join(list, ",") << "."; throw mapnik::datasource_exception("Shape Plugin: " + s.str()); } } }
void shape_datasource::init(shape_io& shape) const { //first read header from *.shp int file_code=shape.shp().read_xdr_integer(); if (file_code!=9994) { //invalid file code throw datasource_exception("Shape Plugin: " + (boost::format("wrong file code : %d") % file_code).str()); } shape.shp().skip(5*4); file_length_=shape.shp().read_xdr_integer(); int version=shape.shp().read_ndr_integer(); if (version!=1000) { //invalid version number throw datasource_exception("Shape Plugin: " + (boost::format("invalid version number: %d") % version).str()); } shape_type_ = static_cast<shape_io::shapeType>(shape.shp().read_ndr_integer()); if (shape_type_ == shape_io::shape_multipatch) throw datasource_exception("Shape Plugin: shapefile multipatch type is not supported"); shape.shp().read_envelope(extent_); #ifdef MAPNIK_DEBUG double zmin = shape.shp().read_double(); double zmax = shape.shp().read_double(); double mmin = shape.shp().read_double(); double mmax = shape.shp().read_double(); std::clog << "Shape Plugin: Z min/max " << zmin << "," << zmax << std::endl; std::clog << "Shape Plugin: M min/max " << mmin << "," << mmax << "\n"; #else shape.shp().skip(4*8); #endif // check if we have an index file around indexed_ = shape.has_index(); //std::string index_name(shape_name_+".index"); //std::ifstream file(index_name.c_str(),std::ios::in | std::ios::binary); //if (file) //{ // indexed_=true; // file.close(); //} //else //{ // std::clog << "### Notice: no .index file found for " + shape_name_ + ".shp, use the 'shapeindex' program to build an index for faster rendering\n"; //} #ifdef MAPNIK_DEBUG std::clog << "Shape Plugin: extent=" << extent_ << std::endl; std::clog << "Shape Plugin: file_length=" << file_length_ << std::endl; std::clog << "Shape Plugin: shape_type=" << shape_type_ << std::endl; #endif }