Geographic Information Systems Asked by Amir S on March 31, 2021
I have GeoJSON coord:
{"type":"FeatureCollection",
"features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":
[[[66.87480926513672,48.111213657240576],
[66.89043045043945,48.111213657240576],
[66.89043045043945,48.119751843350834],
[66.87480926513672,48.119751843350834],
[66.87480926513672,48.111213657240576]
]]}}]}
And I have image from satelite of this area in PNG format:
How can I connect coords and image in one TIFF/GeoTIFF file?
I tried this solution Georeferencing raster using GDAL and Python?, but I cannot understand how to convert my coord to this format:
gt = [-7916400, 100, 0, 5210940, 0, -100]
The polygon seems to be a north-up oriented rectangle so you can simply assign the upper-left and lower-right coordinates into the image.
With Python you can then use https://gdal.org/python/osgeo.gdal-module.html#Translate and use the options as documented in https://gdal.org/python/osgeo.gdal-module.html#TranslateOptions
You can test the conversion with the gdal_translate utility https://gdal.org/programs/gdal_translate.html#gdal-translate
Usage:
gdal_translate -of GTiff -co tiled=yes -ullr 66.87480926513672 48.119751843350834 66.89043045043945 48.111213657240576 input.png output.tif
The coordinate system of the polygon is probably EPSG:4326 and you can assign that with -a_srs epsg:4326
. However, the png that you have may actually use some other crs like EPSG:3857. In this case some additional steps are needed.
Answered by user30184 on March 31, 2021
In Georeferencing raster using GDAL and Python?
# Specify raster location through geotransform array
# (uperleftx, scalex, skewx, uperlefty, skewy, scaley)
# Scale = size of one pixel in units of raster projection
# this example below assumes 100x100
gt = [-7916400, 100, 0, 5210940, 0, -100]
You can use the script of Ian Turton in Convert GeoJSON object to bounding box using Python 3.6, the library geojson-bbox and others.
import gbbox #geojson-bbox
pol = {"type":"FeatureCollection",
"features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":
[[[66.87480926513672,48.111213657240576],
[66.89043045043945,48.111213657240576],
[66.89043045043945,48.119751843350834],
[66.87480926513672,48.119751843350834],
[66.87480926513672,48.111213657240576]
]]}}]}
min_x, min_y, max_x, max_y = gbbox.GeoJSON(pol).bbox()
print( min_x, min_y, max_x, max_y)
66.87480926513672 48.111213657240576 66.89043045043945 48.119751843350834
And you get uperleftx (min_x), and uperlefty (max_y). Assuming 100x100 as in Georeferencing raster using GDAL and Python?
gt = [66.87480926513672 , 100, 0, 48.119751843350834, 0, -100]
But in reality you need the size of the raster (width, height) to compute the real size of the pixel
Answered by gene on March 31, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP