ShpDetail.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.ruoyi.test;
  2. import java.io.*;
  3. import java.util.*;
  4. public class ShpDetail {
  5. public static void main(String[] args) throws Exception {
  6. String shpPath = "d:\\Web\\PlatformModel\\ruoyi-admin\\uploads\\models\\geojson\\d18ae556145b4615ba93d1c52210166c\\流域.shp";
  7. File shpFile = new File(shpPath);
  8. FileInputStream fis = new FileInputStream(shpFile);
  9. fis.skip(100);
  10. byte[] recordHeader = new byte[8];
  11. int recordNum = 0;
  12. int successCount = 0;
  13. int failCount = 0;
  14. while (fis.available() > 8) {
  15. if (fis.read(recordHeader) < 8) break;
  16. int contentLengthWords = readIntBE(recordHeader, 4);
  17. int contentLength = contentLengthWords * 2;
  18. recordNum++;
  19. byte[] recordContent = new byte[contentLength];
  20. int bytesRead = fis.read(recordContent);
  21. if (bytesRead < contentLength) break;
  22. int recShapeType = recordContent[0] & 0xFF;
  23. if (recShapeType == 5 || recShapeType == 15) {
  24. int numParts = readIntLE(recordContent, 36);
  25. int numPoints = readIntLE(recordContent, 40);
  26. boolean success = numParts > 0 && numPoints > 0 && numParts < 1000 && numPoints < 100000;
  27. System.out.println("Record " + recordNum + ": ShapeType=" + recShapeType +
  28. ", numParts=" + numParts + ", numPoints=" + numPoints +
  29. ", contentLength=" + contentLength + " -> " + (success ? "OK" : "SKIP"));
  30. if (success) successCount++;
  31. else failCount++;
  32. }
  33. }
  34. fis.close();
  35. System.out.println("\nTotal: " + recordNum + ", Success: " + successCount + ", Failed: " + failCount);
  36. }
  37. static int readIntBE(byte[] data, int offset) {
  38. return ((data[offset] & 0xFF) << 24) |
  39. ((data[offset + 1] & 0xFF) << 16) |
  40. ((data[offset + 2] & 0xFF) << 8) |
  41. (data[offset + 3] & 0xFF);
  42. }
  43. static int readIntLE(byte[] data, int offset) {
  44. return (data[offset] & 0xFF) |
  45. ((data[offset + 1] & 0xFF) << 8) |
  46. ((data[offset + 2] & 0xFF) << 16) |
  47. ((data[offset + 3] & 0xFF) << 24);
  48. }
  49. }