Can't create Projection Coordinate System in GeoTiff - gdal

I have a jpg image that I would like to convert to a GeoTiff. I have done the following with GDAL:
gdal_translate -a_srs "+proj=latlong +datum=WGS84" -of GTiff -co "INTERLEAVE=PIXEL" -a_ullr -112.749767303467 40.2223700746836 -112.731463909149 40.2063119735618 image0.jpg image0.tif
This provides a GeoTiff with the following Geo Data (using gdalinfo):
Driver: GTiff/GeoTIFF
Files: image0.tif
Size is 853, 980
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (-112.749767303467000,40.222370074683603)
Pixel Size = (0.000021457672120,-0.000016385817471)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left (-112.7497673, 40.2223701) (112d44'59.16"W, 40d13'20.53"N)
Lower Left (-112.7497673, 40.2063120) (112d44'59.16"W, 40d12'22.72"N)
Upper Right (-112.7314639, 40.2223701) (112d43'53.27"W, 40d13'20.53"N)
Lower Right (-112.7314639, 40.2063120) (112d43'53.27"W, 40d12'22.72"N)
Center (-112.7406156, 40.2143410) (112d44'26.22"W, 40d12'51.63"N)
Band 1 Block=853x3 Type=Byte, ColorInterp=Red
Band 2 Block=853x3 Type=Byte, ColorInterp=Green
Band 3 Block=853x3 Type=Byte, ColorInterp=Blue
I now want to add a projection to the file using gdalwarp so I do this:
gdalwarp -of GTiff -co "INTERLEAVE=PIXEL" -s_srs "+proj=utm +zone=12 +datum=WGS84" - t_srs "+proj=latlong +datum=WGS84" -r cubic image0.tif image0proj.tif
The output from gdal info for this is:
Driver: GTiff/GeoTIFF
Files: image0proj.tif
Size is 974, 860
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (-115.489754008884220,0.000362780166170)
Pixel Size = (0.000000000168394,-0.000000000168394)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left (-115.4897540, 0.0003628) (115d29'23.11"W, 0d 0' 1.31"N)
Lower Left (-115.4897540, 0.0003626) (115d29'23.11"W, 0d 0' 1.31"N)
Upper Right (-115.4897538, 0.0003628) (115d29'23.11"W, 0d 0' 1.31"N)
Lower Right (-115.4897538, 0.0003626) (115d29'23.11"W, 0d 0' 1.31"N)
Center (-115.4897539, 0.0003627) (115d29'23.11"W, 0d 0' 1.31"N)
Band 1 Block=974x2 Type=Byte, ColorInterp=Red
Band 2 Block=974x2 Type=Byte, ColorInterp=Green
Band 3 Block=974x2 Type=Byte, ColorInterp=Blue
I was expecting the output to contain projection information in UTM starting like this:
Coordinate System is:
PROJCS["UTM",
GEOGCS["WGS 84",
What am I doing wrong?
Thanks in advance.
JC

Related

How to convert image coordinates to UTM coordinates in Python

I labeled a part of a GeoTiff image with polygon using an annotation software which output is X,Y image coordinates (including sub-pixel ones) for each point in the polygon in XML format.
The question is how to convert these points to UTM coordinates in Python in GeoJson format.
From the GeoTiff image, I can extract the following information:
gdalinfo -mm test-area.tif
Driver: GTiff/GeoTIFF
Files: test-area.tif
Size is 1356, 1351
Coordinate System is:
PROJCRS["WGS 84 / UTM zone 11N",
BASEGEOGCRS["WGS 84",
DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4326]],
CONVERSION["UTM zone 11N",
METHOD["Transverse Mercator",
ID["EPSG",9807]],
PARAMETER["Latitude of natural origin",0,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8801]],
PARAMETER["Longitude of natural origin",-117,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8802]],
PARAMETER["Scale factor at natural origin",0.9996,
SCALEUNIT["unity",1],
ID["EPSG",8805]],
PARAMETER["False easting",500000,
LENGTHUNIT["metre",1],
ID["EPSG",8806]],
PARAMETER["False northing",0,
LENGTHUNIT["metre",1],
ID["EPSG",8807]]],
CS[Cartesian,2],
AXIS["(E)",east,
ORDER[1],
LENGTHUNIT["metre",1]],
AXIS["(N)",north,
ORDER[2],
LENGTHUNIT["metre",1]],
USAGE[
SCOPE["unknown"],
AREA["World - N hemisphere - 120°W to 114°W - by country"],
BBOX[0,-120,84,-114]],
ID["EPSG",32611]]
Data axis to CRS axis mapping: 1,2
Origin = (432390.000000000000000,3727776.000000000000000)
Pixel Size = (3.000000000000000,-3.000000000000000)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 432390.000, 3727776.000) (117d43'46.05"W, 33d41'15.97"N)
Lower Left ( 432390.000, 3723723.000) (117d43'44.94"W, 33d39' 4.38"N)
Upper Right ( 436458.000, 3727776.000) (117d41' 8.05"W, 33d41'16.87"N)
Lower Right ( 436458.000, 3723723.000) (117d41' 7.01"W, 33d39' 5.28"N)
Center ( 434424.000, 3725749.500) (117d42'26.51"W, 33d40'10.63"N)
Band 1 Block=1356x1 Type=Int16, ColorInterp=Gray
Computed Min/Max=185.000,4470.000
NoData Value=32767
Band 2 Block=1356x1 Type=Int16, ColorInterp=Undefined
Computed Min/Max=299.000,4895.000
NoData Value=32767
Band 3 Block=1356x1 Type=Int16, ColorInterp=Undefined
Computed Min/Max=276.000,5419.000
NoData Value=32767
Band 4 Block=1356x1 Type=Int16, ColorInterp=Undefined
Computed Min/Max=659.000,5466.000
NoData Value=32767

Transforming Lambert Conformal Conic to EPSG:3857

I have a map file in a tiff format that is not geo-referenced, but I know the following projection information: +proj=lcc +lon_0=10.856 +lat_0=51.322 +lat_1=42 +lat_2=57 +datum=WGS84. I would like to transform it into EPSG:3857.
In my first attempt I tried to fix four arbitrary points and perform warping
gdal_translate -a_srs "+proj=lcc +lon_0=10.856 +lat_0=51.322 +lat_1=42 +lat_2=57 +datum=WGS84" -of GTiff -gcp 19725 11865 1 56 -gcp 103755 12990 23 56 -gcp 112755 80400 23 46 -gcp 8925 78990 1 46 original.tif translated.tif
But the coordinates of the corners of the warped image where not as expected and the map was distorted.
Corner Coordinates:
Upper Left ( 1208480.629, 6678543.890) ( 10d51'21.48"E, 51d19'21.08"N)
Lower Left ( 1208480.629, 6678541.123) ( 10d51'21.48"E, 51d19'21.03"N)
Upper Right ( 1208486.180, 6678543.890) ( 10d51'21.66"E, 51d19'21.08"N)
Lower Right ( 1208486.180, 6678541.123) ( 10d51'21.66"E, 51d19'21.03"N)
Center ( 1208483.404, 6678542.507) ( 10d51'21.57"E, 51d19'21.06"N)
After reading many posts, here and elsewhere, I came to this:
Converting the UL and LR corners to x and y
cs2cs +proj=latlong +lon_0=10.856 +lat_0=51.322 +lat_1=42 +lat_2=57 +datum=WGS84 +to +init=epsg:3857
-3.63 57.28 > -404089.75 7817564.89
23.76 44.39 > 2644951.10 5525995.28
Geo-referencing the tiff
gdal_translate -a_srs "+proj=lcc +lon_0=10.856 +lat_0=51.322 +lat_1=42 +lat_2=57 +datum=WGS84" -a_ullr -404089.75 7817564.89 2644951.10 5525995.28 original.tif translated.tif
The result of gdalinfo translated.tif is as follows:
Size is 14735, 11333
Coordinate System is:
PROJCS["unnamed",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]],
PROJECTION["Lambert_Conformal_Conic_2SP"],
PARAMETER["standard_parallel_1",42],
PARAMETER["standard_parallel_2",57],
PARAMETER["latitude_of_origin",51.322],
PARAMETER["central_meridian",10.856],
PARAMETER["false_easting",0],
PARAMETER["false_northing",0],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]]]
Origin = (-404089.750000000000000,7817564.889999999664724)
Pixel Size = (206.925066168985410,-202.203265684284787)
Metadata:
AREA_OR_POINT=Area
TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
TIFFTAG_XRESOLUTION=144
TIFFTAG_YRESOLUTION=144
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( -404089.750, 7817564.890) (146d18'53.31"E, 73d27'53.56"N)
Lower Left ( -404089.750, 5525995.280) (158d45'33.92"W, 88d 1'24.64"N)
Upper Right ( 2644951.100, 7817564.890) (172d26'19.88"W, 64d26'59.68"N)
Lower Right ( 2644951.100, 5525995.280) (138d13'57.20"E, 73d22'12.76"N)
Center ( 1120430.675, 6671780.085) (161d52'17.63"W, 79d37'35.75"N)
However, the coordinates of the corners above are completely off. When I attempted to warp it, the image could become so huge that I had to stop the process after a couple of minutes.
gdalwarp -overwrite -t_srs EPSG:3857 -r near -co COMPRESS=LZW translated.tif warped.tif
The result of gdalinfo warped.tif is as follows:
Corner Coordinates:
Upper Left (-20037508.339,29704755.766) (180d 0' 0.00"W, 88d54'44.28"N)
Lower Left (-20037508.339, 9464937.842) (180d 0' 0.00"W, 64d26'59.58"N)
Upper Right (20037503.600,29704755.766) (179d59'59.85"E, 88d54'44.28"N)
Lower Right (20037503.600, 9464937.842) (179d59'59.85"E, 64d26'59.58"N)
Center ( -2.370,19584846.804) ( 0d 0' 0.08"W, 84d41'15.52"N)
What did I miss?
Let's simplify the problem: how do I geo-reference the image file without converting the projection into EPSG:3857?
The first step I took was to embed the projection info and the four corner points:
gdal_translate -a_srs "+proj=lcc +lon_0=10.856 +lat_0=51.322 +lat_1=42 +lat_2=57 +datum=WGS84" -of GTiff -gcp 0 0 -4.226944 57.35083 -gcp 14735 0 27.78 57.59555 -gcp 14735 11333 24.30917 44.06611 -gcp 0 11333 -3.537778 43.6 original.tif georeferenced.tif
In the second step I warped georeferenced.tif without specifying a target projection:
gdalwarp -overwrite -r near georeferenced.tif warped.tif
When I checked warped.tif info got the following corner coordinates:
Corner Coordinates:
Upper Left ( -4.5777770, 57.6508975) ( 10d51'21.36"E, 51d19'21.08"N)
Lower Left ( -4.5777770, 43.6558450) ( 10d51'21.36"E, 51d19'20.62"N)
Upper Right ( 26.7396454, 57.6508975) ( 10d51'22.99"E, 51d19'21.08"N)
Lower Right ( 26.7396454, 43.6558450) ( 10d51'22.99"E, 51d19'20.62"N)
I was hoping to get:
Corner Coordinates:
Upper Left (0.0, 0.0) (-4.226944, 57.35083,0)
Lower Left (0.0, 11333.0) (-3.537778, 43.6,0)
Upper Right (14735.0, 0.0) (27.78, 57.59555,0)
Lower Right (14735.0, 11333.0) (24.30917, 44.06611,0)
Are you sure you GCP's are correct? They should be in the form:
-gcp pixel line easting northing [elevation]]*
You have one GCP which suggest that your input file is at least 112755 x 80400 pixels (w x h) in size. Its possible of course, but its a large file.
I think you should combine your first attempt with your later gdalwarp step. Since gdalwarp doesn't take gcp's, and gdal_translate can't warp, it takes two steps.
You can output your first step to a VRT file, so it takes less processing and disk space.
gdal_translate -of VRT -a_srs "+proj=lcc +lon_0=10.856 +lat_0=51.322 +lat_1=42 +lat_2=57 +datum=WGS84" -gcp 19725 11865 1 56 -gcp 103755 12990 23 56 -gcp 112755 80400 23 46 -gcp 8925 78990 1 46 original.tif georeferenced.vrt
And then warp the VRT:
gdalwarp -overwrite -t_srs EPSG:3857 -r near -co COMPRESS=LZW georeferenced.vrt warped.tif

Graphing code size

I was curious if there exists a ready-made script that would provide some starting point for an ultimate code size tracker tool. To start with I'd like to be able to graph size with various optimisation options for an number of cross-compiler targets and I'm quite tempted to put this on revision timeline later as well.
So taken the output from size command:
text data bss dec hex filename
1634 0 128 1762 6e2 csv_data.o (ex libs/libxyz.a)
28 0 0 28 1c csv_data_layer.o (ex libs/libxyz.a)
1063 0 0 1063 427 http_parser.o (ex libs/libxyz.a)
1312 0 1024 2336 920 http_queries.o (ex libs/libxyz.a)
8 36 0 44 2c transport.o (ex libs/libxyz.a)
1748 0 3688 5436 153c transport_layer.o (ex libs/libxyz.a)
8 0 0 8 8 misc_allocator.o (ex libs/libxyz.a)
847 108 1 956 3bc misc_err.o (ex libs/libxyz.a)
0 4 0 4 4 misc_globals.o (ex libs/libxyz.a)
273 0 0 273 111 misc_helpers.o (ex libs/libxyz.a)
71 0 4 75 4b misc_printf.o (ex libs/libxyz.a)
1044 0 44 1088 440 misc_time.o (ex libs/libxyz.a)
3724 0 0 3724 e8c xyz.o (ex libs/libxyz.a)
627 0 0 627 273 dummy.o (ex libs/libxyz.a)
8 16 0 24 18 dummy_layer.o (ex libs/libxyz.a)
12395 164 4889 17448 4428 (TOTALS)
With most of values being different when the library is being compiled with various optimisation flags (i.e.: -Os, -O0, -O1, -O2) and a variety of cross-compilers (e.g.: AVR, MSP430, ARMv6, i386), I'd like to make a combined graph or set of graphs using either gnuplot, d3.js, matplotlib or any other package. Has anyone have a seen ready-made script which would help this partially (e.g. at least convert the above tabular format to CSV, JSON or XML) or some study paper that presents a decent visualisation example? I have to admit, it's rather hard to find this using a web search engine.
Here is a possible visualization of the data as bar chart using gnuplot. This is of course not the ultimate visualization, but should be a good starting point.
set style data histogram
set style histogram rowstacked
set style fill solid 1.0 border lc rgb "white"
set xtics rotate 90
set key outside reverse Left
set bmargin 8
plot 'file.dat' using (!(stringcolumn(6) eq "(TOTALS)") ? column(1) : 1/0):xtic(6) title columnheader(1), \
for [i=2:5] '' using (!(stringcolumn(6) eq "(TOTALS)") ? column(i) : 1/0) title columnheader(i)
With the settings set terminal pngcairo size 1000,800, this gives
You must also decide, which columns you want to use, because plotting every column for every file for every compiler will be quite messy. Maybe you want to plot only the size:
set style data histogram
set style histogram clustered
set style fill solid 1.0 noborder
set xtics rotate 90
set key outside reverse Left
set bmargin 8
plot 'file.dat' using (!(stringcolumn(6) eq "(TOTALS)") ? $4 : 1/0):xtic(6) title 'i386', \
'' using (!(stringcolumn(6) eq "(TOTALS)") ? $4*1.2 : 1/0) title 'ARMv6',\
'' using (!(stringcolumn(6) eq "(TOTALS)") ? $4*0.7 : 1/0) title 'AVR'
Which gives you:
Note, that the lengthy using statements are only to skip the last line with the TOTAL. Alternatively you could also remove this last line with head, either when generating the data files, or on-the-fly like this:
plot '< head -n -1 file.dat' using 4:xtic(6) title 'i386', \
'' using ($4*1.2) title 'ARMv6',\
'' using ($4*0.7) title 'AVR'
Of course, for your real data you would have something like
plot '< head -n -1 file-i386.dat' using 4:xtic(6) title 'i386', \
'< head -n -1 file-armv6.dat' using ($4*1.2) title 'ARMv6',\
'< head -n -1 file-avr.dat' using ($4*0.7) title 'AVR'
I hope, this gives you an idea of different visualization possiblities. What might be appropriate, you must decide by yourself.

How to Calculate Leading in PDF Document

How do I calculate leading in a PDF document?
For example:
48 0 0 48 72 677.28 Tm
(Hello World) Tj
0 -1.1075 TD
This renders the text Hello World at 48pt/57.6pt (120% line height) in Times-Roman.
According to the PDF Reference manual, "the leading parameter is measured in unscaled text space units. It specifies the vertical distance between the baselines of adjacent lines of text... The number is expressed in thousandths of a unit of text space."
Can someone please explain how 1.1075 and 57.6 are related?
You pdf commands is incorrect. I suppose you mean:
48 0 0 48 72 677.28 Tm
0 -1.1075 TD
(Hello World) Tj
This code set text coordinate system to (Tm command):
Scale x48 on x and x48 on y
Start position (72, 677.28)
Then it's move position to next line. Next line in 1.1075 "text" pixels. And then move start position by -1.1075 "text" pixels on y coordinate. Text pixel in this example it's pdf pixel multiplyed by 48. It's set by Tm command.
I may simplify you PDF code. It's the same:
48 0 0 48 72 570.096 Tm
(Hello World) Tj
Explanation: 677.28 - (1.1075*48) - (1.1075*48)
YOU should always remember that PDF it's a language. To calculate the real coordinates you shoud parse all previous commands.
There may be something like this before you commands:
10 0 0 10 0 0 cm
The leading is usually set in the PDF by the command TL, just like this:
12 TL
(El ingenioso hidalgo don Quijote de la Mancha)'
That 12 indicates a leading of 12 points until another TL is found.
I hope it helps you. I think this is the easiest way to do it :)

Where is rebol fill-pen documented (to get glow effect on a round rectangle)?

There is some discussion here about fill-pen
http://www.mail-archive.com/rebol-bounce#rebol.com/msg02019.html
But I can't see documentation about cubic, diamond, etc... effect for fill-pen in rebol's official doc ?
I'm trying to draw some round rectangle with glowing effect but don't really understand the parameters I'm playing with so I can't get exactly what I'd like (I'd like the glow effect starting from the center not from the dark left top corner):
view layout [
box 278x185 effect [ ; default box face size is 100x100
draw [
anti-alias on
; information for the next draw element (not required)
line-width 2.5 ; number of pixels in width of the border
pen black ; color of the edge of the next draw element
; fill pen is a little complex:
;fill-pen 10x10 0 90 0 1 1 0.0.0 255.0.0 255.0.255
fill-pen radial 20x20 5 55 5 5 10 0.0.0 55.0.5 55.0.5
; the draw element
box ; another box drawn as an effect
15 ; size of rounding in pixels
0x0 ; upper left corner
278x170 ; lower right corner
]
]
]
Finally I made it so not sure how I did manage to get :)
(source: reboltutorial.com)
view banner: layout/size [
;layout (window client area) size is 278x170 at the end of the spec block
at 0x0 ;put the banner on the top left corner
box 278x170 effect [ ; default box face size is 100x100
draw [
anti-alias on
; information for the next draw element (not required)
line-width 2.5 ; number of pixels in width of the border
pen black ; color of the edge of the next draw element
; fill pen is a little complex:
;fill-pen 10x10 0 90 0 1 1 0.0.0 255.0.0 255.0.255
;fill-pen radial 100x50 5 55 5 5 10 55.0.5 30.10.10 55.0.5
;fill-pen radial 100x50 5 55 5 10 10 55.0.5 30.10.10 71.0.6
fill-pen radial 100x50 5 55 5 10 10 71.0.6 30.10.10 71.0.6
; the draw element
box ; another box drawn as an effect
15 ; size of rounding in pixels
0x0 ; upper left corner
278x170 ; lower right corner
]
]
pad 30x-150
Text "Experiment" font [name: "Impact" size: 24 color: white]
image http://www.rebol.com/graphics/reb-logo.gif
] 278x170