Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
diapotb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Luc Hermitte
diapotb
Commits
6b2ea716
Commit
6b2ea716
authored
5 years ago
by
Gaëlle USSEGLIO
Browse files
Options
Downloads
Patches
Plain Diff
ENH : New fct an script python to add into tiff files, GCPs
parent
56349854
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python_src/utils/addGCP.py
+89
-0
89 additions, 0 deletions
python_src/utils/addGCP.py
with
89 additions
and
0 deletions
python_src/utils/addGCP.py
0 → 100644
+
89
−
0
View file @
6b2ea716
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
addGCP.py
==========
Python script to add into a tiff file, GCPs information
"""
import
argparse
import
gdal
import
osr
import
re
# addGCP function
def
addGCP
(
dictKWL
,
inTiff
):
"""
Function to add into a tiff file, GCPs information
"""
###### Create GCPs list from input dict ######
# Select keys with gcp in it
filtered_dictKWL
=
{
k
:
v
for
k
,
v
in
dictKWL
.
items
()
if
"
gcp
"
in
k
}
# Create 5 lists : for colunms (pixel), lines, lon, lat and hgt
col_list
=
[
float
(
filtered_dictKWL
[
k
])
for
k
in
filtered_dictKWL
.
keys
()
if
"
im_pt.x
"
in
k
]
line_list
=
[
float
(
filtered_dictKWL
[
k
])
for
k
in
filtered_dictKWL
.
keys
()
if
"
im_pt.y
"
in
k
]
lon_list
=
[
float
(
filtered_dictKWL
[
k
])
for
k
in
filtered_dictKWL
.
keys
()
if
"
world_pt.lon
"
in
k
]
lat_list
=
[
float
(
filtered_dictKWL
[
k
])
for
k
in
filtered_dictKWL
.
keys
()
if
"
world_pt.lat
"
in
k
]
hgt_list
=
[
float
(
filtered_dictKWL
[
k
])
for
k
in
filtered_dictKWL
.
keys
()
if
"
world_pt.hgt
"
in
k
]
gcp_number
=
int
(
filtered_dictKWL
[
'
support_data.geom.gcp.number
'
])
# Check list size
if
len
(
col_list
)
!=
gcp_number
or
len
(
line_list
)
!=
gcp_number
or
\
len
(
lon_list
)
!=
gcp_number
or
len
(
lat_list
)
!=
gcp_number
or
\
len
(
hgt_list
)
!=
gcp_number
:
print
(
"
Wrong size for gcp lists
"
)
quit
()
gcp_list
=
[]
for
i
in
range
(
0
,
gcp_number
):
gcp
=
gdal
.
GCP
(
lon_list
[
i
],
lat_list
[
i
],
hgt_list
[
i
],
col_list
[
i
],
line_list
[
i
])
# lon, lat, hgt, col, line
gcp_list
.
append
(
gcp
)
###### Add GCPs into the input tiff ######
ds
=
gdal
.
Open
(
inTiff
,
gdal
.
GA_Update
)
# First : Adapt Projetion for WGS84
wkt
=
ds
.
GetProjection
()
# if no projection defined => projection by default (ESPG 4326)
if
not
wkt
:
sr
=
osr
.
SpatialReference
()
sr
.
ImportFromEPSG
(
4326
)
# ESPG : 4326 = WGS84
wkt
=
sr
.
ExportToWkt
()
# Set GCPs into tiff image
ds
.
SetGCPs
(
gcp_list
,
wkt
)
ds
=
None
# Main
if
__name__
==
"
__main__
"
:
###### Get the main argument : geom file and input tiff ######
# Check arguments
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"
geomfile
"
,
help
=
"
input geom file with correct GCPs
"
)
parser
.
add_argument
(
"
intiff
"
,
help
=
"
input tiff image to include GCPs in it
"
)
args
=
parser
.
parse_args
()
###### Read geom file ######
f_geom
=
open
(
args
.
geomfile
,
"
r
"
)
keywordlist
=
f_geom
.
read
().
split
(
"
\n
"
)
keywordlist
=
filter
(
None
,
keywordlist
)
# Transfrom file content to dict
dictKWL
=
{
i
.
split
(
'
:
'
)[
0
]
:
re
.
sub
(
r
"
[\n\t\s]*
"
,
""
,
i
.
split
(
'
:
'
)[
1
])
for
i
in
keywordlist
}
addGCP
(
dictKWL
,
args
.
intiff
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment