MCPcopy Create free account
hub / github.com/PDAL/PDAL / read

Method read

pdal/private/gdal/Raster.cpp:540–577  ·  view source on GitHub ↗

Fetch the raster data associated with the point at a position. \param x X position of point to fetch raster data for. \param y Y position of point to fetch raster data for. \param[out] data Vector of raster data associated with the provided point. \return Error code or GDALError::None. */

Source from the content-addressed store, hash-verified

538 \return Error code or GDALError::None.
539*/
540GDALError Raster::read(double x,
541 double y,
542 std::vector<double>& data,
543 std::array<double, 2>& pix)
544{
545 if (!m_ds)
546 {
547 m_errorMsg = "Raster not open.";
548 return GDALError::NotOpen;
549 }
550
551 int32_t pixel(0);
552 int32_t line(0);
553 data.resize(m_numBands);
554
555// std::array<double, 2> pix = { {0.0, 0.0} };
556
557 // No data at this x,y if we can't compute a pixel/line location
558 // for it.
559 if (!getPixelAndLinePosition(x, y, pixel, line))
560 {
561 m_errorMsg = "Requested location is not in the raster.";
562 return GDALError::NoData;
563 }
564
565 for (int i=0; i < m_numBands; ++i)
566 {
567 GDALRasterBandH b = GDALGetRasterBand(m_ds, i + 1);
568 if (GDALRasterIO(b, GF_Read, pixel, line, 1, 1,
569 &pix[0], 1, 1, GDT_Float64, 0, 0) == CE_None)
570 {
571 // we read a pixel put its values in our vector
572 data[i] = pix[0];
573 }
574 }
575
576 return GDALError::None;
577}
578
579GDALError Raster::read(int band, int x, int y, int width, int height, std::vector<double>& data) {
580 if (!m_ds)

Callers 4

getFunction · 0.45
ILeStreamClass · 0.45
IBeStreamClass · 0.45
ISwitchableStreamClass · 0.45

Calls 4

heightMethod · 0.95
widthMethod · 0.95
resizeMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected