shpopen.c

来自「GIS系统支持库Geospatial Data Abstraction Libr」· C语言 代码 · 共 1,802 行 · 第 1/5 页

C
1,802
字号
        || psShape->nSHPType == SHPT_POLYGONZ        || psShape->nSHPType == SHPT_POLYGONM        || psShape->nSHPType == SHPT_ARCZ        || psShape->nSHPType == SHPT_ARCM        || psShape->nSHPType == SHPT_MULTIPATCH )    {	int32		nPoints, nParts;	int    		i, nOffset;/* -------------------------------------------------------------------- *//*	Get the X/Y bounds.						*//* -------------------------------------------------------------------- */        memcpy( &(psShape->dfXMin), psSHP->pabyRec + 8 +  4, 8 );        memcpy( &(psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8 );        memcpy( &(psShape->dfXMax), psSHP->pabyRec + 8 + 20, 8 );        memcpy( &(psShape->dfYMax), psSHP->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) );/* -------------------------------------------------------------------- *//*      Extract part/point count, and build vertex and part arrays      *//*      to proper size.                                                 *//* -------------------------------------------------------------------- */	memcpy( &nPoints, psSHP->pabyRec + 40 + 8, 4 );	memcpy( &nParts, psSHP->pabyRec + 36 + 8, 4 );	if( bBigEndian ) SwapWord( 4, &nPoints );	if( bBigEndian ) SwapWord( 4, &nParts );	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));	psShape->nParts = nParts;        psShape->panPartStart = (int *) calloc(nParts,sizeof(int));        psShape->panPartType = (int *) calloc(nParts,sizeof(int));        for( i = 0; i < nParts; i++ )            psShape->panPartType[i] = SHPP_RING;/* -------------------------------------------------------------------- *//*      Copy out the part array from the record.                        *//* -------------------------------------------------------------------- */	memcpy( psShape->panPartStart, psSHP->pabyRec + 44 + 8, 4 * nParts );	for( i = 0; i < nParts; i++ )	{	    if( bBigEndian ) SwapWord( 4, psShape->panPartStart+i );	}	nOffset = 44 + 8 + 4*nParts;/* -------------------------------------------------------------------- *//*      If this is a multipatch, we will also have parts types.         *//* -------------------------------------------------------------------- */        if( psShape->nSHPType == SHPT_MULTIPATCH )        {            memcpy( psShape->panPartType, psSHP->pabyRec + nOffset, 4*nParts );            for( i = 0; i < nParts; i++ )            {                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,		   psSHP->pabyRec + nOffset + i * 16,		   8 );	    memcpy(psShape->padfY + i,		   psSHP->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), psSHP->pabyRec + nOffset, 8 );            memcpy( &(psShape->dfZMax), psSHP->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,                        psSHP->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), psSHP->pabyRec + nOffset, 8 );            memcpy( &(psShape->dfMMax), psSHP->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,                        psSHP->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, psSHP->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, psSHP->pabyRec + 48 + 16 * i, 8 );	    memcpy(psShape->padfY+i, psSHP->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), psSHP->pabyRec + 8 +  4, 8 );        memcpy( &(psShape->dfYMin), psSHP->pabyRec + 8 + 12, 8 );        memcpy( &(psShape->dfXMax), psSHP->pabyRec + 8 + 20, 8 );        memcpy( &(psShape->dfYMax), psSHP->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), psSHP->pabyRec + nOffset, 8 );            memcpy( &(psShape->dfZMax), psSHP->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,                        psSHP->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), psSHP->pabyRec + nOffset, 8 );            memcpy( &(psShape->dfMMax), psSHP->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,                        psSHP->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, psSHP->pabyRec + 12, 8 );	memcpy( psShape->padfY, psSHP->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, psSHP->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, psSHP->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";    

⌨️ 快捷键说明

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