| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package com.ruoyi.test;
- import java.io.*;
- public class ShpDebug2 {
- public static void main(String[] args) throws Exception {
- String shpPath = "d:\\Web\\PlatformModel\\ruoyi-admin\\uploads\\models\\geojson\\8aa64945328e428d97923165c8b8cf31\\流域.shp";
-
- FileInputStream fis = new FileInputStream(shpPath);
- fis.skip(100); // Skip header
-
- byte[] recordHeader = new byte[8];
- fis.read(recordHeader);
-
- int contentLengthWords = readIntBE(recordHeader, 4);
- int contentLength = contentLengthWords * 2;
-
- byte[] recordContent = new byte[contentLength];
- fis.read(recordContent);
-
- System.out.println("Content Length: " + contentLength);
-
- System.out.println("\n--- CORRECT OFFSETS ---");
- System.out.println("Reading at offset 32-35 (numParts):");
- System.out.printf("Bytes: %02X %02X %02X %02X\n",
- recordContent[32], recordContent[33], recordContent[34], recordContent[35]);
- System.out.println("As LE int: " + readIntLE(recordContent, 32));
-
- System.out.println("\nReading at offset 36-39 (numPoints):");
- System.out.printf("Bytes: %02X %02X %02X %02X\n",
- recordContent[36], recordContent[37], recordContent[38], recordContent[39]);
- System.out.println("As LE int: " + readIntLE(recordContent, 36));
-
- fis.close();
- }
-
- static int readIntBE(byte[] data, int offset) {
- return ((data[offset] & 0xFF) << 24) |
- ((data[offset + 1] & 0xFF) << 16) |
- ((data[offset + 2] & 0xFF) << 8) |
- (data[offset + 3] & 0xFF);
- }
-
- static int readIntLE(byte[] data, int offset) {
- return (data[offset] & 0xFF) |
- ((data[offset + 1] & 0xFF) << 8) |
- ((data[offset + 2] & 0xFF) << 16) |
- ((data[offset + 3] & 0xFF) << 24);
- }
- }
|