QString QgsCurvePolygon::asJson( int precision ) const
{
  // GeoJSON does not support curves
  QString json = QStringLiteral( "{\"type\": \"Polygon\", \"coordinates\": [" );

  std::unique_ptr< QgsLineString > exteriorLineString( exteriorRing()->curveToLine() );
  QgsPointSequence exteriorPts;
  exteriorLineString->points( exteriorPts );
  json += QgsGeometryUtils::pointsToJSON( exteriorPts, precision ) + ", ";

  std::unique_ptr< QgsLineString > interiorLineString;
  for ( int i = 0, n = numInteriorRings(); i < n; ++i )
  {
    interiorLineString.reset( interiorRing( i )->curveToLine() );
    QgsPointSequence interiorPts;
    interiorLineString->points( interiorPts );
    json += QgsGeometryUtils::pointsToJSON( interiorPts, precision ) + ", ";
  }
  if ( json.endsWith( QLatin1String( ", " ) ) )
  {
    json.chop( 2 ); // Remove last ", "
  }
  json += QLatin1String( "] }" );
  return json;
}
QDomElement QgsCurvePolygon::asGml2( QDomDocument &doc, int precision, const QString &ns, const AxisOrder axisOrder ) const
{
  // GML2 does not support curves
  QDomElement elemPolygon = doc.createElementNS( ns, QStringLiteral( "Polygon" ) );

  if ( isEmpty() )
    return elemPolygon;

  QDomElement elemOuterBoundaryIs = doc.createElementNS( ns, QStringLiteral( "outerBoundaryIs" ) );
  std::unique_ptr< QgsLineString > exteriorLineString( exteriorRing()->curveToLine() );
  QDomElement outerRing = exteriorLineString->asGml2( doc, precision, ns, axisOrder );
  outerRing.toElement().setTagName( QStringLiteral( "LinearRing" ) );
  elemOuterBoundaryIs.appendChild( outerRing );
  elemPolygon.appendChild( elemOuterBoundaryIs );
  std::unique_ptr< QgsLineString > interiorLineString;
  for ( int i = 0, n = numInteriorRings(); i < n; ++i )
  {
    QDomElement elemInnerBoundaryIs = doc.createElementNS( ns, QStringLiteral( "innerBoundaryIs" ) );
    interiorLineString.reset( interiorRing( i )->curveToLine() );
    QDomElement innerRing = interiorLineString->asGml2( doc, precision, ns, axisOrder );
    innerRing.toElement().setTagName( QStringLiteral( "LinearRing" ) );
    elemInnerBoundaryIs.appendChild( innerRing );
    elemPolygon.appendChild( elemInnerBoundaryIs );
  }
  return elemPolygon;
}
QDomElement QgsCurvePolygon::asGml3( QDomDocument &doc, int precision, const QString &ns, const QgsAbstractGeometry::AxisOrder axisOrder ) const
{
  QDomElement elemCurvePolygon = doc.createElementNS( ns, QStringLiteral( "Polygon" ) );

  if ( isEmpty() )
    return elemCurvePolygon;

  QDomElement elemExterior = doc.createElementNS( ns, QStringLiteral( "exterior" ) );
  QDomElement curveElem = exteriorRing()->asGml3( doc, precision, ns, axisOrder );
  if ( curveElem.tagName() == QLatin1String( "LineString" ) )
  {
    curveElem.setTagName( QStringLiteral( "LinearRing" ) );
  }
  elemExterior.appendChild( curveElem );
  elemCurvePolygon.appendChild( elemExterior );

  for ( int i = 0, n = numInteriorRings(); i < n; ++i )
  {
    QDomElement elemInterior = doc.createElementNS( ns, QStringLiteral( "interior" ) );
    QDomElement innerRing = interiorRing( i )->asGml3( doc, precision, ns, axisOrder );
    if ( innerRing.tagName() == QLatin1String( "LineString" ) )
    {
      innerRing.setTagName( QStringLiteral( "LinearRing" ) );
    }
    elemInterior.appendChild( innerRing );
    elemCurvePolygon.appendChild( elemInterior );
  }
  return elemCurvePolygon;
}
Exemple #4
0
Polygon::Polygon( const Triangle& triangle ):
    Surface()
{
    _rings.push_back( new LineString() );

    if ( ! triangle.isEmpty() ) {
        for ( size_t i = 0; i < 4; i++ ) {
            exteriorRing().addPoint( triangle.vertex( i ) );
        }
    }
}
QgsPolygon *QgsCurvePolygon::surfaceToPolygon() const
{
  std::unique_ptr< QgsPolygon > polygon( new QgsPolygon() );
  if ( !mExteriorRing )
    return polygon.release();

  polygon->setExteriorRing( exteriorRing()->curveToLine() );
  QVector<QgsCurve *> interiors;
  int n = numInteriorRings();
  interiors.reserve( n );
  for ( int i = 0; i < n; ++i )
  {
    interiors.append( interiorRing( i )->curveToLine() );
  }
  polygon->setInteriorRings( interiors );
  return polygon.release();
}
Exemple #6
0
CGAL::Polygon_with_holes_2<Kernel> Polygon::toPolygon_with_holes_2( bool fixOrientation ) const
{
    std::list<CGAL::Polygon_2<Kernel> > holes;

    for ( size_t i = 0; i < numInteriorRings(); ++i ) {
        // note that the orientation is fixed here to avoid double reverse for interior rings
        CGAL::Polygon_2<Kernel> inner = interiorRingN( i ).toPolygon_2( false );

        if ( fixOrientation && inner.orientation() == CGAL::COUNTERCLOCKWISE ) {
            inner.reverse_orientation();
        }

        holes.push_back( inner );
    }

    CGAL::Polygon_2<Kernel> outer = exteriorRing().toPolygon_2( fixOrientation );
    return CGAL::Polygon_with_holes_2<Kernel>( outer,
            holes.begin(),
            holes.end() );
}
Exemple #7
0
CGAL::Polygon_2<Kernel> Polygon::toPolygon_2( bool fixOrientation ) const
{
    return exteriorRing().toPolygon_2( fixOrientation );
}
Exemple #8
0
bool   Polygon::isMeasured() const
{
    return exteriorRing().isMeasured() ;
}
Exemple #9
0
bool   Polygon::is3D() const
{
    return exteriorRing().is3D() ;
}