Giter Club home page Giter Club logo

Comments (7)

twelch avatar twelch commented on July 19, 2024 2

In the meantime, or as a precursor, here's a technique I'm playing with to use georaster directly to fetch a smaller window from a larger COG based on the bbox of a polygon. The smaller raster then gets passed to the geoblaze function. Feedback welcome.

I'm using a 7.5GB raster with categorical data, 10 meter pixels, that has been reprojected to 4326. I'm keeping full image resolution here for accuracy, I suspect if I increased the resolution (pixel size) of the window it would automatically use the larger overviews of the COG.

  const local_raster_url = "http://127.0.0.1:8080/my_cog.tif";
  console.time("parse");
  const georaster = await parseGeoraster(local_raster_url);
  console.timeEnd("parse");

  const bboxToPixel = (bbox: number[], georaster: any) => {
    return {
      left: Math.floor((bbox[0] - georaster.xmin) / georaster.pixelWidth),
      bottom: Math.floor((georaster.ymax - bbox[1]) / georaster.pixelHeight),
      right: Math.floor((bbox[2] - georaster.xmin) / georaster.pixelWidth),
      top: Math.floor((georaster.ymax - bbox[3]) / georaster.pixelHeight),
    };
  };

  // test polygon
  const poly = {
    type: "Feature",
    geometry: {
      type: "Polygon",
      coordinates: [
        [
          [72.80315092590186, 7.085649871759048],
          [72.80538252380232, 7.086714560376918],
          [72.80692747619494, 7.086757147870481],
          [72.80868700530874, 7.084542592987691],
          [72.80731371429309, 7.082200263746901],
          [72.80611208465437, 7.082285439564114],
          [72.80293634918067, 7.083009433375327],
          [72.80315092590186, 7.085649871759048],
        ],
      ],
    },
    properties: {},
  };

  const polyBbox = bbox(poly);
  const window = bboxToPixel(polyBbox, georaster);

  const options = {
    left: window.left,
    top: window.top,
    right: window.right,
    bottom: window.bottom,
    width: window.right - window.left,
    height: window.bottom - window.top,
    resampleMethod: "nearest",
  };
  console.log("options", options);

  if (georaster.getValues) {
    console.time("read");
    const values = await georaster.getValues(options);
    console.timeEnd("read");
    console.time("reparse");
    const noDataValue = 0;
    const projection = 4326;
    const xmin = polyBbox[0]; // left
    const ymax = polyBbox[3]; // top
    const pixelWidth = georaster.pixelWidth;
    const pixelHeight = georaster.pixelHeight;
    const metadata = {
      noDataValue,
      projection,
      xmin,
      ymax,
      pixelWidth,
      pixelHeight,
    };

    const windowRaster = await parseGeoraster(values, metadata);
    console.timeEnd("reparse");

    const histogram = geoblaze.histogram(windowRaster, poly, {
      scaleType: "nominal",
    })[0];
    console.log("histogram", histogram);
  }
};

Output with raster served on localhost (over the Internet is slower as expected):

parse: 32.611ms
190067
30142
options {
  left: 6270,
  top: 2970,
  right: 6408,
  bottom: 3079,
  width: 138,
  height: 109,
  resampleMethod: 'nearest'
}
read: 69.812ms
reparse: 0.787ms
histogram { '1': 2281, '6': 58 }

from geoblaze.

CarlQLange avatar CarlQLange commented on July 19, 2024 1

identify also needs to use getValues instead of values, I noticed.

Yes, I have a fork already where I started work, but unfortunately I don't have quite enough of an understanding about how lat/long gets mapped to windows and so on. But I'll give it another go in the next few days and try it out - this would be really great functionality!

Do you have any other notes that I might find useful while trying to do this?

from geoblaze.

DanielJDufour avatar DanielJDufour commented on July 19, 2024

Use GeoRaster's getValues function that will be implemented in the future once geotiff.js supports reading COG's.

from geoblaze.

DanielJDufour avatar DanielJDufour commented on July 19, 2024

Approach could be to use GeoRaster to just get pixels inside a bounding box and then run intercept calculations if necessary. It could look like:

let values = georaster.getValues({xmin: -100, xmax: -90, ymin: 10, ymax: 20});

from geoblaze.

CarlQLange avatar CarlQLange commented on July 19, 2024

Is there any update on this?

from geoblaze.

DanielJDufour avatar DanielJDufour commented on July 19, 2024

Hi, Carl. COG support has been added to GeoRaster, but not yet to GeoBlaze. However, adding COG support to GeoBlaze shouldn't be too hard. I believe the only updates would be updating get.module.js to run the getValues method of GeoRaster instead of looking for the values in a values property as well as writing a test of course.

Later on, you could add in a resolution parameter that would allow a user to specify the resolution of the values used for the calculations.

Want to work on it?

from geoblaze.

DanielJDufour avatar DanielJDufour commented on July 19, 2024

Unfortunately, there aren't a lot of great resources out there for your question. I'll try my best to summarize. GeoTIFFs are like any image file JPG, PNG, or regular TIFFs in that the pixels are represented in two dimensional tables (rows and columns of pixels). When locating something in a pixel you usually start at the top left. If you ever use the old MS Paint, and it showed you the pixel location when you hovered over a location in your image, that's the same thing. And that's the location information that you pass in and what geotiff.js uses "under the hood". GeoTIFF metadata tells us where on earth (often in lat/long) the top left of an image is and the width/height of each pixel in degrees (or sometimes meters). We can calculate where a pixel in an image is in relation to the earth (lat/long) by calculating the number of pixels from top edge and left edge it is and then using the distance of each pixel to figure it. I hope that helps a little.

from geoblaze.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.