Enable setting gcps in Reader option #565
Replies: 4 comments 7 replies
-
After couple hours digging, it seems there is no
The import xml.etree.ElementTree as ET
from rasterio.vrt import _boundless_vrt_doc
from rasterio.warp import WarpedVRT
with rasterio.open("image.jpeg") as dataset:
# Use rasterio boundless_vrt_doc to create a VRT xml document
vrt_xml = _boundless_vrt_doc(dataset)
# Update the VRT to add the GCPS
vrtdataset = ET.fromstring(vrt_xml)
gcp_list = ET.SubElement(vrtdataset, 'GCPList')
gcp_list.attrib['Projection'] = str(gcps_crs)
for gcp in self.gcps:
g = ET.SubElement(gcp_list, 'GCP')
g.attrib["Id"] = gcp.id
g.attrib['Pixel'] = str(gcp.col)
g.attrib['Line'] = str(gcp.row)
g.attrib['X'] = str(gcp.x)
g.attrib['Y'] = str(gcp.y)
vrt_xml = ET.tostring(vrtdataset)
# Open the VRT Dataset and pass it to the WarpedVRT
with rasterio.open(vrt_xml.decode()) as dataset:
with WarpedVRT(
dataset,
src_crs=dataset.gcps[1],
src_transform=transform.from_gcps(dataset.gcps[0]),
) as vrt:
... Notes:
Ps: I'm going to convert the issue to discussion because there Is no real actionable right now |
Beta Was this translation helpful? Give feedback.
-
I'd like to add one idea here (a complication, not a solution!), which is that I think the best implementation would also allow passing in a region extent, such that the GCPs could be applied only to a clipped subset of the original image. This would allow various pieces of the same image (think, a scanned atlas sheet with multiple different maps on it, e.g. https://www.loc.gov/resource/g4014nm.g03376188501/?sp=3) to be virtually georeferenced without having to do one of the following:
I'm not sure if this makes much sense in terms of how COGs are structured and read, but I wanted to put it down here for consideration. |
Beta Was this translation helpful? Give feedback.
-
FYI, I think I have something which work quite ok. I ended up creating a temporary VRT file (using a custom version of rasterio's _boundless_vrt_doc: https://github.com/developmentseed/titiler-image/blob/a898fa0dc7f237e70ce2758772730df6a927760b/titiler/image/reader.py#L86-L216) I think there are still some edge cases about nodata/alpha/mask that needs more tests but you can see how it works in https://github.com/developmentseed/titiler-image/blob/main/docs/notebooks/titiler_image_GCPSReader.ipynb |
Beta Was this translation helpful? Give feedback.
-
Woah, incredible, I'm really looking forward to trying this out! Somewhat related to this, the IIIF-Maps committee has been working on a IIIF spec extension for holding georeferencing/GCP information: https://preview.iiif.io/api/georef/extension/georef/... I see now you used |
Beta Was this translation helpful? Give feedback.
-
Let's say you have an Non-geo image (as COG already) and some external GCP (e.g from a Georeferencing UI), it would be nice to pass those GCPS to
rio_tiler.io.Reader
directly to allow virtual georeferencingrio-tiler/rio_tiler/io/rasterio.py
Lines 98 to 110 in 93cf68e
Beta Was this translation helpful? Give feedback.
All reactions