用 OGR_STYLE 标记轮廓线

问题描述 投票:0回答:1

enter image description here

我正在尝试向 DEM 等高线添加标签。

我正在使用 GDAL 3.6.2。 ,我使用 Anaconda 安装的。我有一些来自 USGS 的 DEM 数据,我使用以下方法将其作为等高线图写入 KML 文件:

gdal_contour small.tif /home/ubuntu/node/geotools/contour.kml -i 3.0 -f KML -a ELEVATION

您可以在上面的我的地图中看到它的样子:

当我在vim中打开contour.kml时,我可以看到它由以下功能组成:

<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>

显然有一个可用的样式组件,但我不确定如何使用它来添加海拔标签或自定义颜色。我怀疑 OGR_STYLE 被用来做这样的事情(https://github.com/OSGeo/gdal/issues/835)(https://gdal.org/user/ogr_sql_dialect.html#ogr-style ),但我找不到任何例子。这怎么办?

python gis gdal ogr
1个回答
0
投票

以下示例介绍了如何通过添加样式来实现此目的。我已经在 Google Earth 上测试了这个片段。

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
    <name>KmlFile</name>
    <StyleMap id="msn-pushpin">
        <Pair>
            <key>normal</key>
            <styleUrl>#sn-pushpin</styleUrl>
        </Pair>
        <Pair>
            <key>highlight</key>
            <styleUrl>#sh-pushpin</styleUrl>
        </Pair>
    </StyleMap>
    <Style id="sh-pushpin">
        <BalloonStyle>
        </BalloonStyle>
        <LineStyle>
            <color>ff0000ff</color>
            <width>1</width>
            <gx:physicalWidth>1</gx:physicalWidth>
            <gx:labelVisibility>1</gx:labelVisibility>
        </LineStyle>
    </Style>
    <Style id="sn-pushpin">
        <BalloonStyle>
        </BalloonStyle>
        <LineStyle>
            <color>ff0000ff</color>
            <width>1</width>
            <gx:physicalWidth>1</gx:physicalWidth>
            <gx:labelVisibility>1</gx:labelVisibility>
        </LineStyle>
    </Style>
    <Placemark>
        <name>My Path Name</name>
        <styleUrl>#msn-pushpin</styleUrl>
        <LineString>
            <tessellate>1</tessellate>
            <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>
</Document>
</kml>

enter image description here

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.