ngageoint / geopackage-js

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

Raster geopackage #168

Closed rafaalbert closed 3 years ago

rafaalbert commented 3 years ago

I've tred to load a raster geopackage but I had this error: doneCallback is not a function. How can I solve it?

danielbarela commented 3 years ago

Where were you trying to do this?

rafaalbert commented 3 years ago

I have created my geopackage in qgis using a .tiff image. And tried this:

`var placer = L.geoPackageFeatureLayer([], { geoPackageUrl: 'code/002.gpkg', layerName: 'raster',

}).addTo(map);`

danielbarela commented 3 years ago

You appear to be trying to load a raster layer with the feature layer method. Try something like this

const tileLayer = L.geoPackageTileLayer({
  geoPackageUrl: 'code/002.gpkg',
  layerName: 'raster',
}).addTo(map);
rafaalbert commented 3 years ago

oh, yes. But now I have bunch of lines with the same error: file is not a database. Maybe I'm missing somethng when I create the geopackage in QGIS cos I used a points layer from tutorial and it works fine, but after I had this error with my raster I've created a point layer and it doesn't work

danielbarela commented 3 years ago

Have you tried loading your GeoPackage here: https://ngageoint.github.io/geopackage-js/ If it does not work there, I can look at it if you put it somewhere I can get to.

rafaalbert commented 3 years ago

I have tried right now and it was loaded fine

imagen

danielbarela commented 3 years ago

Your layer is named 002

const tileLayer = L.geoPackageTileLayer({
  geoPackageUrl: 'code/002.gpkg',
  layerName: '002',
}).addTo(map);
rafaalbert commented 3 years ago

Yeii, it woks XD . thanks for the support. I have a final question, how can I zoom to the tile?

danielbarela commented 3 years ago

Assuming that QGIS set the tile matrix set bounding box correctly, you can do this (replace my GeoPackage and layer names with yours):

const tileLayer = L.geoPackageTileLayer({
  geoPackageUrl: 'https://ngageoint.github.io/GeoPackage/examples/rivers.gpkg',
  layerName: 'rivers_tiles',
}).addTo(map);

tileLayer.on('load', function() {
  tileLayer.off('load');
  const tileDao = tileLayer.geoPackage.getTileDao('rivers_tiles');
  const projectedBoundingBox = tileDao.tileMatrixSet.boundingBox.projectBoundingBox(tileDao.projection, 'EPSG:4326');
  map.fitBounds([
    [projectedBoundingBox.minLongitude, projectedBoundingBox.minLatitude],
    [projectedBoundingBox.maxLongitude, projectedBoundingBox.maxLatitude],
  ]);
rafaalbert commented 3 years ago

Great. I'm very grateful with your help. Now it works perfectly. Thank you