Commit 0472472b authored by Julien Osman's avatar Julien Osman
Browse files

BUG: Allow to read Radarsat2 gcp

parent 4420544c
Pipeline #7716 failed with stages
in 82 minutes and 17 seconds
......@@ -2,11 +2,12 @@ SensorID SAR
Mission RADARSAT-2
Instrument RADARSAT-2
ProductType SLC
Polarization HH
OrbitDirection Descending
BeamMode FQ9
TileHintX 2822
TileHintY 185
DataType 11
DataType 4
NumberOfLines 12953
NumberOfColumns 2822
AverageSceneHeight 453.201
......@@ -18,17 +19,10 @@ LineSpacing 4.8254
PixelSpacing 4.73308
ProductionDate 2008-04-05T13:35:50Z
AcquisitionStartTime 2008-04-05T12:49:00.995676Z
SAR <SARParam>
SARCalib <SARCalib>
GCP <GCPParam>
Extra.FACILITY_IDENTIFIER GATN
Polarization HH
SAR <SARParam>
Polarization VV
SAR <SARParam>
Polarization HV
SAR <SARParam>
Polarization VH
SAR <SARParam>
{"Projection": "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"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]",
[{"GCP_Id": "1", "GCP_Info": "", "GCP_Row": "0.5", "GCP_Col": "0.5", "GCP_X": "-97.5857", "GCP_Y": "49.4039", "GCP_Z": "453.201", },
{"GCP_Id": "2", "GCP_Info": "", "GCP_Row": "0.5", "GCP_Col": "217.5", "GCP_X": "-97.5577", "GCP_Y": "49.4002", "GCP_Z": "453.201", },
......
......@@ -26,6 +26,7 @@
#include "otbMacro.h"
#include "itkMetaDataObject.h"
#include "otbImageKeywordlist.h"
#include "otbSpatialReference.h"
// useful constants
#include <otbMath.h>
......@@ -256,6 +257,50 @@ Radarsat2ImageMetadataInterface::UIntVectorType Radarsat2ImageMetadataInterface:
return rgb;
}
void ReadGeorefGCP(const XMLMetadataSupplier & xmlMS, ImageMetadata & imd)
{
Projection::GCPParam gcp;
std::stringstream ss;
// Get the ellipsoid and semi-major, semi-minor axes
if(xmlMS.HasValue("product.imageAttributes.geographicInformation.referenceEllipsoidParameters.ellipsoidName"))
{
auto ellipsoidID = xmlMS.GetAs<std::string>("product.imageAttributes.geographicInformation.referenceEllipsoidParameters.ellipsoidName");
auto minor_axis = xmlMS.GetAs<double>(0, "product.imageAttributes.geographicInformation.referenceEllipsoidParameters.semiMinorAxis");
auto major_axis = xmlMS.GetAs<double>(0, "product.imageAttributes.geographicInformation.referenceEllipsoidParameters.semiMajorAxis");
if(ellipsoidID.empty() || minor_axis == 0 || major_axis == 0)
{
otbGenericExceptionMacro(MissingMetadataException, << "Cannot read GCP's spatial reference");
}
else if(ellipsoidID == "WGS84")
{
gcp.GCPProjection = SpatialReference::FromWGS84().ToWkt();
}
else
{
gcp.GCPProjection = SpatialReference::FromGeogCS("", "", ellipsoidID, major_axis,
major_axis/(major_axis - minor_axis)).ToWkt();
}
}
auto GCPCount = xmlMS.GetNumberOf("product.imageAttributes.geographicInformation.geolocationGrid.imageTiePoint");
for(unsigned int i = 1 ; i <= GCPCount ; ++i)
{
ss.str("");
ss << "product.imageAttributes.geographicInformation.geolocationGrid.imageTiePoint_" << i << ".";
const std::string id = std::to_string(i);
gcp.GCPs.emplace_back(id, // id
"", // info
xmlMS.GetAs<double>(ss.str() + "imageCoordinate.pixel") + 0.5, // col
xmlMS.GetAs<double>(ss.str() + "imageCoordinate.line") + 0.5, // row
xmlMS.GetAs<double>(ss.str() + "geodeticCoordinate.longitude"), // px
xmlMS.GetAs<double>(ss.str() + "geodeticCoordinate.latitude"), // py
xmlMS.GetAs<double>(ss.str() + "geodeticCoordinate.height")); // pz
}
imd.Add(MDGeom::GCP, gcp);
}
void Radarsat2ImageMetadataInterface::ParseGdal(ImageMetadata & imd)
{
// Product file
......@@ -293,6 +338,8 @@ void Radarsat2ImageMetadataInterface::ParseGdal(ImageMetadata & imd)
imd.Add(MDNum::CenterIncidenceAngle, this->GetCenterIncidenceAngle(ProductMS));
SARParam sarParam;
// Fetch the GCP
ReadGeorefGCP(ProductMS, imd);
imd.Add(MDGeom::SAR, sarParam);
SARCalib sarCalib;
......@@ -333,6 +380,8 @@ void Radarsat2ImageMetadataInterface::ParseGeom(ImageMetadata & imd)
imd.Add("FACILITY_IDENTIFIER", ProductMS.GetAs<std::string>("product.sourceAttributes.inputDatasetFacilityId"));
imd.Add(MDStr::OrbitDirection, ProductMS.GetAs<std::string>("product.sourceAttributes.orbitAndAttitude.orbitInformation.passDirection"));
imd.Add(MDStr::ProductType, ProductMS.GetAs<std::string>("product.imageGenerationParameters.generalProcessingInformation.productType"));
ReadGeorefGCP(ProductMS, imd);
}
}
......@@ -360,7 +409,8 @@ void Radarsat2ImageMetadataInterface::Parse(ImageMetadata & imd)
if (m_MetadataSupplierInterface->GetAs<std::string>("", "sensor") == "RADARSAT-2")
this->ParseGeom(imd);
// Try to fetch the metadata from GDAL Metadata Supplier
this->ParseGdal(imd);
else
this->ParseGdal(imd);
}
} // end namespace otb
......@@ -452,7 +452,7 @@ set(formosat_filename LARGEINPUT{FORMOSAT/Sudouest_20071013_MS_fmsat/IMAGERY.TIF
set(ikonos_filename LARGEINPUT{IKONOS/BLOSSEVILLE/po_2619900_blu_0000000.tif})
set(worldview2_filename LARGEINPUT{WORLDVIEW2/ROME/WV-2_standard_8band_bundle_16bit/052298844010_01_P001_MUL/09DEC10103019-M2AS-052298844010_01_P001.TIF})
set(quickbird_filename LARGEINPUT{QUICKBIRD/CEVENNES/06FEB12104912-P1BS-005533998070_01_P001.TIF})
set(Radarsat2_filename LARGEINPUT{RADARSAT2/ALTONA/Fine_Quad-Pol_Dataset/PK6621_DK406_FQ9_20080405_124900_HH_VV_HV_VH_SLC_Altona})
set(Radarsat2_filename LARGEINPUT{RADARSAT2/ALTONA/Fine_Quad-Pol_Dataset/PK6621_DK406_FQ9_20080405_124900_HH_VV_HV_VH_SLC_Altona/imagery_HH.tif})
set(TerraSar_filename LARGEINPUT{TERRASARX/2008-03-10_GrandCanyon_SSC/TSX1_SAR__SSC______SM_S_SRA_20080310T133220_20080310T133228/IMAGEDATA/IMAGE_HH_SRA_strip_011.cos})
set(CosmoSkyMed_filename LARGEINPUT{COSMOSKYMED/Toulouse_spotlight/CSKS3_SCS_B_S2_08_HH_RD_SF_20110418180325_20110418180332.h5})
set(Sentinel1_filename LARGEINPUT{SENTINEL1/S1A_S6_SLC__1SSV_20150619T195043/measurement/s1a-s6-slc-vv-20150619t195043-20150619t195101-006447-00887d-001.tiff})
......
......@@ -35,8 +35,8 @@
int otbImageMetadataInterfaceTest(int itkNotUsed(argc), char* argv[])
{
// Verify the number of parameters in the command line
const char* inputFilename = argv[1];
const char* outputFilename = argv[2];
std::string inputFilename = argv[1];
std::string outputFilename = argv[2];
typedef otb::Image<double, 2> InputImageType;
typedef otb::ImageFileReader<InputImageType> ImageReaderType;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment