# How to drop the Z-dim of a shape file

**URL:** <https://discourse.julialang.org/t/how-to-drop-the-z-dim-of-a-shape-file/91390>\
**Category:** Geo\
**Created:** [December 7, 2022, 8:54pm UTC](https://discourse.julialang.org/t/how-to-drop-the-z-dim-of-a-shape-file/91390 "2022-12-07T20:54:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luraess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luraess/32/16189_2.png) [@luraess](https://discourse.julialang.org/u/luraess)\
**Post date:** [December 7, 2022, 8:54pm UTC](https://discourse.julialang.org/t/how-to-drop-the-z-dim-of-a-shape-file/91390/1 "2022-12-07T20:54:04Z")

</div>

I would like to rasterise and draw border of a polygon from a Shapefile as in [this example](https://rafaqz.github.io/Rasters.jl/dev/#Plotting) from `Rasters.jl`.

I load my Shapefile as following

```julia
julia> vd_bord = Shapefile.Handle("data/Shapefiles/Vaud.shp").shapes[1]
Shapefile.PolygonZ(Shapefile.Rect(494319.65625, 115136.65125000104, 585425.3537500016, 198589.62999999896), Int32[0, 1615, 1633, 1663], Shapefile.Point[Shapefile.Point(519503.5712499991, 176197.8575000018), Shapefile.Point(519799.44249999896, 176509.0162499994), Shapefile.Point(519919.7650000006, 176744.0450000018), Shapefile.Point(519980.78500000015, 176863.1887499988), Shapefile.Point(519971.28125, 177153.04374999925), Shapefile.Point(519748.66750000045, 177428.7412500009), Shapefile.Point(520216.8062499985, 177940.73999999836), Shapefile.Point(520693.0062500015, 178248.2674999982), Shapefile.Point(520965.76000000164, 178169.1712500006), Shapefile.Point(521062.1087500006, 178194.1950000003) … Shapefile.Point(551995.2474999987, 176404.64375000075), Shapefile.Point(551935.2474999987, 176374.6424999982), Shapefile.Point(551815.245000001, 176284.6387500018), Shapefile.Point(551755.245000001, 176264.63749999925), Shapefile.Point(551656.2412500009, 176217.63500000164), Shapefile.Point(551495.2462499999, 176400.63500000164), Shapefile.Point(551038.2274999991, 176067.625), Shapefile.Point(550923.2375000007, 176332.625), Shapefile.Point(550798.2287500016, 176179.62124999985), Shapefile.Point(550702.2312499993, 176260.62124999985)], Shapefile.Interval(-1.4551915228366852e-11, -1.4551915228366852e-11), [-1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11 … -1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11, -1.4551915228366852e-11], Shapefile.Interval(-1.7976931348623157e308, -1.7976931348623157e308), [-1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308 … -1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308, -1.7976931348623157e308])

```

Then `rastserize` it as following (`dim` I get from a geotif file that has correct extent)

```julia
vd = rasterize(vd_border; to=dim, missingval=-9999, fill=1, order=(X, Y), shape=:polygon, boundary=:touches)

```

Plotting `vd` looks good:

`p = plot(vd)`

 ![Screenshot 2022-12-07 at 21.52.33](https://global.discourse-cdn.com/julialang/original/3X/3/b/3b4017cb83b80bdccd9e8d88606ba491bd9a5af8.png)

But when I try adding the border, then it shows a buggy behaviour:

`plot!(p, vd_border; fillalpha=0, linewidth=0.6)`

 ![Screenshot 2022-12-07 at 21.52.59](https://global.discourse-cdn.com/julialang/original/3X/3/5/3550c77350969344b596d0b579f41872e27dd990.png)

I guess it’s because my polygon `vd_border` has a Z-dim

```julia
julia> GeoInterface.extent(vd_border)
Extent(X = (494319.65625, 585425.3537500016), Y = (115136.65125000104, 198589.62999999896), Z = (-1.4551915228366852e-11, -1.4551915228366852e-11))

```

Any hint how I could drop the Z-dim of the polygon? Thanks

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [December 7, 2022, 10:20pm UTC](https://discourse.julialang.org/t/how-to-drop-the-z-dim-of-a-shape-file/91390/2 "2022-12-07T22:20:46Z")

</div>

I’m not sure there is an easy way to drop the third dimension (but there could be something like `GeoInterface.dropz` or similar).

If you post your shapefile here we can work out one of the more difficult ways of doing it.
