⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shpopen.c

📁 Source code, and some other odds and ends can be downloaded from http://shapelib.maptools.org/dl.
💻 C
📖 第 1 页 / 共 5 页
字号:
                if( bBigEndian ) SwapWord( 4, psShape->panPartType+i );            }            nOffset += 4*nParts;        }        /* -------------------------------------------------------------------- *//*      Copy out the vertices from the record.                          *//* -------------------------------------------------------------------- */	for( i = 0; i < nPoints; i++ )	{	    memcpy(psShape->padfX + i,		   pabyRec + nOffset + i * 16,		   8 );	    memcpy(psShape->padfY + i,		   pabyRec + nOffset + i * 16 + 8,		   8 );	    if( bBigEndian ) SwapWord( 8, psShape->padfX + i );	    if( bBigEndian ) SwapWord( 8, psShape->padfY + i );	}        nOffset += 16*nPoints;        /* -------------------------------------------------------------------- *//*      If we have a Z coordinate, collect that now.                    *//* -------------------------------------------------------------------- */        if( psShape->nSHPType == SHPT_POLYGONZ            || psShape->nSHPType == SHPT_ARCZ            || psShape->nSHPType == SHPT_MULTIPATCH )        {            memcpy( &(psShape->dfZMin), pabyRec + nOffset, 8 );            memcpy( &(psShape->dfZMax), pabyRec + nOffset + 8, 8 );                        if( bBigEndian ) SwapWord( 8, &(psShape->dfZMin) );            if( bBigEndian ) SwapWord( 8, &(psShape->dfZMax) );                        for( i = 0; i < nPoints; i++ )            {                memcpy( psShape->padfZ + i,                        pabyRec + nOffset + 16 + i*8, 8 );                if( bBigEndian ) SwapWord( 8, psShape->padfZ + i );            }            nOffset += 16 + 8*nPoints;        }/* -------------------------------------------------------------------- *//*      If we have a M measure value, then read it now.  We assume      *//*      that the measure can be present for any shape if the size is    *//*      big enough, but really it will only occur for the Z shapes      *//*      (options), and the M shapes.                                    *//* -------------------------------------------------------------------- */        if( psSHP->panRecSize[hEntity]+8 >= nOffset + 16 + 8*nPoints )        {            memcpy( &(psShape->dfMMin), pabyRec + nOffset, 8 );            memcpy( &(psShape->dfMMax), pabyRec + nOffset + 8, 8 );                        if( bBigEndian ) SwapWord( 8, &(psShape->dfMMin) );            if( bBigEndian ) SwapWord( 8, &(psShape->dfMMax) );                        for( i = 0; i < nPoints; i++ )            {                memcpy( psShape->padfM + i,                        pabyRec + nOffset + 16 + i*8, 8 );                if( bBigEndian ) SwapWord( 8, psShape->padfM + i );            }        }            }/* ==================================================================== *//*  Extract vertices for a MultiPoint.					*//* ==================================================================== */    else if( psShape->nSHPType == SHPT_MULTIPOINT             || psShape->nSHPType == SHPT_MULTIPOINTM             || psShape->nSHPType == SHPT_MULTIPOINTZ )    {	int32		nPoints;	int    		i, nOffset;	memcpy( &nPoints, pabyRec + 44, 4 );	if( bBigEndian ) SwapWord( 4, &nPoints );	psShape->nVertices = nPoints;        psShape->padfX = (double *) calloc(nPoints,sizeof(double));        psShape->padfY = (double *) calloc(nPoints,sizeof(double));        psShape->padfZ = (double *) calloc(nPoints,sizeof(double));        psShape->padfM = (double *) calloc(nPoints,sizeof(double));	for( i = 0; i < nPoints; i++ )	{	    memcpy(psShape->padfX+i, pabyRec + 48 + 16 * i, 8 );	    memcpy(psShape->padfY+i, pabyRec + 48 + 16 * i + 8, 8 );	    if( bBigEndian ) SwapWord( 8, psShape->padfX + i );	    if( bBigEndian ) SwapWord( 8, psShape->padfY + i );	}        nOffset = 48 + 16*nPoints;        /* -------------------------------------------------------------------- *//*	Get the X/Y bounds.						*//* -------------------------------------------------------------------- */        memcpy( &(psShape->dfXMin), pabyRec + 8 +  4, 8 );        memcpy( &(psShape->dfYMin), pabyRec + 8 + 12, 8 );        memcpy( &(psShape->dfXMax), pabyRec + 8 + 20, 8 );        memcpy( &(psShape->dfYMax), pabyRec + 8 + 28, 8 );	if( bBigEndian ) SwapWord( 8, &(psShape->dfXMin) );	if( bBigEndian ) SwapWord( 8, &(psShape->dfYMin) );	if( bBigEndian ) SwapWord( 8, &(psShape->dfXMax) );	if( bBigEndian ) SwapWord( 8, &(psShape->dfYMax) );/* -------------------------------------------------------------------- *//*      If we have a Z coordinate, collect that now.                    *//* -------------------------------------------------------------------- */        if( psShape->nSHPType == SHPT_MULTIPOINTZ )        {            memcpy( &(psShape->dfZMin), pabyRec + nOffset, 8 );            memcpy( &(psShape->dfZMax), pabyRec + nOffset + 8, 8 );                        if( bBigEndian ) SwapWord( 8, &(psShape->dfZMin) );            if( bBigEndian ) SwapWord( 8, &(psShape->dfZMax) );                        for( i = 0; i < nPoints; i++ )            {                memcpy( psShape->padfZ + i,                        pabyRec + nOffset + 16 + i*8, 8 );                if( bBigEndian ) SwapWord( 8, psShape->padfZ + i );            }            nOffset += 16 + 8*nPoints;        }/* -------------------------------------------------------------------- *//*      If we have a M measure value, then read it now.  We assume      *//*      that the measure can be present for any shape if the size is    *//*      big enough, but really it will only occur for the Z shapes      *//*      (options), and the M shapes.                                    *//* -------------------------------------------------------------------- */        if( psSHP->panRecSize[hEntity]+8 >= nOffset + 16 + 8*nPoints )        {            memcpy( &(psShape->dfMMin), pabyRec + nOffset, 8 );            memcpy( &(psShape->dfMMax), pabyRec + nOffset + 8, 8 );                        if( bBigEndian ) SwapWord( 8, &(psShape->dfMMin) );            if( bBigEndian ) SwapWord( 8, &(psShape->dfMMax) );                        for( i = 0; i < nPoints; i++ )            {                memcpy( psShape->padfM + i,                        pabyRec + nOffset + 16 + i*8, 8 );                if( bBigEndian ) SwapWord( 8, psShape->padfM + i );            }        }    }/* ==================================================================== *//*      Extract vertices for a point.                                   *//* ==================================================================== */    else if( psShape->nSHPType == SHPT_POINT             || psShape->nSHPType == SHPT_POINTM             || psShape->nSHPType == SHPT_POINTZ )    {        int	nOffset;        	psShape->nVertices = 1;        psShape->padfX = (double *) calloc(1,sizeof(double));        psShape->padfY = (double *) calloc(1,sizeof(double));        psShape->padfZ = (double *) calloc(1,sizeof(double));        psShape->padfM = (double *) calloc(1,sizeof(double));	memcpy( psShape->padfX, pabyRec + 12, 8 );	memcpy( psShape->padfY, pabyRec + 20, 8 );	if( bBigEndian ) SwapWord( 8, psShape->padfX );	if( bBigEndian ) SwapWord( 8, psShape->padfY );        nOffset = 20 + 8;        /* -------------------------------------------------------------------- *//*      If we have a Z coordinate, collect that now.                    *//* -------------------------------------------------------------------- */        if( psShape->nSHPType == SHPT_POINTZ )        {            memcpy( psShape->padfZ, pabyRec + nOffset, 8 );                    if( bBigEndian ) SwapWord( 8, psShape->padfZ );                        nOffset += 8;        }/* -------------------------------------------------------------------- *//*      If we have a M measure value, then read it now.  We assume      *//*      that the measure can be present for any shape if the size is    *//*      big enough, but really it will only occur for the Z shapes      *//*      (options), and the M shapes.                                    *//* -------------------------------------------------------------------- */        if( psSHP->panRecSize[hEntity]+8 >= nOffset + 8 )        {            memcpy( psShape->padfM, pabyRec + nOffset, 8 );                    if( bBigEndian ) SwapWord( 8, psShape->padfM );        }/* -------------------------------------------------------------------- *//*      Since no extents are supplied in the record, we will apply      *//*      them from the single vertex.                                    *//* -------------------------------------------------------------------- */        psShape->dfXMin = psShape->dfXMax = psShape->padfX[0];        psShape->dfYMin = psShape->dfYMax = psShape->padfY[0];        psShape->dfZMin = psShape->dfZMax = psShape->padfZ[0];        psShape->dfMMin = psShape->dfMMax = psShape->padfM[0];    }    return( psShape );}/************************************************************************//*                            SHPTypeName()                             *//************************************************************************/const char SHPAPI_CALL1(*)SHPTypeName( int nSHPType ){    switch( nSHPType )    {      case SHPT_NULL:        return "NullShape";      case SHPT_POINT:        return "Point";      case SHPT_ARC:        return "Arc";      case SHPT_POLYGON:        return "Polygon";      case SHPT_MULTIPOINT:        return "MultiPoint";              case SHPT_POINTZ:        return "PointZ";      case SHPT_ARCZ:        return "ArcZ";      case SHPT_POLYGONZ:        return "PolygonZ";      case SHPT_MULTIPOINTZ:        return "MultiPointZ";              case SHPT_POINTM:        return "PointM";      case SHPT_ARCM:        return "ArcM";      case SHPT_POLYGONM:        return "PolygonM";      case SHPT_MULTIPOINTM:        return "MultiPointM";      case SHPT_MULTIPATCH:        return "MultiPatch";      default:        return "UnknownShapeType";    }}/************************************************************************//*                          SHPPartTypeName()                           *//************************************************************************/const char SHPAPI_CALL1(*)SHPPartTypeName( int nPartType ){    switch( nPartType )    {      case SHPP_TRISTRIP:        return "TriangleStrip";              case SHPP_TRIFAN:        return "TriangleFan";      case SHPP_OUTERRING:        return "OuterRing";      case SHPP_INNERRING:        return "InnerRing";      case SHPP_FIRSTRING:        return "FirstRing";      case SHPP_RING:        return "Ring";      default:        return "UnknownPartType";    }}/************************************************************************//*                          SHPDestroyObject()                          *//************************************************************************/void SHPAPI_CALLSHPDestroyObject( SHPObject * psShape ){    if( psShape == NULL )        return;        if( psShape->padfX != NULL )        free( psShape->padfX );    if( psShape->padfY != NULL )        free( psShape->padfY );    if( psShape->padfZ != NULL )        free( psShape->padfZ );    if( psShape->padfM != NULL )        free( psShape->padfM );    if( psShape->panPartStart != NULL )        free( psShape->panPartStart );    if( psShape->panPartType != NULL )        free( psShape->panPartType );    free( psShape );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -