ngageoint / geopackage-js

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

Update feature geometry #170

Closed berkayoruc closed 3 years ago

berkayoruc commented 3 years ago

Hello developers. I want to update geometry of feature but I cannot find any method about it. Is it possible update local file or how can I do that? I try

GeopackageConnection.run("DELETE FROM kat_planlari WHERE mslink=5274")

and error is no such module: rtree

image

I can open and change some features of gpkg in QGIS

danielbarela commented 3 years ago

It appears that the sqljs version you are using does not include rtree in the build. How did you build this?

berkayoruc commented 3 years ago

sqljs version is 1.4.0.

danielbarela commented 3 years ago

You can't use that version. Sql.js made the decision to not include rtree in the build (see: https://github.com/sql-js/sql.js/issues/59 ). I had to create a new package and publish it, so you must use rtree-sql.js v 1.0.0

berkayoruc commented 3 years ago

Oh thank you. But this update function or update sql statement affect local gpkg or just virtual gpkg?

danielbarela commented 3 years ago

If you are using a browser, and consequentially sql.js, everything is read into memory, which is also where the changes are made if you run any update statements. After you have made your changes, to save the file, you will have to do something like this:

window.saveGeoPackage = function() {
  geoPackage.export(function(err, data) {
    fileName = fileName || 'geopackage.gpkg';
    saveByteArray([data.buffer], fileName.substring(0, fileName.lastIndexOf('.')) + '.gpkg');
  });
};

const saveByteArray = (function() {
  const a = document.createElement('a');
  document.body.appendChild(a);
  a.style = 'display: none';
  return function(data, name) {
    const blob = new Blob(data, { type: 'octet/stream' }),
      url = window.URL.createObjectURL(blob);
    a.href = url;
    a.download = name;
    a.click();
    window.URL.revokeObjectURL(url);
  };
})();
berkayoruc commented 3 years ago

Yes, I am developing for browser. So, it is not efficient way usign gpkg or any local files to editing.