| 93 | } |
| 94 | |
| 95 | BOOL LASreaderSHP::open(const char* file_name) |
| 96 | { |
| 97 | if (file_name == 0) |
| 98 | { |
| 99 | laserror("file name pointer is zero"); |
| 100 | return FALSE; |
| 101 | } |
| 102 | |
| 103 | clean(); |
| 104 | |
| 105 | file = fopen_compressed(file_name, "rb", &piped); |
| 106 | if (file == 0) |
| 107 | { |
| 108 | laserror("cannot open file '%s'", file_name); |
| 109 | return FALSE; |
| 110 | } |
| 111 | |
| 112 | // clean the header |
| 113 | |
| 114 | header.clean(); |
| 115 | |
| 116 | // populate the header as much as it makes sense |
| 117 | |
| 118 | snprintf(header.system_identifier, LAS_HEADER_CHAR_LEN, LAS_TOOLS_COPYRIGHT); |
| 119 | snprintf(header.generating_software, LAS_HEADER_CHAR_LEN, "via LASreaderSHP (%d)", LAS_TOOLS_VERSION); |
| 120 | |
| 121 | // maybe set creation date |
| 122 | |
| 123 | #ifdef _WIN32 |
| 124 | WIN32_FILE_ATTRIBUTE_DATA attr; |
| 125 | SYSTEMTIME creation; |
| 126 | GetFileAttributesEx(file_name, GetFileExInfoStandard, &attr); |
| 127 | FileTimeToSystemTime(&attr.ftCreationTime, &creation); |
| 128 | int startday[13] = {-1, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; |
| 129 | header.file_creation_day = startday[creation.wMonth] + creation.wDay; |
| 130 | header.file_creation_year = creation.wYear; |
| 131 | // leap year handling |
| 132 | if ((((creation.wYear)%4) == 0) && (creation.wMonth > 2)) header.file_creation_day++; |
| 133 | #else |
| 134 | header.file_creation_day = 111; |
| 135 | header.file_creation_year = 2011; |
| 136 | #endif |
| 137 | |
| 138 | header.point_data_format = 0; |
| 139 | header.point_data_record_length = 20; |
| 140 | |
| 141 | // initialize point |
| 142 | |
| 143 | point.init(&header, header.point_data_format, header.point_data_record_length); |
| 144 | |
| 145 | // read SHP header and populate the LAS header with the bounding box |
| 146 | |
| 147 | int int_input; |
| 148 | if (fread(&int_input, sizeof(int), 1, file) != 1) return false; // file code (BIG) |
| 149 | from_big_endian(&int_input); |
| 150 | if (int_input != 9994) |
| 151 | { |
| 152 | laserror("wrong shapefile code %d != 9994", int_input); |
nothing calls this directly
no test coverage detected