ngageoint / geopackage-js

GeoPackage JavaScript Library
http://ngageoint.github.io/geopackage-js/
MIT License
304 stars 78 forks source link

Convert GeoPackage to geojson #182

Closed jfoclpf closed 1 year ago

jfoclpf commented 1 year ago

Can you show how to convert GeoPackage file to geojson file in Node/Js

Documentation is very scarce

Thank you

danielbarela commented 1 year ago
async extract(geopackage: GeoPackage, tableName: string): Promise<any> {
    const geoJson = {
      type: 'FeatureCollection',
      features: [],
    };
    const iterator = geopackage.iterateGeoJSONFeatures(tableName);
    for (const feature of iterator) {
      geoJson.features.push(feature);
    }
    return Promise.resolve(geoJson);
  }
jfoclpf commented 1 year ago

For that don't you need to know the tableName beforehand?

caldwellc commented 1 year ago

@jfoclpf you need to know the table's name to request its features. If you want to get the feature table names in the GeoPackage, you can call the getFeatureTables method on the geopackage object.

https://ngageoint.github.io/geopackage-js/classes/geopackage.html#getfeaturetables const featureTables = geopackage.getFeatureTables();