.Tif to .GeoTiff Scaling issue using GDAL Planned maintenance scheduled April 17/18, 2019 at...
Use BFD on a Virtual-Template Interface
How to run gsettings for another user Ubuntu 18.04.2 LTS
Check which numbers satisfy the condition [A*B*C = A! + B! + C!]
What does an IRS interview request entail when called in to verify expenses for a sole proprietor small business?
Single word antonym of "flightless"
Apollo command module space walk?
Denied boarding although I have proper visa and documentation. To whom should I make a complaint?
What does the word "veer" mean here?
Can a non-EU citizen traveling with me come with me through the EU passport line?
How would the world control an invulnerable immortal mass murderer?
List *all* the tuples!
Can an alien society believe that their star system is the universe?
What is the meaning of the new sigil in Game of Thrones Season 8 intro?
How to align text above triangle figure
What does the "x" in "x86" represent?
Why do we bend a book to keep it straight?
What's inside the kernel part of virtual memory of 64 bit linux processes?
String `!23` is replaced with `docker` in command line
Is pollution the main cause of Notre Dame Cathedral's deterioration?
Book where humans were engineered with genes from animal species to survive hostile planets
How to react to hostile behavior from a senior developer?
Can a USB port passively 'listen only'?
Why did the IBM 650 use bi-quinary?
How to call a function with default parameter through a pointer to function that is the return of another function?
.Tif to .GeoTiff Scaling issue using GDAL
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Tilecache positions my gdal_translated map 20km south of where I want itGet the geotransform in Mercator given a pixel size away from the originVSIMalloc3() and UnifiedSrcDensity mask errors when running gdal_warp in OSGEO4w shellHow to duplicate this QGIS workflow with gdal/GRASS? (reproject and crop a raster)?Geotransformation for polar stereographic?Using GDAL to ID a pair of GeoTiff CoordinatesWriting QGIS Plugin or function to find/pan/zoom to coordinate generated from number that has geolocation basis for its creation?extent parameter pyqgis gdal processing rasterizeTranslating and warping tif using python bindings of GDAL?Inaccurate alignment of MODIS HDF image (Dark Target product MYD04)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I was trying to georeference a .tif file generated from a matplotlib output using GDAL's python bindings and it seems to be off-scale. My objective was to create a geotiff file from the output of a contourf function. Code samples are pasted below.
fig = plt.figure()
plt.axis('off')
plt.contour(land_reference,levels=[-9999],origin='upper', cmap='gray',extent=(77.53,81.05,28.65,31.49))
plt.contourf(Z, levels=levels,origin='upper', cmap='RdYlGn',extent=(77.53,81.05,28.65,31.49))
fig.canvas.draw()
plt.savefig(r'C:UsersMRG16-10417DesktopNewtestspecies.tif',transparent='true',bbox_inches='tight')
Then I use GDAL as follows,
from osgeo import gdal, osr
import numpy as np
src_filename ='C:/Users/MRG16-10417/Desktop/New/testspecies.tif'
dst_filename = 'C:/Users/MRG16-10417/Desktop/New/newspecies.tif'
#The row and column values of the tif file was used here
nrows=252
ncols=386
src_ds = gdal.Open(src_filename)
format = "GTiff"
driver = gdal.GetDriverByName(format)
xmin = 77.5000000002060005
xmax = 81.0833333335421997
ymin = 28.6666666666176049
ymax = 31.4999999999532037
# Open destination dataset
dst_ds = driver.CreateCopy(dst_filename, src_ds, 0)
xres = (xmax-xmin)/float(ncols)
yres = (ymax-ymin)/float(nrows)
geotransform=(xmin,xres,0,ymax,0, -yres)
# Set location
dst_ds.SetGeoTransform(geotransform)
# Get raster projection
epsg = 4326
srs = osr.SpatialReference()
srs.ImportFromEPSG(epsg)
dest_wkt = srs.ExportToWkt()
# Set projection
dst_ds.SetProjection(dest_wkt)
# Close files
dst_ds = None
src_ds = None
The resultant image on QGIS,
As you can see the image is slightly off scale and isn't exactly overlapping on the reference .shp file of the same geographic extents and projection.
What could be the reason for this?
Is it because the source image that is incorrect, as matplotlib could be scaling down the image?
pyqgis gdal georeferencing
bumped to the homepage by Community♦ 4 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I was trying to georeference a .tif file generated from a matplotlib output using GDAL's python bindings and it seems to be off-scale. My objective was to create a geotiff file from the output of a contourf function. Code samples are pasted below.
fig = plt.figure()
plt.axis('off')
plt.contour(land_reference,levels=[-9999],origin='upper', cmap='gray',extent=(77.53,81.05,28.65,31.49))
plt.contourf(Z, levels=levels,origin='upper', cmap='RdYlGn',extent=(77.53,81.05,28.65,31.49))
fig.canvas.draw()
plt.savefig(r'C:UsersMRG16-10417DesktopNewtestspecies.tif',transparent='true',bbox_inches='tight')
Then I use GDAL as follows,
from osgeo import gdal, osr
import numpy as np
src_filename ='C:/Users/MRG16-10417/Desktop/New/testspecies.tif'
dst_filename = 'C:/Users/MRG16-10417/Desktop/New/newspecies.tif'
#The row and column values of the tif file was used here
nrows=252
ncols=386
src_ds = gdal.Open(src_filename)
format = "GTiff"
driver = gdal.GetDriverByName(format)
xmin = 77.5000000002060005
xmax = 81.0833333335421997
ymin = 28.6666666666176049
ymax = 31.4999999999532037
# Open destination dataset
dst_ds = driver.CreateCopy(dst_filename, src_ds, 0)
xres = (xmax-xmin)/float(ncols)
yres = (ymax-ymin)/float(nrows)
geotransform=(xmin,xres,0,ymax,0, -yres)
# Set location
dst_ds.SetGeoTransform(geotransform)
# Get raster projection
epsg = 4326
srs = osr.SpatialReference()
srs.ImportFromEPSG(epsg)
dest_wkt = srs.ExportToWkt()
# Set projection
dst_ds.SetProjection(dest_wkt)
# Close files
dst_ds = None
src_ds = None
The resultant image on QGIS,
As you can see the image is slightly off scale and isn't exactly overlapping on the reference .shp file of the same geographic extents and projection.
What could be the reason for this?
Is it because the source image that is incorrect, as matplotlib could be scaling down the image?
pyqgis gdal georeferencing
bumped to the homepage by Community♦ 4 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I was trying to georeference a .tif file generated from a matplotlib output using GDAL's python bindings and it seems to be off-scale. My objective was to create a geotiff file from the output of a contourf function. Code samples are pasted below.
fig = plt.figure()
plt.axis('off')
plt.contour(land_reference,levels=[-9999],origin='upper', cmap='gray',extent=(77.53,81.05,28.65,31.49))
plt.contourf(Z, levels=levels,origin='upper', cmap='RdYlGn',extent=(77.53,81.05,28.65,31.49))
fig.canvas.draw()
plt.savefig(r'C:UsersMRG16-10417DesktopNewtestspecies.tif',transparent='true',bbox_inches='tight')
Then I use GDAL as follows,
from osgeo import gdal, osr
import numpy as np
src_filename ='C:/Users/MRG16-10417/Desktop/New/testspecies.tif'
dst_filename = 'C:/Users/MRG16-10417/Desktop/New/newspecies.tif'
#The row and column values of the tif file was used here
nrows=252
ncols=386
src_ds = gdal.Open(src_filename)
format = "GTiff"
driver = gdal.GetDriverByName(format)
xmin = 77.5000000002060005
xmax = 81.0833333335421997
ymin = 28.6666666666176049
ymax = 31.4999999999532037
# Open destination dataset
dst_ds = driver.CreateCopy(dst_filename, src_ds, 0)
xres = (xmax-xmin)/float(ncols)
yres = (ymax-ymin)/float(nrows)
geotransform=(xmin,xres,0,ymax,0, -yres)
# Set location
dst_ds.SetGeoTransform(geotransform)
# Get raster projection
epsg = 4326
srs = osr.SpatialReference()
srs.ImportFromEPSG(epsg)
dest_wkt = srs.ExportToWkt()
# Set projection
dst_ds.SetProjection(dest_wkt)
# Close files
dst_ds = None
src_ds = None
The resultant image on QGIS,
As you can see the image is slightly off scale and isn't exactly overlapping on the reference .shp file of the same geographic extents and projection.
What could be the reason for this?
Is it because the source image that is incorrect, as matplotlib could be scaling down the image?
pyqgis gdal georeferencing
I was trying to georeference a .tif file generated from a matplotlib output using GDAL's python bindings and it seems to be off-scale. My objective was to create a geotiff file from the output of a contourf function. Code samples are pasted below.
fig = plt.figure()
plt.axis('off')
plt.contour(land_reference,levels=[-9999],origin='upper', cmap='gray',extent=(77.53,81.05,28.65,31.49))
plt.contourf(Z, levels=levels,origin='upper', cmap='RdYlGn',extent=(77.53,81.05,28.65,31.49))
fig.canvas.draw()
plt.savefig(r'C:UsersMRG16-10417DesktopNewtestspecies.tif',transparent='true',bbox_inches='tight')
Then I use GDAL as follows,
from osgeo import gdal, osr
import numpy as np
src_filename ='C:/Users/MRG16-10417/Desktop/New/testspecies.tif'
dst_filename = 'C:/Users/MRG16-10417/Desktop/New/newspecies.tif'
#The row and column values of the tif file was used here
nrows=252
ncols=386
src_ds = gdal.Open(src_filename)
format = "GTiff"
driver = gdal.GetDriverByName(format)
xmin = 77.5000000002060005
xmax = 81.0833333335421997
ymin = 28.6666666666176049
ymax = 31.4999999999532037
# Open destination dataset
dst_ds = driver.CreateCopy(dst_filename, src_ds, 0)
xres = (xmax-xmin)/float(ncols)
yres = (ymax-ymin)/float(nrows)
geotransform=(xmin,xres,0,ymax,0, -yres)
# Set location
dst_ds.SetGeoTransform(geotransform)
# Get raster projection
epsg = 4326
srs = osr.SpatialReference()
srs.ImportFromEPSG(epsg)
dest_wkt = srs.ExportToWkt()
# Set projection
dst_ds.SetProjection(dest_wkt)
# Close files
dst_ds = None
src_ds = None
The resultant image on QGIS,
As you can see the image is slightly off scale and isn't exactly overlapping on the reference .shp file of the same geographic extents and projection.
What could be the reason for this?
Is it because the source image that is incorrect, as matplotlib could be scaling down the image?
pyqgis gdal georeferencing
pyqgis gdal georeferencing
edited May 28 '18 at 13:42
PolyGeo♦
54k1782246
54k1782246
asked May 28 '18 at 6:23
Amruth KiranAmruth Kiran
185
185
bumped to the homepage by Community♦ 4 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 4 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I eventually figured out that matplotlib by default interpolates and I was losing a bunch rows/columns, saving that as an image further reduced the overall quality. Setting interpolation to none and dpi at 300, with a little fix to the lat-longs (extend the bbox) helped me overlay the imagery perfectly.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f284350%2ftif-to-geotiff-scaling-issue-using-gdal%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I eventually figured out that matplotlib by default interpolates and I was losing a bunch rows/columns, saving that as an image further reduced the overall quality. Setting interpolation to none and dpi at 300, with a little fix to the lat-longs (extend the bbox) helped me overlay the imagery perfectly.
add a comment |
I eventually figured out that matplotlib by default interpolates and I was losing a bunch rows/columns, saving that as an image further reduced the overall quality. Setting interpolation to none and dpi at 300, with a little fix to the lat-longs (extend the bbox) helped me overlay the imagery perfectly.
add a comment |
I eventually figured out that matplotlib by default interpolates and I was losing a bunch rows/columns, saving that as an image further reduced the overall quality. Setting interpolation to none and dpi at 300, with a little fix to the lat-longs (extend the bbox) helped me overlay the imagery perfectly.
I eventually figured out that matplotlib by default interpolates and I was losing a bunch rows/columns, saving that as an image further reduced the overall quality. Setting interpolation to none and dpi at 300, with a little fix to the lat-longs (extend the bbox) helped me overlay the imagery perfectly.
answered Jun 7 '18 at 7:14
Amruth KiranAmruth Kiran
185
185
add a comment |
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f284350%2ftif-to-geotiff-scaling-issue-using-gdal%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown