[mapserver-users] Question about python mapscript and point style.
Seth G
sethg at geographika.co.uk
Sat Nov 23 07:58:25 PST 2019
Hi,
The following example works for me - 2 styles are in the output Mapfile. Maybe there is an issue elsewhere?
Is there a Python error, or is the output not what you are expecting?
import mapscript
m = mapscript.fromstring("""
MAP
LAYER
NAME "test"
TYPE POINT
CLASS
NAME "0"
STYLE
COLOR 0 0 0
SYMBOL 1
SIZE 13
END
END
END
END
""")
lyr = m.getLayerByName('test')
cls = lyr.getClass(0)
style = mapscript.styleObj()
style.color.setRGB(0, 0, 0)
style.symbol = 1
style.size = 3
cls.insertStyle(style)
print(m.convertToString())
For Mapfile manipulation in Python you could also try https://pypi.org/project/mappyfile/
Regards,
Seth
--
web:http://geographika.co.uk
twitter: @geographika
On Sat, Nov 23, 2019, at 2:44 PM, Vladimir wrote:
> Hi all again!
>
> Seth, thank you for response.
> I tried this way with a single Point layer, unfortunately this also does not work.
>
> --
> Regards, Vladimir.
>> 23 2019, 2:41 +06:00 от Seth G <sethg at geographika.co.uk>:
>>
>> Hi Vladimir,
>>
>> Could you try the following syntax?
>>
>> new_style = new mapscript.styleObj()
>> new_style.symbolname = 'circle'
>> new_style.size = 10
>> the_class.insertStyle(new_style)
>>
>>
>> Also make sure your variables aren't overriding the class names - e.g. maybe use different variable names than classObj.
>>
>> Regards,
>>
>> Seth
>>
>> --
>> web:http://geographika.co.uk
>> twitter: @geographika
>>
>>
>> On Fri, Nov 15, 2019, at 6:12 PM, Vladimir wrote:
>>> Hi all!
>>>
>>> I unsuccessfully try to style ‘Point’ layer with following code:
>>> (first)
>>> style = mapscript.styleObj(classObj)
>>> style.symbolname = 'circle'
>>> style.size = 10
>>> style.color = mapscript.colorObj(255, 0, 0)
>>>
>>> No error, no picture as result of using this method.
>>> But similar approach works for ‘Line’ and ‘Polygon’ layers.
>>>
>>> Also I figured out working method for the ‘Point’ layer:
>>> (second)
>>> classObj.updateFromString("CLASS STYLE COLOR 255 0 0 SIZE 10 SYMBOL 'circle' END END")
>>>
>>> Output of ‘layer.convertToString()’ is the same for both methods:
>>> LAYER
>>> CONNECTION \"dbname='db' host='db' user='user' password='1'\"
>>> CONNECTIONTYPE POSTGIS
>>> DATA \"value FROM (SELECT value FROM points WHERE ST_Intersects(value, !BOX!)) AS subquery USING UNIQUE id USING srid = 3857\"
>>> LABELITEM \"name\"
>>> NAME \"points\"
>>> STATUS ON
>>> TYPE POINT
>>> UNITS METERS
>>> CLASS
>>> NAME \"points\"
>>> STYLE
>>> COLOR 255 0 0
>>> SIZE 10
>>> SYMBOL \"circle\"
>>> END # STYLE
>>> END # CLASS
>>> END # LAYER
>>>
>>> How to get working ‘Point’ style using first method?
>>> MapServer version: 7.2.1
>>>
>>> Thanks!
>>>
>>> --
>>> Regards, Vladimir.
>>>
>>>
>>> _______________________________________________
>>> mapserver-users mailing list
>>> mapserver-users at lists.osgeo.org <https://www.fastmail.com/compose?To=mapserver%2dusers@lists.osgeo.org>
>>> https://lists.osgeo.org/mailman/listinfo/mapserver-users
>>
>> _______________________________________________
>> mapserver-users mailing list
>> mapserver-users at lists.osgeo.org <https://www.fastmail.com/compose?To=mapserver%2dusers@lists.osgeo.org>
>> https://lists.osgeo.org/mailman/listinfo/mapserver-users
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20191123/5b3054d5/attachment.htm>
More information about the MapServer-users
mailing list