コード例 #1
0
mapnik::geometry::line_string<double> geowave_featureset::create_line_string(LineString line_string)
{
    mapnik::geometry::line_string<double> line_string_out;
    for (int point_idx = line_string.getNumPoints()-1; point_idx >= 0; --point_idx)
    {
        Coordinate coord = line_string.getPointN(point_idx).getCoordinate();
        line_string_out.add_coord(coord.x(), coord.y());
    }
    if (line_string.isClosed())
    {
        Coordinate coord = line_string.getPointN(line_string.getNumPoints()-1).getCoordinate();
        line_string_out.add_coord(coord.x(), coord.y());
    }
    return line_string_out;
}
コード例 #2
0
  bool geosIntersect(const LineSegment& ls1, Meters buffer, const LineSegment& ls2,
                     LineSegment& result)
  {
    boost::shared_ptr<Geometry> g1(ls1.toGeometry(*GeometryFactory::getDefaultInstance())->clone());
    boost::shared_ptr<Geometry> g2(ls2.toGeometry(*GeometryFactory::getDefaultInstance())->clone());
    boost::shared_ptr<Geometry> g(g1->buffer(buffer, 40));

    boost::shared_ptr<Geometry> i(g->intersection(g2.get()));

    if (i->isEmpty())
    {
      result.p0 = Coordinate::getNull();
      return false;
    }
    else if (i->getGeometryTypeId() == GEOS_POINT)
    {
      Point* p = dynamic_cast<Point*>(i.get());
      result.p0 = *(p->getCoordinate());
    }
    else if (i->getGeometryTypeId() == GEOS_LINESTRING)
    {
      LineString* ls = dynamic_cast<LineString*>(i.get());
      assert(ls->getNumPoints() == 2);
      result.p0 = *ls->getPointN(0)->getCoordinate();
      result.p1 = *ls->getPointN(1)->getCoordinate();
    }
    else
    {
      throw HootException();
    }
    return true;
  }
コード例 #3
0
mapnik::geometry::polygon<double>  geowave_featureset::create_polygon(Polygon polygon)
{
    mapnik::geometry::polygon<double> polygon_out;
    
    // handle exterior ring
    {
        LineString geom = polygon.getExteriorRing();
        mapnik::geometry::linear_ring<double> linear_ring;
        for (int point_idx = geom.getNumPoints()-1; point_idx >= 0; --point_idx)
        {
            Coordinate coord = geom.getPointN(point_idx).getCoordinate();
            linear_ring.add_coord(coord.x(), coord.y());
        }
        if (geom.isClosed())
        {
            Coordinate coord = geom.getPointN(geom.getNumPoints()-1).getCoordinate();
            linear_ring.add_coord(coord.x(), coord.y());
        }
        polygon_out.set_exterior_ring(std::move(linear_ring));
    }

    // handle interior rings
    {
        for (int ring_idx = 0; ring_idx < polygon.getNumInteriorRing(); ++ring_idx)
        {
            LineString geom = polygon.getInteriorRingN(ring_idx);
            mapnik::geometry::linear_ring<double> linear_ring;
            for (int point_idx = geom.getNumPoints()-1; point_idx >= 0; --point_idx)
            {
                Coordinate coord = geom.getPointN(point_idx).getCoordinate();
                linear_ring.add_coord(coord.x(), coord.y());
            }
            if (geom.isClosed())
            {
                Coordinate coord = geom.getPointN(geom.getNumPoints()-1).getCoordinate();
                linear_ring.add_coord(coord.x(), coord.y());
            }
            polygon_out.add_hole(std::move(linear_ring));
        }
    }
    return polygon_out;
}