mapshaper icon indicating copy to clipboard operation
mapshaper copied to clipboard

Add support for GPKG file format

Open cgmike opened this issue 6 years ago • 14 comments

GPKG support would be very helpful. They are smaller than GeoJson files and support longer attribute names as shapefile.

cgmike avatar Oct 16 '19 12:10 cgmike

I see that this format has some great features. And there's a JS implementation available (https://github.com/ngageoint/geopackage-js).

On the other hand, geopackage-js is a huge package. The npm install size is 140MB (mapshaper is 12MB). And the browser bundle is 5MB of minified JavaScript.

I don't want to rule out supporting GeoPackage in the future, but right now, I think Mapshaper users will have to use ogr2ogr to convert between GeoPackage and one of Mapshaper's supported formats.

mbloch avatar Oct 16 '19 14:10 mbloch

No pressure as I know how much work it is maintaining OS software, but I agree this would be a great feature. Thanks as always for mapshaper!

ateucher avatar Oct 16 '19 16:10 ateucher

I can't believe that the core code to read GeoPackage in geopackage-js package is that big. I quickly looked into geopackage-js package and here's definitely some other bloat code in it (like reading Shapefiles ;-). I've opened an issue over there: https://github.com/ngageoint/geopackage-js/issues/135

sfkeller avatar Oct 16 '19 19:10 sfkeller

IMHO the best approach would be to integrate GDAL into mapshaper. This would give mapshaper access to the multitude of file formats supported by GDAL. There is a Nodejs package for GDAL: https://github.com/naturalatlas/node-gdal

Unfortunately it doesn't support GPKG for some reason: https://github.com/naturalatlas/node-gdal/issues/234

But perhaps a cooperation between the projects would be helpful.

cgmike avatar Oct 17 '19 07:10 cgmike

@cgmike I like the idea of interfacing with node-gdal. As you point out, it would enable support for many file formats. It looks like the node-gdal project is not being actively maintained (incompatible with Node 12, includes an older version of GDAL, no GeoPackage support, many unanswered issues), which is too bad.

I'd like to keep the core mapshaper install relatively small... perhaps GDAL and/or GeoPackage support could be installed as add-ons.

mbloch avatar Oct 17 '19 15:10 mbloch

I used node-gdal until gyp just couldn't do the binding. Have you tried https://github.com/wavded/ogr2ogr

ffflabs avatar Oct 18 '19 02:10 ffflabs

There is now another js GeoPackage parser which generates GeoJSON:

https://loaders.gl/modules/geopackage/docs/api-reference/geopackage-loader https://github.com/visgl/loaders.gl

https://github.com/ngageoint/geopackage-js/issues/135#issuecomment-1071231493 points out that it is much smaller, about 400KB compressed, mostly due to the sql library.

Maybe worth looking into.

andreasplesch avatar Mar 17 '22 19:03 andreasplesch

I like the idea of interfacing with GDAL to support more file formats. That would give us not only GeoPackage, but also KML, ESRI geodatabase (read-only) and many other widely used formats. This approach probably means that the web interface would not get GeoPackage support, undoubtedly disappointing some folks.

ogr2ogr looks like a good option (thanks @ffflabs for the suggestion), which requires that GDAL be installed separately on your system. This is probably not a problem for most users of mapshaper's command line tool -- more likely it's an advantage.

An alternative would be node-gdal-next, which uses a more recent version of GDAL than node-gdal, and includes GeoPackage support.

I just found node-gdal-async, which seems to improve on node-gdal-next.

mbloch avatar Mar 18 '22 14:03 mbloch

ogr2ogr is a good option for server processing. For me the main attraction would be the browser interface. I would probably rather use ogr2ogr or gdal directly on the commandline.

andreasplesch avatar Mar 18 '22 14:03 andreasplesch

FYI, you can use gdal.vectorTranslate to do something similar to ogr2ogr using node-gdal-async

See small demo at https://gist.github.com/ThomasG77/3f4795f399112c152bc9105b111e6888#file-readme-md

ThomasG77 avatar Mar 18 '22 17:03 ThomasG77

Hi! Just wanted to know if there are any new developments on this front. Mapshaper is so much faster and nicer to use than other alternatives but all my data is in GPKG so converting to SHP and back adds considerable overhead, often times more than the actual clip/dissolve/etc.

FWIW, I use both mapshaper and ogr2ogr on the Command Line

arredond avatar Sep 20 '23 21:09 arredond

+1

nvkelso avatar Oct 09 '23 05:10 nvkelso