Define a buffer/offset around shapefile

Hi friends
I have a shapefile from a city
I want to define a 10 km buffer around this shape file.
How can I define this buffer?
Thanks all

Hi Mohammad,

I am not sure what do you mean with buffer, do you want to add like a circle +10km centered in the city?

Cheers,
Martino

1 Like

Hi thanks for your response
I meen buffer around the shape of a vector file(city shape file), not specific shape like circle.
Thanks @MartinoF

Hi @Mohammad_Gh ,

So take the external shape of your shape file and an offset of +10km?

Cheers,
Martino

1 Like

Thanks, exactly yes

Hi @Mohammad_Gh

I looked around and I believe that snap does not have this functionality as it is not a trivial task.
The simplest way would probably be to write a python script that:

  1. Find the center of the city shape (or you select/set one)
  2. Find all the external points of your shape file and project them out of +10km

However if the shape file is complex find all the external point could take very long.
I will try to write a simple script and I will post it.

Cheers,
Martino

1 Like

Thanks for your response mr @MartinoF
Thanks a lot

Hi @Mohammad_Gh,

I made a small script that takes as input a shape file and an offset (the offset is not really in km as the Geographical coordinate system is not in km) and create a new shapefile containing the offset geometry.

You can find the script here: github or attached to the post (but I will only update the github one)

To execute the script you will need python 3, pyshp, numpy and matplotlib (this is only for the visualization).

This is the result from a shape file with around 40’000 points:
offset
To execute the script type:

python3 shapeoffset.py PATH_TO_YOUR_FILE.shp OFFSET_VALUE

The script will create a new file containing the offset polygon named:

PATH_TO_YOUR_FILE_offset.shp

If you want to visualize the shape before saving it add the argument --showplots=true.

Cheers,
Martino

shapeoffset.py (4.2 KB)

2 Likes

Hi @MartinoF
Thank you very much for your cooperation.
By trial and error, I was able to create the buffer.
I wish you and your team success.

yours sincerely
Mohammad

1 Like

I have S2 data i wanna do buffering 10km in same data its possible ?
If any idea please guide

I would like to create BZ like this Image Any Idea please

SNAP does not provide much vector tools.
You can create the buffer outside SNAP (e.g. in QGIS), then import it as a Shapefile and then use it as valid pixel expression to make all pixels outside the polygon transparent.

Yes, true. SNAP is not a real GIS application and does not support much vector operations.
But you could draw the circle manually once and export either as WKT or shapefile. An then you can import it into other products and use it for masking or use it in processing.

1 Like

Thank you for help…I created shapefile using geometry as shapefile and then imported shp file in existing product kindly please tell next step to complete

Sentinel you save the product, close it and open it again. You will see the imported geometry as a mask as part of the product.
Use its name in the band properties under valid pixel expression. This will remove all pixels outside the maks from the view (at least visually).