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