void object::test<4>() { ensure("SRS handle is NULL", nullptr != srs_); err_ = OSRSetGS(srs_, -117.0, 100000.0, 100000); ensure_equals("OSRSetGS failed", err_, OGRERR_NONE); err_ = OSRSetGeogCS(srs_, "Test GCS", "Test Datum", "WGS84", SRS_WGS84_SEMIMAJOR, SRS_WGS84_INVFLATTENING, nullptr, 0, nullptr, 0); ensure_equals("OSRSetGeogCS failed", err_, OGRERR_NONE); err_ = OSRSetTOWGS84(srs_, 1, 2, 3, 0, 0, 0, 0); ensure_equals("OSRSetTOWGS84 failed", err_, OGRERR_NONE); const int coeffSize = 7; double coeff[coeffSize] = { 0 }; const double expect[coeffSize] = { 1, 2, 3, 0, 0, 0, 0 }; err_ = OSRGetTOWGS84(srs_, coeff, 7); ensure_equals("OSRSetTOWGS84 failed", err_, OGRERR_NONE); ensure("GetTOWGS84 result is wrong", std::equal(coeff, coeff + coeffSize, expect)); OSRSetLinearUnits(srs_, "Metre", 1); char* proj4 = nullptr; err_ = OSRExportToProj4(srs_, &proj4); ensure_equals("OSRExportToProj4 failed", err_, OGRERR_NONE); OGRSpatialReferenceH srs2 = nullptr; srs2 = OSRNewSpatialReference(nullptr); err_ = OSRImportFromProj4(srs2, proj4); ensure_equals("OSRImportFromProj4 failed", err_, OGRERR_NONE); err_ = OSRGetTOWGS84(srs2, coeff, 7); ensure_equals("OSRSetTOWGS84 failed", err_, OGRERR_NONE); ensure("GetTOWGS84 result is wrong", std::equal(coeff, coeff + coeffSize, expect)); OSRDestroySpatialReference(srs2); CPLFree(proj4); }
static dErr VHTCaseSetUp_Jako(VHTCase scase) { VHTCase_Jako *jako = scase->data; dErr err; OGRErr oerr; dFunctionBegin; jako->utmref = OSRNewSpatialReference(NULL); oerr = OSRSetProjCS(jako->utmref,"UTM 22N (WGS84)");dOGRCHK(oerr); oerr = OSRSetWellKnownGeogCS(jako->utmref,"WGS84");dOGRCHK(oerr); oerr = OSRSetUTM(jako->utmref,22,1);dOGRCHK(oerr); oerr = OSRSetLinearUnits(jako->utmref,SRS_UL_METER,1.0);dOGRCHK(oerr); jako->llref = OSRNewSpatialReference(NULL); oerr = OSRSetWellKnownGeogCS(jako->llref,"WGS84");dOGRCHK(oerr); jako->ianref = OSRNewSpatialReference(NULL); oerr = OSRSetProjCS(jako->ianref,"Stereographic Greenland (WGS84)");dOGRCHK(oerr); oerr = OSRSetWellKnownGeogCS(jako->ianref,"WGS84");dOGRCHK(oerr); oerr = OSRSetStereographic(jako->ianref,70.0,-45.0,100.0,-217.75e3,-2302.0e3);dOGRCHK(oerr); // The computational domain is in UTM 22N jako->myref = OSRNewSpatialReference(NULL); oerr = OSRSetProjCS(jako->myref,"Computational Domain: UTM 22N (WGS84)");dOGRCHK(oerr); oerr = OSRSetWellKnownGeogCS(jako->myref,"WGS84");dOGRCHK(oerr); oerr = OSRSetUTM(jako->myref,22,1);dOGRCHK(oerr); oerr = OSRSetLinearUnits(jako->myref,SRS_UL_METER,1.0);dOGRCHK(oerr); jako->fromutm = OCTNewCoordinateTransformation(jako->utmref,jako->myref); jako->fromll = OCTNewCoordinateTransformation(jako->llref,jako->myref); jako->fromian = OCTNewCoordinateTransformation(jako->ianref,jako->myref); if (jako->verbose) {err = VHTCaseView_Jako(scase,PETSC_VIEWER_STDOUT_WORLD);dCHK(err);} if (1) { GDALProgressFunc gdalprogress = jako->verbose ? GDALTermProgress : GDALDummyProgress; double x0,y0,Lx,Ly,dx,dy; GDALDatasetH filedata; GDALErr gerr; GDALRasterBandH band; CPLErr cplerr; x0 = scase->bbox[0][0]; y0 = scase->bbox[1][0]; Lx = scase->bbox[0][1] - x0; Ly = scase->bbox[1][1] - y0; // It appears from gdalwarp.cpp that pixels are cell centered dx = Lx / jako->nx; dy = Ly / jako->ny; // Extend the domain in the positive direction for slope evaluation jako->nx += 2; jako->ny += 2; Lx += 2*dx; Ly += 2*dy; // Convert a pixel to a physical coordinate in the current projection jako->mygeo[0] = x0 + dx/2; jako->mygeo[1] = dx; jako->mygeo[2] = 0; jako->mygeo[3] = y0 + Ly - dy/2; // Physical coordinates are "y up", pixels are "y down" jako->mygeo[4] = 0; jako->mygeo[5] = -dy; // Convert a physical coordinate in the current projection to a pixel coordinate gerr = GDALInvGeoTransform(jako->mygeo,jako->myinvgeo);dGDALCHK(gerr); if (jako->verbose) { dInt i,j; double a,b; err = dRealTableView(3,2,&scase->bbox[0][0],PETSC_VIEWER_STDOUT_WORLD,"bbox");dCHK(err); err = dRealTableView(2,3,jako->mygeo,PETSC_VIEWER_STDOUT_WORLD,"mygeo");dCHK(err); GDALApplyGeoTransform(jako->mygeo,0,0,&a,&b); printf("geo[0,0] = %f,%f\n",a,b); GDALApplyGeoTransform(jako->mygeo,1,1,&a,&b); printf("geo[1,1] = %f,%f\n",a,b); GDALApplyGeoTransform(jako->mygeo,0.5,0.5,&a,&b); printf("geo[0.5,0.5] = %f,%f\n",a,b); err = JakoFindPixel(scase,(dReal[]){scase->bbox[0][0],scase->bbox[1][0]},&i,&j);dCHK(err); printf("xmin,ymin: (%d,%d)\n",i,j); err = JakoFindPixel(scase,(dReal[]){scase->bbox[0][1],scase->bbox[1][1]},&i,&j);dCHK(err); printf("xmax,ymax: (%d,%d)\n",i,j); }