OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.84k stars 2.53k forks source link

OGR Style String LABEL not showing when converting to PDF from a XML composition document #2842

Closed robintw closed 4 years ago

robintw commented 4 years ago

Expected behavior and actual behavior.

I expect that configuring an ogrStyleString of LABEL(t:"Blah",s:30pt,c:#ff0000) in the composition XML for a GDAL output to PDF will label each point in the layer with the text 'Blah' in red. When I try this, I get no labels.

Steps to reproduce the problem.

  1. Download this example POINT Shapefile and extract the zip: test_points.zip
  2. Create an XML file called test.xml with the following contents:
<PDFComposition>
    <Page id="page_1">
        <DPI>72</DPI>
        <Width>841.698</Width>
        <Height>595.14</Height>
        <Georeferencing id="georeferenced">
            <SRS>EPSG:4326</SRS>
            <ControlPoint x="1"  y="1"  GeoY="50"  GeoX="-0.8"/>
            <ControlPoint x="1"  y="595.14" GeoY="50.4"  GeoX="-0.8"/>
            <ControlPoint x="841.698"  y="1"  GeoY="50"  GeoX="-0.1"/>
            <ControlPoint x="841.698"  y="595.14" GeoY="50.4"  GeoX="-0.1"/>
        </Georeferencing>
        <Content>
                <Vector dataset="test_points.shp" layer="test_points" georeferencingId="georeferenced"
                ogrStyleString='LABEL(t:"Blah",s:30pt,c:#ff0000);SYMBOL(c:#bd1b44,s:2,id:"ogr-sym-3")'>
                </Vector>
        </Content>
    </Page>
</PDFComposition>

This is an XML composition file following the documentation here. Note that the ogrStyleString for the vector layer is set to have both a LABEL and a SYMBOL.

Compile this composition file to a PDF by running python gdal_create_pdf.py test.xml out.pdf. The gdal_create_pdf.py script is provided by the GDAL authors (available here) and just creates a PDF dataset with the COMPOSITION_FILE option set to the XML file.

The resulting PDF will look like this: out.pdf. It shows two points (produced by the SYMBOL styling command), but there are no labels.

I have tried this with lots of different format strings (eg. just SYMBOL, just LABEL, both etc) and lots of different shapefiles - and I can't get any of them to work. The documentation for outputting vectors to PDFs says that LABEL feature styles are supported for POINT data. I've also tried using the exact LABEL command given in the documentation for vector PDFs LABEL(c:#000000,t:”Hello World!”,s:5g) and that doesn't seem to work either.

Operating system

OS X 10.13.6

GDAL version and provenance

GDAL 3.1.2, released 2020/07/07, installed via conda-forge

Conda package details # packages in environment at /Users/robin/anaconda3/envs/geopdf: # # Name Version Build Channel boost-cpp 1.72.0 hef959ae_2 conda-forge bzip2 1.0.8 h0b31af3_2 conda-forge c-ares 1.16.1 haf1e3a3_0 conda-forge ca-certificates 2020.6.20 hecda079_0 conda-forge cairo 1.16.0 ha8983da_1005 conda-forge certifi 2020.6.20 py37hc8dfbb8_0 conda-forge cfitsio 3.470 hdf94aef_6 conda-forge curl 7.71.1 hbdca1c0_4 conda-forge expat 2.2.9 h4a8c4bd_2 conda-forge fontconfig 2.13.1 h79c0d67_1002 conda-forge freetype 2.10.2 h8da9a1a_0 conda-forge freexl 1.0.5 h0b31af3_1002 conda-forge gdal 3.1.2 py37h85de8e7_1 conda-forge geos 3.8.1 h4a8c4bd_0 conda-forge geotiff 1.6.0 h4e9c399_1 conda-forge gettext 0.19.8.1 h46ab8bc_1002 conda-forge giflib 5.2.1 h0b31af3_2 conda-forge glib 2.65.0 h577aef8_0 conda-forge hdf4 4.2.13 h84186c3_1003 conda-forge hdf5 1.10.6 nompi_haae91d6_101 conda-forge icu 67.1 h4a8c4bd_0 conda-forge jpeg 9d h0b31af3_0 conda-forge json-c 0.13.1 h575e443_1002 conda-forge kealib 1.4.13 h40102fb_1 conda-forge krb5 1.17.1 h14dd6a4_2 conda-forge libblas 3.8.0 17_openblas conda-forge libcblas 3.8.0 17_openblas conda-forge libcurl 7.71.1 he6690cf_4 conda-forge libcxx 10.0.1 h5f48129_0 conda-forge libdap4 3.20.6 h993cace_1 conda-forge libedit 3.1.20191231 hed1e85f_1 conda-forge libev 4.33 haf1e3a3_0 conda-forge libffi 3.2.1 h4a8c4bd_1007 conda-forge libgdal 3.1.2 h6dfbaa8_1 conda-forge libgfortran 4.0.0 2 conda-forge libiconv 1.15 h0b31af3_1006 conda-forge libkml 1.3.0 h169b8f9_1011 conda-forge liblapack 3.8.0 17_openblas conda-forge libnetcdf 4.7.4 nompi_hc5b2cf3_105 conda-forge libnghttp2 1.41.0 h8a08a2b_1 conda-forge libopenblas 0.3.10 openmp_h63d9170_4 conda-forge libpng 1.6.37 hbbe82c9_1 conda-forge libpq 12.3 h489d428_0 conda-forge libspatialite 4.3.0a h231dce8_1039 conda-forge libssh2 1.9.0 h39bdce6_5 conda-forge libtiff 4.1.0 h2ae36a8_6 conda-forge libwebp-base 1.1.0 h0b31af3_3 conda-forge libxml2 2.9.10 h7fdee97_2 conda-forge llvm-openmp 10.0.1 h28b9765_0 conda-forge lz4-c 1.9.2 h4a8c4bd_1 conda-forge ncurses 6.2 hb1e8313_1 conda-forge numpy 1.19.1 py37h7e69742_0 conda-forge openjpeg 2.3.1 h254dc36_3 conda-forge openssl 1.1.1g h0b31af3_1 conda-forge pcre 8.44 h4a8c4bd_0 conda-forge pip 20.2.1 py_0 conda-forge pixman 0.38.0 h01d97ff_1003 conda-forge poppler 0.89.0 h3232a60_1 conda-forge poppler-data 0.4.9 1 conda-forge postgresql 12.3 h62ab893_0 conda-forge proj 7.1.0 h45baca5_1 conda-forge python 3.7.8 hc9dea61_1_cpython conda-forge python_abi 3.7 1_cp37m conda-forge readline 8.0 h0678c8f_2 conda-forge setuptools 49.2.1 py37hc8dfbb8_0 conda-forge shapely 1.7.0 py37hfcf0db4_3 conda-forge sqlite 3.32.3 h93121df_1 conda-forge tbb 2019.9 ha1b3eb9_1 conda-forge tiledb 2.0.8 h8973ade_0 conda-forge tk 8.6.10 hbbe82c9_0 conda-forge tzcode 2020a h0b31af3_0 conda-forge wheel 0.34.2 py_1 conda-forge xerces-c 3.2.3 h0a0444a_1 conda-forge xz 5.2.5 h0b31af3_1 conda-forge zlib 1.2.11 h0b31af3_1006 conda-forge zstd 1.4.5 h0384e3a_2 conda-forge
robintw commented 4 years ago

Apologies for opening this in error: I've just looked through the GDAL test code and realised I was using a <Vector> layer rather than a <VectorLabel> layer.

I will aim to submit a PR with a small improvement to the .xsd file for the PDF Composition XML to alert users that the entry will not display labels, regardless whether the ogrStyleString has a LABEL entry in it.