VectorUtils { public static String getWkt(Path pathToShp){ Driver driver = ogr.GetDriverByName("ESRI Shapefile"); DataSource dataSource = driver.Open(pathToShp.toString(), 0); Layer layer = dataSource.GetLayer(0); SpatialReference src = layer.GetSpatialRef(); src.MorphFromESRI(); String wkt = src.ExportToPrettyWkt(); driver.delete(); dataSource.delete(); layer.delete(); src.delete(); return wkt; } private  VectorUtils(); static String getWkt(Path pathToShp); static Rectangle2D getEnvelope(Path shapefile); static Set<String> getValues(Path pathToFeatures, String field); static Set<String> getFields(Path pathToFeatures); static Envelope toEnvelope(Rectangle2D rectangle2D);  }
@Test void GetWktReturnsWktString() { File inFile = new File(getClass().getResource( "/Truckee_River_Watershed_5mi_buffer/Truckee_River_Watershed_5mi_buffer.shp").getFile()); String wkt = VectorUtils.getWkt(inFile.toPath()); assertTrue(wkt.contains("USA_Contiguous_Albers_Equal_Area_Conic_USGS_version")); }