void OgrFileImport::importFeature(MapPart* map_part, OGRFeatureDefnH feature_definition, OGRFeatureH feature, OGRGeometryH geometry) { to_map_coord = &OgrFileImport::fromProjected; auto new_srs = OGR_G_GetSpatialReference(geometry); if (new_srs && data_srs != new_srs) { // New SRS, indeed. auto transformation = ogr::unique_transformation{ OCTNewCoordinateTransformation(new_srs, map_srs.get()) }; if (!transformation) { ++no_transformation; return; } // Commit change to data srs and coordinate transformation data_srs = new_srs; data_transform = std::move(transformation); } if (new_srs) { auto error = OGR_G_Transform(geometry, data_transform.get()); if (error) { ++failed_transformation; return; } } else if (!drawing_from_projected) { to_map_coord = &OgrFileImport::fromDrawing; } auto object = importGeometry(map_part, feature, geometry); if (object && feature_definition) { auto num_fields = OGR_FD_GetFieldCount(feature_definition); for (int i = 0; i < num_fields; ++i) { auto value = OGR_F_GetFieldAsString(feature, i); if (value && qstrlen(value) > 0) { auto field_definition = OGR_FD_GetFieldDefn(feature_definition, i); object->setTag(OGR_Fld_GetNameRef(field_definition), value); } } } }
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); }