1

I want to save an image from QGIS but the save image functionality feels limited.

Is it possible to use the python command line to save an image at a specific zoomed in scale and to set a bounding box over the region I want to print?

For example, I want to save an image at scale 1:1000 000 within specific coordinates as a bounding box.

1

Can you try the latest QGis development version ? QGis 3 will feature a much improved "save as image" feature, the version is not yet officially released, but the nightly builds are available and seem quite stable. Presentation of the new feature: http://imhere-asia.com/blog/post/more-qgis-30-improvements-saving-map-canvas-as-image-pdf

Otherwise, you can also use the Composer: add a single map taking all the space, then you can set the scale and coordinates in the properties of the map. Documentation is available here: https://docs.qgis.org/2.18/en/docs/user_manual/print_composer/overview_composer.html

I am sure it is also possible in Python, but it seems overkill for your usecase.

-1

Exkoria, I know you're using QGIS, but I figured I'd post this code from ArcMAP in-case you can get some help from it. It pans to each feature in a shapefile and exports an image, and then repeats for all features in the shapefile you specify. Like I said, its not QGIS, but it might help somehow.

# This script pans ArcMap, once for each feature in Layer (passed in value)
#
# Note the time.sleep(1), this was included because I needed to pause to
# allow ArcBruTile time to download images. Depending on your mileage,
# this probably needs to be adjusted.
#
# 4/19/2012
#
# http://nodedangles.wordpress.com
#
# 

import sys,arcpy,datetime
inLayer = sys.argv[1]

def printit(inMessage):
    print inMessage
    arcpy.AddMessage(inMessage)

mxd = arcpy.mapping.MapDocument("CURRENT")

arcpy.MakeFeatureLayer_management(inLayer, "indexLayer")
cur=arcpy.SearchCursor("indexLayer")

df = arcpy.mapping.ListDataFrames(mxd)[0]
newExtent = df.extent

iCount = 0
iTotal = (arcpy.GetCount_management("indexLayer").getOutput(0))

for row in cur:
    thisPoly = row.getValue("Shape")
    newExtent.XMin, newExtent.YMin = thisPoly.extent.XMin, thisPoly.extent.YMin
    newExtent.XMax, newExtent.YMax = thisPoly.extent.XMax, thisPoly.extent.YMax
    df.extent = newExtent
    iCount+=1
    arcpy.mapping.ExportToJPEG(mxd, r"C:\scratch\Images\Map_%s.jpg" %(iCount), df,
                  df_export_width=3269,
                              df_export_height=1904,
                  resolution=200,
                              world_file=True) 
#    time.sleep(1)

    printit("Panned to feature {0} of {1}".format(iCount,iTotal))

del row
del cur

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.