Breaking that down:
rightX-baseX gives us the width of the base tile
divide by counter to give us the width of one segment
multiply by the column number to get the offset for a particular column
add to baseX so that we have the absolute coordinate, that is base plus offset.
Likewise segmentY is calculated in a similar way from rowNum in 0-3:
segmentY = ((downY-baseY)/counter)*rowNum)+baseY
So a double loop is employed to calculate 16 pairs of values:
for colNum in range(4);
for rowNum in range(4):
segmentX = (((rightX – baseX) / counter) * colNum) + baseX
segmentY = (((downY – baseY) / counter) * rowNum) + baseY
gridX = “x4.” + str(colNum + 1)
gridY = “x4.” + str(rowNum + 1)
print(gridX + ” ” + gridY + “:” + str(segmentX) + “,” + str(segmentY))
That prints out 16 lines of data. gridX and gridY are interesting as they are the segment descriptors which are added to the end of the row and column descriptors of the original file name (basename in the script). For example 92XJ7-92MKF becomes 16 segments whose names run in the sequence from 92XJ7x4.1-92MKFx4.1 through to 92XJ7x4.4-92MKFx4.4
The actual spec of the file’s contents would be as follows (using our existing variable names):
- Line 1: pixelSize
- Line 2: baseSkewX
- Line 3: baseSkewY
- Line 4: –pixelSize (in other words the pixelSize string with a – in front of it)
- Line 5: segmentX
- Line 6: segmentY
- strip the extension off the base file (92XJ7-92MKF.jgw) so that we get 92XJ7-92MKF
- split the filename at the hyphen so we get two pieces, baseColDescriptor and baseRowDescriptor respectively being 92XJ7 and 92MKF in this example.
- set gridRowDescriptor to be a concatenation of baseRowDescriptor and gridY e.g. 92XJ7x4.1
- set gridColDescriptor to be a concatenation of baseColDescriptor and gridX e.g. 92MKFx4.3
- set gridFilename to be gridColDescriptor + “-” + gridRowDescriptor + “.jpg”
- search for a filename that ends with gridFileName (it will start with something else like K1977full-)
- If the file name exists then change the full name into “.jgw” extension and write the 6 lines mentioned just above.
- There may be more than one filename that ends with gridFileName so we need to go through all the filenames in the directory.
The code needed to do that will appear in the next part in this series.