999{
1000 char *pszFullname;
1003 uchar abyHeader[100];
1005 double dValue;
1006 int nLenWithoutExtension;
1007
1008
1009
1010
1011#if !defined(bBigEndian)
1012 {
1013 int i = 1;
1014 if( *((
uchar *) &i) == 1 )
1016 else
1018 }
1019#endif
1020
1021
1022
1023
1026 memcpy(pszFullname, pszLayer, nLenWithoutExtension);
1027 memcpy(pszFullname + nLenWithoutExtension, ".shp", 5);
1028 fpSHP = psHooks->
FOpen(pszFullname,
"wb" );
1030 {
1031 char szErrorMsg[200];
1032 snprintf( szErrorMsg, sizeof(szErrorMsg),
1033 "Failed to create file %s: %s",
1034 pszFullname, strerror(errno) );
1035 psHooks->
Error( szErrorMsg );
1036
1037 goto error;
1038 }
1039
1040 memcpy(pszFullname + nLenWithoutExtension, ".shx", 5);
1041 fpSHX = psHooks->
FOpen(pszFullname,
"wb" );
1043 {
1044 char szErrorMsg[200];
1045 snprintf( szErrorMsg, sizeof(szErrorMsg),
1046 "Failed to create file %s: %s",
1047 pszFullname, strerror(errno) );
1048 psHooks->
Error( szErrorMsg );
1049 goto error;
1050 }
1051
1053
1054
1055
1056
1057 memset( abyHeader, 0, sizeof(abyHeader) );
1058
1059 abyHeader[2] = 0x27;
1060 abyHeader[3] = 0x0a;
1061
1062 i32 = 50;
1065
1066 i32 = 1000;
1069
1070 i32 = nShapeType;
1073
1074 dValue = 0.0;
1075 ByteCopy( &dValue, abyHeader+36, 8 );
1076 ByteCopy( &dValue, abyHeader+44, 8 );
1077 ByteCopy( &dValue, abyHeader+52, 8 );
1078 ByteCopy( &dValue, abyHeader+60, 8 );
1079
1080
1081
1082
1083 if( psHooks->
FWrite( abyHeader, 100, 1, fpSHP ) != 1 )
1084 {
1085 char szErrorMsg[200];
1086
1087 snprintf( szErrorMsg, sizeof(szErrorMsg),
1088 "Failed to write .shp header: %s", strerror(errno) );
1089 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
1090 psHooks->
Error( szErrorMsg );
1091
1092 goto error;
1093 }
1094
1095
1096
1097
1098 i32 = 50;
1101
1102 if( psHooks->
FWrite( abyHeader, 100, 1, fpSHX ) != 1 )
1103 {
1104 char szErrorMsg[200];
1105
1106 snprintf( szErrorMsg, sizeof(szErrorMsg),
1107 "Failure writing .shx header: %s", strerror(errno) );
1108 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
1109 psHooks->
Error( szErrorMsg );
1110
1111 goto error;
1112 }
1113
1114
1115
1116
1117 psHooks->
FClose( fpSHP );
1118 psHooks->
FClose( fpSHX );
1119
1120 return(
SHPOpenLL( pszLayer,
"r+b", psHooks ) );
1121
1122error:
1123 if (pszFullname)
free(pszFullname);
1124 if (fpSHP) psHooks->
FClose( fpSHP );
1125 if (fpSHX) psHooks->
FClose( fpSHX );
1127}
SHPHandle SHPAPI_CALL SHPOpenLL(const char *pszLayer, const char *pszAccess, SAHooks *psHooks)
static void SwapWord(int length, void *wordP)
static int SHPGetLenWithoutExtension(const char *pszBasename)
#define STATIC_CAST(type, x)
#define ByteCopy(a, b, c)
void(* Error)(const char *message)
SAFile(* FOpen)(const char *filename, const char *access)
SAOffset(* FWrite)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
int(* FClose)(SAFile file)