1347{
1349 unsigned int nRecordSize=0;
1350 int i;
1353 int bAppendToLastRecord =
FALSE;
1354 int bAppendToFile =
FALSE;
1355
1357
1358
1359
1360
1361
1364
1365
1366
1367
1368
1369
1371 || (
nShapeId >= 0 && nShapeId < psSHP->nRecords) );
1372
1375
1376
1377
1378
1380 {
1382 unsigned int* panRecOffsetNew;
1383 unsigned int* panRecSizeNew;
1384
1388 return -1;
1390
1394 return -1;
1396
1398 }
1399
1400
1401
1402
1404 + psObject->
nParts * 8 + 128));
1406 return -1;
1407
1408
1409
1410
1418 {
1419 int32 nPoints, nParts;
1420
1422 nParts = psObject->
nParts;
1423
1425
1428
1429 ByteCopy( &nPoints, pabyRec + 40 + 8, 4 );
1430 ByteCopy( &nParts, pabyRec + 36 + 8, 4 );
1431
1432 nRecordSize = 52;
1433
1434
1435
1436
1439 for( i = 0; i < psObject->
nParts; i++ )
1440 {
1442 nRecordSize += 4;
1443 }
1444
1445
1446
1447
1449 {
1450 memcpy( pabyRec + nRecordSize, psObject->
panPartType,
1452 for( i = 0; i < psObject->
nParts; i++ )
1453 {
1455 nRecordSize += 4;
1456 }
1457 }
1458
1459
1460
1461
1462 for( i = 0; i < psObject->
nVertices; i++ )
1463 {
1465 ByteCopy( psObject->
padfY + i, pabyRec + nRecordSize + 8, 8 );
1466
1468 SwapWord( 8, pabyRec + nRecordSize );
1469
1471 SwapWord( 8, pabyRec + nRecordSize + 8 );
1472
1473 nRecordSize += 2 * 8;
1474 }
1475
1476
1477
1478
1482 {
1485 nRecordSize += 8;
1486
1489 nRecordSize += 8;
1490
1491 for( i = 0; i < psObject->
nVertices; i++ )
1492 {
1495 nRecordSize += 8;
1496 }
1497 }
1498
1499
1500
1501
1507#endif
1510 {
1513 nRecordSize += 8;
1514
1517 nRecordSize += 8;
1518
1519 for( i = 0; i < psObject->
nVertices; i++ )
1520 {
1523 nRecordSize += 8;
1524 }
1525 }
1526 }
1527
1528
1529
1530
1534 {
1536
1538
1540
1542 ByteCopy( &nPoints, pabyRec + 44, 4 );
1543
1544 for( i = 0; i < psObject->
nVertices; i++ )
1545 {
1547 ByteCopy( psObject->
padfY + i, pabyRec + 48 + i*16 + 8, 8 );
1548
1551 }
1552
1553 nRecordSize = 48 + 16 * psObject->
nVertices;
1554
1556 {
1559 nRecordSize += 8;
1560
1563 nRecordSize += 8;
1564
1565 for( i = 0; i < psObject->
nVertices; i++ )
1566 {
1569 nRecordSize += 8;
1570 }
1571 }
1572
1576 {
1579 nRecordSize += 8;
1580
1583 nRecordSize += 8;
1584
1585 for( i = 0; i < psObject->
nVertices; i++ )
1586 {
1589 nRecordSize += 8;
1590 }
1591 }
1592 }
1593
1594
1595
1596
1600 {
1603
1606
1607 nRecordSize = 28;
1608
1610 {
1613 nRecordSize += 8;
1614 }
1615
1619 {
1622 nRecordSize += 8;
1623 }
1624 }
1625
1626
1627
1628
1630 {
1631 nRecordSize = 12;
1632 }
1633
1634 else
1635 {
1636
1638 }
1639
1640
1641
1642
1643
1644
1645
1646
1649 {
1651 bAppendToLastRecord =
TRUE;
1652 }
1654 {
1655 if( psSHP->
nFileSize > UINT_MAX - nRecordSize)
1656 {
1658 snprintf(
str,
sizeof(
str),
"Failed to write shape object. "
1659 "File size cannot reach %u + %u.",
1661 str[
sizeof(
str)-1] =
'\0';
1664 return -1;
1665 }
1666
1667 bAppendToFile =
TRUE;
1669 }
1670 else
1671 {
1673 }
1674
1675
1676
1677
1681
1682 i32 = (nRecordSize-8)/2;
1685
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1701 {
1702 char szErrorMsg[200];
1703
1704 snprintf( szErrorMsg, sizeof(szErrorMsg),
1705 "Error in psSHP->sHooks.FSeek() while writing object to .shp file: %s",
1706 strerror(errno) );
1707 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
1709
1711 return -1;
1712 }
1713
1715 {
1716 char szErrorMsg[200];
1717
1718 snprintf( szErrorMsg, sizeof(szErrorMsg),
1719 "Error in psSHP->sHooks.FWrite() while writing object of %u bytes to .shp file: %s",
1720 nRecordSize, strerror(errno) );
1721 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
1723
1725 return -1;
1726 }
1727
1729
1730 if( bAppendToLastRecord )
1731 {
1733 }
1734 else if( bAppendToFile )
1735 {
1738
1741 }
1743
1744
1745
1746
1751 {
1753 {
1758 }
1759 else
1760 {
1765 }
1766 }
1767
1768 for( i = 0; i < psObject->
nVertices; i++ )
1769 {
1774 if( psObject->
padfZ )
1775 {
1778 }
1779 if( psObject->
padfM )
1780 {
1783 }
1784 }
1785
1787}
#define DISABLE_MULTIPATCH_MEASURE
static void * SfRealloc(void *pMem, int nNewSize)
static void SwapWord(int length, void *wordP)
#define STATIC_CAST(type, x)
static void _SHPSetBounds(uchar *pabyRec, SHPObject *psShape)
#define ByteCopy(a, b, c)
void(* Error)(const char *message)
SAOffset(* FWrite)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
SAOffset(* FSeek)(SAFile file, SAOffset offset, int whence)
unsigned int * panRecSize
unsigned int * panRecOffset