I'm using geotools to open gadm36.shp from gadm.org which shapefile containing worldwide administrative areas. I'm trying to get a single Geometry (e.g. org.locationtech.jts.geom.MultiPolygon) for each country. So if for example, there were 195 countries in this shapefile, I would have 195 Geometries. As a side note, I also have the GPKG file for the world so if using that is simpler, I'm happy to use that instead.
// load collection from shapefile
File file = new File("<PATH>/gadm36.shp");
Map<String, Object> map = new HashMap<>();
map.put("url", file.toURI().toURL());
DataStore dataStore = DataStoreFinder.getDataStore(map);
String typeName = dataStore.getTypeNames()[0];
FeatureSource<SimpleFeatureType, SimpleFeature> source = dataStore.getFeatureSource(typeName);
FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(Filter.INCLUDE);
That last line collection has a size of 339127. It seems to contain every sate, country, town, village, etc. How do I get a smaller list of just the countries?