1336{
1338 unsigned int nRecordSize=0;
1339 int i;
1342 int bAppendToLastRecord =
FALSE;
1343 int bAppendToFile =
FALSE;
1344
1346
1347
1348
1349
1350
1353
1354
1355
1356
1357
1358
1360 || (
nShapeId >= 0 && nShapeId < psSHP->nRecords) );
1361
1364
1365
1366
1367
1369 {
1371 unsigned int* panRecOffsetNew;
1372 unsigned int* panRecSizeNew;
1373
1377 return -1;
1379
1383 return -1;
1385
1387 }
1388
1389
1390
1391
1393 + psObject->
nParts * 8 + 128));
1395 return -1;
1396
1397
1398
1399
1407 {
1408 int32 nPoints, nParts;
1409
1411 nParts = psObject->
nParts;
1412
1414
1417
1418 ByteCopy( &nPoints, pabyRec + 40 + 8, 4 );
1419 ByteCopy( &nParts, pabyRec + 36 + 8, 4 );
1420
1421 nRecordSize = 52;
1422
1423
1424
1425
1428 for( i = 0; i < psObject->
nParts; i++ )
1429 {
1431 nRecordSize += 4;
1432 }
1433
1434
1435
1436
1438 {
1439 memcpy( pabyRec + nRecordSize, psObject->
panPartType,
1441 for( i = 0; i < psObject->
nParts; i++ )
1442 {
1444 nRecordSize += 4;
1445 }
1446 }
1447
1448
1449
1450
1451 for( i = 0; i < psObject->
nVertices; i++ )
1452 {
1454 ByteCopy( psObject->
padfY + i, pabyRec + nRecordSize + 8, 8 );
1455
1457 SwapWord( 8, pabyRec + nRecordSize );
1458
1460 SwapWord( 8, pabyRec + nRecordSize + 8 );
1461
1462 nRecordSize += 2 * 8;
1463 }
1464
1465
1466
1467
1471 {
1474 nRecordSize += 8;
1475
1478 nRecordSize += 8;
1479
1480 for( i = 0; i < psObject->
nVertices; i++ )
1481 {
1484 nRecordSize += 8;
1485 }
1486 }
1487
1488
1489
1490
1496#endif
1499 {
1502 nRecordSize += 8;
1503
1506 nRecordSize += 8;
1507
1508 for( i = 0; i < psObject->
nVertices; i++ )
1509 {
1512 nRecordSize += 8;
1513 }
1514 }
1515 }
1516
1517
1518
1519
1523 {
1525
1527
1529
1531 ByteCopy( &nPoints, pabyRec + 44, 4 );
1532
1533 for( i = 0; i < psObject->
nVertices; i++ )
1534 {
1536 ByteCopy( psObject->
padfY + i, pabyRec + 48 + i*16 + 8, 8 );
1537
1540 }
1541
1542 nRecordSize = 48 + 16 * psObject->
nVertices;
1543
1545 {
1548 nRecordSize += 8;
1549
1552 nRecordSize += 8;
1553
1554 for( i = 0; i < psObject->
nVertices; i++ )
1555 {
1558 nRecordSize += 8;
1559 }
1560 }
1561
1565 {
1568 nRecordSize += 8;
1569
1572 nRecordSize += 8;
1573
1574 for( i = 0; i < psObject->
nVertices; i++ )
1575 {
1578 nRecordSize += 8;
1579 }
1580 }
1581 }
1582
1583
1584
1585
1589 {
1592
1595
1596 nRecordSize = 28;
1597
1599 {
1602 nRecordSize += 8;
1603 }
1604
1608 {
1611 nRecordSize += 8;
1612 }
1613 }
1614
1615
1616
1617
1619 {
1620 nRecordSize = 12;
1621 }
1622
1623 else
1624 {
1625
1627 }
1628
1629
1630
1631
1632
1633
1634
1635
1638 {
1640 bAppendToLastRecord =
TRUE;
1641 }
1643 {
1644 if( psSHP->
nFileSize > UINT_MAX - nRecordSize)
1645 {
1647 snprintf(
str,
sizeof(
str),
"Failed to write shape object. "
1648 "File size cannot reach %u + %u.",
1650 str[
sizeof(
str)-1] =
'\0';
1653 return -1;
1654 }
1655
1656 bAppendToFile =
TRUE;
1658 }
1659 else
1660 {
1662 }
1663
1664
1665
1666
1670
1671 i32 = (nRecordSize-8)/2;
1674
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1690 {
1691 char szErrorMsg[200];
1692
1693 snprintf( szErrorMsg, sizeof(szErrorMsg),
1694 "Error in psSHP->sHooks.FSeek() while writing object to .shp file: %s",
1695 strerror(errno) );
1696 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
1698
1700 return -1;
1701 }
1702
1704 {
1705 char szErrorMsg[200];
1706
1707 snprintf( szErrorMsg, sizeof(szErrorMsg),
1708 "Error in psSHP->sHooks.FWrite() while writing object of %u bytes to .shp file: %s",
1709 nRecordSize, strerror(errno) );
1710 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
1712
1714 return -1;
1715 }
1716
1718
1719 if( bAppendToLastRecord )
1720 {
1722 }
1723 else if( bAppendToFile )
1724 {
1727
1730 }
1732
1733
1734
1735
1740 {
1742 {
1747 }
1748 else
1749 {
1754 }
1755 }
1756
1757 for( i = 0; i < psObject->
nVertices; i++ )
1758 {
1763 if( psObject->
padfZ )
1764 {
1767 }
1768 if( psObject->
padfM )
1769 {
1772 }
1773 }
1774
1776}
#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