[Qgis-user] World file

David Fawcett david.fawcett at gmail.com
Fri Dec 19 11:34:38 PST 2008


Augustin,

Below is a Python function that I threw together to calculate world
file params for a rotated image and write them out to a file.  It
might be of some help to you.

David.


############################################
# creates a world file for the air photo
# Args:
#       outputFile - directory to write the world files to
#       xResolution - pixel resolution in x direction
#       yResolution - pixel resolution in y direction
#       angleDeg - the angle of rotation in degrees


def writeWorldFile(outputFile,xResolution,yResolution,angleDeg,rotatedUlXcoord,rotatedUlYcoord):

        angleRad = -math.radians(angleDeg)
        line1 = xResolution * math.cos(angleRad)
        line2 = -xResolution * math.sin(angleRad)
        line3 = -yResolution * math.sin(angleRad)
        line4 = -yResolution * math.cos(angleRad)
        line5 = rotatedUlXcoord
        line6 = rotatedUlYcoord

        try:
                newWorldfFile = open(outputFile+".jgw","w")
        except:
                print "couldn't open file"

        fileText = str(line1) + '\n' + str(line2) + '\n' + str(line3)
+ '\n' + str(line4) + '\n' + str(line5) + '\n' + str(line6) + '\n'

        newWorldfFile.write(fileText)
        newWorldfFile.close()
        return


On Fri, Dec 19, 2008 at 10:31 AM, José María Michia
<jose.maria.michia at gmail.com> wrote:
> 2008/12/19 Agustin Lobo <aloboaleu at gmail.com>:
>> This could be considered a bit off-topic.
>>
>> If a jpg image were well alligned with a N-S grid,
>> the world file would be something like:
>>
>> 0.4007552
>> 0
>> 0
>> -0.4007552
>> 438209.4
>> 4625526
>>
>> but if I have to rotate 90 deg. to the left, how should I make the
>> file?
>>
>> Any orientation,pointer etc?
>
> The file TFW  must be:
>
> 0
> 0.4007552
> 0.4007552
> 0
> 438209.4
> 4625526
>
> For explanations see:
>
> http://www.omg.unb.ca/~jonnyb/processing/geotiff_tifw_format.html
> http://lists.maptools.org/pipermail/geotiff/2007-January/000362.html
>
> Saludos
> José María
>
>> Thanks
>>
>> Agus
>> --
>> Dr. Agustin Lobo
>> Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
>> LLuis Sole Sabaris s/n
>> 08028 Barcelona
>> Spain
>> Tel. 34 934095410
>> Fax. 34 934110012
>> email: Agustin.Lobo at ija.csic.es
>> http://www.ija.csic.es/gt/obster
>> _______________________________________________
>> Qgis-user mailing list
>> Qgis-user at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-user
>>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user
>



More information about the Qgis-user mailing list