[gdal-dev] Copy meta data from one JP2 to another JP2 C++
Dr. Joshua Jackson
josh at nside.io
Wed Apr 22 09:05:57 PDT 2015
So I changed my C++ code to follow the basic path of gdalcopyproj.py instead of copying the complete data set (see code below), and I am getting a separate .aux.xml file generated instead of the data being merged to the JP2 image file.
Someone mentioned testing against GDAL 2.0, but as I have 1.11.2 which according to the GDAL web page is the latest release.
const char *srcProjection = srcDataset->GetProjectionRef();
double *srcTransform;
srcDataset->GetGeoTransform(srcTransform);
int gcpcount = srcDataset->GetGCPCount();
const GDAL_GCP *gcps = srcDataset->GetGCPs();
const char* gcpProj = srcDataset->GetGCPProjection();
dstDataset = (GDALDataset *) GDALOpen(maskPath, GA_Update);
dstDataset->SetGeoTransform(srcTransform);
dstDataset->SetProjection(srcProjection);
if (gcpcount > 0) {
dstDataset->SetGCPs( gcpcount, gcps, gcpProj);
}
if(dstDataset != NULL)
{
GDALClose((GDALDatasetH)dstDataset);
}
Joshua Jackson, PhD
Senior ResearchEngineer
(800) 604-1822 Ext. 5109 <tel:8006041822,5109> (256) 648-5109 <tel:2566485109>
josh at nside.io <mailto:josh at nside.io> www.nSide.io
<http://www.nside.io/> 4031 Parkway Dr, Suite B, Florence, AL 35630
<http://www.linkedin.com/company/nside/> <http://twitter.com/nSide__Out>
> On Apr 15, 2015, at 4:06 PM, Dr. Joshua Jackson <josh at nside.io> wrote:
>
> Yes. For example original file is middle.jp2 New file is middle_mask.jp2.
>
> gdalcopyproj.py middle.jp2 middle_mask.jp2
>
> Result is middle_mask.jp2 isn’t even modified according to OS time stamp, but new file is created middle_mask.jp2.aux.xml.
>
>
>
>
> Joshua Jackson, PhD
> Senior ResearchEngineer
> (800) 604-1822 Ext. 5109 <tel:8006041822,5109> (256) 648-5109 <tel:2566485109>
> josh at nside.io <mailto:josh at nside.io> www.nSide.io <http://www.nside.io/>
> <http://www.nside.io/> 4031 Parkway Dr, Suite B, Florence, AL 35630
> <http://www.linkedin.com/company/nside/> <http://twitter.com/nSide__Out>
>> On Apr 15, 2015, at 4:02 PM, Even Rouault <even.rouault at spatialys.com <mailto:even.rouault at spatialys.com>> wrote:
>>
>> Le mercredi 15 avril 2015 22:58:07, Dr. Joshua Jackson a écrit :
>>> gdalcopyproj does not work for me because it outputs a separate xml file
>>> instead of overlaying the data into the new image file.
>>
>> Weird. I've just tested it works properly with the latest GDAL trunk (2.0dev).
>>
>>>
>>>
>>> Joshua Jackson, PhD
>>> Senior ResearchEngineer
>>> (800) 604-1822 Ext. 5109 <tel:8006041822,5109> (256) 648-5109
>>> <tel:2566485109> josh at nside.io <mailto:josh at nside.io> <mailto:josh at nside.io <mailto:josh at nside.io>> www.nSide.io <http://www.nside.io/>
>>> <http://www.nside.io/ <http://www.nside.io/>> 4031 Parkway Dr, Suite B, Florence, AL 35630
>>> <http://www.linkedin.com/company/nside/ <http://www.linkedin.com/company/nside/>> <http://twitter.com/nSide__Out <http://twitter.com/nSide__Out>>
>>>
>>>> On Apr 15, 2015, at 3:06 PM, Even Rouault <even.rouault at spatialys.com <mailto:even.rouault at spatialys.com>>
>>>> wrote:
>>>>
>>>> Le mercredi 15 avril 2015 21:46:26, Dr. Joshua Jackson a écrit :
>>>>> I’m looking for a good solution to copy the image meta data from one JP2
>>>>> to another JP2 in C++. I have a folder full of 4096x4096 JPEG2000
>>>>> images that I am processing with OpenCV. On some of them I create a
>>>>> copy of the image and do some manipulations to. As expected the new
>>>>> image file is missing all the metadata.
>>>>>
>>>>> I have tried using CreateCopy() with the OpenJPEG library; and while
>>>>> this does work it takes a really long time per image ~40sec. (My image
>>>>> manipulations take only ~10sec).
>>>>>
>>>>> Is there some way to use the GetGDALDataSet() on the source file and
>>>>> then call SetMetaData() on the destination file for each meta data
>>>>> item? How would one iterate through the metadata items?
>>>>
>>>> The "metadata" you're talking about are more the georeferencing info,
>>>> right ? (In GDAL "metadata" is about all other metadata, excluding the
>>>> georeferencing)
>>>>
>>>> If you use trunk, you could likely try the new USE_SRC_CODESTREAM=YES
>>>> creation open of the jp2openjpeg driver
>>>>
>>>> Something like:
>>>>
>>>> gdal_translate your_jp2_without_georef.jp2 out.jp2 -co
>>>> USE_SRC_CODESTREAM=YES -a_srs EPSG:4326 -a_ullr -96.9653320 32.4645996
>>>> -96.9598389 32.4591064
>>>>
>>>> The SetGeoTransform() and SetProjection() API also do something similar
>>>> internally, so you could also do :
>>>>
>>>> gdal_edit.py your_jp2_without_georef.jp2 -a_srs EPSG:4326 -a_ullr
>>>> -96.9653320 32.4645996 -96.9598389 32.4591064
>>>>
>>>> or more conveniently:
>>>>
>>>> gdalcopyproj.py middle_mask.jp2 out.jp2
>>>>
>>>> (http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/gdalcopyproj.py <http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/gdalcopyproj.py>
>>>> <http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/gdalcopyproj.p <http://svn.osgeo.org/gdal/trunk/gdal/swig/python/samples/gdalcopyproj.p>
>>>> y>)
>>>>
>>>> Even
>>>>
>>>>> Here is a sample GDALInfo printout for a source image:
>>>>>
>>>>> Driver: JP2OpenJPEG/JPEG-2000 driver based on OpenJPEG library
>>>>> Files: middle_mask.jp2
>>>>> Size is 4096, 4096
>>>>> Coordinate System is:
>>>>> GEOGCS["WGS 84",
>>>>>
>>>>> DATUM["WGS_1984",
>>>>>
>>>>> SPHEROID["WGS 84",6378137,298.257223563,
>>>>>
>>>>> AUTHORITY["EPSG","7030"]],
>>>>>
>>>>> AUTHORITY["EPSG","6326"]],
>>>>>
>>>>> PRIMEM["Greenwich",0],
>>>>> UNIT["degree",0.0174532925199433],
>>>>> AUTHORITY["EPSG","4326"]]
>>>>>
>>>>> Origin = (-96.965332031250000,32.464599609375000)
>>>>> Pixel Size = (0.000001341104507,-0.000001341104507)
>>>>>
>>>>> Image Structure Metadata:
>>>>> INTERLEAVE=PIXEL
>>>>>
>>>>> Corner Coordinates:
>>>>> Upper Left ( -96.9653320, 32.4645996) ( 96d57'55.20"W, 32d27'52.56"N)
>>>>> Lower Left ( -96.9653320, 32.4591064) ( 96d57'55.20"W, 32d27'32.78"N)
>>>>> Upper Right ( -96.9598389, 32.4645996) ( 96d57'35.42"W, 32d27'52.56"N)
>>>>> Lower Right ( -96.9598389, 32.4591064) ( 96d57'35.42"W, 32d27'32.78"N)
>>>>> Center ( -96.9625854, 32.4618530) ( 96d57'45.31"W, 32d27'42.67"N)
>>>>> Band 1 Block=1024x1024 Type=Byte, ColorInterp=Red
>>>>>
>>>>> Overviews: 2048x2048, 1024x1024, 512x512, 256x256
>>>>> Overviews: arbitrary
>>>>>
>>>>> Band 2 Block=1024x1024 Type=Byte, ColorInterp=Green
>>>>>
>>>>> Overviews: 2048x2048, 1024x1024, 512x512, 256x256
>>>>> Overviews: arbitrary
>>>>>
>>>>> Band 3 Block=1024x1024 Type=Byte, ColorInterp=Blue
>>>>>
>>>>> Overviews: 2048x2048, 1024x1024, 512x512, 256x256
>>>>> Overviews: arbitrary
>>>>>
>>>>> Joshua Jackson, PhD
>>>>> Senior ResearchEngineer
>>>>> (800) 604-1822 Ext. 5109 <tel:8006041822,5109> (256) 648-5109
>>>>> <tel:2566485109> josh at nside.io <mailto:josh at nside.io> <mailto:josh at nside.io <mailto:josh at nside.io>>
>>>>> <mailto:josh at nside.io <mailto:josh at nside.io> <mailto:josh at nside.io <mailto:josh at nside.io>>> www.nSide.io <http://www.nside.io/>
>>>>> <http://www.nside.io/ <http://www.nside.io/>> <http://www.nside.io/ <http://www.nside.io/> <http://www.nside.io/ <http://www.nside.io/>>>
>>>>> 4031 Parkway Dr, Suite B, Florence, AL 35630
>>>>>
>>>>> <http://www.linkedin.com/company/nside/ <http://www.linkedin.com/company/nside/>
>>>>> <http://www.linkedin.com/company/nside/ <http://www.linkedin.com/company/nside/>>>
>>>>> <http://twitter.com/nSide__Out <http://twitter.com/nSide__Out> <http://twitter.com/nSide__Out <http://twitter.com/nSide__Out>>>
>>
>> --
>> Spatialys - Geospatial professional services
>> http://www.spatialys.com <http://www.spatialys.com/>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20150422/773dae60/attachment-0001.html>
More information about the gdal-dev
mailing list