Skip to content

Fix CRS parser and proj4 cea projection support - #2403

Merged
pomadchin merged 6 commits into
locationtech:masterfrom
pomadchin:fix/crs-parser
Oct 4, 2017
Merged

pomadchin merged 6 commits into
locationtech:masterfrom
pomadchin:fix/crs-parser

Conversation

@pomadchin

Copy link
Copy Markdown
Member

Fixes #1415

@pomadchin

pomadchin commented Oct 3, 2017 •

Copy link
Copy Markdown
Member Author

This PR fixes biggis-project/biggis-landuse#2 and cea projection support (before it produced black tile or even could not reproject anything). But this PR introduces a new question.

The rasters below:

(original in cea projection)
image

(reprojected into WebMercator via GDAL)
image

(reprojected into WebMercator via GeoTrellis)
image

The question is where is the mistake? In proj4j library (though i tried to check various of CylindricalEqualAreaProjection implementations in proj4, proj4js and jmaprojlib) or in GDAL (i don't think its a gdal issue though)?

For sure this bug (if it's a bug) can be addressed in a separate PR.

GDAL info:

Cea -> WebMercator (GeoTrellis):

$ gdalinfo -proj4 /tmp/cea_wm_gt.tiff 
Driver: GTiff/GeoTIFF
Files: /tmp/cea_wm_gt.tiff
Size is 352, 637
Coordinate System is:
PROJCS["WGS 84 / Pseudo-Mercator",
    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"]],
    PROJECTION["Mercator_1SP"],
    PARAMETER["central_meridian",0],
    PARAMETER["scale_factor",1],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["X",EAST],
    AXIS["Y",NORTH],
    EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],
    AUTHORITY["EPSG","3857"]]
PROJ.4 string is:
'+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs'
Origin = (-13089969.861130239441991,5176329.847734357230365)
Pixel Size = (87.619885062502533,-87.619885062500600)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (-13089969.861, 5176329.848) (117d35'21.12"W, 42d 6' 8.62"N)
Lower Left  (-13089969.861, 5120515.981) (117d35'21.12"W, 41d43'45.49"N)
Upper Right (-13059127.662, 5176329.848) (117d18'43.70"W, 42d 6' 8.62"N)
Lower Right (-13059127.662, 5120515.981) (117d18'43.70"W, 41d43'45.49"N)
Center      (-13074548.761, 5148422.914) (117d27' 2.41"W, 41d54'58.03"N)
Band 1 Block=352x12 Type=Byte, ColorInterp=Gray

Cea -> WebMercator (GDAL):

$ gdalinfo -proj4 ~/Downloads/cea_wm.tiff 
Driver: GTiff/GeoTIFF
Files: /Users/daunnc/Downloads/cea_wm.tiff
Size is 512, 517
Coordinate System is:
PROJCS["WGS 84 / Pseudo-Mercator",
    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"]],
    PROJECTION["Mercator_1SP"],
    PARAMETER["central_meridian",0],
    PARAMETER["scale_factor",1],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["X",EAST],
    AXIS["Y",NORTH],
    EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],
    AUTHORITY["EPSG","3857"]]
PROJ.4 string is:
'+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs'
Origin = (-13095817.809482177719474,4021262.748792563565075)
Pixel Size = (72.328612721326948,-72.328612721326948)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (-13095817.809, 4021262.749) (117d38'30.24"W, 33d56'37.80"N)
Lower Left  (-13095817.809, 3983868.856) (117d38'30.24"W, 33d39'52.95"N)
Upper Right (-13058785.560, 4021262.749) (117d18'32.64"W, 33d56'37.80"N)
Lower Right (-13058785.560, 3983868.856) (117d18'32.64"W, 33d39'52.95"N)
Center      (-13077301.685, 4002565.802) (117d28'31.44"W, 33d48'15.78"N)
Band 1 Block=512x16 Type=Byte, ColorInterp=Gray

@jbouffard

Copy link
Copy Markdown
Contributor

The mistake appears to be with GeoTrellis. Using pyproj, this is the results that I get

In [21]: cea_box = box(-28493.167, 4255884.544, 2358.212, 4224973.143)

In [22]: project = partial(
    ...:     pyproj.transform,
    ...:     pyproj.Proj('+proj=cea +lat_ts=33.75 +lon_0=-117.333333333333 +x_0=0.0 +y_0=0.0 +datum=NAD27 +units=m '),
    ...:     pyproj.Proj('+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=
    ...: @null +wktext +no_defs'))

In [23]: transform(project, cea_box).bounds
Out[23]: 
(-13095817.8097412,
 3983903.7592389523,
 -13058750.785876077,
 4021262.7490324154)

This matches what GDAL returns, but differs in what GeoTrellis calculates.

@pomadchin

Copy link
Copy Markdown
Member Author

I'll dig into it a bit more tomorrow

@pomadchin

pomadchin commented Oct 4, 2017 •

Copy link
Copy Markdown
Member Author

Fixed.

(reprojected into WebMercator via GeoTrellis)
image

GDALINFO:

$ gdalinfo -proj4 /tmp/cea_wm_gt.tif 
Driver: GTiff/GeoTIFF
Files: /tmp/cea_wm_gt.tif
Size is 512, 517
Coordinate System is:
PROJCS["WGS 84 / Pseudo-Mercator",
    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"]],
    PROJECTION["Mercator_1SP"],
    PARAMETER["central_meridian",0],
    PARAMETER["scale_factor",1],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["X",EAST],
    AXIS["Y",NORTH],
    EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],
    AUTHORITY["EPSG","3857"]]
PROJ.4 string is:
'+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs'
Origin = (-13095719.172012956812978,4021260.549522797577083)
Pixel Size = (72.328088445188769,-72.328088445188129)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (-13095719.172, 4021260.550) (117d38'27.05"W, 33d56'37.74"N)
Lower Left  (-13095719.172, 3983866.928) (117d38'27.05"W, 33d39'52.90"N)
Upper Right (-13058687.191, 4021260.550) (117d18'29.46"W, 33d56'37.74"N)
Lower Right (-13058687.191, 3983866.928) (117d18'29.46"W, 33d39'52.90"N)
Center      (-13077203.181, 4002563.739) (117d28'28.25"W, 33d48'15.73"N)
Band 1 Block=512x15 Type=Byte, ColorInterp=Gray

@pomadchin

pomadchin commented Oct 4, 2017 •

Copy link
Copy Markdown
Member Author

Fixed proj4j tests in proj4-epsg.csv (tests set to passing for all cea projections):

  • EPSG:4326→EPSG:3410
  • EPSG:4326→EPSG:3975
  • EPSG:4326→EPSG:6933

@pomadchin pomadchin changed the title Fix CRS Parser Fix CRS parser and proj4 cea projection support Oct 4, 2017
@pomadchin
pomadchin merged commit 6f1e0fb into locationtech:master Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants