0

I'm using Ubuntu 20.04. My goal is to add georeferencing to an image. I have a simple script below. It's confusing because I have gdal installed, but I can't call it by itself. I need to use "from osgeo". When I try to install "osgeo", it fails with quite a long bit of red text. The first part is here. I have to use pip to install b/c I can't get conda install to work with it. Any help you can provide would be much appreciated. I've spent the good part of a day trying to simply add georeferencing, but I'm getting nowhere.

Collecting osgeo Using cached osgeo-0.0.1.tar.gz (1.2 kB) Preparing metadata (setup.py) ... done Building wheels for collected packages: osgeo Building wheel for osgeo (setup.py) ... error ERROR: Command errored out with exit status 1:

from osgeo import gdal, osr

orig_fn = '../images/_qpf_k_means.png'
output_fn = '../images/output.tif'

# Create a copy of the original file and save it as the output filename:
shutil.copy(orig_fn, output_fn)
# Open the output file for writing for writing:
ds = gdal.Open(output_fn, gdal.GA_Update)
# Set spatial reference:
sr = osr.SpatialReference()
sr.ImportFromEPSG(4326) #2193 refers to the NZTM2000, but can use any desired projection

# Enter the GCPs
#   Format: [map x-coordinate(longitude)], [map y-coordinate (latitude)], [elevation],
#   [image column index(x)], [image row index (y)]
gcps = [gdal.GCP(44, -125, 0, 7, 7),
gdal.GCP(40.8, -119.2, 0, 603, 335)]

# Apply the GCPs to the open output file:
ds.SetGCPs(gcps, sr.ExportToWkt())

# Close the output file in order to be able to work with it in other programs:
ds = None```
user1475191
  • 121
  • 1
  • 1
  • 5
  • 1
    `from osgeo import gdal` is by design for gdal version 3 and onwards. See docs, https://pypi.org/project/GDAL/ . If you are using `conda`, just install gdal and you should be good to go. Hopefully the environment will work independently of this broken install. – Robert Davy Feb 01 '22 at 23:34
  • Worked perfectly. I just created a new env and installed gdal via conda. Thank you! – user1475191 Feb 02 '22 at 03:53

0 Answers0