ShpDebug2.java 1.9 KB

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