# Pygmt.grdcontour - Dump contours as data line segments (?)

**URL:** <https://forum.generic-mapping-tools.org/t/pygmt-grdcontour-dump-contours-as-data-line-segments/3984>\
**Category:** PyGMT Q&A\
**Created:** [June 1, 2023, 2:16pm UTC](https://forum.generic-mapping-tools.org/t/pygmt-grdcontour-dump-contours-as-data-line-segments/3984 "2023-06-01T14:16:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrebelem](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/andrebelem/32/1218_2.png) [@andrebelem](https://forum.generic-mapping-tools.org/u/andrebelem)\
**Post date:** [June 1, 2023, 2:16pm UTC](https://forum.generic-mapping-tools.org/t/pygmt-grdcontour-dump-contours-as-data-line-segments/3984/1 "2023-06-01T14:16:15Z")

</div>

Hello fellow Pygmtnians,  
Checking pygmt’s grdcontour documentation, I noticed that it doesn’t have the (fantastic!) option to Dump contours as data line segments, as a file or as an array. Is that right or does it exist and I didn’t find it?  
Cheers

---

<div class="post-metadata">

**Author:** ![yvonnefroehlich](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/yvonnefroehlich/32/5064_2.png) [@yvonnefroehlich](https://forum.generic-mapping-tools.org/u/yvonnefroehlich)\
**Post date:** [June 1, 2023, 9:27pm UTC](https://forum.generic-mapping-tools.org/t/pygmt-grdcontour-dump-contours-as-data-line-segments/3984/2 "2023-06-01T21:27:33Z")

</div>

Hello @andrebelem,

so far no alias for the **D** flag of `grdcontour` is available in PyGMT.

In the meanwhile, you can try using **D** itself to write the contour lines as data line segments to a text file. Please note, I did not check in detail, whether all functionality, which is documented in the upstream GMT documentation ([https://docs.generic-mapping-tools.org/latest/grdcontour.html#d](https://docs.generic-mapping-tools.org/latest/grdcontour.html#d)) is available.

```python
import pygmt

study_region = [0, 20, 40, 50]

# Download Earth relief data
grid_relief = pygmt.datasets.load_earth_relief(
    region=study_region,
    resolution="15m",
    registration="gridline",
)

# Create new figure intance
fig = pygmt.Figure()

fig.grdcontour(
    projection="M10c",
    region=study_region,
    frame=True,
    grid=grid_relief,
    interval=500,
    # Write contour lines to txt file, do NOT plot something
    D="export_contours_relief.txt",
)

```

---

<div class="post-metadata">

**Author:** ![andrebelem](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/andrebelem/32/1218_2.png) [@andrebelem](https://forum.generic-mapping-tools.org/u/andrebelem)\
**Post date:** [June 2, 2023, 4:21pm UTC](https://forum.generic-mapping-tools.org/t/pygmt-grdcontour-dump-contours-as-data-line-segments/3984/3 "2023-06-02T16:21:11Z")

</div>

> [@yvonnefroehlich](#):
>
> `fig = pygmt.Figure()`

Cool ! Many thans @yvonnefroehlich. It worked !
