Esempio n. 1
0
    shape_datasource::shape_datasource(const parameters &params)
	: shape_name_(params.get("file")),
	  type_(datasource::Vector),
	  file_length_(0),
	  indexed_(false),
	  desc_(params.get("name"))
{
    try
    {
        shape_io shape(shape_name_);
        init(shape);
        for (int i=0;i<shape.dbf().num_fields();++i)
        {
            field_descriptor const& fd=shape.dbf().descriptor(i);
            std::string fld_name=fd.name_;
            switch (fd.type_)
            {
            case 'C':
            case 'D':
            case 'M':
            case 'L':		
                desc_.add_descriptor(attribute_descriptor(fld_name,String));
                break;
            case 'N':
            case 'F':
                {
                    if (fd.dec_>0)
                    {   
                        desc_.add_descriptor(attribute_descriptor(fld_name,Double,false,8));
                    }
                    else
                    {
                        desc_.add_descriptor(attribute_descriptor(fld_name,Integer,false,4));
                    }
                    break;
                }
            default:
                //
                std::clog << "unknown type "<<fd.type_<<"\n";
                break;

            }
        }
    }
    catch  (datasource_exception& ex)
    {
        std::clog<<ex.what()<<std::endl;
        throw;
    }
}
Esempio n. 2
0
 /// Convenience function to create attribute descriptors with less typing.
 static attribute_descriptor
 desc(std::string const& name, std::string const& class_name) {
   return attribute_descriptor(name, class_name);
 }