NASAWorldWind / WorldWindServerKit

The NASA WorldWind Server Kit (WWSK) is an open source Java project that assembles GeoServer for easy distribution and implementation.
92 stars 54 forks source link

Map isn't showing correctly for tiles tables with a custom Bounding Box using EPSG:4326 #11

Closed mescalantea closed 7 years ago

mescalantea commented 7 years ago

I had try to visualize a GeoPackage (tile) layer wich has a custom Bounding Box (a Bounding Box distincts to entire world Bounding Box), but the tiles aren't showing correctly. You can see this by your own following this steps:

  1. Download the sample geopackage file from: https://drive.google.com/file/d/0B5dDZ1w9dOC5eUNsZ0Q3ZHNPNzQ/view?usp=sharing
  2. Add it as a new datastore in Geoserver.
  3. Add a new layer in the Geoserver for the "usa_box" tile table and another for the "world_bbox" table.
  4. Enter in the layer preview option for both layers. Then, you'll see that the "world_bbox" map is showing correctly while the "usa_bbox" map shows malformed tiles.
emxsys commented 7 years ago

@mescalantea, thanks for the good bug report. It was very easy for me to replicate your issue using your test_gpkg.gpkg file and instructions. However, I cannot replicate the problem from a GeoPackage created from the WWSK with a custom BBOX. Can you please describe how your test_gpkg.gpkg file was created?

Using the develop branch, I generated a working GeoPackage with a custom BBOX via a WPS request. Here are the contents of the<wps:ComplexData mimeType="text/xml; subtype=geoserver/geopackage"/> for a GeoPackage with a custom BBOX:

<geopackage xmlns="http://www.opengis.net/gpkg"  name="worldtopobathy">
    <tiles identifier="L01" name="world_bbox">
        <description>World terrain and bathometry</description>
        <srs>EPSG:4326</srs>
        <bbox>
            <minx>-180</minx>
            <miny>-90</miny>
            <maxx>180</maxx>
            <maxy>90</maxy>
        </bbox>        
        <coverage>
            <minZoom>1</minZoom>
            <maxZoom>3</maxZoom>
        </coverage>
        <layers>nasa:world.topo.bathy</layers>
        <styles>raster</styles>
    </tiles>
    <tiles identifier="L02" name="usa_bbox">
        <description>USA terrain and bathometry</description>
        <srs>EPSG:4326</srs>
        <bbox>
            <minx>-171.791111</minx>
            <miny>18.91619</miny>
            <maxx>-66.96466</maxx>
            <maxy>71.357764</maxy>
        </bbox>        
        <coverage>
            <minZoom>1</minZoom>
            <maxZoom>3</maxZoom>
        </coverage>
        <layers>nasa:world.topo.bathy</layers>
        <styles>raster</styles>
    </tiles>
</geopackage>

Using the GeoServer web admin interface, you can paste the XML into a WPS gs:GeoPackage request to create a GeoPackage:

  1. Click Demos
  2. Click WPS request builder
  3. Choose the gs:GeoPackage process
  4. Paste the XML into the Process Inputs
  5. Execute
  6. Open/download the link
mescalantea commented 7 years ago

Hi @emxsys . The test_gpkg GeoPackage was generated using the "GeoPackage Java" library developed by National Geospatial-Intelligence Agency. You can found info about the library here: [http://ngageoint.github.io/geopackage-java/]()

I used the "SWAGD Verified Tool" ([https://gitlab.com/GitLabRGI/swagd-geopackage-verifier]()) program for validate the resulting geopackage and everything is ok. So, I'm sure about there's no problem with the metadata and data.

emxsys commented 7 years ago

@mescalantea, the test-gpkg data doesn't look correct to me. I used GDAL to convert the test-gpkg GeoPackage to GeoTiffs and then I loaded the two .tif images into QGIS to visualize the imagery and validate the georeferencing. The two images do not align with themselves, nor with the EPSG:4326 CRS.

Here's the command I used to create the GeoTiffs: gdal_translate -of GTiff -sds test-gpkg.gpkg test.tif

emxsys commented 7 years ago

This appears to be a bug in the data, not in the server. Closing this issue.

mescalantea commented 7 years ago

Hello @emxsys ,

I don't think the data has problems. The tiles were downloaded from a WMS and compared to the ones returned by the service and are identical. On the other hand, zoom_level, tile_row, and tile_column are correct as well. I do not know why you get unaligned tiles after using the tools you mention. Perhaps it is an error introduced at some point in the transformation and subsequent visualization. And supposing my data to be incorrect, why are the tiles well displayed when the bounding box corresponds to the whole world? I wasn't satisfied with your answer, so I looked for a solution to this problem on my own.

After a bit of debugging in gov.nasa.worldwind.geopkg.mosaic.GeoPackageReader, I discovered that the "read" procedure returns an image with the set of tiles retrieved from GeoPackage that belong to the requested bounding box. This is in theory correct, however it fails. The problem seems to be elsewhere in the GeoServer or GeoTools implementation.

As I checked, it happens when you return an image that does not match the dimensions expected by GeoServer according to the requested bounding box (for example, the requested bounding box is equivalent to an image of 512 x 256 px but you have an image of 256 x 256 px because a tile can not be found in GeoPackage). In this case GeoServer deforms the image to fit the expected size.

The solution I found was to limit the range of rows and columns to be retrieved based on the requested Bounding Box and not the tile availability in the GeoPackage. Now, everything works fine.

Regards