void object::test<2>() { ensure("SRS UTM handle is NULL", NULL != srs_utm_); ensure("SRS LL handle is NULL", NULL != srs_ll_); err_ = OSRSetUTM(srs_utm_, 11, TRUE); ensure_equals("Can't set UTM zone", err_, OGRERR_NONE); err_ = OSRSetWellKnownGeogCS(srs_utm_, "WGS84"); ensure_equals("Can't set GeogCS", err_, OGRERR_NONE); err_ = OSRSetWellKnownGeogCS(srs_ll_, "WGS84"); ensure_equals("Can't set GeogCS", err_, OGRERR_NONE); ct_ = OCTNewCoordinateTransformation(srs_ll_, srs_utm_); ensure("PROJ.4 missing, transforms not available", NULL != ct_); const int size = 1; double x[size] = { -117.5 }; double y[size] = { 32.0 }; double z[size] = { 0.0 }; ensure_equals("OCTTransform() failed", OCTTransform(ct_, size, x, y, z), TRUE); ensure("Wrong X from LL to UTM result", std::fabs(x[0] - 452772.06) <= 0.01); ensure("Wrong Y from LL to UTM result", std::fabs(y[0] - 3540544.89) <= 0.01); ensure("Wrong Z from LL to UTM result", std::fabs(z[0] - 0.0) <= 0.01); }
void object::test<1>() { ensure("SRS UTM handle is NULL", NULL != srs_utm_); ensure("SRS LL handle is NULL", NULL != srs_ll_); err_ = OSRSetUTM(srs_utm_, 11, TRUE); ensure_equals("Can't set UTM zone", err_, OGRERR_NONE); err_ = OSRSetWellKnownGeogCS(srs_utm_, "WGS84"); ensure_equals("Can't set GeogCS", err_, OGRERR_NONE); err_ = OSRSetWellKnownGeogCS(srs_ll_, "WGS84"); ensure_equals("Can't set GeogCS", err_, OGRERR_NONE); ct_ = OCTNewCoordinateTransformation(srs_ll_, srs_utm_); ensure("PROJ.4 missing, transforms not available", NULL != ct_); }
void object::test<3>() { ensure("SRS UTM handle is NULL", NULL != srs_utm_); ensure("SRS LL handle is NULL", NULL != srs_ll_); err_ = OSRSetUTM(srs_utm_, 11, TRUE); ensure_equals("Can't set UTM zone", err_, OGRERR_NONE); err_ = OSRSetWellKnownGeogCS(srs_utm_, "WGS84"); ensure_equals("Can't set GeogCS", err_, OGRERR_NONE); err_ = OSRSetWellKnownGeogCS(srs_ll_, "WGS84"); ensure_equals("Can't set GeogCS", err_, OGRERR_NONE); ct_ = OCTNewCoordinateTransformation(srs_ll_, srs_utm_); ensure("PROJ.4 missing, transforms not available", NULL != ct_); const char* wkt = "POINT(-117.5 32.0)"; OGRGeometryH geom = NULL; err_ = OGR_G_CreateFromWkt((char**) &wkt, NULL, &geom); ensure_equals("Can't import geometry from WKT", OGRERR_NONE, err_); ensure("Can't create geometry", NULL != geom); err_ = OGR_G_Transform(geom, ct_); ensure_equals("OGR_G_Transform() failed", err_, OGRERR_NONE); OGRSpatialReferenceH srs = NULL; srs = OGR_G_GetSpatialReference(geom); char* wktSrs = NULL; err_ = OSRExportToPrettyWkt(srs, &wktSrs, FALSE); ensure("Exported SRS to WKT is NULL", NULL != wktSrs); std::string pretty(wktSrs); ensure_equals("SRS output is incorrect", pretty.substr(0, 6), std::string("PROJCS")); OGRFree(wktSrs); OGR_G_DestroyGeometry(geom); }
void object::test<1>() { ensure("SRS handle is NULL", NULL != srs_); err_ = OSRSetUTM(srs_, 11, TRUE); ensure_equals("Can't set UTM zone", err_, OGRERR_NONE); err_ = OSRSetWellKnownGeogCS(srs_, "WGS84"); ensure_equals("Can't set GeogCS", err_, OGRERR_NONE); double val = 0; val = OSRGetProjParm(srs_, SRS_PP_CENTRAL_MERIDIAN, -1111, &err_); ensure("Invalid UTM central meridian", std::fabs(val - (-117.0)) <= .00000000000010); val = OSRGetProjParm(srs_, SRS_PP_LATITUDE_OF_ORIGIN, -1111, &err_); ensure("Invalid UTM latitude of origin", std::fabs(val - 0.0) <= .00000000000010); val = OSRGetProjParm(srs_, SRS_PP_SCALE_FACTOR, -1111, &err_); ensure("Invalid UTM scale factor", std::fabs(val - 0.9996) <= .00000000000010); val = OSRGetProjParm(srs_, SRS_PP_FALSE_EASTING, -1111, &err_); ensure("Invalid UTM false easting", std::fabs(val - 500000.0) <= .00000000000010); val = OSRGetProjParm(srs_, SRS_PP_FALSE_NORTHING, -1111, &err_); ensure("Invalid UTM false northing", std::fabs(val - 0.0) <= .00000000000010); ensure_equals("Invalid authority name", std::string(OSRGetAuthorityName(srs_, "GEOGCS")), std::string("EPSG")); ensure_equals("Invalid authority code", std::string(OSRGetAuthorityCode(srs_, "GEOGCS")), std::string("4326")); ensure_equals("Invalid authority name", std::string(OSRGetAuthorityName(srs_, "DATUM")), std::string("EPSG")); ensure_equals("Invalid authority code", std::string(OSRGetAuthorityCode(srs_, "DATUM")), std::string("6326")); }
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); }
OgrFileImport::OgrFileImport(QIODevice* stream, Map* map, MapView* view, bool drawing_from_projected) : Importer(stream, map, view) , map_srs{ OSRNewSpatialReference(nullptr) } , manager{ OGR_SM_Create(nullptr) } , drawing_from_projected{ drawing_from_projected } { GdalManager().configure(); setOption(QLatin1String{ "Separate layers" }, QVariant{ false }); auto spec = QByteArray::fromRawData("WGS84", 6); auto error = OSRSetWellKnownGeogCS(map_srs.get(), spec); if (!map->getGeoreferencing().isLocal() && !error) { spec = map->getGeoreferencing().getProjectedCRSSpec().toLatin1(); error = OSRImportFromProj4(map_srs.get(), spec); } if (error) { addWarning(tr("Unable to setup \"%1\" SRS for GDAL: %2") .arg(QString::fromLatin1(spec), QString::number(error))); } // Reasonable default? // OGR feature style defaults default_pen_color = new MapColor("Black", 0); default_pen_color->setRgb({0.0, 0.0, 0.0}); default_pen_color->setCmykFromRgb(); map->addColor(default_pen_color, 0); auto default_brush_color = new MapColor("Black 50%", 0); default_brush_color->setRgb({0.5, 0.5, 0.5}); default_brush_color->setCmykFromRgb(); map->addColor(default_brush_color, 1); default_point_symbol = new PointSymbol(); default_point_symbol->setName(tr("Point")); default_point_symbol->setNumberComponent(0, 1); default_point_symbol->setInnerColor(default_pen_color); map->addSymbol(default_point_symbol, 0); default_line_symbol = new LineSymbol(); default_line_symbol->setName(tr("Line")); default_line_symbol->setNumberComponent(0, 2); default_line_symbol->setColor(default_pen_color); default_line_symbol->setLineWidth(0.1); // (0.1 mm, nearly cosmetic) default_line_symbol->setCapStyle(LineSymbol::FlatCap); default_line_symbol->setJoinStyle(LineSymbol::MiterJoin); map->addSymbol(default_line_symbol, 1); default_area_symbol = new AreaSymbol(); default_area_symbol->setName(tr("Area")); default_area_symbol->setNumberComponent(0, 3); default_area_symbol->setColor(default_brush_color); map->addSymbol(default_area_symbol, 2); default_text_symbol = new TextSymbol(); default_text_symbol->setName(tr("Text")); default_text_symbol->setNumberComponent(0, 4); default_text_symbol->setColor(default_pen_color); map->addSymbol(default_text_symbol, 3); }