00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef FEATURE_HPP
00026 #define FEATURE_HPP
00027
00028 #include <mapnik/value.hpp>
00029 #include <mapnik/geometry.hpp>
00030 #include <mapnik/raster.hpp>
00031
00032 #include <boost/property_map.hpp>
00033 #include <boost/utility.hpp>
00034 #include <boost/shared_ptr.hpp>
00035
00036 #include <map>
00037
00038 namespace mapnik {
00039 typedef boost::shared_ptr<raster> raster_ptr;
00040 typedef boost::associative_property_map<
00041 std::map<std::string,value
00042 > > properties;
00043
00044 template <typename T1,typename T2>
00045 struct feature : public properties,
00046 private boost::noncopyable
00047 {
00048 public:
00049 typedef T1 geometry_type;
00050 typedef T2 raster_type;
00051 typedef std::map<std::string,value>::value_type value_type;
00052 typedef std::map<std::string,value>::size_type size_type;
00053
00054 private:
00055 int id_;
00056 boost::ptr_vector<geometry_type> geom_cont_;
00057 raster_type raster_;
00058 std::map<std::string,value> props_;
00059 public:
00060 typedef std::map<std::string,value>::iterator iterator;
00061 explicit feature(int id)
00062 : properties(props_),
00063 id_(id),
00064 geom_cont_(),
00065 raster_() {}
00066
00067
00068
00069
00070
00071
00072
00073 int id() const
00074 {
00075 return id_;
00076 }
00077
00078 void add_geometry(geometry_type * geom)
00079 {
00080 geom_cont_.push_back(geom);
00081 }
00082
00083 unsigned num_geometries() const
00084 {
00085 return geom_cont_.size();
00086 }
00087
00088 geometry_type const& get_geometry(unsigned index) const
00089 {
00090 return geom_cont_[index];
00091 }
00092
00093 geometry_type& get_geometry(unsigned index)
00094 {
00095 return geom_cont_[index];
00096 }
00097
00098 const raster_type& get_raster() const
00099 {
00100 return raster_;
00101 }
00102
00103 void set_raster(raster_type const& raster)
00104 {
00105 raster_=raster;
00106 }
00107
00108 std::map<std::string,value> const& props() const
00109 {
00110 return props_;
00111 }
00112
00113 iterator begin() const
00114 {
00115 return props_.begin();
00116 }
00117
00118 iterator end() const
00119 {
00120 return props_.end();
00121 }
00122
00123 std::string to_string() const
00124 {
00125 std::stringstream ss;
00126 ss << "feature (" << std::endl;
00127 for (std::map<std::string,value>::const_iterator itr=props_.begin();
00128 itr != props_.end();++itr)
00129 {
00130 ss << " " << itr->first << ":" << itr->second << std::endl;
00131 }
00132 ss << ")" << std::endl;
00133 return ss.str();
00134 }
00135 };
00136
00137 typedef feature<geometry2d,raster_ptr> Feature;
00138
00139 inline std::ostream& operator<< (std::ostream & out,Feature const& f)
00140 {
00141 out << f.to_string();
00142 return out;
00143 }
00144 }
00145
00146 #endif //FEATURE_HPP