Beispiel #1
0
int msDBFJoinClose(joinObj *join) 
{
  msDBFJoinInfo *joininfo = join->joininfo;

  if(!joininfo) return(MS_SUCCESS); /* already closed */

  if(joininfo->hDBF) msDBFClose(joininfo->hDBF);
  if(joininfo->target) free(joininfo->target);
  free(joininfo);
  joininfo = NULL;

  return(MS_SUCCESS);
}
Beispiel #2
0
int main( int argc, char ** argv )

{
    SHPHandle	hSHP;
    DBFHandle   hDBF;
    SHPTreeHandle	qix;

    int		i;
    char	*myfile = NULL;

    treeNodeObj *node;

#ifdef MAPSERVER
    shapeObj	shape;
    lineObj	line[3];
    pointObj	pts[6];
#else
    SHPObject	*shape;
    double	X[6], Y[6];
#endif
    int		result;
    char	mBigEndian;

    int		this_rec, factor;

    /* -------------------------------------------------------------------- */
    /*      Display a usage message.                                        */
    /* -------------------------------------------------------------------- */
    if( argc <= 2 )
    {
        printf( "shptreevis shapefile new_shapefile \n" );
        exit( 1 );
    }

    i = 1;
    if( *((unsigned char *) &i) == 1 )
        mBigEndian = 0;
    else
        mBigEndian = 1;


    qix = msSHPDiskTreeOpen (AddFileSuffix(argv[1],".qix"), 0 /* no debug*/);
    if( qix == NULL )
    {
        printf("unable to open index file %s \n", argv[1]);
        exit(-1);
    }

    /* -------------------------------------------------------------------- */
    /*      Open the passed shapefile.                                      */
    /* -------------------------------------------------------------------- */
    myfile = AddFileSuffix(argv[2],".shp");

#ifdef MAPSERVER
    hSHP = msSHPCreate ( myfile, SHPT_POLYGON );
    hDBF = msDBFCreate (  AddFileSuffix(argv[2],".dbf") );
#else
    hSHP = SHPCreate ( myfile, SHPT_POLYGON );
    hDBF = DBFCreate (  AddFileSuffix(argv[2],".dbf") );
#endif

    if ( (!hSHP) || (!hDBF) )
    {
        printf ("create error for %s    ... exiting \n", myfile);
        exit (-1);
    }

    /* add fields to dbf */
#ifdef MAPSERVER
    msDBFAddField ( hDBF, "ITEMS", FTInteger, 15,0 );
    msDBFAddField ( hDBF, "SUBNODES", FTInteger, 15,0 );
    msDBFAddField ( hDBF, "FACTOR", FTInteger, 15,0 );
#else
    DBFAddField ( hDBF, "ITEMS", FTInteger, 15,0 );
    DBFAddField ( hDBF, "SUBNODES", FTInteger, 15,0 );
    DBFAddField ( hDBF, "FACTOR", FTInteger, 15,0 );
#endif

#ifndef MAPSERVER
    SHPClose ( hSHP );
    hSHP = SHPOpen ( myfile, "r+b" );

    DBFClose (hDBF);
    hDBF = DBFOpen ( myfile, "r+b");
#endif

    printf ("This %s %s index supports a shapefile with %d shapes, %d depth \n",
            (qix->version ? "new": "old"), (qix->LSB_order? "LSB": "MSB"), (int) qix->nShapes, (int) qix->nDepth);


    /* -------------------------------------------------------------------- */
    /*	Skim over the list of shapes, printing all the vertices.	*/
    /* -------------------------------------------------------------------- */

    while( 1 )
    {
        node = readTreeNode (qix);
        if (node )
        {

            this_rec = hDBF->nRecords;

#ifdef  MAPSERVER
            msDBFWriteIntegerAttribute( hDBF, this_rec, 0, node->numshapes);
            msDBFWriteIntegerAttribute( hDBF, this_rec, 1, node->numsubnodes);
#else
            DBFWriteIntegerAttribute( hDBF, this_rec, 0, node->numshapes);
            DBFWriteIntegerAttribute( hDBF, this_rec, 1, node->numsubnodes);
#endif
            factor = node->numshapes + node->numsubnodes;

#ifdef  MAPSERVER
            shape.numlines = 1;
            shape.type = SHPT_POLYGON;

            pts[0].x = node->rect.minx;
            pts[0].y = node->rect.miny;
            pts[1].x = node->rect.maxx;
            pts[1].y = node->rect.miny;
            pts[2].x = node->rect.maxx;
            pts[2].y = node->rect.maxy;
            pts[3].x = node->rect.minx;
            pts[3].y = node->rect.maxy;
            pts[4].x = node->rect.minx;
            pts[4].y = node->rect.miny;

            line[0].numpoints = 5;
            line[0].point = &pts[0];
            shape.line = &line[0];
            shape.bounds = node->rect;

            result = msSHPWriteShape ( hSHP, &shape );
            if ( result < 0 )
            {
                printf ("unable to write shape \n");
                exit (0);
            }

#else
            X[0] = node->rect.minx;
            X[1] = node->rect.maxx;
            X[2] = node->rect.maxx;
            X[3] = node->rect.minx;
            X[4] = node->rect.minx;

            Y[0] = node->rect.miny;
            Y[1] = node->rect.miny;
            Y[2] = node->rect.maxy;
            Y[3] = node->rect.maxy;
            Y[4] = node->rect.miny;

            shape = SHPCreateSimpleObject( SHPT_POLYGON, 5, X, Y, NULL);
            SHPWriteObject(hSHP, -1, shape);
            SHPDestroyObject ( shape );
#endif
        }
        else
            break;
    }

#ifdef MAPSERVER
    msSHPClose( hSHP );
    msDBFClose( hDBF );
#else
    SHPClose( hSHP );
    DBFClose( hDBF );
#endif

    msSHPDiskTreeClose (qix);

    return(0);
}