kartena / Proj4Leaflet

Smooth Proj4js integration with Leaflet.
http://kartena.github.io/Proj4Leaflet/
BSD 2-Clause "Simplified" License
587 stars 172 forks source link

Calculating resolutions for tiled geotiff #129

Closed sconnelley closed 7 years ago

sconnelley commented 7 years ago

Looking for help in calculating the resolution values for a geotiff tiled with gdal2tiles.py with profile set to 'raster'. Here is the output from gdalinfo.py:

Size is 46237, 56448
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
PROJ.4 string is:
'+proj=longlat +datum=WGS84 +no_defs '
Origin = (-74.099545953845322,40.884738003171933)
Pixel Size = (0.000004985649827,-0.000004985649827)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  ( -74.0995460,  40.8847380) ( 74d 5'58.37"W, 40d53' 5.06"N)
Lower Left  ( -74.0995460,  40.6033080) ( 74d 5'58.37"W, 40d36'11.91"N)
Upper Right ( -73.8690245,  40.8847380) ( 73d52' 8.49"W, 40d53' 5.06"N)
Lower Right ( -73.8690245,  40.6033080) ( 73d52' 8.49"W, 40d36'11.91"N)
Center      ( -73.9842852,  40.7440230) ( 73d59' 3.43"W, 40d44'38.48"N)
perliedman commented 7 years ago

It's been a while since I did something like that, but I'd assume Pixel Size is the same as resolution; that is, resolution is projected units per pixel, which is the same as a pixel's size.

sconnelley commented 7 years ago

thanks @perliedman, I still don't know exactly what to do with the Pixel Size values?

perliedman commented 7 years ago

Well, the pixel size is the resolution of the tiff, wasn't that what you asked in the question?

sconnelley commented 7 years ago

Sorry yes, I wasn't very clear with my response. I plugged in the positive Pixel Size number and wasn't seeing any improvement, but I finally figured out I needed the bounds property configured. Everything seems to be working pretty good, but placing markers tend to be a little off (20 pixels or so) when compared to a standard leaflet instantiation.

Here is what I came up with:

return new L.Proj.CRS('EPSG:4326',
    '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs',
    {
        origin: [-90.307150990844619, 38.722811704256983],
        resolutions: [
          ...,
          0.000004756579429 // Positive Pixel Size from gdalinfo
         ],
         bounds: L.bounds([-90.3071510,  38.7228117], [-90.1801741,  38.5330955])
      }
)

Thanks for your time

perliedman commented 7 years ago

Huh, that's weird (the offset, I mean). BTW, you should be fine with just bounds, origin is calculated from the bounds if they are provided, IIRC.