ShpDebug.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package com.ruoyi.test;
  2. import java.io.*;
  3. public class ShpDebug {
  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("First 64 bytes (hex):");
  16. for (int i = 0; i < 64; i++) {
  17. System.out.printf("%02X ", recordContent[i]);
  18. if ((i + 1) % 16 == 0) System.out.println();
  19. }
  20. System.out.println("\n\nReading at offset 24-27 (numParts):");
  21. System.out.printf("Bytes: %02X %02X %02X %02X\n",
  22. recordContent[24], recordContent[25], recordContent[26], recordContent[27]);
  23. System.out.println("As LE int: " + readIntLE(recordContent, 24));
  24. System.out.println("As BE int: " + readIntBE(recordContent, 24));
  25. System.out.println("\nReading at offset 28-31 (numPoints):");
  26. System.out.printf("Bytes: %02X %02X %02X %02X\n",
  27. recordContent[28], recordContent[29], recordContent[30], recordContent[31]);
  28. System.out.println("As LE int: " + readIntLE(recordContent, 28));
  29. System.out.println("As BE int: " + readIntBE(recordContent, 28));
  30. fis.close();
  31. }
  32. static int readIntBE(byte[] data, int offset) {
  33. return ((data[offset] & 0xFF) << 24) |
  34. ((data[offset + 1] & 0xFF) << 16) |
  35. ((data[offset + 2] & 0xFF) << 8) |
  36. (data[offset + 3] & 0xFF);
  37. }
  38. static int readIntLE(byte[] data, int offset) {
  39. return (data[offset] & 0xFF) |
  40. ((data[offset + 1] & 0xFF) << 8) |
  41. ((data[offset + 2] & 0xFF) << 16) |
  42. ((data[offset + 3] & 0xFF) << 24);
  43. }
  44. }