ngageoint / geopackage-js

GeoPackage JavaScript Library
http://ngageoint.github.io/geopackage-js/
MIT License
310 stars 78 forks source link

"zoom to" on a layer extends to whole world #105

Closed bradh closed 6 years ago

bradh commented 6 years ago

I have a layer with four points, all in Europe. Selecting "zoom to" extends to whole world (plus some).

Probably using the declared layer extent rather than actual extent, but the effect is surprising.

Features Spatial Reference System
SRS Name: WGS 84 geodetic
SRS ID: 4326
Organization: EPSG
Coordsys ID: 4326
Definition: GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]
Description: longitude/latitude coordinates in decimal degrees on the WGS 84 spheroid
Contents
Table Name: cats_feature
Data Type: features
Identifier: cats_feature
Description:
Last Change: 2017-12-24T23:58:46.092Z
Min X: -180
MinY: -90
Max X: 180
Max Y: 90
Contents Spatial Reference System
SRS Name: WGS 84 geodetic
SRS ID: 4326
Organization: EPSG
Coordsys ID: 4326
Definition: GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]
Description: longitude/latitude coordinates in decimal degrees on the WGS 84 spheroid
Geometry Columns
Table Name: cats_feature
Column Name:
Geometry Type Name: POINT
Z: 0
M: 0
cats_feature columns:
Index: 0
Name: id
Data Type: INTEGER
Max:
Not Null: false
Default Value:
Primary Key: true
Index: 1
Name: geometry
Data Type:
Max:
Not Null: false
Default Value:
Primary Key: false
Index: 2
Name: text_attribute
Data Type: TEXT
Max:
Not Null: false
Default Value:
Primary Key: false
Index: 3
Name: real_attribute
Data Type: REAL
Max:
Not Null: false
Default Value:
Primary Key: false
Index: 4
Name: relation
Data Type: TEXT
Max:
Not Null: false
Default Value:
Primary Key: false
danielbarela commented 6 years ago

You are correct. The demo page zooms to the extent that is declared in the feature table. It is shown on a web Mercator map and that is why it appears to zoom to the entire world plus some because web Mercator only extends to ~85 and ~-85 degrees latitude.

bosborn commented 6 years ago

Hi @bradh ,

The Contents (gpkg_contents) table is the only place a feature table identifies the overall bounds of the data. Evaluating each feature row for it's envelope or bounds does not make sense for a zoom operation. There could be thousands of geometries in each feature table saved with or without individual envelopes specified.

Although the bounds in the Contents are optional, we recommend specifying the minimum data encompassing bounds. For your example, the entire world is specified as the feature table data bounds. If you update the gpkg_contents min_x, min_y, max_x, max_y values, zoom should work correctly for you.

bradh commented 6 years ago

I'm fairly familiar with GeoPackage, it was more just user surprise.

I realise that its just a demo app, but keeping a bounding box during rendering wouldn't be that onerous.

danielbarela commented 6 years ago

I would argue that the bounding box specified by the contents table is the one that should be used because what if the application does not actually load all of the data into the map and only queries for what is visible. Then there would be no way of knowing how many other features there are that fall outside of the current viewport. Additionally, some applications will query for a count of features in the current viewport and not display them if there are too many. This would also cause the application to not actually know the actual bounding box of the data. Since a contents table is required for all feature tables, and that table has a bounding box, I feel that the only reliable way of zooming, regardless of the implementation of how the features are loaded, is to use the bounding box provided. Otherwise why even bother having that in the contents table if everyone is going to just set it to the world extents?