Jump to content

JP2 to GeoTIFF


Colin S

Recommended Posts

How does one go about converting JP2 image files with geo metadata to GeoTIFF without altering or losing the embedded metadata? If anyone has any suggestions, please let me know... or even if you know how to import JP2 geotagged imagery directly into X-Plane 10 (WED doesn't read JP2). I know this should be in scenery development, but lots of people who don't do scenery do graphics.

 

Cheers.

Link to comment
Share on other sites

Try GDAL_utilities (GDAL is a geodata library, and has already a few command line tools which can do a lot of magic).

http://www.gdal.org/gdal_utilities.html

There are versions for most common OSes too but its originally from the Linux/Unix world:

http://trac.osgeo.org/gdal/wiki/DownloadingGdalBinaries

 

And then search for "GDAL jp2 geotiff" on google.

Link to comment
Share on other sites

I'm not a command line guy, I can't get my head around that kind of program (since they never seem to work on my Mac, it just runs the program then logs out of Terminal without asking me what I actually wanted to do). I'll look into that one. Thanks so much! 

 

EDIT: I think I may need a long time to learn this stuff. So far reading through the program function descriptions I'm not understanding it in any way. Before I take that time... GDAL does maintain those coordinates then, right?

Edited by Colin S
Link to comment
Share on other sites

Knowing nothing about how to perform anything within Terminal, I attempted to run one of the included sample scripts and it gave me exactly the same thing that every single other script that I've ever tried running has given me.

Last login: Tue Jul  9 XX:XX:XX on ttys000XXXX:~ XXXX$ /Volumes/GDAL\ Complete/GDAL\ python\ samples/gdal_edit.py ; exit;Usage: gdal_edit [--help-general] [-a_srs srs_def] [-a_ullr ulx uly lrx lry]                 [-tr xres yres] [-unsetgt] [-a_nodata value]                  [-mo "META-TAG=VALUE"]*  datasetnameEdit in place various information of an existing GDAL dataset.logout[Process completed]

I can't find any basic (like for absolute morons like me) instructions on how to use Mac command line tools, are you able to give a basic walkthrough (or at least explain how on earth you even open them without just being shut out immediately?) What I need to use (I think) is GDAL Translate, could you give an example of what to type into Terminal (or into CMD on a PC) to make this work? I understand what all the functions within the programs are and what they mean, but actually running the program is a story in itself...

Link to comment
Share on other sites

1. You open a terminal

 

2. You "cd" to where the executable and your files are

 

3. You run the program by typing in it's name.

 

4. You reap the rewards.

 

i.e.

 

1. Open a Terminal

Last login: Wed Jul 10 05:57:32 on ttys001chrisk@MacBookPro:~>

2. Get into the directory where you downloaded and uncompressed your command line utility

chrisk@MacBookPro:~> cd Downloads/chrisk@MacBookPro:~/Downloads>

3. Figure out how to use the program via --help:

chrisk@MacPro:/Volumes/XP/Projects/Burlington Skyway/jp2> geojasper --helpusage: geojasper [options]The following options are supported:    --help                  Print this help information and exit.    --version               Print version information and exit.    --verbose               Enable verbose mode.    --debug-level $lev      Set the debug level to $lev.    --input $file           Read the input image from the file named $file                            instead of standard input.    --input-format $fmt     Specify the format of the input image as $fmt.                            (See below for the list of supported formats.)    --input-option $opt     Provide the option $opt to the decoder.    --output $file          Write the output image to the file named $file                            instead of standard output.    --output-format $fmt    Specify the format of the output image as $fmt.                            (See below for the list of supported formats.)    --output-option $opt    Provide the option $opt to the encoder.    --force-srgb            Force conversion to the sRGB color space.Some of the above option names can be abbreviated as follows:    --input = -f, --input-format = -t, --input-option = -o,    --output = -F, --output-format = -T, --output-option = -OThe following formats are supported:    mif      My Image Format (MIF)    pnm      Portable Graymap/Pixmap (PNM)    bmp      Microsoft Bitmap (BMP)    ras      Sun Rasterfile (RAS)    jp2      JPEG-2000 JP2 File Format Syntax (ISO/IEC 15444-1)    jpc      JPEG-2000 Code Stream Syntax (ISO/IEC 15444-1)    jpg      JPEG (ISO/IEC 10918-1)    pgx      JPEG-2000 VM Format (PGX)    tif      Tagged Image File (TIFF)

4. Run the program giving it the arguments you want to use:

chrisk@MacBookPro:~/Downloads> geojasper --input 17TNH955970_200810_0x3000m_CL_1.jp2 --output myfile.tifGeoJp2 info found...TIFF file encoded!Done!chrisk@MacBookPro:~/Downloads>

You should now have a file called "myfile.tif" sitting in your downloads directory - which is a TIFF encoded Georefrenced Orthophoto of the input file (in this case, it was a USGS JP2 orthophoto named "17TNH955970_200810_0x3000m_CL_1.jp2" - and the TIFF is ready to import into WED.

 

Repeat

 

- CK.

 

P.S. GeoJasper is the program I use for image/GeoReferencing transcoding. It's a universal binary, meaning it works on OSX 10.1 all the way through Leopard/Snow Leopard, to the current 10.8 Mountain Lion. It probably works on 10.9 Mavericks too.

Edited by chris k
  • Upvote 1
Link to comment
Share on other sites

 

 

Knowing nothing about how to perform anything within Terminal

 

 

 

You'll have to fix that if you want to do this regularly.

 

 

The first thing on OSX is to make sure you have the GDAL command line tools available.  You can do this at a mac terminal by typing any of the following:

 

$  which gdalinfo    

$  which gdal_translate 

$  which gdalwarp

 

....and hopfully you'll get back something that looks like this:

 

/opt/local/bin/gdalinfo

/opt/local/bin/gdal_translate

/opt/local/bin/gdalwarp

 

If you get nothing back but only see another command prompt appear, then you don't have the gdal command line tools installed and you should go here:

 

http://www.kyngchaos.com/software/frameworks

 

and download / install the "GDAL 1.10 Complete" package. (maybe 1.9... depends on several factors but start with 1.10)  THEN after you do that, try the "which gdalinfo" command again and see if you get a path back as shown above.  If you do, then you're 70% of the way to where you need to be. Advise you avoid anything that says 'python' or ends in .py

 

Once you have the GDAL command line tools installed, you should not have to 'cd' to their directory to use them as their path will be put in your environement variables by the installer (I don't expect any of this to make sense to you but need to negate Chris's advice to 'cd' above as it probably isn't relevant in your case, being on a mac and using the above installer; however the concept of "cd'ing" around a computer's directory structure from a command line is as fundamental to using the command line as walking is to humans so best to understand it before attempting anything else.

 

You use one of these programs by typing in the name of the program, the parameters you want it to do (usually called "switches") then the name of the input file (along with its path....UNLESS you have cd'd to the directory containg the file)  and a name of the output file (which you pick).   for example to change formats, you would type something like so:

 

> gdal_translate   -of    GTiff    path/to/the/file/somefile.jp2    path/you/want/to/save/to/the_converted_file.tif 

 

the switch, "-of" stands for "output format" and what you are doing is calling gdal_translate...telling it to convert a file and output in the Geotiff format, taking "somefile.jp2" as the input file and spitting out "the_converted_file.tif" as the output file.

 

I cannot stress just how simplified this is and I can think of a dozen things that would cause this not to work right off the bat and the potential pitfalls that can crop up in this type of scenario including whether or not gdal_translate actually supports the jp2 format (which I don't know).  It is not my intention to teach you how to use the gdal tools or even see you to success on this one task but only provide further information because the puzzle is large and each piece helps.  Command line work on geo files can be glorious or laborious.   I've auto-merged, resized and automagically cut up and auto-named 192 super high rez orthophotos in x-plane with nary but 4  gdal command lines (the planets were in alignement that day)....but also spent hours trying to convert a single image because it was lacking some info in its header.  Geo files are like a box of chocolates......you know the rest.

 

And finally....when  you try to use a command line tool and it just "spits you out" or gives you the "help/usage instructions" instead, then 9 times out of 10 (if not 10 out of 10), you have not supplied the right arguments in the right order the program was expecting.  Most every GIS command line tool expects arguments to be typed in a certain format and a certain order (but not always)  and NO typos allowed.  If it expects a number, you can't be providing it a letter, etc.  For really long command line entries, its super common to mess it up a few times and leave out parameters.

 

Suffice to say though, if you can get the GDAL command line tools available to you on your mac, then you'll have quite the toolset for doing just about anything and your next step will be to read all you can on GIS processing.    I recommend the following book if you plan to go deeper into geo-processing for x-plane.  This book has numerous examples for working with all sorts of open-source software, including the GDAL tools (or enough of them for you to research the net on your own thereafter)

 

http://www.barnesandnoble.com/listing/2688978942539?r=1&cm_mmca2=pla&cm_mmc=GooglePLA-_-TextBook_NotInStock_26To75-_-Q000000633-_-2688978942539

 

You will find though that the problem is usually finding the right data in the right format...that can be a needle in a haystack hunt.  Just wait till you download that killer 1.0GB orthophoto only to find that it's in a .sid format ;)...and the gdal tools are useless.....and its off to the mrsiddecode tools.....only to find that the converted sid doesn't have the right projection information and you have no clue what projection it is....oh there will be frustations.

 

TomK

Edited by tkyler
  • Upvote 2
Link to comment
Share on other sites

 This is what you suggested, Chris K:

chrisk@MacBookPro:~/Downloads> geojasper --input 17TNH955970_200810_0x3000m_CL_1.jp2 --output myfile.tifGeoJp2 info found...TIFF file encoded!Done!chrisk@MacBookPro:~/Downloads>

This is what I did: (my terminal opens with my username along with my computer name) geoapps is the name of the folder within my downloads folder that contains all the geojasper files.

Am-I-Invisible:geoapps Colin9$ > geojasper --input 04QDK635300_201002_0x5000m_CL_1.jp2 --output apt8174.tif-bash: --input: command not foundAm-I-Invisible:geoapps ColinStepney$ 

Why?

Link to comment
Share on other sites

Wait a minute, WTF? You typed the ">" character in?!?!!1!!oneone~!!eleven :)

 

Egads - no wonder it didn't work.

 

the ">"  - that's part of my command line prompt on my computer.

 

Notice in my example, how the next prompt after the conversion has been completed looks like "chrisk@MacBookPro:~/Downloads>"   i.e. It's pretty plain to see that the ">" character is part of my prompt - it's not something I typed in... (Just like I dont type in "chrisk@MacBookPro" into my command prompt, as that's the name of my computer and my current username Im using.

 

Ok - the line Line you should type in is:

geojasper --input 04QDK635300_201002_0x5000m_CL_1.jp2 --output apt8174.tif

and not:

> geojasper --input 04QDK635300_201002_0x5000m_CL_1.jp2 --output apt8174.tif

Do not type that leading ">" .. that has nothing to do with running a command line prorgam (in fact, ">" has a special meaning, meaning to send the output to a file & overwrite it..!)

 

Guaranteed you've over-written the geojasper program at this point.

 

- CK.

 

If you get this working - you've taken your first steps into a larger (and much more powerful) world.

Edited by chris k
Link to comment
Share on other sites

I re-extracted the original files. Now, after running them, bam. What the hell am I doing wrong!? I've even re-downloaded the files in case my stupidity destroyed even the zip file. 

Last login: Tue Jul  9 21:24:35 on ttys000Am-I-Invisible:~ ColinS$ cd desktop/geoappsAm-I-Invisible:geoapps ColinS$ geojasper --help-bash: geojasper: command not foundAm-I-Invisible:geoapps ColinStepney$

This is getting aggravating, and I'm sure as hell it isn't putting you in a good mood either. Don't worry, I leave for 4 days tomorrow morning, you get 4 days of peace.

 

EDIT: I noticed a difference. As you mentioned in your post regarding the forsaken > symbol, your command line was was terminated by (...)Downloads> while mine is terminated by (...)ColinS$ and not the directory within which I'm trying to screw around. What's happening there?

Edited by Colin S
Link to comment
Share on other sites

By jove, holy shiznitz, I did it. Thanks a million... 

 

My lord that was way harder for you to teach me than it should have been. Now I get it. And I'm out of your hair. Sing hallelujah. 

 

Thanks... yet again. :)

 

I'm going to find myself a nice bash shell for dummies pdf to drop onto my ereader for the trip.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...