Water/Blend Masking using shapefile

Kelvin Richardson

Resource contributor
#1
Hi anyone that can help,

I am looking for a way to clip an fs earth tile bmp file using a shape file to avoid having to manually apply water and blend masks.

I really hope there is an easier way.

Now the bmp file is not a geotif so no coordinates but I'm hoping someone can steer me in the direction of some useful instructions.
Thanks
Kelvin
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
#2
Hi,

It won't help you much now, but I have some scenproc features in development that will help with this. I only never tested them with FSET input, but it should work I think. I hope to get some of these features out in not too long.
 

Kelvin Richardson

Resource contributor
#3
Hi,

It won't help you much now, but I have some scenproc features in development that will help with this. I only never tested them with FSET input, but it should work I think. I hope to get some of these features out in not too long.
Thanks Arno,
I am undertaking a massive task for a freeware New Zealand photorealism and I have hundreds of tiles, it would be great to move away from the ancient way of Masking and have a smarter and more intuitive method.

Keep me posted as I would love to try out these alpha features.
 

Kelvin Richardson

Resource contributor
#4
Hi,

It won't help you much now, but I have some scenproc features in development that will help with this. I only never tested them with FSET input, but it should work I think. I hope to get some of these features out in not too long.
Hi Arno,

Has there been any progress on being able to create water/blend masks using shapefiles for photo scenery?
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
#5
Hi,

This feature is still not released. I have been working on it the last weeks, since I needed it for a project I'm working on. But I'm not clear yet when it will be released.
 

dave hoeffgen

Resource contributor
#9
Could you share with me how to do this? I use Global Mapper and QGis and i'm having trouble converting the shapefiles to Raster.
My trick:
As you can geo reference images in QGis I create a black one, reference it to cover the entire world and call it "globalsource.tif". Why? I need an input file because I didn't get along with the creation option.
Next I use gdalwarp.exe (see documentation: https://gdal.org/gdalwarp.html) to crop an image out of "globalsource.tif" that matches my aerial imagery exactly regarding georeference and resolution.
Last I use gdal_rasterize.exe (documentation: https://gdal.org/gdal_rasterize.html) to rasterize the information from the shapefile into the image.

It is advisable to write a batch file for the gdal steps. I use them directly through command line, not via QGis.

Alternatively, if your imagery has an alpha channel you can skip the first two steps and directly rasterize your water mask into the image's alpha channel.
The alpha channel is where resample.exe looks for the water mask by default anyway, if you don't specify a "Channel_LandWaterMask = ..." entry.
 

Kelvin Richardson

Resource contributor
#10
My trick:
As you can geo reference images in QGis I create a black one, reference it to cover the entire world and call it "globalsource.tif". Why? I need an input file because I didn't get along with the creation option.
Next I use gdalwarp.exe (see documentation: https://gdal.org/gdalwarp.html) to crop an image out of "globalsource.tif" that matches my aerial imagery exactly regarding georeference and resolution.
Last I use gdal_rasterize.exe (documentation: https://gdal.org/gdal_rasterize.html) to rasterize the information from the shapefile into the image.

It is advisable to write a batch file for the gdal steps. I use them directly through command line, not via QGis.

Alternatively, if your imagery has an alpha channel you can skip the first two steps and directly rasterize your water mask into the image's alpha channel.
The alpha channel is where resample.exe looks for the water mask by default anyway, if you don't specify a "Channel_LandWaterMask = ..." entry.
Thanks very much Dave. Would you mind me asking further questions if I get stuck?
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
#12
Hi,

gdal_rasterize can make the GeoTIFF file for you as well (if you use a recent version). With -te you specify the extends (lat/lon) and with -tr you can specify the resolution you want or with -ts the size. Here is an example I use:

Code:
gdal_rasterize -te -127.99 22.76 -65.26 51.65 -tr 0.01 0.01 -burn 1 -ot Byte myfile.shp myfile.tif
 

Kelvin Richardson

Resource contributor
#13
Hi,

gdal_rasterize can make the GeoTIFF file for you as well (if you use a recent version). With -te you specify the extends (lat/lon) and with -tr you can specify the resolution you want or with -ts the size. Here is an example I use:

Code:
gdal_rasterize -te -127.99 22.76 -65.26 51.65 -tr 0.01 0.01 -burn 1 -ot Byte myfile.shp myfile.tif
Thanks Arno! Is there a way to use the extents in the shape file?
 

Kelvin Richardson

Resource contributor
#14
Hi Dave,

Can you give me a breakdown of the process below that you noted as I have the Tif file with RGB channels and the correct projection all done.
"Next I use gdalwarp.exe (see documentation httpsgdal.orggdalwarp.html) to crop an image out of globalsource.tif that matches my aerial imagery exactly regarding georeference and resolution."

The bit i'm concerned about is now getting matching tiles with my BMP aerial imagery then doing the masking thing, this is where i'm a little lost.

Thanks in advance.
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
#15
Thanks Arno! Is there a way to use the extents in the shape file?
I assume that normally you want to match the extends of your images for the water/blend mask and not those of your SHP that might cover a different area.

According to the gdal_rasterize documentation it will use the shp extends if you don't provide the -te option. So probably if you use only -tr or -ts it should pick the extends from the SHP.
 

dave hoeffgen

Resource contributor
#16
Hi Dave,

Can you give me a breakdown of the process below that you noted as I have the Tif file with RGB channels and the correct projection all done.
"Next I use gdalwarp.exe (see documentation httpsgdal.orggdalwarp.html) to crop an image out of globalsource.tif that matches my aerial imagery exactly regarding georeference and resolution."

The bit i'm concerned about is now getting matching tiles with my BMP aerial imagery then doing the masking thing, this is where i'm a little lost.

Thanks in advance.
Do you know your bmp's extents?
 

Kelvin Richardson

Resource contributor
#17
Do you know your bmp's extents?
yes I do. I still seem to be having some issues. When resampling the image comes out transparent in Prepar3d. I'll get the steps i've taken and post them here with screenshots so hopefully I can get some assistance. I feel like i'm close.

Is there any good info on how to make the water mask colours in the output.Tiff file?
 

Kelvin Richardson

Resource contributor
#18
Ok, Arno and Dave, I have had a breakthrough with this and have 100% success now converting shape files to rasters while maintaining projection as well as editing masks in photoshop using the rasters and subsequently resampling into Prepar3d. Many hours trying to understand how this works and now have a repeatable process. If you want to see how I did this let me know and I can explain my steps. In fact I have documented my process. Thanks for the initial help. The rasters act as my water and blend masks which will save me many months of manual work.
 

dave hoeffgen

Resource contributor
#19
Ok, Arno and Dave, I have had a breakthrough with this and have 100% success now converting shape files to rasters while maintaining projection as well as editing masks in photoshop using the rasters and subsequently resampling into Prepar3d. Many hours trying to understand how this works and now have a repeatable process. If you want to see how I did this let me know and I can explain my steps. In fact I have documented my process. Thanks for the initial help. The rasters act as my water and blend masks which will save me many months of manual work.
Of course I'd like to see how you were doing it and how the result looks ;)
 

Kelvin Richardson

Resource contributor
#20
Here's some initial work, took me about 20 minutes to do (once my process was ironed out). i'm going to refine the edges but all in all i am happy. Now to do the rest of New Zealand. Yup, I'm doing the whole country. I also have autogen I made some time back using shape files also so should look pretty good. I do need to find a way to remove the clouds from the images though.
 

Attachments

Top