mapnik / mapnik-support

Use the issues queue here to ask questions and offer help on using Mapnik (maybe if this works well we can retire the mailing list at http://mapnik.org/contact/?)
6 stars 6 forks source link

How to symbolize text with mapnik3 #109

Open giantchen2012 opened 6 years ago

giantchen2012 commented 6 years ago

Guys, I'm using mapnik3 in python3, and unfortunately found that TextSymbolizer and ShieldSymbolizer has no support in python3, so any alternative solution?

image

How to show the name of these points??

talaj commented 6 years ago

Unfortunately these symbolizers are not well covered by current Python bindings, but you can style them in the XML style.

giantchen2012 commented 6 years ago

Alright, but how can i programmatically use apply style in xml to each point? BTW any plan for this issue?

talaj commented 6 years ago

Can you be more precise, please? I cannot imagine what exactly you want to do.

BTW any plan for this issue?

I have plans, but no time or energy.

giantchen2012 commented 6 years ago

@talaj ,great appreciate for your quick reply. In my case, all the points was generated in my program dynamically.More specifically, I want to find points in ten miles around the point where my mouse clicked and show them off with specified icon and text.

talaj commented 6 years ago

I think there is more ways how to do that. If you are using Postgis, you can simply mark geometries around some point by query such as this:

select geometry, ST_Distance(geometry, 'SRID=my_srid;POINT(my_x my_y)'::geometry) < my_distance as highlight from my_geom_table

You can prepare an XML file with following style definition:

<Style name="my_points">
    <Rule>
        <Filter>[highlight]</Filter>
            ... highlighted style ...
    </Rule>
    <Rule>
        <ElseFilter />
            ... normal style ...
    </Rule>
</Style>

Then load the XML and create Layer programatically like in the following test: https://github.com/mapnik/python-mapnik/blob/8481096ebaa94e907a505c1dc6bebec4294ab19f/test/python_tests/postgis_test.py#L1022-L1026


Simplest way from point of Mapnik is to emit XML style with required properties programmatically, and then just load it with Mapnik.


Another way how to achieve this could be render-time variables. These can be used in queries, like in this test: https://github.com/mapnik/python-mapnik/blob/master/test/python_tests/postgis_test.py#L1250-L1253 There is python call render_with_vars(): https://github.com/mapnik/python-mapnik/blob/master/src/mapnik_python.cpp#L829-L837 But it is not much tested and documented.

giantchen2012 commented 6 years ago

Alright, you mean I can first get the datasource from postgis, then apply styles in an existing map xml to this layer, am I right? If so, I'll try it out. And thanks again.