Convert worldfile for jpg to worldfile for png Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?how to georeference my png using gdalAutomate creating Rectified files from georeferenced imagesTilecache positions my gdal_translated map 20km south of where I want itCreate 6 band IMG file with GDAL out of two JPG files, one with WorldFile coordinatesWorldfile incorrect for QGIS?Generate PNG/JPG maps from multiple ASCI/GeoTIFF in Python/GDALImporting JPG into SWMM model asks for BPW world fileSaving raster as *.tif with tfw worldfileConvert multiple bsq files to jpg images in pythonInconsistent origin when using GDAL translate to generate worldfileCompressing 16 bit 4 band RGBI (.img)
What is the difference between globalisation and imperialism?
Putting class ranking in CV, but against dept guidelines
Is there any word for a place full of confusion?
Why do aircraft stall warning systems use angle-of-attack vanes rather than detecting airflow separation directly?
How does the math work when buying airline miles?
What does it mean that physics no longer uses mechanical models to describe phenomena?
Why can't I install Tomboy in Ubuntu Mate 19.04?
The Nth Gryphon Number
Lagrange four-squares theorem --- deterministic complexity
Is multiple magic items in one inherently imbalanced?
Does the Mueller report show a conspiracy between Russia and the Trump Campaign?
What's the point of the test set?
What is an "asse" in Elizabethan English?
Why are vacuum tubes still used in amateur radios?
Trademark violation for app?
How much damage would a cupful of neutron star matter do to the Earth?
What would you call this weird metallic apparatus that allows you to lift people?
How long can equipment go unused before powering up runs the risk of damage?
Do I really need to have a message in a novel to appeal to readers?
Converted a Scalar function to a TVF function for parallel execution-Still running in Serial mode
How many time has Arya actually used Needle?
How did Fremen produce and carry enough thumpers to use Sandworms as de facto Ubers?
Can a sorcerer use careful spell on himself?
preposition before coffee
Convert worldfile for jpg to worldfile for png
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?how to georeference my png using gdalAutomate creating Rectified files from georeferenced imagesTilecache positions my gdal_translated map 20km south of where I want itCreate 6 band IMG file with GDAL out of two JPG files, one with WorldFile coordinatesWorldfile incorrect for QGIS?Generate PNG/JPG maps from multiple ASCI/GeoTIFF in Python/GDALImporting JPG into SWMM model asks for BPW world fileSaving raster as *.tif with tfw worldfileConvert multiple bsq files to jpg images in pythonInconsistent origin when using GDAL translate to generate worldfileCompressing 16 bit 4 band RGBI (.img)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am using 3 band jpeg files with 1 band png masks for image analysis. The names match except for extension, and I am merging the jpgs using gdalbuildvrt, then gdal_translate to generate a geotiff. I would like to merge the pngs in the same manner (reusing my existing scripts if possible), but my mask generator does not create a worldfile.
Example files:
tileset_nn_0_0.jpg
tileset_nn_0_0.jpg.aux.xml
tileset_nn_0_0.png
tileset_nn_1_0.jpg
tileset_nn_1_0.jpg.aux.xml
tileset_nn_1_0.png
tileset_nn_2_0.jpg
...
The worldfile I have for the jpgs is a PAM/GDAL dataset, and looking inside the files, they won't work by just renaming because they include attributes regarding JPEG compression, bands, etc that don't exist in the pngs.
I have thought of using gdal_translate to convert each jpg image to a grayscale png in a temp directory, then delete the png and copy the worldfile out, but I will be doing this repeatedly for several datasets, so I would prefer a cleaner solution.
python gdal world-file
add a comment |
I am using 3 band jpeg files with 1 band png masks for image analysis. The names match except for extension, and I am merging the jpgs using gdalbuildvrt, then gdal_translate to generate a geotiff. I would like to merge the pngs in the same manner (reusing my existing scripts if possible), but my mask generator does not create a worldfile.
Example files:
tileset_nn_0_0.jpg
tileset_nn_0_0.jpg.aux.xml
tileset_nn_0_0.png
tileset_nn_1_0.jpg
tileset_nn_1_0.jpg.aux.xml
tileset_nn_1_0.png
tileset_nn_2_0.jpg
...
The worldfile I have for the jpgs is a PAM/GDAL dataset, and looking inside the files, they won't work by just renaming because they include attributes regarding JPEG compression, bands, etc that don't exist in the pngs.
I have thought of using gdal_translate to convert each jpg image to a grayscale png in a temp directory, then delete the png and copy the worldfile out, but I will be doing this repeatedly for several datasets, so I would prefer a cleaner solution.
python gdal world-file
What are your scripts written in? To georeference a PNG you only need the SRS and GeoTransform elements from the XML - everything else is optional. Some python code to read one XML and write another with only those tags can be done in a few lines. There might even be a command-line processor to do it...
– Spacedman
Apr 11 at 18:03
related (pgw) gis.stackexchange.com/questions/84363/…
– Mapperz♦
Apr 11 at 18:05
Does anyone have an example xml file for a png?
– user15741
Apr 11 at 19:00
Edit your JPG metafile and leave only the SRS and GeoTransform - rename it and save it and that will be a valid metadatafile for a PNG.
– Spacedman
Apr 11 at 19:25
add a comment |
I am using 3 band jpeg files with 1 band png masks for image analysis. The names match except for extension, and I am merging the jpgs using gdalbuildvrt, then gdal_translate to generate a geotiff. I would like to merge the pngs in the same manner (reusing my existing scripts if possible), but my mask generator does not create a worldfile.
Example files:
tileset_nn_0_0.jpg
tileset_nn_0_0.jpg.aux.xml
tileset_nn_0_0.png
tileset_nn_1_0.jpg
tileset_nn_1_0.jpg.aux.xml
tileset_nn_1_0.png
tileset_nn_2_0.jpg
...
The worldfile I have for the jpgs is a PAM/GDAL dataset, and looking inside the files, they won't work by just renaming because they include attributes regarding JPEG compression, bands, etc that don't exist in the pngs.
I have thought of using gdal_translate to convert each jpg image to a grayscale png in a temp directory, then delete the png and copy the worldfile out, but I will be doing this repeatedly for several datasets, so I would prefer a cleaner solution.
python gdal world-file
I am using 3 band jpeg files with 1 band png masks for image analysis. The names match except for extension, and I am merging the jpgs using gdalbuildvrt, then gdal_translate to generate a geotiff. I would like to merge the pngs in the same manner (reusing my existing scripts if possible), but my mask generator does not create a worldfile.
Example files:
tileset_nn_0_0.jpg
tileset_nn_0_0.jpg.aux.xml
tileset_nn_0_0.png
tileset_nn_1_0.jpg
tileset_nn_1_0.jpg.aux.xml
tileset_nn_1_0.png
tileset_nn_2_0.jpg
...
The worldfile I have for the jpgs is a PAM/GDAL dataset, and looking inside the files, they won't work by just renaming because they include attributes regarding JPEG compression, bands, etc that don't exist in the pngs.
I have thought of using gdal_translate to convert each jpg image to a grayscale png in a temp directory, then delete the png and copy the worldfile out, but I will be doing this repeatedly for several datasets, so I would prefer a cleaner solution.
python gdal world-file
python gdal world-file
edited Apr 13 at 3:56
user15741
asked Apr 11 at 17:31
user15741user15741
31017
31017
What are your scripts written in? To georeference a PNG you only need the SRS and GeoTransform elements from the XML - everything else is optional. Some python code to read one XML and write another with only those tags can be done in a few lines. There might even be a command-line processor to do it...
– Spacedman
Apr 11 at 18:03
related (pgw) gis.stackexchange.com/questions/84363/…
– Mapperz♦
Apr 11 at 18:05
Does anyone have an example xml file for a png?
– user15741
Apr 11 at 19:00
Edit your JPG metafile and leave only the SRS and GeoTransform - rename it and save it and that will be a valid metadatafile for a PNG.
– Spacedman
Apr 11 at 19:25
add a comment |
What are your scripts written in? To georeference a PNG you only need the SRS and GeoTransform elements from the XML - everything else is optional. Some python code to read one XML and write another with only those tags can be done in a few lines. There might even be a command-line processor to do it...
– Spacedman
Apr 11 at 18:03
related (pgw) gis.stackexchange.com/questions/84363/…
– Mapperz♦
Apr 11 at 18:05
Does anyone have an example xml file for a png?
– user15741
Apr 11 at 19:00
Edit your JPG metafile and leave only the SRS and GeoTransform - rename it and save it and that will be a valid metadatafile for a PNG.
– Spacedman
Apr 11 at 19:25
What are your scripts written in? To georeference a PNG you only need the SRS and GeoTransform elements from the XML - everything else is optional. Some python code to read one XML and write another with only those tags can be done in a few lines. There might even be a command-line processor to do it...
– Spacedman
Apr 11 at 18:03
What are your scripts written in? To georeference a PNG you only need the SRS and GeoTransform elements from the XML - everything else is optional. Some python code to read one XML and write another with only those tags can be done in a few lines. There might even be a command-line processor to do it...
– Spacedman
Apr 11 at 18:03
related (pgw) gis.stackexchange.com/questions/84363/…
– Mapperz♦
Apr 11 at 18:05
related (pgw) gis.stackexchange.com/questions/84363/…
– Mapperz♦
Apr 11 at 18:05
Does anyone have an example xml file for a png?
– user15741
Apr 11 at 19:00
Does anyone have an example xml file for a png?
– user15741
Apr 11 at 19:00
Edit your JPG metafile and leave only the SRS and GeoTransform - rename it and save it and that will be a valid metadatafile for a PNG.
– Spacedman
Apr 11 at 19:25
Edit your JPG metafile and leave only the SRS and GeoTransform - rename it and save it and that will be a valid metadatafile for a PNG.
– Spacedman
Apr 11 at 19:25
add a comment |
1 Answer
1
active
oldest
votes
Based on the comments by Spacedman, I put together the following script which works in my case:
import glob
import os
from pathlib import Path
from xml.etree import ElementTree
srcpath = 'D:/jpglocation/'
destpath = 'D:/pnglocation/'
filemask = '*.jpg.aux.xml'
wfs = glob.glob(f'srcpathfilemask')
i = 0
for wf in wfs:
et = ElementTree.parse(wf)
root = et.getroot()
# Strip jpg metadata
for metadata in root.findall('Metadata'):
root.remove(metadata)
for metadata in root.findall('PAMRasterBand'):
root.remove(metadata)
#add png metadata
#domain="IMAGE_STRUCTURE"
metaImg = ElementTree.SubElement(root, "Metadata", domain="IMAGE_STRUCTURE")
#<MDI key="INTERLEAVE">PIXEL</MDI>
mdi = ElementTree.Element("MDI", key="INTERLEAVE")
mdi.text = "PIXEL"
metaImg.append(mdi)
meta = ElementTree.SubElement(root, "Metadata")
mdi = ElementTree.Element("MDI", key="AREA_OR_POINT")
mdi.text = "AREA"
meta.append(mdi)
mdi = ElementTree.Element("MDI", key="COLORSPACE")
mdi.text = "RGB"
meta.append(mdi)
mdi = ElementTree.Element("MDI", key="COMPRESSION_RATE_TARGET")
mdi.text = "1"
meta.append(mdi)
# Write back to file
p = Path(wf)
destfile = destpath + (p.stem).replace('.jpg', '.png') + '.xml'
print(destfile)
et.write(destfile)
And it works with gdalbuildvrt now to easily merge the png tiles into a larger composite:
gdalbuildvrt -input_file_list merged.vrt *.png
gdal_translate merged.vrt merged.tif
The worldfile didn't function with only SRS and GeoTransform, but it worked with generic png settings (my pngs are grayscale but the png metadata was from an RGB file).
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%2f318526%2fconvert-worldfile-for-jpg-to-worldfile-for-png%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
Based on the comments by Spacedman, I put together the following script which works in my case:
import glob
import os
from pathlib import Path
from xml.etree import ElementTree
srcpath = 'D:/jpglocation/'
destpath = 'D:/pnglocation/'
filemask = '*.jpg.aux.xml'
wfs = glob.glob(f'srcpathfilemask')
i = 0
for wf in wfs:
et = ElementTree.parse(wf)
root = et.getroot()
# Strip jpg metadata
for metadata in root.findall('Metadata'):
root.remove(metadata)
for metadata in root.findall('PAMRasterBand'):
root.remove(metadata)
#add png metadata
#domain="IMAGE_STRUCTURE"
metaImg = ElementTree.SubElement(root, "Metadata", domain="IMAGE_STRUCTURE")
#<MDI key="INTERLEAVE">PIXEL</MDI>
mdi = ElementTree.Element("MDI", key="INTERLEAVE")
mdi.text = "PIXEL"
metaImg.append(mdi)
meta = ElementTree.SubElement(root, "Metadata")
mdi = ElementTree.Element("MDI", key="AREA_OR_POINT")
mdi.text = "AREA"
meta.append(mdi)
mdi = ElementTree.Element("MDI", key="COLORSPACE")
mdi.text = "RGB"
meta.append(mdi)
mdi = ElementTree.Element("MDI", key="COMPRESSION_RATE_TARGET")
mdi.text = "1"
meta.append(mdi)
# Write back to file
p = Path(wf)
destfile = destpath + (p.stem).replace('.jpg', '.png') + '.xml'
print(destfile)
et.write(destfile)
And it works with gdalbuildvrt now to easily merge the png tiles into a larger composite:
gdalbuildvrt -input_file_list merged.vrt *.png
gdal_translate merged.vrt merged.tif
The worldfile didn't function with only SRS and GeoTransform, but it worked with generic png settings (my pngs are grayscale but the png metadata was from an RGB file).
add a comment |
Based on the comments by Spacedman, I put together the following script which works in my case:
import glob
import os
from pathlib import Path
from xml.etree import ElementTree
srcpath = 'D:/jpglocation/'
destpath = 'D:/pnglocation/'
filemask = '*.jpg.aux.xml'
wfs = glob.glob(f'srcpathfilemask')
i = 0
for wf in wfs:
et = ElementTree.parse(wf)
root = et.getroot()
# Strip jpg metadata
for metadata in root.findall('Metadata'):
root.remove(metadata)
for metadata in root.findall('PAMRasterBand'):
root.remove(metadata)
#add png metadata
#domain="IMAGE_STRUCTURE"
metaImg = ElementTree.SubElement(root, "Metadata", domain="IMAGE_STRUCTURE")
#<MDI key="INTERLEAVE">PIXEL</MDI>
mdi = ElementTree.Element("MDI", key="INTERLEAVE")
mdi.text = "PIXEL"
metaImg.append(mdi)
meta = ElementTree.SubElement(root, "Metadata")
mdi = ElementTree.Element("MDI", key="AREA_OR_POINT")
mdi.text = "AREA"
meta.append(mdi)
mdi = ElementTree.Element("MDI", key="COLORSPACE")
mdi.text = "RGB"
meta.append(mdi)
mdi = ElementTree.Element("MDI", key="COMPRESSION_RATE_TARGET")
mdi.text = "1"
meta.append(mdi)
# Write back to file
p = Path(wf)
destfile = destpath + (p.stem).replace('.jpg', '.png') + '.xml'
print(destfile)
et.write(destfile)
And it works with gdalbuildvrt now to easily merge the png tiles into a larger composite:
gdalbuildvrt -input_file_list merged.vrt *.png
gdal_translate merged.vrt merged.tif
The worldfile didn't function with only SRS and GeoTransform, but it worked with generic png settings (my pngs are grayscale but the png metadata was from an RGB file).
add a comment |
Based on the comments by Spacedman, I put together the following script which works in my case:
import glob
import os
from pathlib import Path
from xml.etree import ElementTree
srcpath = 'D:/jpglocation/'
destpath = 'D:/pnglocation/'
filemask = '*.jpg.aux.xml'
wfs = glob.glob(f'srcpathfilemask')
i = 0
for wf in wfs:
et = ElementTree.parse(wf)
root = et.getroot()
# Strip jpg metadata
for metadata in root.findall('Metadata'):
root.remove(metadata)
for metadata in root.findall('PAMRasterBand'):
root.remove(metadata)
#add png metadata
#domain="IMAGE_STRUCTURE"
metaImg = ElementTree.SubElement(root, "Metadata", domain="IMAGE_STRUCTURE")
#<MDI key="INTERLEAVE">PIXEL</MDI>
mdi = ElementTree.Element("MDI", key="INTERLEAVE")
mdi.text = "PIXEL"
metaImg.append(mdi)
meta = ElementTree.SubElement(root, "Metadata")
mdi = ElementTree.Element("MDI", key="AREA_OR_POINT")
mdi.text = "AREA"
meta.append(mdi)
mdi = ElementTree.Element("MDI", key="COLORSPACE")
mdi.text = "RGB"
meta.append(mdi)
mdi = ElementTree.Element("MDI", key="COMPRESSION_RATE_TARGET")
mdi.text = "1"
meta.append(mdi)
# Write back to file
p = Path(wf)
destfile = destpath + (p.stem).replace('.jpg', '.png') + '.xml'
print(destfile)
et.write(destfile)
And it works with gdalbuildvrt now to easily merge the png tiles into a larger composite:
gdalbuildvrt -input_file_list merged.vrt *.png
gdal_translate merged.vrt merged.tif
The worldfile didn't function with only SRS and GeoTransform, but it worked with generic png settings (my pngs are grayscale but the png metadata was from an RGB file).
Based on the comments by Spacedman, I put together the following script which works in my case:
import glob
import os
from pathlib import Path
from xml.etree import ElementTree
srcpath = 'D:/jpglocation/'
destpath = 'D:/pnglocation/'
filemask = '*.jpg.aux.xml'
wfs = glob.glob(f'srcpathfilemask')
i = 0
for wf in wfs:
et = ElementTree.parse(wf)
root = et.getroot()
# Strip jpg metadata
for metadata in root.findall('Metadata'):
root.remove(metadata)
for metadata in root.findall('PAMRasterBand'):
root.remove(metadata)
#add png metadata
#domain="IMAGE_STRUCTURE"
metaImg = ElementTree.SubElement(root, "Metadata", domain="IMAGE_STRUCTURE")
#<MDI key="INTERLEAVE">PIXEL</MDI>
mdi = ElementTree.Element("MDI", key="INTERLEAVE")
mdi.text = "PIXEL"
metaImg.append(mdi)
meta = ElementTree.SubElement(root, "Metadata")
mdi = ElementTree.Element("MDI", key="AREA_OR_POINT")
mdi.text = "AREA"
meta.append(mdi)
mdi = ElementTree.Element("MDI", key="COLORSPACE")
mdi.text = "RGB"
meta.append(mdi)
mdi = ElementTree.Element("MDI", key="COMPRESSION_RATE_TARGET")
mdi.text = "1"
meta.append(mdi)
# Write back to file
p = Path(wf)
destfile = destpath + (p.stem).replace('.jpg', '.png') + '.xml'
print(destfile)
et.write(destfile)
And it works with gdalbuildvrt now to easily merge the png tiles into a larger composite:
gdalbuildvrt -input_file_list merged.vrt *.png
gdal_translate merged.vrt merged.tif
The worldfile didn't function with only SRS and GeoTransform, but it worked with generic png settings (my pngs are grayscale but the png metadata was from an RGB file).
answered Apr 13 at 3:55
user15741user15741
31017
31017
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%2f318526%2fconvert-worldfile-for-jpg-to-worldfile-for-png%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
What are your scripts written in? To georeference a PNG you only need the SRS and GeoTransform elements from the XML - everything else is optional. Some python code to read one XML and write another with only those tags can be done in a few lines. There might even be a command-line processor to do it...
– Spacedman
Apr 11 at 18:03
related (pgw) gis.stackexchange.com/questions/84363/…
– Mapperz♦
Apr 11 at 18:05
Does anyone have an example xml file for a png?
– user15741
Apr 11 at 19:00
Edit your JPG metafile and leave only the SRS and GeoTransform - rename it and save it and that will be a valid metadatafile for a PNG.
– Spacedman
Apr 11 at 19:25