Пример #1
0
featureset_ptr shape_datasource::features(const query& q) const
{
    filter_in_box filter(q.get_bbox());
    if (indexed_)
    {
        return featureset_ptr(new shape_index_featureset<filter_in_box>(filter,shape_name_,q.property_names()));
    }
    return featureset_ptr(new shape_featureset<filter_in_box>(filter,shape_name_,q.property_names(),file_length_));
}
Пример #2
0
featureset_ptr memory_datasource::features_at_point(coord2d const& pt) const
{
    box2d<double> box = box2d<double>(pt.x, pt.y, pt.x, pt.y);
#ifdef MAPNIK_DEBUG
    std::clog << "box=" << box << ", pt x=" << pt.x << ", y=" << pt.y << "\n";
#endif
    return featureset_ptr(new memory_featureset(box,*this));
}
Пример #3
0
featureset_ptr Map::query_point(unsigned index, double x, double y) const
{
    if (!current_extent_.valid())
    {
        throw std::runtime_error("query_point: map extent is not intialized, you need to set a valid extent before querying");
    }
    if (!current_extent_.intersects(x,y))
    {
        throw std::runtime_error("query_point: x,y coords do not intersect map extent");
    }
    if (index < layers_.size())
    {
        mapnik::layer const& layer = layers_[index];
        mapnik::datasource_ptr ds = layer.datasource();
        if (ds)
        {
            mapnik::projection dest(srs_);
            mapnik::projection source(layer.srs());
            proj_transform prj_trans(source,dest);
            double z = 0;
            if (!prj_trans.equal() && !prj_trans.backward(x,y,z))
            {
                throw std::runtime_error("query_point: could not project x,y into layer srs");
            }
            // calculate default tolerance
            mapnik::box2d<double> map_ex = current_extent_;
            if (maximum_extent_)
            {
                map_ex.clip(*maximum_extent_);
            }
            if (!prj_trans.backward(map_ex,PROJ_ENVELOPE_POINTS))
            {
                std::ostringstream s;
                s << "query_point: could not project map extent '" << map_ex
                  << "' into layer srs for tolerance calculation";
                throw std::runtime_error(s.str());
            }
            double tol = (map_ex.maxx() - map_ex.minx()) / width_ * 3;
            featureset_ptr fs = ds->features_at_point(mapnik::coord2d(x,y), tol);
            MAPNIK_LOG_DEBUG(map) << "map: Query at point tol=" << tol << "(" << x << "," << y << ")";
            if (fs)
            {
                return boost::make_shared<filter_featureset<hit_test_filter> >(fs,
                                                                               hit_test_filter(x,y,tol));
            }
        }
    }
    else
    {
        std::ostringstream s;
        s << "Invalid layer index passed to query_point: '" << index << "'";
        if (!layers_.empty()) s << " for map with " << layers_.size() << " layers(s)";
        else s << " (map has no layers)";
        throw std::out_of_range(s.str());
    }
    return featureset_ptr();
}
Пример #4
0
featureset_ptr Map::query_map_point(unsigned index, double x, double y) const
{
    if ( index< layers_.size())
    {
        mapnik::layer const& layer = layers_[index];
        CoordTransform tr = view_transform();
        tr.backward(&x,&y);
            
        try
        {
            mapnik::projection dest(srs_);
            mapnik::projection source(layer.srs());
            proj_transform prj_trans(source,dest);
            double z = 0;
            prj_trans.backward(x,y,z);
                
            double minx = current_extent_.minx();
            double miny = current_extent_.miny();
            double maxx = current_extent_.maxx();
            double maxy = current_extent_.maxy();
                
            prj_trans.backward(minx,miny,z);
            prj_trans.backward(maxx,maxy,z);
            double tol = (maxx - minx) / width_ * 3;
            mapnik::datasource_ptr ds = layer.datasource();
            if (ds)
            {
#ifdef MAPNIK_DEBUG
                std::clog << " query at point tol = " << tol << " (" << x << "," << y << ")\n";
#endif
                featureset_ptr fs = ds->features_at_point(mapnik::coord2d(x,y));
                if (fs) 
                    return featureset_ptr(new filter_featureset<hit_test_filter>(fs,hit_test_filter(x,y,tol)));
            }
        }
        catch (...)
        {
#ifdef MAPNIK_DEBUG
            std::clog << "exception caught in \"query_map_point\"\n";
#endif
        }
    }
    return featureset_ptr();
}
Пример #5
0
featureset_ptr memory_datasource::features(const query& q) const
{
    return featureset_ptr(new memory_featureset(q.get_bbox(),*this));
}