package com.ruoyi.test; import java.io.*; public class ShpCount { public static void main(String[] args) throws Exception { String shpPath = "d:\\Web\\PlatformModel\\ruoyi-admin\\uploads\\models\\geojson\\8351f649bb8443f8bf3adc0d34f89a62\\流域.shp"; File shpFile = new File(shpPath); System.out.println("SHP File Size: " + shpFile.length() + " bytes"); FileInputStream fis = new FileInputStream(shpFile); fis.skip(100); byte[] recordHeader = new byte[8]; int polygonCount = 0; int polylineCount = 0; int pointCount = 0; int totalRecords = 0; while (fis.available() > 8) { if (fis.read(recordHeader) < 8) break; int contentLengthWords = readIntBE(recordHeader, 4); int contentLength = contentLengthWords * 2; byte[] recordContent = new byte[contentLength]; int bytesRead = fis.read(recordContent); if (bytesRead < contentLength) break; int recShapeType = recordContent[0] & 0xFF; totalRecords++; if (recShapeType == 5 || recShapeType == 15) { polygonCount++; } else if (recShapeType == 3 || recShapeType == 13) { polylineCount++; } else if (recShapeType == 1 || recShapeType == 11) { pointCount++; } } fis.close(); System.out.println("Total Records: " + totalRecords); System.out.println("Polygon Count: " + polygonCount); System.out.println("Polyline Count: " + polylineCount); System.out.println("Point Count: " + pointCount); } 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); } }