ogrvrtlayer.cpp

来自「支持各种栅格图像和矢量图像读取的库」· C++ 代码 · 共 1,133 行 · 第 1/3 页

CPP
1,133
字号
{    CPLFree( pszAttrFilter );    if( pszNewQuery == NULL || strlen(pszNewQuery) == 0 )        pszAttrFilter = NULL;    else        pszAttrFilter = CPLStrdup( pszNewQuery );    ResetReading();    return OGRERR_NONE;}/************************************************************************//*                           TestCapability()                           *//************************************************************************/int OGRVRTLayer::TestCapability( const char * pszCap ){    return FALSE;}/************************************************************************//*                           GetSpatialRef()                            *//************************************************************************/OGRSpatialReference *OGRVRTLayer::GetSpatialRef(){    return poSRS;}/************************************************************************//*                          GetFeatureCount()                           *//************************************************************************/int OGRVRTLayer::GetFeatureCount( int bForce ){    if( m_poFilterGeom == NULL && m_poAttrQuery == NULL )        return poSrcLayer->GetFeatureCount( bForce );    else        return OGRLayer::GetFeatureCount( bForce );}/************************************************************************//*                         createFromShapeBin()                         *//*                                                                      *//*      Translate shapefile binary representation to an OGR             *//*      geometry.                                                       *//************************************************************************/#define SHPT_NULL	0#define SHPT_POINT	1#define SHPT_ARC	3#define SHPT_POLYGON	5#define SHPT_MULTIPOINT	8#define SHPT_POINTZ	11#define SHPT_ARCZ	13#define SHPT_POLYGONZ	15#define SHPT_MULTIPOINTZ 18#define SHPT_POINTM	21#define SHPT_ARCM	23#define SHPT_POLYGONM	25#define SHPT_MULTIPOINTM 28#define SHPT_MULTIPATCH 31OGRErr OGRVRTLayer::createFromShapeBin( GByte *pabyShape, OGRGeometry **ppoGeom,                                        int nBytes ){    *ppoGeom = NULL;    if( nBytes < 1 )        return OGRERR_FAILURE;//    printf( "%s\n", CPLBinaryToHex( nBytes, pabyShape ) );    int nSHPType = pabyShape[0];/* ==================================================================== *//*  Extract vertices for a Polygon or Arc.				*//* ==================================================================== */    if( nSHPType == SHPT_POLYGON         || nSHPType == SHPT_ARC        || nSHPType == SHPT_POLYGONZ        || nSHPType == SHPT_POLYGONM        || nSHPType == SHPT_ARCZ        || nSHPType == SHPT_ARCM        || nSHPType == SHPT_MULTIPATCH )    {	GInt32		nPoints, nParts;	int    		i, nOffset;        GInt32         *panPartStart;/* -------------------------------------------------------------------- *//*      Extract part/point count, and build vertex and part arrays      *//*      to proper size.                                                 *//* -------------------------------------------------------------------- */	memcpy( &nPoints, pabyShape + 40, 4 );	memcpy( &nParts, pabyShape + 36, 4 );	CPL_LSBPTR32( &nPoints );	CPL_LSBPTR32( &nParts );        panPartStart = (GInt32 *) CPLCalloc(nParts,sizeof(GInt32));/* -------------------------------------------------------------------- *//*      Copy out the part array from the record.                        *//* -------------------------------------------------------------------- */	memcpy( panPartStart, pabyShape + 44, 4 * nParts );	for( i = 0; i < nParts; i++ )	{            CPL_LSBPTR32( panPartStart + i );	}	nOffset = 44 + 4*nParts;/* -------------------------------------------------------------------- *//*      If this is a multipatch, we will also have parts types.  For    *//*      now we ignore and skip past them.                               *//* -------------------------------------------------------------------- */        if( nSHPType == SHPT_MULTIPATCH )            nOffset += 4*nParts;        /* -------------------------------------------------------------------- *//*      Copy out the vertices from the record.                          *//* -------------------------------------------------------------------- */        double *padfX = (double *) CPLMalloc(sizeof(double)*nPoints);        double *padfY = (double *) CPLMalloc(sizeof(double)*nPoints);        double *padfZ = (double *) CPLCalloc(sizeof(double),nPoints);	for( i = 0; i < nPoints; i++ )	{	    memcpy(padfX + i, pabyShape + nOffset + i * 16, 8 );	    memcpy(padfY + i, pabyShape + nOffset + i * 16 + 8, 8 );            CPL_LSBPTR64( padfX + i );            CPL_LSBPTR64( padfY + i );	}        nOffset += 16*nPoints;        /* -------------------------------------------------------------------- *//*      If we have a Z coordinate, collect that now.                    *//* -------------------------------------------------------------------- */        if( nSHPType == SHPT_POLYGONZ            || nSHPType == SHPT_ARCZ            || nSHPType == SHPT_MULTIPATCH )        {            for( i = 0; i < nPoints; i++ )            {                memcpy( padfZ + i, pabyShape + nOffset + 16 + i*8, 8 );                CPL_LSBPTR64( padfZ + i );            }            nOffset += 16 + 8*nPoints;        }/* -------------------------------------------------------------------- *//*      Build corresponding OGR objects.                                *//* -------------------------------------------------------------------- */        if( nSHPType == SHPT_ARC             || nSHPType == SHPT_ARCZ            || nSHPType == SHPT_ARCM )        {/* -------------------------------------------------------------------- *//*      Arc - As LineString                                             *//* -------------------------------------------------------------------- */            if( nParts == 1 )            {                OGRLineString *poLine = new OGRLineString();                *ppoGeom = poLine;                poLine->setPoints( nPoints, padfX, padfY, padfX );            }/* -------------------------------------------------------------------- *//*      Arc - As MultiLineString                                        *//* -------------------------------------------------------------------- */            else            {                OGRMultiLineString *poMulti = new OGRMultiLineString;                *ppoGeom = poMulti;                for( i = 0; i < nParts; i++ )                {                    OGRLineString *poLine = new OGRLineString;                    int nVerticesInThisPart;                    if( i == nParts-1 )                        nVerticesInThisPart = nPoints - panPartStart[i];                    else                        nVerticesInThisPart =                             panPartStart[i+1] - panPartStart[i];                    poLine->setPoints( nVerticesInThisPart,                                        padfX + panPartStart[i],                                        padfY + panPartStart[i],                                        padfZ + panPartStart[i] );                    poMulti->addGeometryDirectly( poLine );                }            }        } /* ARC *//* -------------------------------------------------------------------- *//*      Polygon                                                         *//* -------------------------------------------------------------------- */        else if( nSHPType == SHPT_POLYGON                 || nSHPType == SHPT_POLYGONZ                 || nSHPType == SHPT_POLYGONM )        {            OGRPolygon *poMulti = new OGRPolygon;            *ppoGeom = poMulti;            for( i = 0; i < nParts; i++ )            {                OGRLinearRing *poRing = new OGRLinearRing;                int nVerticesInThisPart;                if( i == nParts-1 )                    nVerticesInThisPart = nPoints - panPartStart[i];                else                    nVerticesInThisPart =                         panPartStart[i+1] - panPartStart[i];                poRing->setPoints( nVerticesInThisPart,                                    padfX + panPartStart[i],                                    padfY + panPartStart[i],                                    padfZ + panPartStart[i] );                poMulti->addRingDirectly( poRing );            }        } /* polygon *//* -------------------------------------------------------------------- *//*      Multipatch                                                      *//* -------------------------------------------------------------------- */        else if( nSHPType == SHPT_MULTIPATCH )        {            /* return to this later */        }         CPLFree( panPartStart );        CPLFree( padfX );        CPLFree( padfY );        CPLFree( padfZ );        if( nSHPType == SHPT_ARC            || nSHPType == SHPT_POLYGON )            (*ppoGeom)->setCoordinateDimension( 2 );        return OGRERR_NONE;    }/* ==================================================================== *//*  Extract vertices for a MultiPoint.					*//* ==================================================================== */    else if( nSHPType == SHPT_MULTIPOINT             || nSHPType == SHPT_MULTIPOINTM             || nSHPType == SHPT_MULTIPOINTZ )    {#ifdef notdef	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 );            }        }#endif    }/* ==================================================================== *//*      Extract vertices for a point.                                   *//* ==================================================================== */    else if( nSHPType == SHPT_POINT             || nSHPType == SHPT_POINTM             || nSHPType == SHPT_POINTZ )    {        int	nOffset;        double  dfX, dfY, dfZ = 0;        	memcpy( &dfX, pabyShape + 4, 8 );	memcpy( &dfY, pabyShape + 4 + 8, 8 );        CPL_LSBPTR64( &dfX );        CPL_LSBPTR64( &dfY );        nOffset = 20 + 8;                if( nSHPType == SHPT_POINTZ )        {            memcpy( &dfZ, pabyShape + 4 + 16, 8 );            CPL_LSBPTR64( &dfY );        }        *ppoGeom = new OGRPoint( dfX, dfY, dfZ );        if( nSHPType != SHPT_POINTZ )            (*ppoGeom)->setCoordinateDimension( 2 );        return OGRERR_NONE;    }    return OGRERR_FAILURE;}

⌨️ 快捷键说明

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