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

Function msSHPWritePoint

mapshape.c:582–672  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

580}
581
582int msSHPWritePoint(SHPHandle psSHP, pointObj *point )
583{
584 int nRecordOffset, nRecordSize=0;
585 uchar *pabyRec;
586 ms_int32 i32, nPoints, nParts;
587
588 if( psSHP->nShapeType != SHP_POINT) return(-1);
589
590 psSHP->bUpdated = MS_TRUE;
591
592 /* Fill the SHX buffer if it is not already full. */
593 if( ! psSHP->panRecAllLoaded ) msSHXLoadAll( psSHP );
594
595 /* -------------------------------------------------------------------- */
596 /* Add the new entity to the in memory index. */
597 /* -------------------------------------------------------------------- */
598 psSHP->nRecords++;
599 if( psSHP->nRecords > psSHP->nMaxRecords ) {
600 psSHP->nMaxRecords = (int) (psSHP->nMaxRecords * 1.3 + 100);
601
602 psSHP->panRecOffset = (int *) SfRealloc(psSHP->panRecOffset,sizeof(int) * psSHP->nMaxRecords );
603 psSHP->panRecSize = (int *) SfRealloc(psSHP->panRecSize,sizeof(int) * psSHP->nMaxRecords );
604 }
605
606 /* -------------------------------------------------------------------- */
607 /* Compute a few things. */
608 /* -------------------------------------------------------------------- */
609 nPoints = 1;
610 nParts = 1;
611
612 /* -------------------------------------------------------------------- */
613 /* Initialize record. */
614 /* -------------------------------------------------------------------- */
615 psSHP->panRecOffset[psSHP->nRecords-1] = nRecordOffset = psSHP->nFileSize;
616
617 pabyRec = (uchar *) msSmallMalloc(nPoints * 2 * sizeof(double) + nParts * 4 + 128);
618
619 /* -------------------------------------------------------------------- */
620 /* Write vertices for a point. */
621 /* -------------------------------------------------------------------- */
622 ByteCopy( &(point->x), pabyRec + 12, 8 );
623 ByteCopy( &(point->y), pabyRec + 20, 8 );
624
625
626 if( bBigEndian ) {
627 SwapWord( 8, pabyRec + 12 );
628 SwapWord( 8, pabyRec + 20 );
629 }
630
631 nRecordSize = 20;
632
633 /* -------------------------------------------------------------------- */
634 /* Set the shape type, record number, and record size. */
635 /* -------------------------------------------------------------------- */
636 i32 = psSHP->nRecords-1+1; /* record # */
637 if( !bBigEndian ) i32 = SWAP_FOUR_BYTES(i32);
638 ByteCopy( &i32, pabyRec, 4 );
639

Callers 1

shapefileObj_addPointFunction · 0.85

Calls 4

msSHXLoadAllFunction · 0.85
msSmallMallocFunction · 0.85
SfReallocFunction · 0.70
SwapWordFunction · 0.70

Tested by

no test coverage detected