You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@baremaps.apache.org by bc...@apache.org on 2023/05/21 18:38:26 UTC

[incubator-baremaps] branch gdal updated (af5b01bd -> a8957664)

This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a change to branch gdal
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git


 discard af5b01bd Experiment with TwelveMonkeys
 discard f63e7f12 Serve contour tiles
 discard 9695cc0e Improve tile store
 discard ff2e1721 WIP - experiment with gdal
     add c8e6dc66 Improve ip to location workflow
     add 7f257a72 Support js files in export command (#626)
     add 84778f3c Correctly reproject geometries (#628)
     add ce5a02a2 Update the OGC API specification files (#630)
     add 09b3b2b2 ogcapi, maintenance dependencies (#631)
     add 72130184 Add raster split view for dev (#636)
     add 41f57fc1 Improve raster split view for dev (#637)
     add 2a4d6b83 Fix invalid query execution (#627)
     add 419f3c7b Catch null pointer exception server resources (#638)
     add c705fdad Add third-party licenses to the bin distribution (#642)
     add 9d3febb7 Add version of the application into the README (#613)
     add 56952c74 Fix encoding issue in geocoder (#643)
     add 41229c1a Update and simplify OGCAPI implementation (#633)
     add b06833d2 Merge the mvt and vectortile packages (#644)
     add 533480f8 Rename Tile into TileCoord (#645)
     add 75d8093e Move tile store in a dedicated package (#646)
     add cfbbe996 Merge the database and openstreetmap packages (#647)
     add ae15b686 Infer user IP from HTTP headers or connection (#648)
     add dceae807 Fix layering order and color (#650)
     add 572a1557 Simplify IpLoc package (#649)
     add 1bae9022 Enable support for ipv6 location (#653)
     add b5f598c3 Add renderer and integration tests for the basemap (#659)
     new 27084300 WIP - experiment with gdal
     new 28678b1f Improve tile store
     new 9b12ea27 Serve contour tiles
     new 6d9d62ff Experiment with TwelveMonkeys
     new a8957664 Fix issues after rebase

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (af5b01bd)
            \
             N -- N -- N   refs/heads/gdal (a8957664)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .run/ContourTileStore.run.xml                      |   16 -
 .run/geocoder-serve.run.xml                        |    4 +-
 README                                             |    2 +-
 baremaps-cli/pom.xml                               |   17 +
 baremaps-cli/src/assembly/bin.xml                  |   18 +
 baremaps-cli/src/assembly/src.xml                  |    7 +
 .../java/org/apache/baremaps/cli/iploc/Serve.java  |   23 +-
 .../java/org/apache/baremaps/cli/map/Contour.java  |   14 +-
 .../main/java/org/apache/baremaps/cli/map/Dev.java |    6 +-
 .../java/org/apache/baremaps/cli/map/Init.java     |   12 +-
 .../java/org/apache/baremaps/cli/map/Serve.java    |   16 +-
 .../org/apache/baremaps/cli/ogcapi/OgcApi.java     |   82 +-
 .../org/apache/baremaps/cli/workflow/Execute.java  |    6 +-
 .../org/apache/baremaps/cli/workflow/Init.java     |    4 +-
 baremaps-core/pom.xml                              |    4 +
 .../collection/memory/MemoryMappedDirectory.java   |    4 +-
 .../collection/memory/MemoryMappedFile.java        |    2 +-
 .../baremaps/collection/type/WKBDataType.java      |    2 +-
 .../org/apache/baremaps/config}/ConfigReader.java  |    2 +-
 .../baremaps/geocoder/GeonamesDocumentMapper.java  |    1 +
 .../apache/baremaps/geocoder/GeonamesReader.java   |    9 +-
 .../InetAddressUtils.java}                         |   30 +-
 .../ColumnImpl.java => iploc/InetRange.java}       |   10 +-
 .../main/java/org/apache/baremaps/iploc/IpLoc.java |  230 --
 .../org/apache/baremaps/iploc/IpLocMapper.java     |  225 ++
 .../OsmReader.java => iploc/IpLocObject.java}      |   17 +-
 .../org/apache/baremaps/iploc/IpLocReader.java     |   48 +
 .../org/apache/baremaps/iploc/IpLocRepository.java |  236 ++
 .../baremaps/iploc/{nic => }/NicAttribute.java     |    2 +-
 .../apache/baremaps/iploc/{nic => }/NicObject.java |   27 +-
 .../iploc/{nic/NicParser.java => NicReader.java}   |   17 +-
 .../baremaps/iploc/{nic => }/NicSpliterator.java   |   19 +-
 .../java/org/apache/baremaps/iploc/NicUtils.java   |   51 +
 .../baremaps/iploc/data/InetnumLocation.java       |   92 -
 .../org/apache/baremaps/iploc/data/IpLocStats.java |   73 -
 .../java/org/apache/baremaps/iploc/data/Ipv4.java  |  101 -
 .../org/apache/baremaps/iploc/data/Ipv4Range.java  |   71 -
 .../org/apache/baremaps/iploc/data/Location.java   |   55 -
 .../org/apache/baremaps/iploc/database/Dao.java    |   63 -
 .../iploc/database/InetnumLocationDao.java         |   37 -
 .../database/InetnumLocationDaoSqliteImpl.java     |  202 --
 .../baremaps/iploc/dto/InetnumLocationDto.java     |   80 -
 .../org/apache/baremaps/iploc/nic/NicUtils.java    |   44 -
 .../baremaps/openstreetmap/CollectionUtils.java    |   69 -
 .../{database => openstreetmap}/DiffService.java   |   18 +-
 .../function/EntityProjectionTransformer.java      |    2 +-
 .../function/NodeGeometryBuilder.java              |    2 +-
 .../function/RelationGeometryBuilder.java          |    2 +-
 .../openstreetmap/function/WayGeometryBuilder.java |    2 +-
 .../postgres}/PostgresCoordinateMap.java           |    2 +-
 .../postgres}/PostgresHeaderRepository.java        |    6 +-
 .../postgres}/PostgresIterator.java                |    2 +-
 .../postgres}/PostgresJsonbMapper.java             |    2 +-
 .../postgres}/PostgresNodeRepository.java          |   12 +-
 .../postgres}/PostgresReferenceMap.java            |    2 +-
 .../postgres}/PostgresRelationRepository.java      |   21 +-
 .../postgres}/PostgresWayRepository.java           |   12 +-
 .../repository}/BlockImporter.java                 |    9 +-
 .../repository}/ChangeImporter.java                |    8 +-
 .../repository/HeaderRepository.java               |    2 +-
 .../repository/NodeRepository.java}                |    8 +-
 .../repository/RelationRepository.java}            |    8 +-
 .../repository/Repository.java                     |    2 +-
 .../repository/RepositoryException.java            |    2 +-
 .../repository/WayRepository.java}                 |    8 +-
 .../openstreetmap/utils/InputStreamProgress.java   |   83 -
 .../openstreetmap/utils/StreamProgress.java        |   59 -
 .../{database => postgres}/PostgresUtils.java      |    2 +-
 .../{database => postgres}/copy/CopyWriter.java    |    2 +-
 .../copy/PostgisGeometryValueHandler.java          |    5 +-
 .../metadata/ColumnResult.java                     |    2 +-
 .../metadata/DatabaseMetadata.java                 |    2 +-
 .../metadata/PrimaryKeyResult.java                 |    2 +-
 .../metadata/TableMetadata.java                    |    2 +-
 .../metadata/TableResult.java                      |    2 +-
 .../java/org/apache/baremaps/raster/AsterDem.java  |   58 +
 .../apache/baremaps/raster/ContourTileStore.java   |   43 +-
 ...eGeometryDecorator.java => TableDecorator.java} |   51 +-
 .../baremaps/storage/postgres/PostgresStore.java   |   22 +-
 .../baremaps/storage/postgres/PostgresTable.java   |    2 +-
 .../utils => stream}/ProgressLogger.java           |   26 +-
 .../org/apache/baremaps/stream/StreamUtils.java    |   39 +-
 .../tile => tilestore}/TileBatchPredicate.java     |   10 +-
 .../{database/tile => tilestore}/TileCache.java    |   31 +-
 .../{database/tile => tilestore}/TileChannel.java  |   12 +-
 .../tile/Tile.java => tilestore/TileCoord.java}    |   68 +-
 .../TileCoordIterator.java}                        |   30 +-
 .../{database/tile => tilestore}/TileStore.java    |   14 +-
 .../tile => tilestore}/TileStoreException.java     |    2 +-
 .../tile => tilestore}/VariableUtils.java          |    2 +-
 .../tile => tilestore/file}/FileTileStore.java     |   21 +-
 .../tile => tilestore/mbtiles}/MBTiles.java        |   29 +-
 .../tile => tilestore/postgres}/PostgresGroup.java |    2 +-
 .../tile => tilestore/postgres}/PostgresQuery.java |    2 +-
 .../postgres}/PostgresQueryGenerator.java          |    6 +-
 .../postgres}/PostgresTileStore.java               |   45 +-
 .../baremaps/{collection => }/utils/FileUtils.java |    2 +-
 .../{openstreetmap => }/utils/GeometryUtils.java   |    2 +-
 .../{geocoder => utils}/IsoCountriesUtils.java     |    2 +-
 .../utils/MappedByteBufferUtils.java               |    2 +-
 .../apache/baremaps/utils/ObjectMapperUtils.java   |    8 +-
 .../utils/ProjectionTransformer.java               |    2 +-
 .../{iploc/database => utils}/SqliteUtils.java     |    2 +-
 .../vectortile/{Tile.java => VectorTile.java}      |    6 +-
 .../baremaps/vectortile/VectorTileDecoder.java     |   21 +-
 .../baremaps/vectortile/VectorTileEncoder.java     |   35 +-
 .../baremaps/vectortile/VectorTileUtils.java       |   10 +-
 .../expression/Expressions.java                    |    2 +-
 .../baremaps/{mvt => vectortile}/style/Style.java  |    2 +-
 .../{mvt => vectortile}/style/StyleLayer.java      |    2 +-
 .../{mvt => vectortile}/style/StyleSource.java     |    2 +-
 .../{mvt => vectortile}/tileset/Tileset.java       |    2 +-
 .../{mvt => vectortile}/tileset/TilesetLayer.java  |    2 +-
 .../{mvt => vectortile}/tileset/TilesetQuery.java  |    2 +-
 .../apache/baremaps/workflow/WorkflowContext.java  |    2 +-
 .../workflow/tasks/CreateEntityCollection.java     |    4 +-
 .../workflow/tasks/CreateGeonamesIndex.java        |    1 -
 .../baremaps/workflow/tasks/CreateIplocIndex.java  |   48 +-
 .../baremaps/workflow/tasks/DownloadUrl.java       |    9 +-
 .../baremaps/workflow/tasks/ExportVectorTiles.java |   50 +-
 .../baremaps/workflow/tasks/ImportGeoPackage.java  |   10 +-
 .../workflow/tasks/ImportOpenStreetMap.java        |   10 +-
 .../baremaps/workflow/tasks/ImportShapefile.java   |    6 +-
 .../workflow/tasks/TransformEntityCollection.java  |    2 +-
 .../apache/baremaps/workflow/tasks/UngzipFile.java |    8 +-
 .../workflow/tasks/UpdateOpenStreetMap.java        |   12 +-
 baremaps-core/src/main/resources/iploc_init.sql    |   21 -
 .../database/database/WayRepositoryTest.java       |   82 -
 .../iploc/{IpLocTest.java => IpLocObjectTest.java} |  101 +-
 .../org/apache/baremaps/iploc/Ipv4RangeTest.java   |   57 -
 .../java/org/apache/baremaps/iploc/Ipv4Test.java   |   38 -
 .../apache/baremaps/iploc/{nic => }/NicData.java   |    4 +-
 .../baremaps/iploc/{nic => }/NicObjectTest.java    |    2 +-
 .../baremaps/iploc/{nic => }/NicParserTest.java    |    2 +-
 .../postgres}/PostgresHeaderRepositoryTest.java    |   13 +-
 .../postgres}/PostgresNodeRepositoryTest.java      |    8 +-
 .../postgres}/PostgresRelationRepositoryTest.java  |    8 +-
 .../postgres/PostgresRepositoryTest.java}          |    6 +-
 .../postgres}/PostgresWayRepositoryTest.java       |    8 +-
 .../repository}/BlockImporterTest.java             |   14 +-
 .../repository}/Constants.java                     |    2 +-
 .../{database => }/postgres/TestContainers.java    |    2 +-
 .../metadata/PostgresMetadataTest.java}            |    6 +-
 .../org/apache/baremaps/storage/MockTable.java     |    2 +-
 .../storage/postgres/PostgresStoreTest.java        |    2 +-
 .../storage/postgres/PostgresTableTest.java        |    2 +-
 .../baremaps/testing/PostgresContainerTest.java    |    5 +-
 .../tile => tilestore}/TileBatcherTest.java        |   18 +-
 .../TileCoordIteratorTest.java}                    |   30 +-
 .../TileTest.java => tilestore/TileCoordTest.java} |   18 +-
 .../tile => tilestore}/TileStoreTest.java          |   14 +-
 .../tile => tilestore/file}/FileTileStoreTest.java |    8 +-
 .../tile => tilestore/mbtiles}/MBTilesTest.java    |    5 +-
 .../postgres}/JSQLParserTest.java                  |    2 +-
 .../postgres}/PostgresQueryGeneratorTest.java      |    6 +-
 .../postgres}/PostgresQueryParserTest.java         |    2 +-
 .../postgres}/PostgresTileStoreTest.java           |    9 +-
 .../ProjectionTransformerTest.java                 |    3 +-
 .../{mvt => vectortile}/ExpressionsTest.java       |    6 +-
 .../apache/baremaps/vectortile/VectorTileTest.java |    5 +-
 .../baremaps/vectortile/VectorTileViewer.java      |    7 +-
 .../CreateAndTransformEntityCollectionTest.java    |    2 +-
 .../baremaps/workflow/tasks/DownloadUrlTest.java   |    2 +-
 .../baremaps/workflow/tasks/ImportMonacoTest.java  |   18 +-
 .../workflow/tasks/ImportShapefileTest.java        |    2 +-
 .../workflow/tasks/ImportUpdateDataTest.java       |   16 +-
 .../tasks/ImportUpdateLiechtensteinTest.java       |   18 +-
 .../baremaps/workflow/tasks/UngzipFileTest.java    |    2 +-
 .../baremaps/workflow/tasks/UnzipFileTest.java     |    2 +-
 baremaps-ogcapi/pom.xml                            |   51 +-
 .../org/apache/baremaps/ogcapi/ApiResource.java    |   87 +-
 .../baremaps/ogcapi/CollectionsResource.java       |  115 +-
 .../baremaps/ogcapi/ConformanceResource.java       |   30 +-
 .../apache/baremaps/ogcapi/DefaultResource.java    |   73 +
 .../org/apache/baremaps/ogcapi/ImportResource.java |   75 -
 .../org/apache/baremaps/ogcapi/PostgisPlugin.java  |  151 --
 .../org/apache/baremaps/ogcapi/RootResource.java   |   50 -
 .../org/apache/baremaps/ogcapi/StudioResource.java |  109 -
 .../org/apache/baremaps/ogcapi/StylesResource.java |  120 +-
 .../apache/baremaps/ogcapi/SwaggerResource.java    |   37 -
 .../org/apache/baremaps/ogcapi/TilesResource.java  |  118 +
 .../apache/baremaps/ogcapi/TilesetsResource.java   |  128 -
 .../src/main/resources/map.html                    |   22 +-
 .../src/main/resources/ogcapi-openapi.yaml         |  607 -----
 baremaps-ogcapi/src/main/resources/ogcapi.yaml     | 2745 ++++++++++++++++++++
 .../src/main/resources/schemas/TileJSON.yaml       |   58 -
 .../src/main/resources/schemas/collection.yaml     |   48 -
 .../src/main/resources/schemas/collections.yaml    |   13 -
 .../src/main/resources/schemas/confClasses.yaml    |    8 -
 .../src/main/resources/schemas/exception.yaml      |    8 -
 .../src/main/resources/schemas/extent.yaml         |   59 -
 .../src/main/resources/schemas/landingPage.yaml    |   14 -
 .../src/main/resources/schemas/link.yaml           |   21 -
 .../src/main/resources/schemas/mb-layer.yaml       |   38 -
 .../src/main/resources/schemas/mb-style.yaml       |   41 -
 .../src/main/resources/schemas/query.yaml          |    9 -
 .../main/resources/schemas/style-set-entry.yaml    |   19 -
 .../src/main/resources/schemas/style-set.yaml      |   34 -
 .../src/main/resources/schemas/vector_layer.yaml   |   18 -
 .../apache/baremaps/ogcapi/ApiResourceTest.java    |   42 +
 .../ogcapi/CollectionsResourceIntegrationTest.java |  105 -
 .../baremaps/ogcapi/CollectionsResourceTest.java   |   44 +
 .../baremaps/ogcapi/ConformanceResourceTest.java   |   21 +-
 .../baremaps/ogcapi/DefaultResourceTest.java       |   24 +-
 .../ogcapi/ImportResourceIntegrationTest.java      |   86 -
 .../org/apache/baremaps/ogcapi/OgcApiTest.java     |   99 +
 .../apache/baremaps/ogcapi/PostgisPluginTest.java  |   55 -
 .../org/apache/baremaps/ogcapi/PostgisRecord.java  |   61 -
 .../ogcapi/RootResourceIntegrationTest.java        |   38 -
 .../ogcapi/StudioResourceIntegrationTest.java      |   97 -
 .../ogcapi/StylesResourceIntegrationTest.java      |   93 -
 .../apache/baremaps/ogcapi/StylesResourceTest.java |   43 +
 .../apache/baremaps/ogcapi/TilesResourceTest.java  |   40 +
 .../ogcapi/TilesetsResourceIntegrationTest.java    |   88 -
 baremaps-renderer/.gitignore                       |    2 +
 baremaps-renderer/.prettierignore                  |    3 +
 baremaps-renderer/.prettierrc.json                 |    4 +
 baremaps-renderer/README.md                        |   78 +
 baremaps-renderer/assets/report-template.html      |  334 +++
 .../declaration.d.ts                               |    6 +-
 baremaps-renderer/package-lock.json                | 1722 ++++++++++++
 baremaps-renderer/package.json                     |   34 +
 baremaps-renderer/src/index.ts                     |  129 +
 baremaps-renderer/src/lib/browserPool.ts           |   86 +
 .../src/lib/maplibreBrowserHelpers.ts              |  128 +
 baremaps-renderer/src/lib/reportGenerator.ts       |  124 +
 .../src/lib/runnableTask.ts                        |   18 +-
 baremaps-renderer/src/lib/test.ts                  |  178 ++
 baremaps-renderer/src/lib/testManager.ts           |   90 +
 baremaps-renderer/src/lib/testsLogger.ts           |  112 +
 .../src/types/index.ts                             |   39 +-
 baremaps-renderer/tsconfig.json                    |   20 +
 baremaps-server/pom.xml                            |   13 +-
 .../baremaps/server/BaseUriRequestFilter.java      |    8 +-
 .../org/apache/baremaps/server/CorsFilter.java     |    6 +-
 .../org/apache/baremaps/server/DevResources.java   |   29 +-
 .../apache/baremaps/server/DirectoryWatcher.java   |    2 +-
 .../apache/baremaps/server/GeocoderResources.java  |    5 +-
 .../org/apache/baremaps/server/IpLocResources.java |  136 +
 .../org/apache/baremaps/server/IplocResources.java |   74 -
 .../apache/baremaps/server/ServerResources.java    |   19 +-
 .../resources/assets/maplibre-custom-controls.css  |    6 +
 .../resources/assets/maplibre-custom-controls.js   |   71 +
 .../src/main/resources/assets/server.html          |    8 +-
 .../src/main/resources/assets/viewer.html          |   87 +-
 .../src/main/resources/iploc/index.html            |   18 +-
 basemap/layers/aeroway/polygon.js                  |    2 +-
 basemap/style.js                                   |    2 +-
 basemap/tests/.gitignore                           |    2 +
 basemap/tests/integration/lausanne/metadata.json   |    6 +
 examples/ip-to-location/workflow.js                |  110 +-
 pom.xml                                            |   36 +-
 252 files changed, 8440 insertions(+), 4855 deletions(-)
 delete mode 100644 .run/ContourTileStore.run.xml
 rename {baremaps-server/src/main/java/org/apache/baremaps/server => baremaps-core/src/main/java/org/apache/baremaps/config}/ConfigReader.java (98%)
 copy baremaps-core/src/main/java/org/apache/baremaps/{collection/type/MemoryAlignedDataType.java => iploc/InetAddressUtils.java} (50%)
 copy baremaps-core/src/main/java/org/apache/baremaps/{storage/ColumnImpl.java => iploc/InetRange.java} (75%)
 delete mode 100644 baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLoc.java
 create mode 100644 baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocMapper.java
 copy baremaps-core/src/main/java/org/apache/baremaps/{openstreetmap/OsmReader.java => iploc/IpLocObject.java} (66%)
 create mode 100644 baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocReader.java
 create mode 100644 baremaps-core/src/main/java/org/apache/baremaps/iploc/IpLocRepository.java
 rename baremaps-core/src/main/java/org/apache/baremaps/iploc/{nic => }/NicAttribute.java (97%)
 rename baremaps-core/src/main/java/org/apache/baremaps/iploc/{nic => }/NicObject.java (75%)
 rename baremaps-core/src/main/java/org/apache/baremaps/iploc/{nic/NicParser.java => NicReader.java} (68%)
 rename baremaps-core/src/main/java/org/apache/baremaps/iploc/{nic => }/NicSpliterator.java (85%)
 create mode 100644 baremaps-core/src/main/java/org/apache/baremaps/iploc/NicUtils.java
 delete mode 100644 baremaps-core/src/main/java/org/apache/baremaps/iploc/data/InetnumLocation.java
 delete mode 100644 baremaps-core/src/main/java/org/apache/baremaps/iploc/data/IpLocStats.java
 delete mode 100644 baremaps-core/src/main/java/org/apache/baremaps/iploc/data/Ipv4.java
 delete mode 100644 baremaps-core/src/main/java/org/apache/baremaps/iploc/data/Ipv4Range.java
 delete mode 100644 baremaps-core/src/main/java/org/apache/baremaps/iploc/data/Location.java
 delete mode 100644 baremaps-core/src/main/java/org/apache/baremaps/iploc/database/Dao.java
 delete mode 100644 baremaps-core/src/main/java/org/apache/baremaps/iploc/database/InetnumLocationDao.java
 delete mode 100644 baremaps-core/src/main/java/org/apache/baremaps/iploc/database/InetnumLocationDaoSqliteImpl.java
 delete mode 100644 baremaps-core/src/main/java/org/apache/baremaps/iploc/dto/InetnumLocationDto.java
 delete mode 100644 baremaps-core/src/main/java/org/apache/baremaps/iploc/nic/NicUtils.java
 delete mode 100644 baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/CollectionUtils.java
 rename baremaps-core/src/main/java/org/apache/baremaps/{database => openstreetmap}/DiffService.java (90%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/collection => openstreetmap/postgres}/PostgresCoordinateMap.java (99%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/repository => openstreetmap/postgres}/PostgresHeaderRepository.java (97%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/collection => openstreetmap/postgres}/PostgresIterator.java (96%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/repository => openstreetmap/postgres}/PostgresJsonbMapper.java (96%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/repository => openstreetmap/postgres}/PostgresNodeRepository.java (96%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/collection => openstreetmap/postgres}/PostgresReferenceMap.java (99%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/repository => openstreetmap/postgres}/PostgresRelationRepository.java (94%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/repository => openstreetmap/postgres}/PostgresWayRepository.java (96%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database => openstreetmap/repository}/BlockImporter.java (89%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database => openstreetmap/repository}/ChangeImporter.java (90%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database => openstreetmap}/repository/HeaderRepository.java (95%)
 copy baremaps-core/src/main/java/org/apache/baremaps/{storage/ColumnImpl.java => openstreetmap/repository/NodeRepository.java} (73%)
 copy baremaps-core/src/main/java/org/apache/baremaps/{storage/ColumnImpl.java => openstreetmap/repository/RelationRepository.java} (72%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database => openstreetmap}/repository/Repository.java (97%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database => openstreetmap}/repository/RepositoryException.java (96%)
 copy baremaps-core/src/main/java/org/apache/baremaps/{storage/ColumnImpl.java => openstreetmap/repository/WayRepository.java} (74%)
 delete mode 100644 baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/utils/InputStreamProgress.java
 delete mode 100644 baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/utils/StreamProgress.java
 rename baremaps-core/src/main/java/org/apache/baremaps/{database => postgres}/PostgresUtils.java (98%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database => postgres}/copy/CopyWriter.java (99%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database => postgres}/copy/PostgisGeometryValueHandler.java (91%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database => postgres}/metadata/ColumnResult.java (95%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database => postgres}/metadata/DatabaseMetadata.java (99%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database => postgres}/metadata/PrimaryKeyResult.java (93%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database => postgres}/metadata/TableMetadata.java (94%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database => postgres}/metadata/TableResult.java (94%)
 create mode 100644 baremaps-core/src/main/java/org/apache/baremaps/raster/AsterDem.java
 rename baremaps-core/src/main/java/org/apache/baremaps/storage/{TableGeometryDecorator.java => TableDecorator.java} (58%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{openstreetmap/utils => stream}/ProgressLogger.java (70%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/tile => tilestore}/TileBatchPredicate.java (81%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/tile => tilestore}/TileCache.java (67%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/tile => tilestore}/TileChannel.java (86%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/tile/Tile.java => tilestore/TileCoord.java} (70%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/tile/TileIterator.java => tilestore/TileCoordIterator.java} (67%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/tile => tilestore}/TileStore.java (72%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/tile => tilestore}/TileStoreException.java (96%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/tile => tilestore}/VariableUtils.java (96%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/tile => tilestore/file}/FileTileStore.java (66%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/tile => tilestore/mbtiles}/MBTiles.java (86%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/tile => tilestore/postgres}/PostgresGroup.java (98%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/tile => tilestore/postgres}/PostgresQuery.java (98%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/tile => tilestore/postgres}/PostgresQueryGenerator.java (95%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{database/tile => tilestore/postgres}/PostgresTileStore.java (86%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{collection => }/utils/FileUtils.java (95%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{openstreetmap => }/utils/GeometryUtils.java (98%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{geocoder => utils}/IsoCountriesUtils.java (96%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{collection => }/utils/MappedByteBufferUtils.java (97%)
 rename baremaps-server/src/main/java/org/apache/baremaps/server/DefaultObjectMapper.java => baremaps-core/src/main/java/org/apache/baremaps/utils/ObjectMapperUtils.java (86%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{openstreetmap => }/utils/ProjectionTransformer.java (99%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{iploc/database => utils}/SqliteUtils.java (97%)
 rename baremaps-core/src/main/java/org/apache/baremaps/vectortile/{Tile.java => VectorTile.java} (92%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{mvt => vectortile}/expression/Expressions.java (99%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{mvt => vectortile}/style/Style.java (99%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{mvt => vectortile}/style/StyleLayer.java (99%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{mvt => vectortile}/style/StyleSource.java (97%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{mvt => vectortile}/tileset/Tileset.java (99%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{mvt => vectortile}/tileset/TilesetLayer.java (98%)
 rename baremaps-core/src/main/java/org/apache/baremaps/{mvt => vectortile}/tileset/TilesetQuery.java (96%)
 delete mode 100644 baremaps-core/src/main/resources/iploc_init.sql
 delete mode 100644 baremaps-core/src/test/java/org/apache/baremaps/database/database/WayRepositoryTest.java
 rename baremaps-core/src/test/java/org/apache/baremaps/iploc/{IpLocTest.java => IpLocObjectTest.java} (51%)
 delete mode 100644 baremaps-core/src/test/java/org/apache/baremaps/iploc/Ipv4RangeTest.java
 delete mode 100644 baremaps-core/src/test/java/org/apache/baremaps/iploc/Ipv4Test.java
 rename baremaps-core/src/test/java/org/apache/baremaps/iploc/{nic => }/NicData.java (91%)
 rename baremaps-core/src/test/java/org/apache/baremaps/iploc/{nic => }/NicObjectTest.java (98%)
 rename baremaps-core/src/test/java/org/apache/baremaps/iploc/{nic => }/NicParserTest.java (96%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/database => openstreetmap/postgres}/PostgresHeaderRepositoryTest.java (87%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/database => openstreetmap/postgres}/PostgresNodeRepositoryTest.java (91%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/database => openstreetmap/postgres}/PostgresRelationRepositoryTest.java (91%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/database/DatabaseContainerTest.java => openstreetmap/postgres/PostgresRepositoryTest.java} (87%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/database => openstreetmap/postgres}/PostgresWayRepositoryTest.java (91%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/database => openstreetmap/repository}/BlockImporterTest.java (86%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/database => openstreetmap/repository}/Constants.java (98%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database => }/postgres/TestContainers.java (93%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/database/PostgresSchemaTest.java => postgres/metadata/PostgresMetadataTest.java} (92%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/tile => tilestore}/TileBatcherTest.java (74%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/tile/TileIteratorTest.java => tilestore/TileCoordIteratorTest.java} (56%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/tile/TileTest.java => tilestore/TileCoordTest.java} (70%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/tile => tilestore}/TileStoreTest.java (81%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/tile => tilestore/file}/FileTileStoreTest.java (82%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/tile => tilestore/mbtiles}/MBTilesTest.java (93%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/tile => tilestore/postgres}/JSQLParserTest.java (97%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/tile => tilestore/postgres}/PostgresQueryGeneratorTest.java (87%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/tile => tilestore/postgres}/PostgresQueryParserTest.java (98%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{database/tile => tilestore/postgres}/PostgresTileStoreTest.java (93%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{openstreetmap/geometry => utils}/ProjectionTransformerTest.java (91%)
 rename baremaps-core/src/test/java/org/apache/baremaps/{mvt => vectortile}/ExpressionsTest.java (98%)
 create mode 100644 baremaps-ogcapi/src/main/java/org/apache/baremaps/ogcapi/DefaultResource.java
 delete mode 100644 baremaps-ogcapi/src/main/java/org/apache/baremaps/ogcapi/ImportResource.java
 delete mode 100644 baremaps-ogcapi/src/main/java/org/apache/baremaps/ogcapi/PostgisPlugin.java
 delete mode 100644 baremaps-ogcapi/src/main/java/org/apache/baremaps/ogcapi/RootResource.java
 delete mode 100644 baremaps-ogcapi/src/main/java/org/apache/baremaps/ogcapi/StudioResource.java
 delete mode 100644 baremaps-ogcapi/src/main/java/org/apache/baremaps/ogcapi/SwaggerResource.java
 create mode 100644 baremaps-ogcapi/src/main/java/org/apache/baremaps/ogcapi/TilesResource.java
 delete mode 100644 baremaps-ogcapi/src/main/java/org/apache/baremaps/ogcapi/TilesetsResource.java
 copy baremaps-server/src/main/resources/assets/server.html => baremaps-ogcapi/src/main/resources/map.html (64%)
 delete mode 100644 baremaps-ogcapi/src/main/resources/ogcapi-openapi.yaml
 create mode 100644 baremaps-ogcapi/src/main/resources/ogcapi.yaml
 delete mode 100644 baremaps-ogcapi/src/main/resources/schemas/TileJSON.yaml
 delete mode 100644 baremaps-ogcapi/src/main/resources/schemas/collection.yaml
 delete mode 100644 baremaps-ogcapi/src/main/resources/schemas/collections.yaml
 delete mode 100644 baremaps-ogcapi/src/main/resources/schemas/confClasses.yaml
 delete mode 100644 baremaps-ogcapi/src/main/resources/schemas/exception.yaml
 delete mode 100644 baremaps-ogcapi/src/main/resources/schemas/extent.yaml
 delete mode 100644 baremaps-ogcapi/src/main/resources/schemas/landingPage.yaml
 delete mode 100644 baremaps-ogcapi/src/main/resources/schemas/link.yaml
 delete mode 100644 baremaps-ogcapi/src/main/resources/schemas/mb-layer.yaml
 delete mode 100644 baremaps-ogcapi/src/main/resources/schemas/mb-style.yaml
 delete mode 100644 baremaps-ogcapi/src/main/resources/schemas/query.yaml
 delete mode 100644 baremaps-ogcapi/src/main/resources/schemas/style-set-entry.yaml
 delete mode 100644 baremaps-ogcapi/src/main/resources/schemas/style-set.yaml
 delete mode 100644 baremaps-ogcapi/src/main/resources/schemas/vector_layer.yaml
 create mode 100644 baremaps-ogcapi/src/test/java/org/apache/baremaps/ogcapi/ApiResourceTest.java
 delete mode 100644 baremaps-ogcapi/src/test/java/org/apache/baremaps/ogcapi/CollectionsResourceIntegrationTest.java
 create mode 100644 baremaps-ogcapi/src/test/java/org/apache/baremaps/ogcapi/CollectionsResourceTest.java
 copy baremaps-core/src/test/java/org/apache/baremaps/workflow/tasks/ExecuteSqlFileTest.java => baremaps-ogcapi/src/test/java/org/apache/baremaps/ogcapi/ConformanceResourceTest.java (57%)
 copy baremaps-core/src/test/java/org/apache/baremaps/workflow/tasks/ImportGeoPackageTest.java => baremaps-ogcapi/src/test/java/org/apache/baremaps/ogcapi/DefaultResourceTest.java (53%)
 delete mode 100644 baremaps-ogcapi/src/test/java/org/apache/baremaps/ogcapi/ImportResourceIntegrationTest.java
 create mode 100644 baremaps-ogcapi/src/test/java/org/apache/baremaps/ogcapi/OgcApiTest.java
 delete mode 100644 baremaps-ogcapi/src/test/java/org/apache/baremaps/ogcapi/PostgisPluginTest.java
 delete mode 100644 baremaps-ogcapi/src/test/java/org/apache/baremaps/ogcapi/PostgisRecord.java
 delete mode 100644 baremaps-ogcapi/src/test/java/org/apache/baremaps/ogcapi/RootResourceIntegrationTest.java
 delete mode 100644 baremaps-ogcapi/src/test/java/org/apache/baremaps/ogcapi/StudioResourceIntegrationTest.java
 delete mode 100644 baremaps-ogcapi/src/test/java/org/apache/baremaps/ogcapi/StylesResourceIntegrationTest.java
 create mode 100644 baremaps-ogcapi/src/test/java/org/apache/baremaps/ogcapi/StylesResourceTest.java
 create mode 100644 baremaps-ogcapi/src/test/java/org/apache/baremaps/ogcapi/TilesResourceTest.java
 delete mode 100644 baremaps-ogcapi/src/test/java/org/apache/baremaps/ogcapi/TilesetsResourceIntegrationTest.java
 create mode 100644 baremaps-renderer/.gitignore
 create mode 100644 baremaps-renderer/.prettierignore
 create mode 100644 baremaps-renderer/.prettierrc.json
 create mode 100644 baremaps-renderer/README.md
 create mode 100644 baremaps-renderer/assets/report-template.html
 copy basemap/layers/highway/highway_construction.js => baremaps-renderer/declaration.d.ts (73%)
 create mode 100644 baremaps-renderer/package-lock.json
 create mode 100644 baremaps-renderer/package.json
 create mode 100644 baremaps-renderer/src/index.ts
 create mode 100644 baremaps-renderer/src/lib/browserPool.ts
 create mode 100644 baremaps-renderer/src/lib/maplibreBrowserHelpers.ts
 create mode 100644 baremaps-renderer/src/lib/reportGenerator.ts
 copy basemap/config.js => baremaps-renderer/src/lib/runnableTask.ts (60%)
 create mode 100644 baremaps-renderer/src/lib/test.ts
 create mode 100644 baremaps-renderer/src/lib/testManager.ts
 create mode 100644 baremaps-renderer/src/lib/testsLogger.ts
 copy basemap/layers/leisure/nature_reserve.js => baremaps-renderer/src/types/index.ts (52%)
 create mode 100644 baremaps-renderer/tsconfig.json
 create mode 100644 baremaps-server/src/main/java/org/apache/baremaps/server/IpLocResources.java
 delete mode 100644 baremaps-server/src/main/java/org/apache/baremaps/server/IplocResources.java
 create mode 100644 baremaps-server/src/main/resources/assets/maplibre-custom-controls.css
 create mode 100644 baremaps-server/src/main/resources/assets/maplibre-custom-controls.js
 create mode 100644 basemap/tests/.gitignore
 create mode 100644 basemap/tests/integration/lausanne/metadata.json


[incubator-baremaps] 02/05: Improve tile store

Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a commit to branch gdal
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git

commit 28678b1f22196c2c674bdf21ff3f0cb81e2f7050
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Sun Apr 23 11:03:36 2023 +0200

    Improve tile store
---
 .run/ContourTileStore.run.xml                      |  16 +++
 .../apache/baremaps/raster/ContourTileStore.java   | 116 ++++++++++++---------
 .../main/java/org/apache/baremaps/raster/Main.java |  35 +++----
 .../org/apache/baremaps/tilestore/TileCoord.java   |   4 +-
 4 files changed, 100 insertions(+), 71 deletions(-)

diff --git a/.run/ContourTileStore.run.xml b/.run/ContourTileStore.run.xml
new file mode 100644
index 00000000..307d971d
--- /dev/null
+++ b/.run/ContourTileStore.run.xml
@@ -0,0 +1,16 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="ContourTileStore" type="Application" factoryName="Application" nameIsGenerated="true">
+    <option name="MAIN_CLASS_NAME" value="org.apache.baremaps.raster.ContourTileStore" />
+    <module name="baremaps-core" />
+    <option name="VM_PARAMETERS" value="-Djava.library.path=$PROJECT_DIR$/../../osgeo/gdal/build/swig/java" />
+    <extension name="coverage">
+      <pattern>
+        <option name="PATTERN" value="org.apache.baremaps.raster.*" />
+        <option name="ENABLED" value="true" />
+      </pattern>
+    </extension>
+    <method v="2">
+      <option name="Make" enabled="true" />
+    </method>
+  </configuration>
+</component>
\ No newline at end of file
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/raster/ContourTileStore.java b/baremaps-core/src/main/java/org/apache/baremaps/raster/ContourTileStore.java
index a352fa20..9e2b093b 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/raster/ContourTileStore.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/raster/ContourTileStore.java
@@ -12,73 +12,79 @@
 
 package org.apache.baremaps.raster;
 
-import java.net.URL;
 import java.nio.ByteBuffer;
-import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.List;
 import java.util.Vector;
+import java.util.stream.IntStream;
+import java.util.stream.LongStream;
+
 import org.apache.baremaps.database.tile.Tile;
 import org.apache.baremaps.database.tile.TileStore;
 import org.apache.baremaps.database.tile.TileStoreException;
+import org.apache.baremaps.openstreetmap.utils.GeometryUtils;
+import org.apache.baremaps.openstreetmap.utils.ProjectionTransformer;
+import org.gdal.gdal.Dataset;
+import org.gdal.gdal.WarpOptions;
 import org.gdal.gdal.gdal;
 import org.gdal.gdalconst.gdalconstConstants;
 import org.gdal.ogr.FieldDefn;
 import org.gdal.ogr.ogr;
 import org.gdal.osr.SpatialReference;
+import org.locationtech.jts.geom.util.GeometryTransformer;
+import org.locationtech.proj4j.ProjCoordinate;
 
-public class ContourTileStore implements TileStore {
-  @Override
-  public ByteBuffer read(Tile tile) throws TileStoreException {
-    var file = Paths.get(String.format("%s/%s/%s.tif", tile.z(), tile.x(), tile.y()));
-    var source = String.format("https://s3.amazonaws.com/elevation-tiles-prod/geotiff/%s", file);
-
-    try {
-      Files.deleteIfExists(file);
-      Files.createDirectories(file.getParent());
-      Files.createFile(file);
-      try (var stream = new URL(source).openStream()) {
-        Files.copy(stream, file);
-      }
-    } catch (Exception e) {
-      e.printStackTrace();
-    }
-
-    var dataset = gdal.Open(file.toString(), gdalconstConstants.GA_ReadOnly);
-
-    dataset.GetGeoTransform();
-    dataset.GetRasterXSize();
-    dataset.GetRasterYSize();
-
-
-    var band = dataset.GetRasterBand(1);
-
-    band.ReadRaster_Direct(0, 0, 100, 100);
-
-    var wkt = dataset.GetProjection();
-    var srs = new SpatialReference(wkt);
-
-    var driver = ogr.GetDriverByName("Memory");
-    var dataSource = driver.CreateDataSource("memory_name");
+public class ContourTileStore implements TileStore, AutoCloseable {
 
-    var layer = dataSource.CreateLayer("contour", srs, ogr.wkbLineString);
+  static {
+    gdal.AllRegister();
+    ogr.RegisterAll();
+  }
 
-    var field = new FieldDefn("ID", ogr.OFTInteger);
-    field.SetWidth(8);
-    layer.CreateField(field, 0);
-    field.delete();
+  private final Dataset sourceDataset;
 
-    gdal.ContourGenerateEx(band, layer, new Vector<>(List.of(
-        "LEVEL_INTERVAL=" + 10)));
+  public ContourTileStore() {
+    var dem = Paths.get("examples/contour/dem.xml").toAbsolutePath().toString();
+    sourceDataset = gdal.Open(dem, gdalconstConstants.GA_ReadOnly);
+  }
 
-    for (int i = 0; i < layer.GetFeatureCount(); i++) {
-      var feature = layer.GetFeature(i);
-      var geometry = feature.GetGeometryRef();
-      // System.out.println(geometry.ExportToWkt());
-    }
+  @Override
+  public ByteBuffer read(Tile tile) throws TileStoreException {
+    var sourceBand = sourceDataset.GetRasterBand(1);
+    var envelope = tile.envelope();
+
+    // Warp the raster to the requested extent
+    var rasterOptions = new WarpOptions(new Vector<>(List.of(
+            "-of", "MEM",
+            "-te", Double.toString(envelope.getMinX()), Double.toString(envelope.getMinY()), Double.toString(envelope.getMaxX()), Double.toString(envelope.getMaxY()),
+            "-te_srs", "EPSG:4326")));
+    var rasterDataset = gdal.Warp("", new Dataset[]{sourceDataset}, rasterOptions);
+    var rasterBand = rasterDataset.GetRasterBand(1);
+
+    // Generate the contours
+    //var wkt = rasterDataset.GetProjection();
+    //var srs = new SpatialReference(wkt);
+    var srs = new SpatialReference("EPSG:4326");
+    var vectorDriver = ogr.GetDriverByName("Memory");
+    var vectorDataSource = vectorDriver.CreateDataSource("vector");
+    var vectorLayer = vectorDataSource.CreateLayer("vector", srs, ogr.wkbLineString);
+    gdal.ContourGenerateEx(rasterBand, vectorLayer, new Vector<>(List.of("LEVEL_INTERVAL=" + 10)));
+
+    // return the contours
+    var geometries = LongStream.range(0, vectorLayer.GetFeatureCount())
+            .mapToObj(vectorLayer::GetFeature)
+            .map(feature -> feature.GetGeometryRef())
+            .map(geometry -> GeometryUtils.deserialize(geometry.ExportToWkb()))
+            .toList();
+
+    var transformer = GeometryUtils.coordinateTransform(4326, 3857);
+    var min = transformer.transform(new ProjCoordinate(envelope.getMinX(), envelope.getMinY()), new ProjCoordinate());
+    var max = transformer.transform(new ProjCoordinate(envelope.getMaxX(), envelope.getMaxY()), new ProjCoordinate());
+
+    rasterBand.delete();
+    rasterDataset.delete();
+    sourceBand.delete();
 
-    dataSource.delete();
-    dataset.delete();
     return null;
   }
 
@@ -91,4 +97,16 @@ public class ContourTileStore implements TileStore {
   public void delete(Tile tile) throws TileStoreException {
     throw new UnsupportedOperationException();
   }
+
+  @Override
+  public void close() throws Exception {
+    sourceDataset.delete();
+  }
+
+  public static void main(String[] args) throws Exception {
+    var store = new ContourTileStore();
+    store.read(new Tile(8492, 5792, 14).parent());
+  }
+
+
 }
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/raster/Main.java b/baremaps-core/src/main/java/org/apache/baremaps/raster/Main.java
index 4e37b4d5..f447f5c5 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/raster/Main.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/raster/Main.java
@@ -26,17 +26,15 @@ import org.gdal.osr.SpatialReference;
 public class Main {
 
   public static void main(String[] args) {
-
-    // var sourceFilename = Paths.get("examples/contour/liecthenstein-aster-dem-v2-3857.tif")
-    // .toAbsolutePath().toString();
-    // var hillshadeFilename =
-    // Paths.get("examples/contour/liecthenstein-aster-dem-v2-3857-hillshade.tif").toAbsolutePath()
-    // .toString();
-    // var outputFilename = Paths.get("examples/contour/liecthenstein-aster-dem-v2-3857.shp")
-    // .toAbsolutePath().toString();
-    // var warpFilename = Paths.get("examples/contour/liecthenstein-aster-dem-v2-3857-warp.tif")
-    // .toAbsolutePath().toString();
-
+     var sourceFilename = Paths.get("examples/contour/liecthenstein-aster-dem-v2-3857.tif")
+     .toAbsolutePath().toString();
+     var hillshadeFilename =
+     Paths.get("examples/contour/liecthenstein-aster-dem-v2-3857-hillshade.tif").toAbsolutePath()
+     .toString();
+     var outputFilename = Paths.get("examples/contour/liecthenstein-aster-dem-v2-3857.shp")
+     .toAbsolutePath().toString();
+     var warpFilename = Paths.get("examples/contour/liecthenstein-aster-dem-v2-3857-warp.tif")
+     .toAbsolutePath().toString();
 
     var dem = Paths.get("examples/contour/dem.xml")
         .toAbsolutePath().toString();
@@ -44,15 +42,15 @@ public class Main {
     gdal.AllRegister();
     ogr.RegisterAll();
 
-    planetContour("https://s3.amazonaws.com/elevation-tiles-prod/geotiff/%s/%s/%s.tif");
+    planetContour();
 
-    // hillshade(sourceFilename, 1, hillshadeFilename, 45d, 315d);
-    // contourEx(hillshadeFilename, 1, outputFilename, 50, 0);
-    // warp(sourceFilename, warpFilename);
-    // shadow(hillshadeFilename, outputFilename);
+   hillshade(sourceFilename, 1, hillshadeFilename, 45d, 315d);
+   contourEx(hillshadeFilename, 1, outputFilename, 50, 0);
+   warp(sourceFilename, warpFilename);
+   shadow(hillshadeFilename, outputFilename);
   }
 
-  public static void planetContour(String source) {
+  public static void planetContour() {
     var file = Paths.get(String.format("%s/%s/%s.tif", 14, 8514, 5816));
     var url = String.format("https://s3.amazonaws.com/elevation-tiles-prod/geotiff/%s", file);
     System.out.println(url);
@@ -69,7 +67,6 @@ public class Main {
       e.printStackTrace();
     }
 
-
     var dataset = gdal.Open(file.toString(), gdalconstConstants.GA_ReadOnly);
 
     var band = dataset.GetRasterBand(1);
@@ -231,10 +228,8 @@ public class Main {
 
     dataSource.delete();
     dataset.delete();
-
   }
 
-
   public static void hillshade(String source, Integer sourceBand, String target, Double azimuth,
       Double altitude) {
     var options = new Vector<>(List.of(
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/TileCoord.java b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/TileCoord.java
index 707a4480..671606fb 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/TileCoord.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/TileCoord.java
@@ -193,8 +193,8 @@ public final class TileCoord implements Comparable<TileCoord> {
   public Envelope envelope() {
     double x1 = tile2lon(x, z);
     double x2 = tile2lon(x + 1, z);
-    double y1 = tile2lat(y + 1, z);
-    double y2 = tile2lat(y, z);
+    double y1 = tile2lat(y, z);
+    double y2 = tile2lat(y + 1, z);
     return new Envelope(x1, x2, y1, y2);
   }
 


[incubator-baremaps] 01/05: WIP - experiment with gdal

Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a commit to branch gdal
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git

commit 270843003b7d002eaac06f33503cce6e7270b09d
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Fri Mar 24 16:05:09 2023 +0100

    WIP - experiment with gdal
---
 baremaps-core/pom.xml                              |   4 +
 .../apache/baremaps/raster/ContourTileStore.java   |  94 ++++++++
 .../main/java/org/apache/baremaps/raster/Main.java | 257 +++++++++++++++++++++
 examples/contour/dem.xml                           |  29 +++
 pom.xml                                            |   6 +
 5 files changed, 390 insertions(+)

diff --git a/baremaps-core/pom.xml b/baremaps-core/pom.xml
index 2359597c..23e108b3 100644
--- a/baremaps-core/pom.xml
+++ b/baremaps-core/pom.xml
@@ -105,6 +105,10 @@
       <groupId>org.graalvm.sdk</groupId>
       <artifactId>graal-sdk</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.gdal</groupId>
+      <artifactId>gdal</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.locationtech.jts</groupId>
       <artifactId>jts-core</artifactId>
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/raster/ContourTileStore.java b/baremaps-core/src/main/java/org/apache/baremaps/raster/ContourTileStore.java
new file mode 100644
index 00000000..a352fa20
--- /dev/null
+++ b/baremaps-core/src/main/java/org/apache/baremaps/raster/ContourTileStore.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.baremaps.raster;
+
+import java.net.URL;
+import java.nio.ByteBuffer;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Vector;
+import org.apache.baremaps.database.tile.Tile;
+import org.apache.baremaps.database.tile.TileStore;
+import org.apache.baremaps.database.tile.TileStoreException;
+import org.gdal.gdal.gdal;
+import org.gdal.gdalconst.gdalconstConstants;
+import org.gdal.ogr.FieldDefn;
+import org.gdal.ogr.ogr;
+import org.gdal.osr.SpatialReference;
+
+public class ContourTileStore implements TileStore {
+  @Override
+  public ByteBuffer read(Tile tile) throws TileStoreException {
+    var file = Paths.get(String.format("%s/%s/%s.tif", tile.z(), tile.x(), tile.y()));
+    var source = String.format("https://s3.amazonaws.com/elevation-tiles-prod/geotiff/%s", file);
+
+    try {
+      Files.deleteIfExists(file);
+      Files.createDirectories(file.getParent());
+      Files.createFile(file);
+      try (var stream = new URL(source).openStream()) {
+        Files.copy(stream, file);
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+
+    var dataset = gdal.Open(file.toString(), gdalconstConstants.GA_ReadOnly);
+
+    dataset.GetGeoTransform();
+    dataset.GetRasterXSize();
+    dataset.GetRasterYSize();
+
+
+    var band = dataset.GetRasterBand(1);
+
+    band.ReadRaster_Direct(0, 0, 100, 100);
+
+    var wkt = dataset.GetProjection();
+    var srs = new SpatialReference(wkt);
+
+    var driver = ogr.GetDriverByName("Memory");
+    var dataSource = driver.CreateDataSource("memory_name");
+
+    var layer = dataSource.CreateLayer("contour", srs, ogr.wkbLineString);
+
+    var field = new FieldDefn("ID", ogr.OFTInteger);
+    field.SetWidth(8);
+    layer.CreateField(field, 0);
+    field.delete();
+
+    gdal.ContourGenerateEx(band, layer, new Vector<>(List.of(
+        "LEVEL_INTERVAL=" + 10)));
+
+    for (int i = 0; i < layer.GetFeatureCount(); i++) {
+      var feature = layer.GetFeature(i);
+      var geometry = feature.GetGeometryRef();
+      // System.out.println(geometry.ExportToWkt());
+    }
+
+    dataSource.delete();
+    dataset.delete();
+    return null;
+  }
+
+  @Override
+  public void write(Tile tile, ByteBuffer blob) throws TileStoreException {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public void delete(Tile tile) throws TileStoreException {
+    throw new UnsupportedOperationException();
+  }
+}
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/raster/Main.java b/baremaps-core/src/main/java/org/apache/baremaps/raster/Main.java
new file mode 100644
index 00000000..4e37b4d5
--- /dev/null
+++ b/baremaps-core/src/main/java/org/apache/baremaps/raster/Main.java
@@ -0,0 +1,257 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.baremaps.raster;
+
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.List;
+import java.util.Vector;
+import org.gdal.gdal.*;
+import org.gdal.gdalconst.gdalconstConstants;
+import org.gdal.ogr.*;
+import org.gdal.osr.SpatialReference;
+
+public class Main {
+
+  public static void main(String[] args) {
+
+    // var sourceFilename = Paths.get("examples/contour/liecthenstein-aster-dem-v2-3857.tif")
+    // .toAbsolutePath().toString();
+    // var hillshadeFilename =
+    // Paths.get("examples/contour/liecthenstein-aster-dem-v2-3857-hillshade.tif").toAbsolutePath()
+    // .toString();
+    // var outputFilename = Paths.get("examples/contour/liecthenstein-aster-dem-v2-3857.shp")
+    // .toAbsolutePath().toString();
+    // var warpFilename = Paths.get("examples/contour/liecthenstein-aster-dem-v2-3857-warp.tif")
+    // .toAbsolutePath().toString();
+
+
+    var dem = Paths.get("examples/contour/dem.xml")
+        .toAbsolutePath().toString();
+
+    gdal.AllRegister();
+    ogr.RegisterAll();
+
+    planetContour("https://s3.amazonaws.com/elevation-tiles-prod/geotiff/%s/%s/%s.tif");
+
+    // hillshade(sourceFilename, 1, hillshadeFilename, 45d, 315d);
+    // contourEx(hillshadeFilename, 1, outputFilename, 50, 0);
+    // warp(sourceFilename, warpFilename);
+    // shadow(hillshadeFilename, outputFilename);
+  }
+
+  public static void planetContour(String source) {
+    var file = Paths.get(String.format("%s/%s/%s.tif", 14, 8514, 5816));
+    var url = String.format("https://s3.amazonaws.com/elevation-tiles-prod/geotiff/%s", file);
+    System.out.println(url);
+
+    try {
+      Files.deleteIfExists(file);
+      Files.createDirectories(file.getParent());
+      Files.createFile(file);
+      try (var stream = new URL(url).openStream()) {
+        Files.copy(stream, file, StandardCopyOption.REPLACE_EXISTING);
+      }
+      System.out.println(Files.size(file));
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+
+
+    var dataset = gdal.Open(file.toString(), gdalconstConstants.GA_ReadOnly);
+
+    var band = dataset.GetRasterBand(1);
+
+    band.ReadRaster_Direct(0, 0, 100, 100);
+
+    var wkt = dataset.GetProjection();
+    var srs = new SpatialReference(wkt);
+
+    var driver = ogr.GetDriverByName("Memory");
+    var dataSource = driver.CreateDataSource("memory_name");
+
+    var layer = dataSource.CreateLayer("contour", srs, ogr.wkbLineString);
+
+    var field = new FieldDefn("ID", ogr.OFTInteger);
+    field.SetWidth(8);
+    layer.CreateField(field, 0);
+    field.delete();
+
+    gdal.ContourGenerateEx(band, layer, new Vector<>(List.of(
+        "LEVEL_INTERVAL=" + 10)));
+
+    for (int i = 0; i < layer.GetFeatureCount(); i++) {
+      var feature = layer.GetFeature(i);
+      var geometry = feature.GetGeometryRef();
+      System.out.println(geometry.ExportToWkt());
+    }
+
+    dataSource.delete();
+    dataset.delete();
+  }
+
+  public static void contour(String source, Integer sourceBand, String target,
+      Integer contourInterval,
+      Integer contourBase) {
+
+    var dataset = gdal.Open(source, gdalconstConstants.GA_ReadOnly);
+    var band = dataset.GetRasterBand(sourceBand);
+    var wkt = dataset.GetProjection();
+    var srs = new SpatialReference(wkt);
+
+    var driver = ogr.GetDriverByName("ESRI Shapefile");
+    var dataSource = driver.CreateDataSource(target);
+    var layer = dataSource.CreateLayer("contour", srs, ogr.wkbLineString);
+    var field = new FieldDefn("ID", ogr.OFTInteger);
+
+    field.SetWidth(8);
+    layer.CreateField(field, 0);
+    field.delete();
+
+    var feature = layer.GetLayerDefn();
+    gdal.ContourGenerate(band, contourInterval, contourBase, null,
+        0, 0, layer, feature.GetFieldIndex("ID"),
+        -1);
+
+    dataSource.delete();
+    dataset.delete();
+  }
+
+  public static void contourEx(String source, Integer sourceBand, String target,
+      Integer contourInterval,
+      Integer contourBase) {
+
+    var dataset = gdal.Open(source, gdalconstConstants.GA_ReadOnly);
+    var band = dataset.GetRasterBand(sourceBand);
+    var wkt = dataset.GetProjection();
+    var srs = new SpatialReference(wkt);
+
+    var driver = ogr.GetDriverByName("ESRI Shapefile");
+    var dataSource = driver.CreateDataSource(target);
+    var layer = dataSource.CreateLayer("contour", srs, ogr.wkbLineString);
+    var field = new FieldDefn("ID", ogr.OFTInteger);
+
+    field.SetWidth(8);
+    layer.CreateField(field, 0);
+    field.delete();
+
+    gdal.ContourGenerateEx(band, layer, new Vector<>(List.of(
+        "LEVEL_BASE=" + contourBase,
+        "LEVEL_INTERVAL=" + contourInterval,
+        "POLYGONIZE=YES")));
+
+    dataSource.delete();
+    dataset.delete();
+  }
+
+  public static void polygonize(String source, Integer sourceBand, String target) {
+    var dataset = gdal.Open(source, gdalconstConstants.GA_ReadOnly);
+    var band = dataset.GetRasterBand(sourceBand);
+    var wkt = dataset.GetProjection();
+    var srs = new SpatialReference(wkt);
+
+    var driver = ogr.GetDriverByName("ESRI Shapefile");
+    var dataSource = driver.CreateDataSource(target);
+    var layer = dataSource.CreateLayer("polygonize", srs, ogr.wkbPolygon);
+    var field = new FieldDefn("ID", ogr.OFTInteger);
+
+    field.SetWidth(8);
+    layer.CreateField(field, 0);
+    field.delete();
+
+    var feature = layer.GetLayerDefn();
+    gdal.Polygonize(band, null, layer, feature.GetFieldIndex("ID"),
+        null, null);
+
+    dataSource.delete();
+    dataset.delete();
+  }
+
+  public static void warp(String source, String target) {
+    var dataset = gdal.Open(source, gdalconstConstants.GA_ReadOnly);
+    var transform = dataset.GetGeoTransform();
+    var xRes = transform[1];
+    var yRes = transform[5];
+
+    var options = new Vector<>(List.of(
+        "-tr", Double.toString(xRes * 10), Double.toString(yRes * 10)));
+
+    var warp = gdal.Warp(target, new Dataset[] {dataset}, new WarpOptions(options));
+
+    warp.delete();
+    dataset.delete();
+  }
+
+
+  public record ShadowClass(int a, int b, int c) {
+  }
+
+  private static final List<ShadowClass> shadowClasses = List.of(
+      new ShadowClass(1, 250, 255),
+      new ShadowClass(2, 240, 255),
+      new ShadowClass(3, 1, 150),
+      new ShadowClass(4, 1, 100),
+      new ShadowClass(5, 1, 65),
+      new ShadowClass(6, 1, 2));
+
+  private static void shadow(String source, String target) {
+    var dataset = gdal.Open(source, gdalconstConstants.GA_ReadOnly);
+    var band = dataset.GetRasterBand(1);
+    var wkt = dataset.GetProjection();
+    var srs = new SpatialReference(wkt);
+
+    var driver = ogr.GetDriverByName("ESRI Shapefile");
+    var dataSource = driver.CreateDataSource(target);
+
+    for (var shadowClass : shadowClasses) {
+      var layer = dataSource.CreateLayer("shadow-" + shadowClass.a(), srs, ogr.wkbPolygon);
+      var field = new FieldDefn("ID", ogr.OFTInteger);
+
+      field.SetWidth(8);
+      layer.CreateField(field, 0);
+      field.delete();
+
+      gdal.ContourGenerateEx(band, layer, new Vector<>(List.of(
+          "LEVEL_BASE=" + shadowClass.b(),
+          "LEVEL_INTERVAL=" + shadowClass.c(),
+          "POLYGONIZE=YES")));
+    }
+
+    dataSource.delete();
+    dataset.delete();
+
+  }
+
+
+  public static void hillshade(String source, Integer sourceBand, String target, Double azimuth,
+      Double altitude) {
+    var options = new Vector<>(List.of(
+        "-az", azimuth.toString(),
+        "-alt", altitude.toString(),
+        "-z", "1.0",
+        "-s", "1.0",
+        "-b", sourceBand.toString(),
+        "-of", "GTiff",
+        "-combined"));
+
+    var dataset = gdal.Open(source, gdalconstConstants.GA_ReadOnly);
+    var hillshadeDataset =
+        gdal.DEMProcessing(target, dataset, "hillshade", null, new DEMProcessingOptions(options));
+
+    hillshadeDataset.delete();
+    dataset.delete();
+  }
+
+}
diff --git a/examples/contour/dem.xml b/examples/contour/dem.xml
new file mode 100644
index 00000000..178ca466
--- /dev/null
+++ b/examples/contour/dem.xml
@@ -0,0 +1,29 @@
+<GDAL_WMS>
+    <!--
+    Generate contour lines for the planet.
+    gdal_contour -a elevation -nln contour -i 10 -f GPKG dem.xml dem.gpkg
+    -->
+    <Service name="TMS">
+        <ServerUrl>https://s3.amazonaws.com/elevation-tiles-prod/geotiff/${z}/${x}/${y}.tif</ServerUrl>
+    </Service>
+    <DataWindow>
+        <UpperLeftX>-20037508.34</UpperLeftX>
+        <UpperLeftY>20037508.34</UpperLeftY>
+        <LowerRightX>20037508.34</LowerRightX>
+        <LowerRightY>-20037508.34</LowerRightY>
+        <TileLevel>14</TileLevel>
+        <TileCountX>1</TileCountX>
+        <TileCountY>1</TileCountY>
+        <YOrigin>top</YOrigin>
+    </DataWindow>
+    <Projection>EPSG:3857</Projection>
+    <BlockSizeX>512</BlockSizeX>
+    <BlockSizeY>512</BlockSizeY>
+    <BandsCount>1</BandsCount>
+    <DataType>Int16</DataType>
+    <ZeroBlockHttpCodes>403,404</ZeroBlockHttpCodes>
+    <DataValues>
+        <NoData>-32768</NoData>
+    </DataValues>
+    <Cache/>
+</GDAL_WMS>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 71b72de6..73cdc728 100644
--- a/pom.xml
+++ b/pom.xml
@@ -83,6 +83,7 @@
     <version.lib.commons-compress>1.21</version.lib.commons-compress>
     <version.lib.fastutil>8.5.9</version.lib.fastutil>
     <version.lib.flatgeobuf>3.24.0</version.lib.flatgeobuf>
+    <version.lib.gdal>3.6.3</version.lib.gdal>
     <version.lib.geopackage>6.5.0</version.lib.geopackage>
     <version.lib.graalvm>22.2.0</version.lib.graalvm>
     <version.lib.guava>31.1-jre</version.lib.guava>
@@ -370,6 +371,11 @@
         <version>${version.lib.awaitability}</version>
         <scope>test</scope>
       </dependency>
+      <dependency>
+        <groupId>org.gdal</groupId>
+        <artifactId>gdal</artifactId>
+        <version>${version.lib.gdal}</version>
+      </dependency>
       <dependency>
         <groupId>org.glassfish.jaxb</groupId>
         <artifactId>jaxb-runtime</artifactId>


[incubator-baremaps] 03/05: Serve contour tiles

Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a commit to branch gdal
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git

commit 9b12ea278d6ca76fb1f4dfca9cedd563a5d525f7
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Sun Apr 23 12:44:02 2023 +0200

    Serve contour tiles
---
 .../java/org/apache/baremaps/cli/map/Contour.java  | 91 ++++++++++++++++++++++
 .../main/java/org/apache/baremaps/cli/map/Map.java |  2 +-
 .../apache/baremaps/raster/ContourTileStore.java   | 33 +++++---
 .../org/apache/baremaps/vectortile/Feature.java    |  8 +-
 .../baremaps/vectortile/VectorTileEncoder.java     |  5 +-
 .../baremaps/vectortile/VectorTileUtils.java       | 21 +++--
 .../apache/baremaps/vectortile/VectorTileTest.java |  4 +-
 .../baremaps/vectortile/VectorTileViewer.java      | 13 +++-
 .../apache/baremaps/server/ServerResources.java    |  8 +-
 examples/contour/style.json                        |  4 +-
 examples/contour/tileset.json                      | 11 +--
 11 files changed, 155 insertions(+), 45 deletions(-)

diff --git a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Contour.java b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Contour.java
new file mode 100644
index 00000000..b301876b
--- /dev/null
+++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Contour.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.baremaps.cli.map;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.github.benmanes.caffeine.cache.CaffeineSpec;
+import io.servicetalk.http.netty.HttpServers;
+import io.servicetalk.http.router.jersey.HttpJerseyRouterBuilder;
+import org.apache.baremaps.cli.Options;
+import org.apache.baremaps.database.PostgresUtils;
+import org.apache.baremaps.database.tile.PostgresTileStore;
+import org.apache.baremaps.database.tile.TileCache;
+import org.apache.baremaps.database.tile.TileStore;
+import org.apache.baremaps.mvt.tileset.Tileset;
+import org.apache.baremaps.raster.ContourTileStore;
+import org.apache.baremaps.server.ConfigReader;
+import org.apache.baremaps.server.CorsFilter;
+import org.apache.baremaps.server.ServerResources;
+import org.glassfish.hk2.utilities.binding.AbstractBinder;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Mixin;
+import picocli.CommandLine.Option;
+
+import java.nio.file.Path;
+import java.util.concurrent.Callable;
+
+import static io.servicetalk.data.jackson.jersey.ServiceTalkJacksonSerializerFeature.contextResolverFor;
+import static org.apache.baremaps.server.DefaultObjectMapper.defaultObjectMapper;
+
+@Command(name = "contour", description = "Start a tile server with caching capabilities.")
+public class Contour implements Callable<Integer> {
+
+  private static final Logger logger = LoggerFactory.getLogger(Contour.class);
+
+  @Option(names = {"--cache"}, paramLabel = "CACHE", description = "The caffeine cache directive.")
+  private String cache = "";
+
+  @Option(names = {"--tileset"}, paramLabel = "TILESET", description = "The tileset file.",
+      required = true)
+  private Path tileset;
+
+  @Option(names = {"--style"}, paramLabel = "STYLE", description = "The style file.",
+      required = true)
+  private Path style;
+
+  @Option(names = {"--host"}, paramLabel = "HOST", description = "The host of the server.")
+  private String host = "localhost";
+
+  @Option(names = {"--port"}, paramLabel = "PORT", description = "The port of the server.")
+  private int port = 9000;
+
+  @Override
+  public Integer call() throws Exception {
+    var objectMapper = defaultObjectMapper();
+    var tileStore = new ContourTileStore();
+
+    // Configure the application
+    var application =
+        new ResourceConfig().register(CorsFilter.class).register(ServerResources.class)
+            .register(contextResolverFor(objectMapper)).register(new AbstractBinder() {
+              @Override
+              protected void configure() {
+                bind(Contour.this.tileset).to(Path.class).named("tileset");
+                bind(style).to(Path.class).named("style");
+                bind(objectMapper).to(ObjectMapper.class);
+                bind(tileStore).to(TileStore.class);
+              }
+            });
+
+    var httpService = new HttpJerseyRouterBuilder().buildBlockingStreaming(application);
+    var serverContext = HttpServers.forPort(port).listenBlockingStreamingAndAwait(httpService);
+
+    logger.info("Listening on {}", serverContext.listenAddress());
+
+    serverContext.awaitShutdown();
+    return 0;
+  }
+}
diff --git a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Map.java b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Map.java
index 9ed602d0..e1d1a3e5 100644
--- a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Map.java
+++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Map.java
@@ -18,7 +18,7 @@ import picocli.CommandLine;
 import picocli.CommandLine.Command;
 
 @Command(name = "map", description = "Map commands.",
-    subcommands = {Init.class, Export.class, Serve.class, Dev.class}, sortOptions = false)
+    subcommands = {Init.class, Export.class, Serve.class, Dev.class, Contour.class}, sortOptions = false)
 public class Map implements Runnable {
 
   @Override
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/raster/ContourTileStore.java b/baremaps-core/src/main/java/org/apache/baremaps/raster/ContourTileStore.java
index 9e2b093b..bd206eee 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/raster/ContourTileStore.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/raster/ContourTileStore.java
@@ -15,6 +15,7 @@ package org.apache.baremaps.raster;
 import java.nio.ByteBuffer;
 import java.nio.file.Paths;
 import java.util.List;
+import java.util.Map;
 import java.util.Vector;
 import java.util.stream.IntStream;
 import java.util.stream.LongStream;
@@ -24,6 +25,10 @@ import org.apache.baremaps.database.tile.TileStore;
 import org.apache.baremaps.database.tile.TileStoreException;
 import org.apache.baremaps.openstreetmap.utils.GeometryUtils;
 import org.apache.baremaps.openstreetmap.utils.ProjectionTransformer;
+import org.apache.baremaps.vectortile.Feature;
+import org.apache.baremaps.vectortile.Layer;
+import org.apache.baremaps.vectortile.VectorTileEncoder;
+import org.apache.baremaps.vectortile.VectorTileUtils;
 import org.gdal.gdal.Dataset;
 import org.gdal.gdal.WarpOptions;
 import org.gdal.gdal.gdal;
@@ -31,6 +36,8 @@ import org.gdal.gdalconst.gdalconstConstants;
 import org.gdal.ogr.FieldDefn;
 import org.gdal.ogr.ogr;
 import org.gdal.osr.SpatialReference;
+import org.locationtech.jts.geom.Envelope;
+import org.locationtech.jts.geom.GeometryFactory;
 import org.locationtech.jts.geom.util.GeometryTransformer;
 import org.locationtech.proj4j.ProjCoordinate;
 
@@ -53,6 +60,12 @@ public class ContourTileStore implements TileStore, AutoCloseable {
     var sourceBand = sourceDataset.GetRasterBand(1);
     var envelope = tile.envelope();
 
+    // Transform the extent to the source projection
+    var transformer = GeometryUtils.coordinateTransform(4326, 3857);
+    var min = transformer.transform(new ProjCoordinate(envelope.getMinX(), envelope.getMinY()), new ProjCoordinate());
+    var max = transformer.transform(new ProjCoordinate(envelope.getMaxX(), envelope.getMaxY()), new ProjCoordinate());
+    var targetEnvelope = new Envelope(min.x, max.x, min.y, max.y);
+
     // Warp the raster to the requested extent
     var rasterOptions = new WarpOptions(new Vector<>(List.of(
             "-of", "MEM",
@@ -62,30 +75,30 @@ public class ContourTileStore implements TileStore, AutoCloseable {
     var rasterBand = rasterDataset.GetRasterBand(1);
 
     // Generate the contours
-    //var wkt = rasterDataset.GetProjection();
-    //var srs = new SpatialReference(wkt);
-    var srs = new SpatialReference("EPSG:4326");
+    var wkt = rasterDataset.GetProjection();
+    var srs = new SpatialReference(wkt);
     var vectorDriver = ogr.GetDriverByName("Memory");
     var vectorDataSource = vectorDriver.CreateDataSource("vector");
     var vectorLayer = vectorDataSource.CreateLayer("vector", srs, ogr.wkbLineString);
-    gdal.ContourGenerateEx(rasterBand, vectorLayer, new Vector<>(List.of("LEVEL_INTERVAL=" + 10)));
+    gdal.ContourGenerateEx(rasterBand, vectorLayer, new Vector<>(List.of("LEVEL_INTERVAL=" + 50)));
 
     // return the contours
-    var geometries = LongStream.range(0, vectorLayer.GetFeatureCount())
+    var features = LongStream.range(0, vectorLayer.GetFeatureCount())
             .mapToObj(vectorLayer::GetFeature)
             .map(feature -> feature.GetGeometryRef())
             .map(geometry -> GeometryUtils.deserialize(geometry.ExportToWkb()))
+            .map(geometry -> VectorTileUtils.asVectorTileGeom(geometry, targetEnvelope, 4096, 0, true))
+            .map(geometry -> new Feature(null, Map.of(), geometry))
             .toList();
 
-    var transformer = GeometryUtils.coordinateTransform(4326, 3857);
-    var min = transformer.transform(new ProjCoordinate(envelope.getMinX(), envelope.getMinY()), new ProjCoordinate());
-    var max = transformer.transform(new ProjCoordinate(envelope.getMaxX(), envelope.getMaxY()), new ProjCoordinate());
+    var vectorTile = VectorTileUtils.asVectorTile(new org.apache.baremaps.vectortile.Tile(List.of(new Layer("contours", 4096, features))));
+
 
     rasterBand.delete();
     rasterDataset.delete();
     sourceBand.delete();
 
-    return null;
+    return vectorTile;
   }
 
   @Override
@@ -106,7 +119,7 @@ public class ContourTileStore implements TileStore, AutoCloseable {
   public static void main(String[] args) throws Exception {
     var store = new ContourTileStore();
     store.read(new Tile(8492, 5792, 14).parent());
-  }
 
+  }
 
 }
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/Feature.java b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/Feature.java
index c9d7dccb..71ba3fb9 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/Feature.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/Feature.java
@@ -21,7 +21,7 @@ import org.locationtech.jts.geom.Geometry;
  */
 public class Feature {
 
-  private long id;
+  private Long id;
 
   private Map<String, Object> tags;
 
@@ -39,7 +39,7 @@ public class Feature {
    * @param tags The tags of the feature.
    * @param geometry The geometry of the feature.
    */
-  public Feature(long id, Map<String, Object> tags, Geometry geometry) {
+  public Feature(Long id, Map<String, Object> tags, Geometry geometry) {
     this.id = id;
     this.tags = tags;
     this.geometry = geometry;
@@ -50,7 +50,7 @@ public class Feature {
    *
    * @return The id of the feature.
    */
-  public long getId() {
+  public Long getId() {
     return id;
   }
 
@@ -59,7 +59,7 @@ public class Feature {
    *
    * @param id The id of the feature.
    */
-  public void setId(long id) {
+  public void setId(Long id) {
     this.id = id;
   }
 
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileEncoder.java b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileEncoder.java
index 7dcad1f7..4e4b427d 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileEncoder.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileEncoder.java
@@ -120,9 +120,10 @@ public class VectorTileEncoder {
     cy = 0;
 
     VectorTile.Tile.Feature.Builder builder = VectorTile.Tile.Feature.newBuilder();
-    builder.setId(feature.getId());
+    if (feature.getId() != null) {
+      builder.setId(feature.getId());
+    }
     builder.setType(encodeGeometryType(feature.getGeometry()));
-
     encodeTag(feature.getTags(), builder::addTags);
     encodeGeometry(feature.getGeometry(), builder::addGeometry);
 
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileUtils.java b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileUtils.java
index 9f4d72e6..1862c157 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileUtils.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileUtils.java
@@ -88,11 +88,12 @@ public class VectorTileUtils {
    * @return The transformed tile
    */
   public static ByteBuffer asVectorTile(Tile vectorTile) {
-    return new VectorTileEncoder()
-        .encodeTile(vectorTile)
-        .toByteString()
-        .asReadOnlyByteBuffer();
-
+    ByteBuffer clone = ByteBuffer.allocate(original.capacity());
+    original.rewind();//copy from the beginning
+    clone.put(original);
+    original.rewind();
+    clone.flip();
+    return clone;
   }
 
   /**
@@ -102,10 +103,18 @@ public class VectorTileUtils {
    * @return The transformed layer
    */
   public static ByteBuffer asVectorTileLayer(Layer layer) {
-    return new VectorTileEncoder()
+    ByteBuffer original = new VectorTileEncoder()
         .encodeLayer(layer)
         .toByteString()
         .asReadOnlyByteBuffer();
+
+    ByteBuffer clone = ByteBuffer.allocate(original.capacity());
+    original.rewind();//copy from the beginning
+    clone.put(original);
+    original.rewind();
+    clone.flip();
+
+    return clone;
   }
 
   /**
diff --git a/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileTest.java b/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileTest.java
index 1fb353bc..db66f294 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileTest.java
@@ -36,9 +36,9 @@ public class VectorTileTest {
   public void endToEnd() {
     var tile = new Tile(List.of(
         new Layer("layer", 256, List.of(
-            new Feature(1, Map.of("a", 1.0, "b", "2"),
+            new Feature(1l, Map.of("a", 1.0, "b", "2"),
                 GEOMETRY_FACTORY.createPoint(new Coordinate(1, 2))),
-            new Feature(2, Map.of("c", 3.0, "d", "4"),
+            new Feature(2l, Map.of("c", 3.0, "d", "4"),
                 GEOMETRY_FACTORY.createPoint(new Coordinate(2, 3)))))));
 
     var encoded = new VectorTileEncoder().encodeTile(tile);
diff --git a/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileViewer.java b/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileViewer.java
index 079d70a1..349c666c 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileViewer.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileViewer.java
@@ -14,6 +14,7 @@ package org.apache.baremaps.vectortile;
 
 import java.awt.*;
 import java.awt.Dimension;
+import java.net.URL;
 import java.nio.ByteBuffer;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -29,10 +30,14 @@ import org.locationtech.jts.geom.Polygon;
 public class VectorTileViewer {
 
   public static void main(String... args) throws Exception {
-    String arg =
-        args.length > 0 ? args[0] : "baremaps-core/src/test/resources/vectortile/14-8493-5795.mvt";
-    var path = Path.of(arg);
-    try (var input = new GZIPInputStream(Files.newInputStream(path))) {
+//    String arg =
+//        args.length > 0 ? args[0] : "baremaps-core/src/test/resources/vectortile/14-8493-5795.mvt";
+//    var path = Path.of(arg);
+//    try (var input = new GZIPInputStream(Files.newInputStream(path))) {
+
+    var url = new URL("http://localhost:9000/tiles/14/8628/5750.mvt");
+
+    try (var input = url.openStream()) {
       var buffer = ByteBuffer.wrap(input.readAllBytes());
       var parsed = org.apache.baremaps.mvt.binary.VectorTile.Tile.parseFrom(buffer);
       var tile = new VectorTileDecoder().decodeTile(parsed);
diff --git a/baremaps-server/src/main/java/org/apache/baremaps/server/ServerResources.java b/baremaps-server/src/main/java/org/apache/baremaps/server/ServerResources.java
index 54df7bdb..f6312649 100644
--- a/baremaps-server/src/main/java/org/apache/baremaps/server/ServerResources.java
+++ b/baremaps-server/src/main/java/org/apache/baremaps/server/ServerResources.java
@@ -86,14 +86,12 @@ public class ServerResources {
     try {
       ByteBuffer blob = tileStore.read(tileCoord);
       if (blob != null) {
-        byte[] bytes = new byte[blob.remaining()];
-        blob.get(bytes);
+        var array = blob.array();
         return Response.status(200) // lgtm [java/xss]
             .header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
             .header(CONTENT_TYPE, TILE_TYPE)
-            .header(CONTENT_ENCODING, TILE_ENCODING)
-            .entity(bytes)
-            .build();
+            //.header(CONTENT_ENCODING, TILE_ENCODING)
+            .entity(array).build();
       } else {
         return Response.status(204).build();
       }
diff --git a/examples/contour/style.json b/examples/contour/style.json
index 16047415..bb982ecc 100644
--- a/examples/contour/style.json
+++ b/examples/contour/style.json
@@ -14,10 +14,10 @@
       "background-color" : "rgba(255, 255, 255, 1)"
     }
   }, {
-    "id" : "aster_dem",
+    "id" : "contours",
     "type" : "line",
     "source" : "baremaps",
-    "source-layer" : "aster_dem",
+    "source-layer" : "contours",
     "layout" : {
       "line-cap" : "round",
       "line-join" : "round"
diff --git a/examples/contour/tileset.json b/examples/contour/tileset.json
index 7999eb55..98108edf 100644
--- a/examples/contour/tileset.json
+++ b/examples/contour/tileset.json
@@ -5,23 +5,16 @@
     47.166,
     14.0
   ],
-  "bounds": [
-    9.471078,
-    47.04774,
-    9.636217,
-    47.27128
-  ],
   "tiles": [
     "http://localhost:9000/tiles/{z}/{x}/{y}.mvt"
   ],
   "vector_layers": [
     {
-      "id": "aster_dem",
+      "id": "contours",
       "queries": [
         {
           "minzoom": 0,
-          "maxzoom": 20,
-          "sql": "SELECT ogc_fid, jsonb_build_object('elevation', elevation::text), wkb_geometry FROM aster_dem"
+          "maxzoom": 20
         }
       ]
     }


[incubator-baremaps] 05/05: Fix issues after rebase

Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a commit to branch gdal
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git

commit a895766433cc1521ca1eff7b3ec3240273740291
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Sun May 21 20:10:26 2023 +0200

    Fix issues after rebase
---
 .run/ContourTileStore.run.xml                      | 16 ------
 .../java/org/apache/baremaps/cli/map/Contour.java  | 14 ++----
 .../java/org/apache/baremaps/raster/AsterDem.java  | 58 ++++++++++++++++++++++
 .../apache/baremaps/raster/ContourTileStore.java   | 43 +++++++---------
 .../vectortile/{Tile.java => VectorTile.java}      |  6 +--
 .../baremaps/vectortile/VectorTileDecoder.java     | 21 ++++----
 .../baremaps/vectortile/VectorTileEncoder.java     | 35 ++++++-------
 .../baremaps/vectortile/VectorTileUtils.java       |  6 ++-
 .../apache/baremaps/vectortile/VectorTileTest.java |  5 +-
 .../baremaps/vectortile/VectorTileViewer.java      |  7 +--
 10 files changed, 120 insertions(+), 91 deletions(-)

diff --git a/.run/ContourTileStore.run.xml b/.run/ContourTileStore.run.xml
deleted file mode 100644
index 307d971d..00000000
--- a/.run/ContourTileStore.run.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<component name="ProjectRunConfigurationManager">
-  <configuration default="false" name="ContourTileStore" type="Application" factoryName="Application" nameIsGenerated="true">
-    <option name="MAIN_CLASS_NAME" value="org.apache.baremaps.raster.ContourTileStore" />
-    <module name="baremaps-core" />
-    <option name="VM_PARAMETERS" value="-Djava.library.path=$PROJECT_DIR$/../../osgeo/gdal/build/swig/java" />
-    <extension name="coverage">
-      <pattern>
-        <option name="PATTERN" value="org.apache.baremaps.raster.*" />
-        <option name="ENABLED" value="true" />
-      </pattern>
-    </extension>
-    <method v="2">
-      <option name="Make" enabled="true" />
-    </method>
-  </configuration>
-</component>
\ No newline at end of file
diff --git a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Contour.java b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Contour.java
index b301876b..32b4482b 100644
--- a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Contour.java
+++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Contour.java
@@ -13,32 +13,24 @@
 package org.apache.baremaps.cli.map;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
-import com.github.benmanes.caffeine.cache.CaffeineSpec;
 import io.servicetalk.http.netty.HttpServers;
 import io.servicetalk.http.router.jersey.HttpJerseyRouterBuilder;
-import org.apache.baremaps.cli.Options;
-import org.apache.baremaps.database.PostgresUtils;
-import org.apache.baremaps.database.tile.PostgresTileStore;
-import org.apache.baremaps.database.tile.TileCache;
-import org.apache.baremaps.database.tile.TileStore;
-import org.apache.baremaps.mvt.tileset.Tileset;
 import org.apache.baremaps.raster.ContourTileStore;
-import org.apache.baremaps.server.ConfigReader;
 import org.apache.baremaps.server.CorsFilter;
 import org.apache.baremaps.server.ServerResources;
+import org.apache.baremaps.tilestore.TileStore;
+import org.apache.baremaps.utils.ObjectMapperUtils;
 import org.glassfish.hk2.utilities.binding.AbstractBinder;
 import org.glassfish.jersey.server.ResourceConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import picocli.CommandLine.Command;
-import picocli.CommandLine.Mixin;
 import picocli.CommandLine.Option;
 
 import java.nio.file.Path;
 import java.util.concurrent.Callable;
 
 import static io.servicetalk.data.jackson.jersey.ServiceTalkJacksonSerializerFeature.contextResolverFor;
-import static org.apache.baremaps.server.DefaultObjectMapper.defaultObjectMapper;
 
 @Command(name = "contour", description = "Start a tile server with caching capabilities.")
 public class Contour implements Callable<Integer> {
@@ -64,7 +56,7 @@ public class Contour implements Callable<Integer> {
 
   @Override
   public Integer call() throws Exception {
-    var objectMapper = defaultObjectMapper();
+    var objectMapper = ObjectMapperUtils.objectMapper();
     var tileStore = new ContourTileStore();
 
     // Configure the application
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/raster/AsterDem.java b/baremaps-core/src/main/java/org/apache/baremaps/raster/AsterDem.java
new file mode 100644
index 00000000..47f9a363
--- /dev/null
+++ b/baremaps-core/src/main/java/org/apache/baremaps/raster/AsterDem.java
@@ -0,0 +1,58 @@
+package org.apache.baremaps.raster;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class AsterDem {
+
+    public static void main(String[] args) throws IOException {
+
+        var target = Paths.get("/Volumes/Data/data/ASTGTMV003");
+        if (Files.notExists(target)) {
+            Files.createDirectories(target);
+        }
+        var baseUrl = "https://e4ftl01.cr.usgs.gov/ASTT/ASTGTM.003/2000.03.01/";
+        var token = "...";
+
+        var directoryUrl = new URL(baseUrl);
+        var directoryConnection = (HttpURLConnection) directoryUrl.openConnection();
+
+        var files = new ArrayList<String>();
+        try(var stream = new BufferedInputStream(directoryConnection.getInputStream())) {
+            var bytes = stream.readAllBytes();
+            var html = new String(bytes);
+            Pattern p = Pattern.compile("href=\"(ASTGTMV003_.*?)\"");
+            Matcher m = p.matcher(html);
+            while (m.find()) {
+                files.add(m.group(1));
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        files.parallelStream().forEach(file -> {
+            try {
+                if (Files.exists(target.resolve(file))) {
+                    return;
+                }
+                System.out.println("Downloading " + file);
+                var fileUrl = new URL(baseUrl + file);
+                var fileConnection = (HttpURLConnection) fileUrl.openConnection();
+                fileConnection.setRequestProperty("Authorization", "Bearer " + token);
+                try(var stream = new BufferedInputStream(fileConnection.getInputStream())) {
+                    Files.copy(stream, target.resolve(file), StandardCopyOption.REPLACE_EXISTING);
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        });
+    }
+}
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/raster/ContourTileStore.java b/baremaps-core/src/main/java/org/apache/baremaps/raster/ContourTileStore.java
index bd206eee..2f2f9455 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/raster/ContourTileStore.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/raster/ContourTileStore.java
@@ -12,35 +12,30 @@
 
 package org.apache.baremaps.raster;
 
-import java.nio.ByteBuffer;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.Map;
-import java.util.Vector;
-import java.util.stream.IntStream;
-import java.util.stream.LongStream;
-
-import org.apache.baremaps.database.tile.Tile;
-import org.apache.baremaps.database.tile.TileStore;
-import org.apache.baremaps.database.tile.TileStoreException;
-import org.apache.baremaps.openstreetmap.utils.GeometryUtils;
-import org.apache.baremaps.openstreetmap.utils.ProjectionTransformer;
+import org.apache.baremaps.tilestore.TileCoord;
+import org.apache.baremaps.tilestore.TileStore;
+import org.apache.baremaps.tilestore.TileStoreException;
+import org.apache.baremaps.utils.GeometryUtils;
 import org.apache.baremaps.vectortile.Feature;
 import org.apache.baremaps.vectortile.Layer;
-import org.apache.baremaps.vectortile.VectorTileEncoder;
+import org.apache.baremaps.vectortile.VectorTile;
 import org.apache.baremaps.vectortile.VectorTileUtils;
 import org.gdal.gdal.Dataset;
 import org.gdal.gdal.WarpOptions;
 import org.gdal.gdal.gdal;
 import org.gdal.gdalconst.gdalconstConstants;
-import org.gdal.ogr.FieldDefn;
 import org.gdal.ogr.ogr;
 import org.gdal.osr.SpatialReference;
 import org.locationtech.jts.geom.Envelope;
-import org.locationtech.jts.geom.GeometryFactory;
-import org.locationtech.jts.geom.util.GeometryTransformer;
 import org.locationtech.proj4j.ProjCoordinate;
 
+import java.nio.ByteBuffer;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+import java.util.stream.LongStream;
+
 public class ContourTileStore implements TileStore, AutoCloseable {
 
   static {
@@ -51,12 +46,12 @@ public class ContourTileStore implements TileStore, AutoCloseable {
   private final Dataset sourceDataset;
 
   public ContourTileStore() {
-    var dem = Paths.get("examples/contour/dem.xml").toAbsolutePath().toString();
+    var dem = Paths.get("dem.xml").toAbsolutePath().toString();
     sourceDataset = gdal.Open(dem, gdalconstConstants.GA_ReadOnly);
   }
 
   @Override
-  public ByteBuffer read(Tile tile) throws TileStoreException {
+  public ByteBuffer read(TileCoord tile) throws TileStoreException {
     var sourceBand = sourceDataset.GetRasterBand(1);
     var envelope = tile.envelope();
 
@@ -91,8 +86,7 @@ public class ContourTileStore implements TileStore, AutoCloseable {
             .map(geometry -> new Feature(null, Map.of(), geometry))
             .toList();
 
-    var vectorTile = VectorTileUtils.asVectorTile(new org.apache.baremaps.vectortile.Tile(List.of(new Layer("contours", 4096, features))));
-
+    var vectorTile = VectorTileUtils.asVectorTile(new VectorTile(List.of(new Layer("contours", 4096, features))));
 
     rasterBand.delete();
     rasterDataset.delete();
@@ -102,12 +96,12 @@ public class ContourTileStore implements TileStore, AutoCloseable {
   }
 
   @Override
-  public void write(Tile tile, ByteBuffer blob) throws TileStoreException {
+  public void write(TileCoord tile, ByteBuffer blob) throws TileStoreException {
     throw new UnsupportedOperationException();
   }
 
   @Override
-  public void delete(Tile tile) throws TileStoreException {
+  public void delete(TileCoord tile) throws TileStoreException {
     throw new UnsupportedOperationException();
   }
 
@@ -118,8 +112,7 @@ public class ContourTileStore implements TileStore, AutoCloseable {
 
   public static void main(String[] args) throws Exception {
     var store = new ContourTileStore();
-    store.read(new Tile(8492, 5792, 14).parent());
-
+    store.read(new TileCoord(8492, 5792, 14).parent());
   }
 
 }
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/Tile.java b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTile.java
similarity index 92%
rename from baremaps-core/src/main/java/org/apache/baremaps/vectortile/Tile.java
rename to baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTile.java
index 7fb6b7c4..24c63992 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/Tile.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTile.java
@@ -18,14 +18,14 @@ import java.util.List;
 /**
  * A vector tile layer.
  */
-public class Tile {
+public class VectorTile {
 
   private List<Layer> layers;
 
   /**
    * Creates a new tile.
    */
-  public Tile(List<Layer> layers) {
+  public VectorTile(List<Layer> layers) {
     this.layers = layers;
   }
 
@@ -53,7 +53,7 @@ public class Tile {
       return true;
     if (o == null || getClass() != o.getClass())
       return false;
-    Tile tile = (Tile) o;
+    VectorTile tile = (VectorTile) o;
     return Objects.equal(layers, tile.layers);
   }
 
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileDecoder.java b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileDecoder.java
index 5e5a9cad..5b90747e 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileDecoder.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileDecoder.java
@@ -19,7 +19,8 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.*;
 import java.util.stream.Collectors;
-import org.apache.baremaps.mvt.binary.VectorTile;
+
+import org.apache.baremaps.mvt.binary.VectorTile.Tile;
 import org.apache.baremaps.mvt.binary.VectorTile.Tile.GeomType;
 import org.apache.baremaps.mvt.binary.VectorTile.Tile.Value;
 import org.locationtech.jts.geom.*;
@@ -52,9 +53,9 @@ public class VectorTileDecoder {
    * @return The decoded vector tile
    * @throws IOException If an error occurs while decoding the vector tile
    */
-  public Tile decodeTile(ByteBuffer buffer) throws IOException {
+  public VectorTile decodeTile(ByteBuffer buffer) throws IOException {
     try {
-      VectorTile.Tile tile = VectorTile.Tile.parseFrom(buffer);
+      org.apache.baremaps.mvt.binary.VectorTile.Tile tile = Tile.parseFrom(buffer);
       return decodeTile(tile);
     } catch (InvalidProtocolBufferException e) {
       throw new IOException(e);
@@ -67,11 +68,11 @@ public class VectorTileDecoder {
    * @param tile The vector tile to decode
    * @return The decoded vector tile
    */
-  public Tile decodeTile(VectorTile.Tile tile) {
+  public VectorTile decodeTile(Tile tile) {
     List<Layer> layers = tile.getLayersList().stream()
         .map(this::decodeLayer)
         .collect(Collectors.toList());
-    return new Tile(layers);
+    return new VectorTile(layers);
   }
 
   /**
@@ -83,7 +84,7 @@ public class VectorTileDecoder {
    */
   public Layer decodeLayer(ByteBuffer buffer) throws IOException {
     try {
-      VectorTile.Tile.Layer layer = VectorTile.Tile.Layer.parseFrom(buffer);
+      Tile.Layer layer = Tile.Layer.parseFrom(buffer);
       return decodeLayer(layer);
     } catch (InvalidProtocolBufferException e) {
       throw new IOException(e);
@@ -96,7 +97,7 @@ public class VectorTileDecoder {
    * @param layer The vector tile layer
    * @return The decoded layer
    */
-  public Layer decodeLayer(VectorTile.Tile.Layer layer) {
+  public Layer decodeLayer(Tile.Layer layer) {
     String name = layer.getName();
     int extent = layer.getExtent();
 
@@ -147,7 +148,7 @@ public class VectorTileDecoder {
    * @param feature The vector tile feature to decode
    * @return The decoded feature
    */
-  protected Feature decodeFeature(VectorTile.Tile.Feature feature) {
+  protected Feature decodeFeature(Tile.Feature feature) {
 
     cx = 0;
     cy = 0;
@@ -164,7 +165,7 @@ public class VectorTileDecoder {
    * @param feature The feature to decode
    * @return The tags of the feature
    */
-  protected Map<String, Object> decodeTags(VectorTile.Tile.Feature feature) {
+  protected Map<String, Object> decodeTags(Tile.Feature feature) {
     Map<String, Object> tags = new HashMap<>();
     List<Integer> encoding = feature.getTagsList();
     for (int i = 0; i < encoding.size(); i += 2) {
@@ -181,7 +182,7 @@ public class VectorTileDecoder {
    * @param feature The vector tile feature
    * @return The decoded geometry
    */
-  protected Geometry decodeGeometry(VectorTile.Tile.Feature feature) {
+  protected Geometry decodeGeometry(Tile.Feature feature) {
     GeomType type = feature.getType();
     List<Integer> encoding = feature.getGeometryList();
     switch (type) {
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileEncoder.java b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileEncoder.java
index 4e4b427d..715bcf25 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileEncoder.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileEncoder.java
@@ -20,7 +20,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.function.Consumer;
-import org.apache.baremaps.mvt.binary.VectorTile;
+
+import org.apache.baremaps.mvt.binary.VectorTile.Tile;
 import org.locationtech.jts.geom.*;
 
 /**
@@ -51,8 +52,8 @@ public class VectorTileEncoder {
    * @param tile The tile to encode
    * @return The vector tile
    */
-  public VectorTile.Tile encodeTile(Tile tile) {
-    VectorTile.Tile.Builder builder = VectorTile.Tile.newBuilder();
+  public Tile encodeTile(VectorTile tile) {
+    Tile.Builder builder = Tile.newBuilder();
     tile.getLayers().forEach(layer -> builder.addLayers(encodeLayer(layer)));
     return builder.build();
   }
@@ -63,11 +64,11 @@ public class VectorTileEncoder {
    * @param layer The layer to encode
    * @return The vector tile layer
    */
-  public VectorTile.Tile.Layer encodeLayer(Layer layer) {
+  public Tile.Layer encodeLayer(Layer layer) {
     keys = new ArrayList<>();
     values = new ArrayList<>();
 
-    VectorTile.Tile.Layer.Builder builder = VectorTile.Tile.Layer.newBuilder();
+    Tile.Layer.Builder builder = Tile.Layer.newBuilder();
     builder.setName(layer.getName());
     builder.setVersion(2);
     builder.setExtent(layer.getExtent());
@@ -89,8 +90,8 @@ public class VectorTileEncoder {
    * @param object The object to encode
    * @return The vector tile value
    */
-  protected VectorTile.Tile.Value encodeValue(Object object) {
-    VectorTile.Tile.Value.Builder builder = VectorTile.Tile.Value.newBuilder();
+  protected Tile.Value encodeValue(Object object) {
+    Tile.Value.Builder builder = Tile.Value.newBuilder();
 
     // Encode the value based on its type
     if (object instanceof String value) {
@@ -115,11 +116,11 @@ public class VectorTileEncoder {
    *
    * @param feature The feature to encode.
    */
-  protected void encodeFeature(Feature feature, Consumer<VectorTile.Tile.Feature> consumer) {
+  protected void encodeFeature(Feature feature, Consumer<Tile.Feature> consumer) {
     cx = 0;
     cy = 0;
 
-    VectorTile.Tile.Feature.Builder builder = VectorTile.Tile.Feature.newBuilder();
+    Tile.Feature.Builder builder = Tile.Feature.newBuilder();
     if (feature.getId() != null) {
       builder.setId(feature.getId());
     }
@@ -130,21 +131,21 @@ public class VectorTileEncoder {
     consumer.accept(builder.build());
   }
 
-  protected VectorTile.Tile.GeomType encodeGeometryType(Geometry geometry) {
+  protected Tile.GeomType encodeGeometryType(Geometry geometry) {
     if (geometry instanceof Point) {
-      return VectorTile.Tile.GeomType.POINT;
+      return Tile.GeomType.POINT;
     } else if (geometry instanceof MultiPoint) {
-      return VectorTile.Tile.GeomType.POINT;
+      return Tile.GeomType.POINT;
     } else if (geometry instanceof LineString) {
-      return VectorTile.Tile.GeomType.LINESTRING;
+      return Tile.GeomType.LINESTRING;
     } else if (geometry instanceof MultiLineString) {
-      return VectorTile.Tile.GeomType.LINESTRING;
+      return Tile.GeomType.LINESTRING;
     } else if (geometry instanceof Polygon) {
-      return VectorTile.Tile.GeomType.POLYGON;
+      return Tile.GeomType.POLYGON;
     } else if (geometry instanceof MultiPolygon) {
-      return VectorTile.Tile.GeomType.POLYGON;
+      return Tile.GeomType.POLYGON;
     } else {
-      return VectorTile.Tile.GeomType.UNKNOWN;
+      return Tile.GeomType.UNKNOWN;
     }
   }
 
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileUtils.java b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileUtils.java
index 1862c157..3bab5c83 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileUtils.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/VectorTileUtils.java
@@ -87,7 +87,11 @@ public class VectorTileUtils {
    * @param vectorTile The tile to transform
    * @return The transformed tile
    */
-  public static ByteBuffer asVectorTile(Tile vectorTile) {
+  public static ByteBuffer asVectorTile(VectorTile vectorTile) {
+    ByteBuffer original = new VectorTileEncoder()
+            .encodeTile(vectorTile)
+            .toByteString()
+            .asReadOnlyByteBuffer();
     ByteBuffer clone = ByteBuffer.allocate(original.capacity());
     original.rewind();//copy from the beginning
     clone.put(original);
diff --git a/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileTest.java b/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileTest.java
index db66f294..d8c91e7b 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileTest.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileTest.java
@@ -15,7 +15,6 @@ package org.apache.baremaps.vectortile;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
-import java.awt.*;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.file.Files;
@@ -23,7 +22,7 @@ import java.nio.file.Path;
 import java.util.List;
 import java.util.Map;
 import java.util.zip.GZIPInputStream;
-import javax.swing.*;
+
 import org.junit.jupiter.api.Test;
 import org.locationtech.jts.geom.Coordinate;
 import org.locationtech.jts.geom.GeometryFactory;
@@ -34,7 +33,7 @@ public class VectorTileTest {
 
   @Test
   public void endToEnd() {
-    var tile = new Tile(List.of(
+    var tile = new VectorTile(List.of(
         new Layer("layer", 256, List.of(
             new Feature(1l, Map.of("a", 1.0, "b", "2"),
                 GEOMETRY_FACTORY.createPoint(new Coordinate(1, 2))),
diff --git a/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileViewer.java b/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileViewer.java
index 349c666c..844367ad 100644
--- a/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileViewer.java
+++ b/baremaps-core/src/test/java/org/apache/baremaps/vectortile/VectorTileViewer.java
@@ -16,9 +16,6 @@ import java.awt.*;
 import java.awt.Dimension;
 import java.net.URL;
 import java.nio.ByteBuffer;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.zip.GZIPInputStream;
 import javax.swing.*;
 import org.locationtech.jts.geom.*;
 import org.locationtech.jts.geom.Point;
@@ -51,11 +48,11 @@ public class VectorTileViewer {
 
   static class TilePanel extends JPanel {
 
-    private final Tile tile;
+    private final VectorTile tile;
 
     private final int extent;
 
-    public TilePanel(Tile tile, int extent) {
+    public TilePanel(VectorTile tile, int extent) {
       this.tile = tile;
       this.extent = extent;
     }


[incubator-baremaps] 04/05: Experiment with TwelveMonkeys

Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a commit to branch gdal
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git

commit 6d9d62ffc2676d29a4cf393928cda3e9995efb0e
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Mon Apr 24 13:20:23 2023 +0200

    Experiment with TwelveMonkeys
---
 baremaps-core/pom.xml                              | 22 ++++++++++++++++++++++
 .../java/org/apache/baremaps/raster/Image.java     | 22 ++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/baremaps-core/pom.xml b/baremaps-core/pom.xml
index 23e108b3..ae470399 100644
--- a/baremaps-core/pom.xml
+++ b/baremaps-core/pom.xml
@@ -20,7 +20,29 @@
 
   <artifactId>baremaps-core</artifactId>
 
+  <repositories>
+    <repository>
+      <id>twelvemonkeys</id>
+      <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
+    </repository>
+  </repositories>
+
   <dependencies>
+    <dependency>
+      <groupId>com.twelvemonkeys.imageio</groupId>
+      <artifactId>imageio-tiff</artifactId>
+      <version>3.10.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>com.twelvemonkeys.imageio</groupId>
+      <artifactId>imageio-metadata</artifactId>
+      <version>3.9.4</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sis.storage</groupId>
+      <artifactId>sis-geotiff</artifactId>
+      <version>1.3</version>
+    </dependency>
     <dependency>
       <groupId>com.fasterxml.jackson.core</groupId>
       <artifactId>jackson-annotations</artifactId>
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/raster/Image.java b/baremaps-core/src/main/java/org/apache/baremaps/raster/Image.java
new file mode 100644
index 00000000..896304be
--- /dev/null
+++ b/baremaps-core/src/main/java/org/apache/baremaps/raster/Image.java
@@ -0,0 +1,22 @@
+package org.apache.baremaps.raster;
+
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.net.URL;
+
+
+public class Image {
+
+    public static void main(String[] args) throws IOException {
+        String urlString = String.format("https://s3.amazonaws.com/elevation-tiles-prod/geotiff/%s/%s/%s.tif", 14, 8492, 5792);
+        URL url = new URL(urlString);
+        BufferedImage tiffImage = ImageIO.read(url);
+        var raster = tiffImage.getRaster();
+        for (int x = 0; x < raster.getWidth(); x++) {
+            for (int y = 0; y < raster.getHeight(); y++) {
+                System.out.println(raster.getSampleFloat(y, y, 0));
+            }
+        }
+    }
+}