Beispiel #1
0
void shape_io::read_polyline( shape_file::record_type & record, mapnik::geometry_container & geom)
{
    int num_parts = record.read_ndr_integer();
    int num_points = record.read_ndr_integer();
    if (num_parts == 1)
    {
        std::auto_ptr<geometry_type> line(new geometry_type(mapnik::LineString));
        record.skip(4);
        double x = record.read_double();
        double y = record.read_double();
        line->move_to(x, y);
        for (int i = 1; i < num_points; ++i)
        {
            x = record.read_double();
            y = record.read_double();
            line->line_to(x, y);
        }
        geom.push_back(line);
    }
    else
    {
        std::vector<int> parts(num_parts);
        for (int i = 0; i < num_parts; ++i)
        {
            parts[i] = record.read_ndr_integer();
        }

        int start, end;
        for (int k = 0; k < num_parts; ++k)
        {
            std::auto_ptr<geometry_type> line(new geometry_type(mapnik::LineString));
            start = parts[k];
            if (k == num_parts - 1)
            {
                end = num_points;
            }
            else
            {
                end = parts[k + 1];
            }

            double x = record.read_double();
            double y = record.read_double();
            line->move_to(x, y);

            for (int j = start + 1; j < end; ++j)
            {
                x = record.read_double();
                y = record.read_double();
                line->line_to(x, y);
            }
            geom.push_back(line);
        }
    }
}
Beispiel #2
0
void shape_io::read_polygon(mapnik::geometry_container & geom)
{
    shape_file::record_type record(reclength_ * 2 - 36);
    shp_.read_record(record);
    
    int num_parts = record.read_ndr_integer();
    int num_points = record.read_ndr_integer();
    std::vector<int> parts(num_parts);
    
    for (int i = 0; i < num_parts; ++i)
    {
        parts[i] = record.read_ndr_integer();
    }

    for (int k = 0; k < num_parts; k++)
    {
        geometry_type* poly = new geometry_type(mapnik::Polygon);
        int start = parts[k];
        int end;
        if (k == num_parts - 1)
        {
            end = num_points;
        }
        else
        {
            end = parts[k + 1];
        }

        double x = record.read_double();
        double y = record.read_double();
        poly->move_to(x, y);

        for (int j=start+1;j<end;j++)
        {
            x = record.read_double();
            y = record.read_double();
            poly->line_to(x, y);
        }
        geom.push_back(poly);
    }
    // z-range
    //double z0=record.read_double();
    //double z1=record.read_double();
    //for (int i=0;i<num_points;++i)
    //{
    //  double z=record.read_double();
    //}

    // m-range
    //double m0=record.read_double();
    //double m1=record.read_double();

    //for (int i=0;i<num_points;++i)
    //{
    //   double m=record.read_double();
    //}
}
 static inline void to_ds_type(mapnik::geometry_container const& paths,
                 boost::optional<mapnik::datasource::geometry_t> & result)
 {
     if (paths.size() == 1)
     {
         result.reset(static_cast<mapnik::datasource::geometry_t>(paths.front().type()));
     }
     else if (paths.size() > 1)
     {
         int multi_type = 0;
         for (auto const& geom : paths)
         {
             int type = static_cast<int>(geom.type());
             if (multi_type > 0 && multi_type != type)
             {
                 result.reset(datasource::Collection);
             }
             multi_type = type;
             result.reset(static_cast<mapnik::datasource::geometry_t>(type));
         }
     }
 }
Beispiel #4
0
 void to_ds_type(mapnik::geometry_container const& paths,
                 boost::optional<mapnik::datasource::geometry_t> & result)
 {
     if (paths.size() == 1)
     {
         result.reset(static_cast<mapnik::datasource::geometry_t>(paths.front().type()));
     }
     else if (paths.size() > 1)
     {
         int multi_type = 0;
         geometry_container::const_iterator itr = paths.begin();
         geometry_container::const_iterator end = paths.end();
         for ( ; itr!=end; ++itr)
         {
             int type = static_cast<int>(itr->type());
             if (multi_type > 0 && multi_type != type)
             {
                 result.reset(datasource::Collection);
             }
             multi_type = type;
             result.reset(static_cast<mapnik::datasource::geometry_t>(type));
         }
     }
 }
Beispiel #5
0
void shape_io::read_polygon(shape_file::record_type & record, mapnik::geometry_container & geom)
{
    int num_parts = record.read_ndr_integer();
    int num_points = record.read_ndr_integer();
    std::vector<int> parts(num_parts);

    for (int i = 0; i < num_parts; ++i)
    {
        parts[i] = record.read_ndr_integer();
    }

    for (int k = 0; k < num_parts; ++k)
    {
        std::auto_ptr<geometry_type> poly(new geometry_type(mapnik::Polygon));
        int start = parts[k];
        int end;
        if (k == num_parts - 1)
        {
            end = num_points;
        }
        else
        {
            end = parts[k + 1];
        }

        double x = record.read_double();
        double y = record.read_double();
        poly->move_to(x, y);

        for (int j=start+1;j<end-1;j++)
        {
            x = record.read_double();
            y = record.read_double();
            poly->line_to(x, y);
        }
        x = record.read_double();
        y = record.read_double();
        poly->close(x, y);

        geom.push_back(poly);
    }
}
Beispiel #6
0
void shape_io::read_polyline(mapnik::geometry_container & geom)
{
    shape_file::record_type record(reclength_ * 2 - 36);
    shp_.read_record(record);
    
    int num_parts = record.read_ndr_integer();
    int num_points = record.read_ndr_integer();
    if (num_parts == 1)
    {
        geometry_type* line = new geometry_type(mapnik::LineString);   
        record.skip(4);
        double x = record.read_double();
        double y = record.read_double();
        line->move_to(x, y);
        for (int i = 1; i < num_points; ++i)
        {
            x = record.read_double();
            y = record.read_double();
            line->line_to(x, y);
        }
        geom.push_back(line);
    }
    else
    {
        std::vector<int> parts(num_parts);
        for (int i = 0; i < num_parts; ++i)
        {
            parts[i] = record.read_ndr_integer();
        }

        int start, end;
        for (int k = 0; k < num_parts; ++k)
        {
            geometry_type* line = new geometry_type(mapnik::LineString);  
            start = parts[k];
            if (k == num_parts - 1)
            {
                end = num_points;
            }
            else
            {
                end = parts[k + 1];
            }

            double x = record.read_double();
            double y = record.read_double();
            line->move_to(x, y);

            for (int j = start + 1; j < end; ++j)
            {
                x = record.read_double();
                y = record.read_double();
                line->line_to(x, y);
            }
            geom.push_back(line);
        }
    }
    // z-range
    //double z0=record.read_double();
    //double z1=record.read_double();
    //for (int i=0;i<num_points;++i)
    // {
    //  double z=record.read_double();
    // }

    // m-range
    //double m0=record.read_double();
    //double m1=record.read_double();

    //for (int i=0;i<num_points;++i)
    //{
    //   double m=record.read_double();
    //}

}