1008{
1009 char *pszFullname;
1012 uchar abyHeader[100];
1014 double dValue;
1015 int nLenWithoutExtension;
1016
1017
1018
1019
1020#if !defined(bBigEndian)
1021 {
1022 int i = 1;
1023 if( *((
uchar *) &i) == 1 )
1025 else
1027 }
1028#endif
1029
1030
1031
1032
1037 memcpy(pszFullname, pszLayer, nLenWithoutExtension);
1038 memcpy(pszFullname + nLenWithoutExtension, ".shp", 5);
1039 fpSHP = psHooks->
FOpen(pszFullname,
"wb" );
1041 {
1042 char szErrorMsg[200];
1043 snprintf( szErrorMsg, sizeof(szErrorMsg),
1044 "Failed to create file %s: %s",
1045 pszFullname, strerror(errno) );
1046 psHooks->
Error( szErrorMsg );
1047
1048 goto error;
1049 }
1050
1051 memcpy(pszFullname + nLenWithoutExtension, ".shx", 5);
1052 fpSHX = psHooks->
FOpen(pszFullname,
"wb" );
1054 {
1055 char szErrorMsg[200];
1056 snprintf( szErrorMsg, sizeof(szErrorMsg),
1057 "Failed to create file %s: %s",
1058 pszFullname, strerror(errno) );
1059 psHooks->
Error( szErrorMsg );
1060 goto error;
1061 }
1062
1064
1065
1066
1067
1068 memset( abyHeader, 0, sizeof(abyHeader) );
1069
1070 abyHeader[2] = 0x27;
1071 abyHeader[3] = 0x0a;
1072
1073 i32 = 50;
1076
1077 i32 = 1000;
1080
1081 i32 = nShapeType;
1084
1085 dValue = 0.0;
1086 ByteCopy( &dValue, abyHeader+36, 8 );
1087 ByteCopy( &dValue, abyHeader+44, 8 );
1088 ByteCopy( &dValue, abyHeader+52, 8 );
1089 ByteCopy( &dValue, abyHeader+60, 8 );
1090
1091
1092
1093
1094 if( psHooks->
FWrite( abyHeader, 100, 1, fpSHP ) != 1 )
1095 {
1096 char szErrorMsg[200];
1097
1098 snprintf( szErrorMsg, sizeof(szErrorMsg),
1099 "Failed to write .shp header: %s", strerror(errno) );
1100 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
1101 psHooks->
Error( szErrorMsg );
1102
1103 goto error;
1104 }
1105
1106
1107
1108
1109 i32 = 50;
1112
1113 if( psHooks->
FWrite( abyHeader, 100, 1, fpSHX ) != 1 )
1114 {
1115 char szErrorMsg[200];
1116
1117 snprintf( szErrorMsg, sizeof(szErrorMsg),
1118 "Failure writing .shx header: %s", strerror(errno) );
1119 szErrorMsg[sizeof(szErrorMsg)-1] = '\0';
1120 psHooks->
Error( szErrorMsg );
1121
1122 goto error;
1123 }
1124
1125
1126
1127
1128 psHooks->
FClose( fpSHP );
1129 psHooks->
FClose( fpSHX );
1130
1131 return(
SHPOpenLL( pszLayer,
"r+b", psHooks ) );
1132
1133error:
1134 if (pszFullname)
free(pszFullname);
1135 if (fpSHP) psHooks->
FClose( fpSHP );
1136 if (fpSHX) psHooks->
FClose( fpSHX );
1138}
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)