MCPcopy Index your code
hub / github.com/MapServer/MapServer / msSHPCreate

Function msSHPCreate

mapshape.c:428–540  ·  view source on GitHub ↗

/ msSHPCreate() */ / Create a new shape file and return a handle to the open */ shape file with read/write access. */ /

Source from the content-addressed store, hash-verified

426/* shape file with read/write access. */
427/************************************************************************/
428SHPHandle msSHPCreate( const char * pszLayer, int nShapeType )
429{
430 char *pszBasename, *pszFullname;
431 int i;
432 FILE *fpSHP, *fpSHX;
433 uchar abyHeader[100];
434 ms_int32 i32;
435 double dValue;
436
437#ifndef USE_POINT_Z_M
438 if( nShapeType == SHP_POLYGONZ
439 || nShapeType == SHP_POLYGONM
440 || nShapeType == SHP_ARCZ
441 || nShapeType == SHP_ARCM
442 || nShapeType == SHP_POINTZ
443 || nShapeType == SHP_POINTM
444 || nShapeType == SHP_MULTIPOINTZ
445 || nShapeType == SHP_MULTIPOINTM )
446 {
447 msSetError( MS_SHPERR,
448 "Attempt to create M/Z shapefile but without having enabled Z/M support.",
449 "msSHPCreate()" );
450 return NULL;
451 }
452#endif
453
454 /* -------------------------------------------------------------------- */
455 /* Establish the byte order on this system. */
456 /* -------------------------------------------------------------------- */
457 i = 1;
458 if( *((uchar *) &i) == 1 )
459 bBigEndian = MS_FALSE;
460 else
461 bBigEndian = MS_TRUE;
462
463 /* -------------------------------------------------------------------- */
464 /* Compute the base (layer) name. If there is any extension */
465 /* on the passed in filename we will strip it off. */
466 /* -------------------------------------------------------------------- */
467 pszBasename = (char *) msSmallMalloc(strlen(pszLayer)+5);
468 strcpy( pszBasename, pszLayer );
469 for( i = strlen(pszBasename)-1;
470 i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/' && pszBasename[i] != '\\';
471 i-- ) {}
472
473 if( pszBasename[i] == '.' )
474 pszBasename[i] = '\0';
475
476 /* -------------------------------------------------------------------- */
477 /* Open the two files so we can write their headers. */
478 /* -------------------------------------------------------------------- */
479 pszFullname = (char *) msSmallMalloc(strlen(pszBasename) + 5);
480 sprintf( pszFullname, "%s.shp", pszBasename );
481 fpSHP = fopen(pszFullname, "wb" );
482 if( fpSHP == NULL )
483 return( NULL );
484
485 sprintf( pszFullname, "%s.shx", pszBasename );

Callers 4

process_shapefilesFunction · 0.85
mainFunction · 0.85
msShapefileCreateFunction · 0.85
mainFunction · 0.85

Calls 4

msSetErrorFunction · 0.85
msSmallMallocFunction · 0.85
msSHPOpenFunction · 0.85
SwapWordFunction · 0.70

Tested by

no test coverage detected