5

How to pull crs information from a world file when reading an image using python GDAL or Rasterio? The images I am reading to not have in built metadata, it is stored in the projection file (.prj) and world files (.tfw or .jpw for tiff and jpg files, respectively). When I read these images using python GDAL or Rasterio, it ignores these metadata files and therefore does not read any coordinate metadata.

How would I go about reading these files?

Edit 1. Code example: Using python 2 (Anaconda distribution). I want to read an image file and get it's bound box.

image1.prj
image1.jgw
image1.jpg
import rasterio
img = rasterio.open('image1.jpg')
bounds = img.bounds
crs = img.crs
transform = img.transform

When the code is run, the following warning appears:

C:\Anaconda2\lib\site-packages\rasterio\__init__.py:193: UserWarning: Dataset has no geotransform set. Default transform will be applied (Affine.identity())
tinlyx
11.3k18 gold badges78 silver badges130 bronze badges
asked May 15, 2018 at 1:02
6
  • 1
    How are you reading these? In python, C#, VB.net, C++ or ANSI C? Do you have some code to work from? if so, please post a snippet of what you have. Please clarify if you're after the projection information or cell to world transformation, it's not really clear in your question. Commented May 15, 2018 at 1:06
  • 1
    Welcome to GIS SE. As a new user, please take the Tour, which explains how our "Focused question / Best answer" model operates. We require coding questions to contain code. Please Edit your question to provide more details. Commented May 15, 2018 at 1:12
  • 1
    What is the content of image1.jgw? You ask also about GDAL, is this API any better? img = gdal.Open("Image1.jpg", gdal.GA_ReadOnly) gt = img.GetGeoTransform() gt should be a tuple or list of 6 floating point numbers. Commented May 15, 2018 at 1:48
  • Hi Michael, image1.jgw is a 3-band, 8-bit image. Using the GDAL API, the tuple returned from img.GetGeoTransform() is (0.0, 1.0, 0.0, 60.0, 0.0, -1.0), so I think I have the same problem using GDAL. Commented May 15, 2018 at 1:53
  • 1
    is that what's in the world file (jgw)? Open with Notepad (or other text editor) it should be only 6 lines with one real (float) number on each. If the world file matches what you're getting with GetGeoTransform() your problem isn't API it's data, track the image back to its source and try to obtain the correct geolocation information. Commented May 15, 2018 at 2:04

1 Answer 1

3

The world file (.jpw) did not have valid data. Therefore I was trying to read coordinate metadata that was not there in the first place. After re-exporting the images with valid world files, I had no problem reading them using Rasterio or GDAL python bindings. I guess you could say user error strikes again.

answered May 15, 2018 at 2:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.