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 <map>
00029
00030 #include <boost/property_map.hpp>
00031 #include <boost/utility.hpp>
00032 #include <boost/shared_ptr.hpp>
00033
00034 #include <mapnik/value.hpp>
00035 #include <mapnik/geometry.hpp>
00036 #include <mapnik/raster.hpp>
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 geometry_type geom_;
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_(),
00065 raster_() {}
00066
00067 feature(int id,const geometry_type& geom)
00068 : properties(props_),
00069 id_(id),
00070 geom_(geom),
00071 raster_() {}
00072
00073 int id() const
00074 {
00075 return id_;
00076 }
00077
00078 void set_geometry(geometry_type& geom)
00079 {
00080 geom_=geom;
00081 }
00082
00083 geometry_type const& get_geometry() const
00084 {
00085 return geom_;
00086 }
00087
00088 const raster_type& get_raster() const
00089 {
00090 return raster_;
00091 }
00092 void set_raster(raster_type const& raster)
00093 {
00094 raster_=raster;
00095 }
00096
00097 std::map<std::string,value> const& props() const
00098 {
00099 return props_;
00100 }
00101
00102 iterator begin() const
00103 {
00104 return props_.begin();
00105 }
00106
00107 iterator end() const
00108 {
00109 return props_.end();
00110 }
00111
00112 std::string to_string() const
00113 {
00114 std::stringstream ss;
00115 ss << "feature (" << std::endl;
00116 for (std::map<std::string,value>::const_iterator itr=props_.begin();
00117 itr != props_.end();++itr)
00118 {
00119 ss << " " << itr->first << ":" << itr->second << std::endl;
00120 }
00121 ss << ")" << std::endl;
00122 return ss.str();
00123 }
00124 };
00125
00126 typedef feature<geometry_ptr,raster_ptr> Feature;
00127
00128 inline std::ostream& operator<< (std::ostream & out,Feature const& f)
00129 {
00130 out << f.to_string();
00131 return out;
00132 }
00133 }
00134
00135 #endif //FEATURE_HPP