[gdal-dev] Fwd: How to add labels to DEM contour lines

Cainã K. Campos rupestre.campos at gmail.com
Thu Jul 18 10:20:23 PDT 2024


While OGR_STYLE works for setting the color I have not seen it working for
setting LABEL neither with pdf nor with kml (not sure how it would appear
thought)
I attach a small.tif elevation raster and bellow commands used to create
contour and try to set style via OGR_STYLE.
Could anyone more experienced check if LABEL is indeed working and how to
do it?

gdal_contour small.tif small_contour.geojson -i 50.0 -f GeoJSON -a ELEVATION

ogr2ogr -f KML small_contour_label.kml small_contour.geojson -sql "SELECT
ELEVATION, 'PEN(c:#FFFF00FF);LABEL(t:{ELEVATION})' AS OGR_STYLE FROM
contour"

The PEN is correctly applied but Label I could not make to work. :'(


On Thu, Jul 18, 2024 at 1:32 PM Kirk Waters - NOAA Federal via gdal-dev <
gdal-dev at lists.osgeo.org> wrote:

> KC,
> I looked into this a few years ago, so things may have changed. A write-up
> of what I did with both kmz and pdf is at
> https://geozoneblog.wordpress.com/2021/12/09/dav-new-products/ with the
> details toward the bottom. It might be that you'd need to add a layer to
> the kmz with a point and label where you want them.
>
> Kirk Waters, PhD
> NOAA Office for Coastal Management
> Applied Sciences Program
> coast.noaa.gov/digitalcoast
>
>
>
>
> On Thu, Jul 18, 2024 at 11:50 AM Open Land LLC via gdal-dev <
> gdal-dev at lists.osgeo.org> wrote:
>
>> Hi Everyone,
>>
>> I just wanted to ask - Is this the right place to post questions? I put
>> in a post several days ago, and just want to make sure I'm putting it in
>> the right place, because I have not posted to this group before. Thank you
>> - KC
>>
>> ---------- Forwarded message ---------
>> From: Open Land LLC <realoption11 at gmail.com>
>> Date: Mon, Jul 15, 2024 at 9:00 PM
>> Subject: How to add labels to DEM contour lines
>> To: <gdal-dev at lists.osgeo.org>
>>
>>
>> Hi everyone, this is my first post. I've also posted this to
>> https://stackoverflow.com/questions/78751101/labelling-contour-lines-with-ogr-style
>>
>> I'm trying to add labels to DEM contour lines.
>>
>> I'm working with GDAL 3.6.2. , which I installed using Anaconda . I have
>> some DEM data from USGS which I wrote as a contour map to a KML file using:
>>
>>     gdal_contour small.tif /home/ubuntu/node/geotools/contour.kml -i 3.0
>> -f KML -a ELEVATION
>>
>> When I open contour.kml in vim, I can see that its made up of features
>> like:
>>
>> <Placemark>
>>
>> <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
>> <ExtendedData><SchemaData schemaUrl="#contour">
>> <SimpleData name="ID">39</SimpleData>
>> <SimpleData name="ELEVATION">525</SimpleData>
>> </SchemaData></ExtendedData>
>> <LineString><coordinates>-89.2626638689733,46.1525006611575
>> -89.262663868958,46.1525469572921 -89.2627325352002,46.152622208059
>> -89.2628251277396,46.1526266807347 -89.2629177202847,46.1526141000471
>> -89.2629982621728,46.1525469573863
>> -89.2629982621882,46.1525006612516</coordinates></LineString>
>> </Placemark>
>>
>> Clearly there is a style component available , but I'm not sure how to
>> work with it to add elevation labels or custom colours. My suspicion is
>> that OGR_STYLE is used to do things like this (
>> https://github.com/OSGeo/gdal/issues/835)(https://gdal.org/user/ogr_sql_dialect.html#ogr-style
>> ), but I can't find any examples. How can this be done?
>>
>> Thank you very much,
>>
>> KC
>>
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20240718/53853423/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: small.tif
Type: image/tiff
Size: 54768 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20240718/53853423/attachment-0001.tif>


More information about the gdal-dev mailing list