Skip to content

Commit

Permalink
Merge branch 'master' into MiraMon-Vector-driver
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Apr 5, 2024
2 parents a129137 + 21bdfc1 commit ea93517
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 123 deletions.
9 changes: 4 additions & 5 deletions alg/gdal_alg.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,10 @@ GDALDatasetH CPL_DLL GDALViewshedGenerate(
void *pProgressArg, GDALViewshedOutputType heightMode,
CSLConstList papszExtraOptions);

bool CPL_DLL GDALIsLineOfSightVisible(const GDALRasterBandH, const int xA,
const int yA, const double zA,
const int xB, const int yB,
const double zB,
CSLConstList papszOptions);
bool CPL_DLL GDALIsLineOfSightVisible(
const GDALRasterBandH, const int xA, const int yA, const double zA,
const int xB, const int yB, const double zB, int *pnxTerrainIntersection,
int *pnyTerrainIntersection, CSLConstList papszOptions);

/************************************************************************/
/* Rasterizer API - geometries burned into GDAL raster. */
Expand Down
30 changes: 24 additions & 6 deletions alg/los.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,31 @@ static bool IsAboveTerrain(const GDALRasterBandH hBand, const int x,
* For example, datasets referenced against geographic coordinate at high latitudes may have issues.
*
* @param hBand The band to read the DEM data from. This must NOT be null.
*
*
* @param xA The X location (raster column) of the first point to check on the raster.
*
* @param yA The Y location (raster row) of the first point to check on the raster.
*
*
* @param zA The Z location (height) of the first point to check.
*
*
* @param xB The X location (raster column) of the second point to check on the raster.
*
* @param yB The Y location (raster row) of the second point to check on the raster.
*
*
* @param zB The Z location (height) of the second point to check.
*
*
* @param[out] pnxTerrainIntersection The X location where the LOS line
* intersects with terrain, or nullptr if it does not intersect
* terrain. Not implemented currently (*pnxTerrainIntersection
* is set to -1)
*
* @param[out] pnyTerrainIntersection The Y location where the LOS line
* intersects with terrain, or nullptr if it does not intersect
* terrain. Not implemented currently (*pnyTerrainIntersection
* is set to -1)
*
* @param papszOptions Options for the line of sight algorithm (currently ignored).
*
*
* @return True if the two points are within Line of Sight.
*
* @since GDAL 3.9
Expand All @@ -185,10 +195,18 @@ static bool IsAboveTerrain(const GDALRasterBandH hBand, const int x,
bool GDALIsLineOfSightVisible(const GDALRasterBandH hBand, const int xA,
const int yA, const double zA, const int xB,
const int yB, const double zB,
int *pnxTerrainIntersection,
int *pnyTerrainIntersection,
CPL_UNUSED CSLConstList papszOptions)
{
VALIDATE_POINTER1(hBand, "GDALIsLineOfSightVisible", false);

if (pnxTerrainIntersection)
*pnxTerrainIntersection = -1;

if (pnyTerrainIntersection)
*pnyTerrainIntersection = -1;

// Perform a preliminary check of the start and end points.
if (!IsAboveTerrain(hBand, xA, yA, zA))
{
Expand Down
12 changes: 8 additions & 4 deletions autotest/alg/los.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ def test_los_basic():

mem_ds = gdal.GetDriverByName("MEM").Create("", 2, 1)

assert gdal.IsLineOfSightVisible(mem_ds.GetRasterBand(1), 0, 0, 1, 1, 0, 1)
assert gdal.IsLineOfSightVisible(mem_ds.GetRasterBand(1), 0, 0, 1, 0, 0, 1)
assert not gdal.IsLineOfSightVisible(mem_ds.GetRasterBand(1), 0, 0, -1, 1, 0, 1)
assert not gdal.IsLineOfSightVisible(mem_ds.GetRasterBand(1), 0, 0, 1, 1, 0, -1)
success, x, y = gdal.IsLineOfSightVisible(mem_ds.GetRasterBand(1), 0, 0, 1, 1, 0, 1)
assert success
assert x == -1
assert y == -1

assert gdal.IsLineOfSightVisible(mem_ds.GetRasterBand(1), 0, 0, 1, 0, 0, 1)[0]
assert not gdal.IsLineOfSightVisible(mem_ds.GetRasterBand(1), 0, 0, -1, 1, 0, 1)[0]
assert not gdal.IsLineOfSightVisible(mem_ds.GetRasterBand(1), 0, 0, 1, 1, 0, -1)[0]

with pytest.raises(Exception, match="Received a NULL pointer"):
gdal.IsLineOfSightVisible(None, 0, 0, 0, 0, 0, 0)
Expand Down
92 changes: 46 additions & 46 deletions autotest/cpp/test_alg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,14 @@ TEST_F(test_alg, GDALIsLineOfSightVisible_single_point_dataset)
ASSERT_TRUE(poDS->RasterIO(GF_Write, 0, 0, 1, 1, &val, 1, 1, GDT_Int8, 1,
nullptr, 0, 0, 0, nullptr) == CE_None);
// Both points below terrain
EXPECT_FALSE(
GDALIsLineOfSightVisible(pBand, 0, 0, 0.0, 0, 0, 0.0, nullptr));
EXPECT_FALSE(GDALIsLineOfSightVisible(pBand, 0, 0, 0.0, 0, 0, 0.0, nullptr,
nullptr, nullptr));
// One point below terrain
EXPECT_FALSE(
GDALIsLineOfSightVisible(pBand, 0, 0, 0.0, 0, 0, 43.0, nullptr));
EXPECT_FALSE(GDALIsLineOfSightVisible(pBand, 0, 0, 0.0, 0, 0, 43.0, nullptr,
nullptr, nullptr));
// Both points above terrain
EXPECT_TRUE(
GDALIsLineOfSightVisible(pBand, 0, 0, 44.0, 0, 0, 43.0, nullptr));
EXPECT_TRUE(GDALIsLineOfSightVisible(pBand, 0, 0, 44.0, 0, 0, 43.0, nullptr,
nullptr, nullptr));
}

// Test GDALIsLineOfSightVisible() with 10x10 default dataset
Expand All @@ -331,25 +331,25 @@ TEST_F(test_alg, GDALIsLineOfSightVisible_default_square_dataset)
const int y2 = 2;

// Both points are above terrain.
EXPECT_TRUE(
GDALIsLineOfSightVisible(pBand, x1, y1, 1.0, x2, y2, 1.0, nullptr));
EXPECT_TRUE(GDALIsLineOfSightVisible(pBand, x1, y1, 1.0, x2, y2, 1.0,
nullptr, nullptr, nullptr));
// Flip the order, same result.
EXPECT_TRUE(
GDALIsLineOfSightVisible(pBand, x2, y2, 1.0, x1, y1, 1.0, nullptr));
EXPECT_TRUE(GDALIsLineOfSightVisible(pBand, x2, y2, 1.0, x1, y1, 1.0,
nullptr, nullptr, nullptr));

// One point is below terrain.
EXPECT_FALSE(
GDALIsLineOfSightVisible(pBand, x1, y1, -1.0, x2, y2, 1.0, nullptr));
EXPECT_FALSE(GDALIsLineOfSightVisible(pBand, x1, y1, -1.0, x2, y2, 1.0,
nullptr, nullptr, nullptr));
// Flip the order, same result.
EXPECT_FALSE(
GDALIsLineOfSightVisible(pBand, x2, y2, -1.0, x1, y1, 1.0, nullptr));
EXPECT_FALSE(GDALIsLineOfSightVisible(pBand, x2, y2, -1.0, x1, y1, 1.0,
nullptr, nullptr, nullptr));

// Both points are below terrain.
EXPECT_FALSE(
GDALIsLineOfSightVisible(pBand, x1, y1, -1.0, x2, y2, -1.0, nullptr));
EXPECT_FALSE(GDALIsLineOfSightVisible(pBand, x1, y1, -1.0, x2, y2, -1.0,
nullptr, nullptr, nullptr));
// Flip the order, same result.
EXPECT_FALSE(
GDALIsLineOfSightVisible(pBand, x2, y2, -1.0, x1, y1, -1.0, nullptr));
EXPECT_FALSE(GDALIsLineOfSightVisible(pBand, x2, y2, -1.0, x1, y1, -1.0,
nullptr, nullptr, nullptr));
}

// Test GDALIsLineOfSightVisible() through a mountain (not a unit test)
Expand Down Expand Up @@ -397,57 +397,57 @@ TEST_F(test_alg, GDALIsLineOfSightVisible_through_mountain)
// Both points are just above terrain, with terrain between.
EXPECT_FALSE(GDALIsLineOfSightVisible(pBand, iMesaTopX, iMesaTopY, 222,
iMesaBottomX, iMesaBottomY, 199,
nullptr));
nullptr, nullptr, nullptr));
// Flip the order, same result.
EXPECT_FALSE(GDALIsLineOfSightVisible(pBand, iMesaBottomX, iMesaBottomY,
199, iMesaTopX, iMesaTopY, 222,
nullptr));
nullptr, nullptr, nullptr));

// Both points above terrain.
EXPECT_TRUE(GDALIsLineOfSightVisible(pBand, iMesaTopX, iMesaTopY, 322,
iMesaBottomX, iMesaBottomY, 322,
nullptr));
nullptr, nullptr, nullptr));

// Both points below terrain.
EXPECT_FALSE(GDALIsLineOfSightVisible(pBand, iMesaTopX, iMesaTopY, 0,
iMesaBottomX, iMesaBottomY, 0,
nullptr));
nullptr, nullptr, nullptr));

// Test negative slope bresenham diagonals across the whole raster.
// Both high above terrain.
EXPECT_TRUE(
GDALIsLineOfSightVisible(pBand, 0, 0, 460, 120, 120, 460, nullptr));
EXPECT_TRUE(GDALIsLineOfSightVisible(pBand, 0, 0, 460, 120, 120, 460,
nullptr, nullptr, nullptr));
// Both heights are 1m above in the corners, but middle terrain violates LOS.
EXPECT_FALSE(
GDALIsLineOfSightVisible(pBand, 0, 0, 295, 120, 120, 183, nullptr));
EXPECT_FALSE(GDALIsLineOfSightVisible(pBand, 0, 0, 295, 120, 120, 183,
nullptr, nullptr, nullptr));

// Test positive slope bresenham diagnoals across the whole raster.
// Both high above terrain.
EXPECT_TRUE(
GDALIsLineOfSightVisible(pBand, 0, 120, 460, 120, 0, 460, nullptr));
EXPECT_TRUE(GDALIsLineOfSightVisible(pBand, 0, 120, 460, 120, 0, 460,
nullptr, nullptr, nullptr));
// Both heights are 1m above in the corners, but middle terrain violates LOS.
EXPECT_FALSE(
GDALIsLineOfSightVisible(pBand, 0, 120, 203, 120, 0, 247, nullptr));
EXPECT_FALSE(GDALIsLineOfSightVisible(pBand, 0, 120, 203, 120, 0, 247,
nullptr, nullptr, nullptr));

// Vertical line tests with hill between two points, in both directions.
EXPECT_FALSE(
GDALIsLineOfSightVisible(pBand, 83, 111, 154, 83, 117, 198, nullptr));
EXPECT_FALSE(
GDALIsLineOfSightVisible(pBand, 83, 117, 198, 83, 111, 154, nullptr));
EXPECT_TRUE(
GDALIsLineOfSightVisible(pBand, 83, 111, 460, 83, 117, 460, nullptr));
EXPECT_TRUE(
GDALIsLineOfSightVisible(pBand, 83, 117, 460, 83, 111, 460, nullptr));
EXPECT_FALSE(GDALIsLineOfSightVisible(pBand, 83, 111, 154, 83, 117, 198,
nullptr, nullptr, nullptr));
EXPECT_FALSE(GDALIsLineOfSightVisible(pBand, 83, 117, 198, 83, 111, 154,
nullptr, nullptr, nullptr));
EXPECT_TRUE(GDALIsLineOfSightVisible(pBand, 83, 111, 460, 83, 117, 460,
nullptr, nullptr, nullptr));
EXPECT_TRUE(GDALIsLineOfSightVisible(pBand, 83, 117, 460, 83, 111, 460,
nullptr, nullptr, nullptr));

// Horizontal line tests with hill between two points, in both directions.
EXPECT_FALSE(
GDALIsLineOfSightVisible(pBand, 75, 115, 192, 89, 115, 191, nullptr));
EXPECT_FALSE(
GDALIsLineOfSightVisible(pBand, 89, 115, 191, 75, 115, 192, nullptr));
EXPECT_TRUE(
GDALIsLineOfSightVisible(pBand, 75, 115, 460, 89, 115, 460, nullptr));
EXPECT_TRUE(
GDALIsLineOfSightVisible(pBand, 89, 115, 460, 75, 115, 460, nullptr));
EXPECT_FALSE(GDALIsLineOfSightVisible(pBand, 75, 115, 192, 89, 115, 191,
nullptr, nullptr, nullptr));
EXPECT_FALSE(GDALIsLineOfSightVisible(pBand, 89, 115, 191, 75, 115, 192,
nullptr, nullptr, nullptr));
EXPECT_TRUE(GDALIsLineOfSightVisible(pBand, 75, 115, 460, 89, 115, 460,
nullptr, nullptr, nullptr));
EXPECT_TRUE(GDALIsLineOfSightVisible(pBand, 89, 115, 460, 75, 115, 460,
nullptr, nullptr, nullptr));
}

} // namespace
84 changes: 42 additions & 42 deletions cmake/modules/packages/FindSQLite3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ endif()

if(SQLite3_INCLUDE_DIR AND SQLite3_LIBRARY)
set(SQLite3_FIND_QUIETLY TRUE)
endif()
else()
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_SQLITE3 QUIET sqlite3)
endif()

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_SQLITE3 QUIET sqlite3)
find_path(SQLite3_INCLUDE_DIR
NAMES sqlite3.h
HINTS ${PC_SQLITE3_INCLUDE_DIRS})
find_library(SQLite3_LIBRARY
NAMES sqlite3 sqlite3_i
HINTS ${PC_SQLITE3_LIBRARY_DIRS})
endif()

find_path(SQLite3_INCLUDE_DIR
NAMES sqlite3.h
HINTS ${PC_SQLITE3_INCLUDE_DIRS})
find_library(SQLite3_LIBRARY
NAMES sqlite3 sqlite3_i
HINTS ${PC_SQLITE3_LIBRARY_DIRS})

# Extract version information from the header file
if(SQLite3_INCLUDE_DIR)
file(STRINGS ${SQLite3_INCLUDE_DIR}/sqlite3.h _ver_line
Expand All @@ -77,37 +77,37 @@ if(SQLite3_INCLUDE_DIR AND SQLite3_LIBRARY)
# check column metadata
set(CMAKE_REQUIRED_INCLUDES ${SQLite3_INCLUDE_DIR})
if( ${SQLite3_LIBRARY} MATCHES "libsqlite3.a")
if(PC_SQLITE3_STATIC_LDFLAGS)
set(CMAKE_REQUIRED_LIBRARIES ${PC_SQLITE3_STATIC_LDFLAGS})
else()
# Manually try likely additional private libraries
set(CMAKE_REQUIRED_LIBRARIES ${SQLite3_LIBRARY})
check_symbol_exists(sqlite3_open sqlite3.h SQLite3_HAS_OPEN)
if(NOT SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN CACHE)
set(CMAKE_REQUIRED_LIBRARIES ${SQLite3_LIBRARY} -lz)
check_symbol_exists(sqlite3_open sqlite3.h SQLite3_HAS_OPEN)
endif()
if(NOT SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN CACHE)
set(CMAKE_REQUIRED_LIBRARIES ${SQLite3_LIBRARY} -lm)
check_symbol_exists(sqlite3_open sqlite3.h SQLite3_HAS_OPEN)
endif()
if(NOT SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN CACHE)
set(CMAKE_REQUIRED_LIBRARIES ${SQLite3_LIBRARY} -lz -lm)
check_symbol_exists(sqlite3_open sqlite3.h SQLite3_HAS_OPEN)
endif()
if(NOT SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN CACHE)
set(CMAKE_REQUIRED_LIBRARIES ${SQLite3_LIBRARY} -lz -lm -lpthread -ldl)
check_symbol_exists(sqlite3_open sqlite3.h SQLite3_HAS_OPEN)
endif()
endif()
if(PC_SQLITE3_STATIC_LDFLAGS)
set(CMAKE_REQUIRED_LIBRARIES ${PC_SQLITE3_STATIC_LDFLAGS})
else()
# Manually try likely additional private libraries
set(CMAKE_REQUIRED_LIBRARIES ${SQLite3_LIBRARY})
check_symbol_exists(sqlite3_open sqlite3.h SQLite3_HAS_OPEN)
if(NOT SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN CACHE)
set(CMAKE_REQUIRED_LIBRARIES ${SQLite3_LIBRARY} -lz)
check_symbol_exists(sqlite3_open sqlite3.h SQLite3_HAS_OPEN)
endif()
if(NOT SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN CACHE)
set(CMAKE_REQUIRED_LIBRARIES ${SQLite3_LIBRARY} -lm)
check_symbol_exists(sqlite3_open sqlite3.h SQLite3_HAS_OPEN)
endif()
if(NOT SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN CACHE)
set(CMAKE_REQUIRED_LIBRARIES ${SQLite3_LIBRARY} -lz -lm)
check_symbol_exists(sqlite3_open sqlite3.h SQLite3_HAS_OPEN)
endif()
if(NOT SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN)
unset(SQLite3_HAS_OPEN CACHE)
set(CMAKE_REQUIRED_LIBRARIES ${SQLite3_LIBRARY} -lz -lm -lpthread -ldl)
check_symbol_exists(sqlite3_open sqlite3.h SQLite3_HAS_OPEN)
endif()
endif()
else()
set(CMAKE_REQUIRED_LIBRARIES ${SQLite3_LIBRARY})
endif()
Expand Down
10 changes: 5 additions & 5 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ If you are getting a ``<jemalloc>: arena 0 background thread creation failed (1)

# Images of releases

Tagged images of recent past releases are available. The last ones (at time of writing) are for GDAL 3.8.4 and PROJ 9.3.1, for linux/amd64 and linux/arm64:
* ghcr.io/osgeo/gdal:alpine-small-3.8.4
* ghcr.io/osgeo/gdal:alpine-normal-3.8.4
* ghcr.io/osgeo/gdal:ubuntu-small-3.8.4
* ghcr.io/osgeo/gdal:ubuntu-full-3.8.4
Tagged images of recent past releases are available. The last ones (at time of writing) are for GDAL 3.8.5 and PROJ 9.4.0, for linux/amd64 and linux/arm64:
* ghcr.io/osgeo/gdal:alpine-small-3.8.5
* ghcr.io/osgeo/gdal:alpine-normal-3.8.5
* ghcr.io/osgeo/gdal:ubuntu-small-3.8.5
* ghcr.io/osgeo/gdal:ubuntu-full-3.8.5

## Multi-arch Images

Expand Down
22 changes: 10 additions & 12 deletions fuzzers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
if (NOT TARGET ogr_SQLite)
return()
endif ()
if (CMAKE_CROSSCOMPILING OR WIN32)
return()
endif ()
if (NOT CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)
return()
endif ()

include(GdalStandardIncludes)
add_library(fuzzingengine EXCLUDE_FROM_ALL OBJECT fuzzingengine.cpp)
Expand Down Expand Up @@ -147,12 +141,16 @@ build_fuzzer(
DEFINITIONS
-DUSE_FILESYSTEM)

add_custom_command(
OUTPUT ${FUZZ_CORPUS}
COMMAND env OUT=${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/build_seed_corpus.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
USES_TERMINAL)
add_custom_target(fuzzers DEPENDS ${FUZZ_TARGETS} ${FUZZ_CORPUS})
if (UNIX)
add_custom_command(
OUTPUT ${FUZZ_CORPUS}
COMMAND env OUT=${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/build_seed_corpus.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
USES_TERMINAL)
add_custom_target(fuzzers DEPENDS ${FUZZ_TARGETS} ${FUZZ_CORPUS})
else()
add_custom_target(fuzzers DEPENDS ${FUZZ_TARGETS})
endif()

unset(FUZZ_TARGETS)
unset(FUZZ_CORPUS)
Loading

0 comments on commit ea93517

Please sign in to comment.