562 |
562 |
{
|
563 |
563 |
Q_ASSERT( 1 + sizeof( wkbType ) + sizeof( int ) <= geomlen );
|
564 |
564 |
geom += 1 + sizeof( wkbType );
|
565 |
|
int nFeatures = *( unsigned int * )geom;
|
|
565 |
unsigned int nFeatures;
|
|
566 |
memcpy( &nFeatures, geom, sizeof( nFeatures ) );
|
566 |
567 |
geom += sizeof( int );
|
567 |
568 |
|
568 |
569 |
unsigned char *feature = geom;
|
... | ... | |
609 |
610 |
case QGis::WKBPoint:
|
610 |
611 |
{
|
611 |
612 |
Q_ASSERT( geom + 2*sizeof( double ) <= geomend );
|
612 |
|
double *pts = ( double * )geom;
|
613 |
|
point.p.set( pts[0], pts[1] );
|
|
613 |
double x, y;
|
|
614 |
memcpy( &x, geom, sizeof(x) );
|
|
615 |
geom += sizeof( x );
|
|
616 |
memcpy( &y, geom, sizeof(y) );
|
|
617 |
geom += sizeof( y );
|
|
618 |
point.p.set( x, y );
|
614 |
619 |
point.angle = 0.0;
|
615 |
|
geom += 2 * sizeof( double );
|
616 |
620 |
}
|
617 |
621 |
break;
|
618 |
622 |
|
... | ... | |
621 |
625 |
case QGis::WKBLineString: // Line center
|
622 |
626 |
{
|
623 |
627 |
Q_ASSERT( geom + sizeof( int ) <= geomend );
|
624 |
|
int nPoints = *( unsigned int * )geom;
|
625 |
|
geom += sizeof( int );
|
|
628 |
unsigned int nPoints;
|
|
629 |
memcpy( &nPoints, geom, sizeof( nPoints ) );
|
|
630 |
geom += sizeof( nPoints );
|
626 |
631 |
|
627 |
632 |
Q_ASSERT( geom + nPoints*sizeof( double )*dims <= geomend );
|
628 |
633 |
|
629 |
634 |
// get line center
|
630 |
|
double *pts = ( double * )geom;
|
631 |
635 |
double tl = 0.0;
|
632 |
636 |
for ( int i = 1; i < nPoints; i++ )
|
633 |
637 |
{
|
634 |
|
double dx = pts[dims*i] - pts[dims*( i-1 )];
|
635 |
|
double dy = pts[dims*i+1] - pts[dims*( i-1 )+1];
|
|
638 |
double x0, x1;
|
|
639 |
memcpy( &x0, geom + ( dims * i * sizeof( x0 ) ), sizeof( x0 ) );
|
|
640 |
memcpy( &x1, geom + ( dims * (i-1) * sizeof( x1 ) ), sizeof( x1 ) );
|
|
641 |
double dx = x0 - x1;
|
|
642 |
double y0, y1;
|
|
643 |
memcpy( &y0, geom + (( (dims * i)+1) * sizeof( y0 ) ), sizeof( y0 ) );
|
|
644 |
memcpy( &y1, geom + ( ((dims * (i-1)) + 1) * sizeof( y1 ) ), sizeof( y1 ) );
|
|
645 |
double dy = y0 - y1;
|
636 |
646 |
tl += sqrt( dx * dx + dy * dy );
|
637 |
647 |
}
|
638 |
648 |
tl /= 2.0;
|
... | ... | |
641 |
651 |
double l = 0.0;
|
642 |
652 |
for ( int i = 1; i < nPoints; i++ )
|
643 |
653 |
{
|
644 |
|
double dx = pts[dims*i] - pts[dims*( i-1 )];
|
645 |
|
double dy = pts[dims*i+1] - pts[dims*( i-1 )+1];
|
|
654 |
double x0, x1;
|
|
655 |
memcpy( &x0, geom + ( dims * i * sizeof( x0 ) ), sizeof( x0 ) );
|
|
656 |
memcpy( &x1, geom + ((( dims * i)-1) * sizeof( x1 ) ), sizeof( x1 ) );
|
|
657 |
double dx = x0 - x1;
|
|
658 |
double y0, y1;
|
|
659 |
memcpy( &y0, geom + ( dims * (i+1) * sizeof( y0 ) ), sizeof( y0 ) );
|
|
660 |
memcpy( &y1, geom + ( ((dims * (i-1)) + 1) * sizeof( y1 ) ), sizeof( y1 ) );
|
|
661 |
double dy = y0 - y1;
|
646 |
662 |
double dl = sqrt( dx * dx + dy * dy );
|
647 |
663 |
|
648 |
664 |
if ( l + dl > tl )
|
649 |
665 |
{
|
650 |
666 |
double k = ( tl - l ) / dl;
|
651 |
667 |
|
652 |
|
point.p.set( pts[dims*( i-1 )] + k * dx,
|
653 |
|
pts[dims*( i-1 )+1] + k * dy );
|
|
668 |
point.p.set( x1 + k * dx,
|
|
669 |
y1 + k * dy );
|
654 |
670 |
point.angle = atan2( dy, dx ) * 180.0 * M_1_PI;
|
655 |
671 |
break;
|
656 |
672 |
}
|
... | ... | |
667 |
683 |
case QGis::WKBPolygon: // centroid of outer ring
|
668 |
684 |
{
|
669 |
685 |
Q_ASSERT( geom + sizeof( int ) <= geomend );
|
670 |
|
int nRings = *( unsigned int * )geom;
|
|
686 |
unsigned int nRings;
|
|
687 |
memcpy( &nRings, geom, sizeof( nRings ) );
|
671 |
688 |
geom += sizeof( int );
|
672 |
689 |
|
673 |
690 |
for ( int i = 0; i < nRings; ++i )
|
674 |
691 |
{
|
675 |
692 |
Q_ASSERT( geom + sizeof( int ) <= geomend );
|
676 |
|
int nPoints = *( unsigned int * )geom;
|
|
693 |
unsigned int nPoints;
|
|
694 |
memcpy( &nPoints, geom, sizeof( nPoints ) );
|
677 |
695 |
geom += sizeof( int );
|
678 |
696 |
|
679 |
697 |
Q_ASSERT( geom + nPoints*sizeof( double )*dims <= geomend );
|
... | ... | |
681 |
699 |
if ( i == 0 )
|
682 |
700 |
{
|
683 |
701 |
double sx = 0.0, sy = 0.0;
|
684 |
|
double *pts = ( double* ) geom;
|
685 |
702 |
for ( int j = 0; j < nPoints - 1; j++ )
|
686 |
703 |
{
|
687 |
|
sx += pts[dims*j];
|
688 |
|
sy += pts[dims*j+1];
|
|
704 |
double x, y;
|
|
705 |
memcpy( &x, geom + ( dims * j * sizeof( x ) ), sizeof( x ) );
|
|
706 |
memcpy( &y, geom + ( (dims * j+1) * sizeof( y ) ), sizeof( y ) );
|
|
707 |
sx += x;
|
|
708 |
sy += y;
|
689 |
709 |
}
|
690 |
710 |
point.p.set( sx / ( nPoints - 1 ),
|
691 |
711 |
sy / ( nPoints - 1 ) );
|