Re: [gdal-dev] Convert alpha to nodata?

2024-01-19 Thread Even Rouault via gdal-dev

Hi Rob,

I can't think an easy way of doing what you want.

Well, you can definitely do that using a VRT Python pixel function, that 
would essentially do your --calc expression


Cf 
https://gdal.org/drivers/raster/vrt.html#using-derived-bands-with-pixel-functions-in-python


The example of 
https://gdal.org/drivers/raster/vrt.html#vrt-that-adds-2-or-more-rasters 
is probably the closest starting point. (you can add  to the 
's to specify bands 1 and 4)


A nice exercice for (Pythonist) contributors would be to add a -f VRT 
capability to gdal_calc.py that would essentially automate the writing 
of such VRT using Python pixel functions. Just saying...


Even

Le 19/01/2024 à 17:40, Robert Coup via gdal-dev a écrit :

Maybe it's just Friday, but I could use a pointer here :-)

My input raster is a RGBA byte image, where the alpha channel value is 
0 or 255 (ie: effectively a mask). The output is ideally a VRT file, 
RGB with Int16 data type, using nodata=-1.


So I want to convert the alpha channel to a nodata value.

The alpha/nodata/mask/band options to translate/warp haven't got me 
very far, neither has hand-crafting various UseMaskBand/MaskBand 
elements in a VRT.


I can do it to concrete tif files with something like this, 
repeating for R,G,B and merge the output bands together, but it's a 
lot of processing.


  gdal_calc.py -A src.tif -B src.tif \
    --outfile out_b1.tif --co TILED=YES --type=Int16 --NoDataValue=-1 \
    --A_band=1 --B_band=4 --calc="where(B >= 128, A, -1)"

I feel like I'm probably missing a simpler path? (Which I will 
definitely add to an Examples section somewhere)


Thanks,

Rob :)

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


--
http://www.spatialys.com
My software is free, but my time generally not.

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


[gdal-dev] Convert alpha to nodata?

2024-01-19 Thread Robert Coup via gdal-dev
Maybe it's just Friday, but I could use a pointer here :-)

My input raster is a RGBA byte image, where the alpha channel value is 0 or
255 (ie: effectively a mask). The output is ideally a VRT file, RGB with
Int16 data type, using nodata=-1.

So I want to convert the alpha channel to a nodata value.

The alpha/nodata/mask/band options to translate/warp haven't got me very
far, neither has hand-crafting various UseMaskBand/MaskBand elements in a
VRT.

I can do it to concrete tif files with something like this, repeating for
R,G,B and merge the output bands together, but it's a lot of processing.

  gdal_calc.py -A src.tif -B src.tif \
--outfile out_b1.tif --co TILED=YES --type=Int16 --NoDataValue=-1 \
--A_band=1 --B_band=4 --calc="where(B >= 128, A, -1)"

I feel like I'm probably missing a simpler path? (Which I will definitely
add to an Examples section somewhere)

Thanks,

Rob :)
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] Fields of type List to simple fields with N times the feature?

2024-01-19 Thread Even Rouault via gdal-dev
Actually, an alternative would be that you type your list fields with 
type=OFTString and subtype=OFSTJSon, and emit a serialized JSON array 
(``[1,2]``). This is probably more in the spirit of nowadays uses, and 
that should make all output drivers happy (at worse they won't 
understand the JSON hint)


--
http://www.spatialys.com
My software is free, but my time generally not.
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] Fields of type List to simple fields with N times the feature?

2024-01-19 Thread Even Rouault via gdal-dev


Le 19/01/2024 à 16:54, Abel Pau via gdal-dev a écrit :


Hello,

we have tried to generate some layers from MiraMon to SHP, KML, or 
GPKG, and we have noticed that they do not support "List" field cases. 
They give a warning like: "The output driver does not seem to natively 
support IntegerList type for field “XX”.


It could be interesting if a driver could output a feature with "List" 
type fields as the same feature repeated as many times as the elements 
in the List, if the user requests it (via –lco). This would be 
beneficial to avoid losing elements from fields that are of type List.


The current implementation generates an IntegerList, but this 
modification could be done.


As we want to export the information somehow, even if it's not 
perfect, we are wondering which of these solutions we can apply:


1. (preferable) export N objects, each with a single attribute, not as 
an "IntegerList" but as N "Integer/Float, etc" objects.


2. export a single object with a single attribute (which could be 
chosen with a -lco).


However, we are wondering how we should handle the GetFeatureCount() 
function in case 1 (from the above).


And we also wonder how to handle the GetNextRawFeature() function. 
Since this function can indicate that it has returned more than one 
element (in case 1).


Don't complicate your driver. This is just a usage issue of ogr2ogr. As 
hinted by it, you need to pass for example -mapFieldType 
IntegerList=String to ask ogr2ogr to transform IntegerLst fields into string



$ cat test.json
{
"type": "FeatureCollection",
"name": "test",
"features": [
{ "type": "Feature", "properties": { "id": 1, "attr": [2,3] }, 
"geometry": null }

]
}

$ ogr2ogr out.shp test.json -mapFieldType IntegerList=String

$ ogrinfo out.shp -al -q

Layer name: out
Metadata:
  DBF_DATE_LAST_UPDATE=2024-01-19
OGRFeature(out):0
  id (Integer) = 1
  attr (String) = (2:2,3)

Even


Thanks for taking it in consideration.

*Abel Pau Garcia*

*GIS developer*



https://www.creaf.cat/sites/default/files/creaf-signature.png

*a@creaf.uab.cat* 

*Let's chat on Teams!* 



*Tel. +34 934814277*



https://www.creaf.cat/sites/default/files/so-en-signature.png

https://www.creaf.cat/sites/default/files/twitter-icon-signature.png 
https://www.creaf.cat/sites/default/files/linkedin-icon-signature.png 
https://www.creaf.cat/sites/default/files/youtube-icon-signature.png 
https://www.creaf.cat/sites/default/files/instagram-icon-signature.png 



*www.creaf.cat* *| **http://blog.creaf.cat* 





https://www.creaf.cat/sites/default/files/uab_logo_signatura.png

CREAF. Campus UAB. Edifici C. 08193 Bellaterra (Barcelona)


Before printing this electronic message, think about the environment.

http://www.creaf.uab.cat/_signatura/line.gif


___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


--
http://www.spatialys.com
My software is free, but my time generally not.
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


[gdal-dev] Fields of type List to simple fields with N times the feature?

2024-01-19 Thread Abel Pau via gdal-dev
Hello,

we have tried to generate some layers from MiraMon to SHP, KML, or GPKG, and we 
have noticed that they do not support "List" field cases. They give a warning 
like: "The output driver does not seem to natively support IntegerList type for 
field "XX".

It could be interesting if a driver could output a feature with "List" type 
fields as the same feature repeated as many times as the elements in the List, 
if the user requests it (via -lco). This would be beneficial to avoid losing 
elements from fields that are of type List.

The current implementation generates an IntegerList, but this modification 
could be done.

As we want to export the information somehow, even if it's not perfect, we are 
wondering which of these solutions we can apply:
1. (preferable) export N objects, each with a single attribute, not as an 
"IntegerList" but as N "Integer/Float, etc" objects.
2. export a single object with a single attribute (which could be chosen with a 
-lco).

However, we are wondering how we should handle the GetFeatureCount() function 
in case 1 (from the above).
And we also wonder how to handle the GetNextRawFeature() function. Since this 
function can indicate that it has returned more than one element (in case 1).

Thanks for taking it in consideration.


Abel Pau Garcia
GIS developer
[https://www.creaf.cat/sites/default/files/creaf-signature.png]
a@creaf.uab.cat
Let's chat on 
Teams!
Tel. +34 934814277
[https://www.creaf.cat/sites/default/files/so-en-signature.png]
[https://www.creaf.cat/sites/default/files/twitter-icon-signature.png][https://www.creaf.cat/sites/default/files/linkedin-icon-signature.png][https://www.creaf.cat/sites/default/files/youtube-icon-signature.png][https://www.creaf.cat/sites/default/files/instagram-icon-signature.png]
www.creaf.cat | http://blog.creaf.cat
[https://www.creaf.cat/sites/default/files/uab_logo_signatura.png]
CREAF. Campus UAB. Edifici C. 08193 Bellaterra (Barcelona)

Before printing this electronic message, think about the environment.



___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] gdal2tiles custom tms configuration not found

2024-01-19 Thread Andreas Neumann via gdal-dev



Hi Even,

Thank you - that explains it. I will probably switch to some other tools 
then - maybe MapProxy. I wanted to use this custom tms configuration 
from Swisstopo - to stay compatible with their web services.


Thank you for adding a better error output!

Andreas

On 2024-01-19 13:08, Even Rouault wrote:


Andreas,

the reason is that the resolution of some consecutive levels in your 
custom TMS files is not varying by a factor of 2, which gdal2tiles 
doesn't support at the moment (debug message just added in master to 
help diagnose)


Even

Le 19/01/2024 à 11:36, Andreas Neumann via gdal-dev a écrit :


Hi,

I would like to use gdal2tiles with a custom tms profile file. I 
prepared the json file attached in this mail and put this json file in 
the /usr/share/gdal folder, there there are already other such files, 
e.g. from New Zealand or Antartica.


However, when I try to use this custon tms config, gdal2tiles tells me 
it can't find this profile. Here is my command I used:


gdal2tiles.py -p 2056_28 -z 16 -w openlayers -t "Swiss Hillshading 
Grayscale" -r cubic -s EPSG:2056 -a 0.0 -e -n 
lv_16_switzerland_hillshading_small-scale_swissalti3d-srtm_100m_jpeg.tif 
tiles


Do I need to register the custom TMS config json file somewhere in 
addition to copying it to the /usr/share/gdal directory?


Thank you for your help!

Andreas

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] gdal2tiles custom tms configuration not found

2024-01-19 Thread Even Rouault via gdal-dev

Andreas,

the reason is that the resolution of some consecutive levels in your 
custom TMS files is not varying by a factor of 2, which gdal2tiles 
doesn't support at the moment (debug message just added in master to 
help diagnose)


Even

Le 19/01/2024 à 11:36, Andreas Neumann via gdal-dev a écrit :


Hi,

I would like to use gdal2tiles with a custom tms profile file. I 
prepared the json file attached in this mail and put this json file in 
the /usr/share/gdal folder, there there are already other such files, 
e.g. from New Zealand or Antartica.


However, when I try to use this custon tms config, gdal2tiles tells me 
it can't find this profile. Here is my command I used:


gdal2tiles.py -p 2056_28 -z 16 -w openlayers -t "Swiss Hillshading 
Grayscale" -r cubic -s EPSG:2056 -a 0.0 -e -n 
lv_16_switzerland_hillshading_small-scale_swissalti3d-srtm_100m_jpeg.tif 
tiles


Do I need to register the custom TMS config json file somewhere in 
addition to copying it to the /usr/share/gdal directory?


Thank you for your help!

Andreas


___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


--
http://www.spatialys.com
My software is free, but my time generally not.

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] gdal2tiles custom tms configuration not found

2024-01-19 Thread Rahkonen Jukka via gdal-dev
Hi,

Support has been added in https://github.com/OSGeo/gdal/pull/2757/files and PR 
seems to include some tests.

-Jukka Rahkonen-

Lähettäjä: gdal-dev  Puolesta Andreas Neumann 
via gdal-dev
Lähetetty: perjantai 19. tammikuuta 2024 13.03
Vastaanottaja: Andreas Neumann 
Kopio: gdal dev 
Aihe: Re: [gdal-dev] gdal2tiles custom tms configuration not found


Hi,

Just found 
https://github.com/OSGeo/gdal/blob/master/swig/python/gdal-utils/osgeo_utils/gdal2tiles.py#L272
 where it seems to look for all files following the naming scheme "tms_*.json". 
Therefore I don't know why my custom tms configuration files is not found - any 
ideas?

My custom tms json file also has an identifier set to '2056_28'.

Here is the error message I get:
gdal2tiles.py: error: option -p: invalid choice: '2056_28' (choose from 
'mercator', 'geodetic', 'raster', 'LINZAntarticaMapTilegrid', 'APSTILE')

Andreas



On 2024-01-19 11:36, Andreas Neumann via gdal-dev wrote:

Hi,

I would like to use gdal2tiles with a custom tms profile file. I prepared the 
json file attached in this mail and put this json file in the /usr/share/gdal 
folder, there there are already other such files, e.g. from New Zealand or 
Antartica.

However, when I try to use this custon tms config, gdal2tiles tells me it can't 
find this profile. Here is my command I used:

gdal2tiles.py -p 2056_28 -z 16 -w openlayers -t "Swiss Hillshading Grayscale" 
-r cubic -s EPSG:2056 -a 0.0 -e -n 
lv_16_switzerland_hillshading_small-scale_swissalti3d-srtm_100m_jpeg.tif tiles

Do I need to register the custom TMS config json file somewhere in addition to 
copying it to the /usr/share/gdal directory?

Thank you for your help!

Andreas

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] gdal2tiles custom tms configuration not found

2024-01-19 Thread Andreas Neumann via gdal-dev



Hi,

Just found 
https://github.com/OSGeo/gdal/blob/master/swig/python/gdal-utils/osgeo_utils/gdal2tiles.py#L272 
where it seems to look for all files following the naming scheme 
"tms_*.json". Therefore I don't know why my custom tms configuration 
files is not found - any ideas?


My custom tms json file also has an identifier set to '2056_28'.

Here is the error message I get:
gdal2tiles.py: error: option -p: invalid choice: '2056_28' (choose from 
'mercator', 'geodetic', 'raster', 'LINZAntarticaMapTilegrid', 'APSTILE')


Andreas

On 2024-01-19 11:36, Andreas Neumann via gdal-dev wrote:


Hi,

I would like to use gdal2tiles with a custom tms profile file. I 
prepared the json file attached in this mail and put this json file in 
the /usr/share/gdal folder, there there are already other such files, 
e.g. from New Zealand or Antartica.


However, when I try to use this custon tms config, gdal2tiles tells me 
it can't find this profile. Here is my command I used:


gdal2tiles.py -p 2056_28 -z 16 -w openlayers -t "Swiss Hillshading 
Grayscale" -r cubic -s EPSG:2056 -a 0.0 -e -n 
lv_16_switzerland_hillshading_small-scale_swissalti3d-srtm_100m_jpeg.tif 
tiles


Do I need to register the custom TMS config json file somewhere in 
addition to copying it to the /usr/share/gdal directory?


Thank you for your help!

Andreas
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


[gdal-dev] gdal2tiles custom tms configuration not found

2024-01-19 Thread Andreas Neumann via gdal-dev



Hi,

I would like to use gdal2tiles with a custom tms profile file. I 
prepared the json file attached in this mail and put this json file in 
the /usr/share/gdal folder, there there are already other such files, 
e.g. from New Zealand or Antartica.


However, when I try to use this custon tms config, gdal2tiles tells me 
it can't find this profile. Here is my command I used:


gdal2tiles.py -p 2056_28 -z 16 -w openlayers -t "Swiss Hillshading 
Grayscale" -r cubic -s EPSG:2056 -a 0.0 -e -n 
lv_16_switzerland_hillshading_small-scale_swissalti3d-srtm_100m_jpeg.tif 
tiles


Do I need to register the custom TMS config json file somewhere in 
addition to copying it to the /usr/share/gdal directory?


Thank you for your help!

Andreas

tms_Swisstopo_2056_28.json
Description: application/json
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev