4

I am using GeoTools for merging my individual shapefiles but I get an exception when the size of the shapefile increases beyond 2GB.

How can I do this using Geotools?

3
  • 2
    You need to use a different data type, e.g. geopackage.
    – Erik
    Commented Sep 28, 2021 at 14:54
  • 2
    Shapefile have an "official" size limit of 2GB, you may try to create bigger shapefile but that's not advised as Erik said it's time to try new a output format
    – J.R
    Commented Sep 28, 2021 at 15:10
  • 3
    In fact Shapefile can go over 2gb (up to 8gb), GDAL OGR shapefile driver can output shapefile up to 4gb (gdal.org/drivers/vector/shapefile.html#size-issues) but it's never a good idea to not follow specification as it may causes compatibility problem down the line. I advise you to try Ian Turton answer using geopackage
    – J.R
    Commented Sep 28, 2021 at 15:55

1 Answer 1

6

As everyone said in the comments - you can't. Shapefiles use a 32bit pointer internally and it breaks if you go over 2Gb. Switch to a GeoPackage, fortunately as Datastores are interchangeable all you will need to do is change the parameters you are creating it with.

HashMap<String, Object> map = new HashMap<>();
map.put(GeoPkgDataStoreFactory.DBTYPE.key, "geopkg");
map.put(GeoPkgDataStoreFactory.DATABASE.key, outFile);
Datastore store = DataStoreFinder.getDataStore(map);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.