Re: Question about python mapscript and p oint style.

"Seth G" <[email protected]> Sat, 23 Nov 2019 16:58:25 +0100
Newsgroups gmane.comp.gis.mapserver.user
Message-ID <[email protected]>
--===============8446407279640455592==
Content-Type: multipart/alternative;
 boundary=5eb775346c94456696443beab91b71fc

--5eb775346c94456696443beab91b71fc
Content-Type: text/plain;charset=utf-8
Content-Transfer-Encoding: quoted-printable

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 =3D 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 =3D m.getLayerByName('test')
cls =3D lyr.getClass(0)
style =3D mapscript.styleObj()
style.color.setRGB(0, 0, 0)
style.symbol =3D 1
style.size =3D 3
cls.insertStyle(style)
print(m.convertToString())

For Mapfile manipulation in Python you could also try https://pypi.org/p=
roject/mappyfile/
Regards,

Seth


--
web:http://geographika.co.uk
twitter: @geographika


On Sat, Nov 23, 2019, at 2:44 PM, Vladimir wrote:
> Hi all again!
>=20
> Seth, thank you for response.
>  I tried this way with a single Point layer, unfortunately this also d=
oes not work.
>=20
>  --
>  Regards, Vladimir.
>> 23 2019, 2:41 +06:00 =D0=BE=D1=82 Seth G <[email protected]>:
>>=20
>> Hi Vladimir,
>>=20
>> Could you try the following syntax?
>>=20
>> new_style =3D new mapscript.styleObj()
>> new_style.symbolname =3D 'circle'
>> new_style.size =3D 10
>> the_class.insertStyle(new_style)

>>=20
>>=20
>> Also make sure your variables aren't overriding the class names - e.g=
. maybe use different variable names than classObj.
>>=20
>> Regards,
>>=20
>> Seth
>>=20
>> --
>> web:http://geographika.co.uk
>> twitter: @geographika
>>=20
>>=20
>> On Fri, Nov 15, 2019, at 6:12 PM, Vladimir wrote:
>>> Hi all!
>>>=20
>>> I unsuccessfully try to style =E2=80=98Point=E2=80=99 layer with fol=
lowing code:
>>> (first)
>>>  style =3D mapscript.styleObj(classObj)
>>>  style.symbolname =3D 'circle'
>>>  style.size =3D 10
>>>  style.color =3D mapscript.colorObj(255, 0, 0)
>>>=20
>>> No error, no picture as result of using this method.
>>> But similar approach works for =E2=80=98Line=E2=80=99 and =E2=80=98P=
olygon=E2=80=99 layers.
>>>=20
>>> Also I figured out working method for the =E2=80=98Point=E2=80=99 la=
yer:
>>> (second)
>>> classObj.updateFromString("CLASS STYLE COLOR 255 0 0 SIZE 10 SYMBOL =
'circle' END END")
>>>=20
>>> Output of =E2=80=98layer.convertToString()=E2=80=99 is the same for =
both methods:
>>> LAYER
>>>  CONNECTION \"dbname=3D'db' host=3D'db' user=3D'user' password=3D'1'=
\"
>>>  CONNECTIONTYPE POSTGIS=20
>>>  DATA \"value FROM (SELECT value FROM points WHERE ST_Intersects(val=
ue, !BOX!)) AS subquery USING UNIQUE id USING srid =3D 3857\"
>>>  LABELITEM \"name\"
>>>  NAME \"points\"
>>>  STATUS ON
>>>  TYPE POINT
>>>  UNITS METERS
>>>  CLASS
>>>  NAME \"points\"
>>>  STYLE=20
>>>  COLOR 255 0 0
>>>  SIZE 10=20
>>>  SYMBOL \"circle\"
>>>  END # STYLE
>>>  END # CLASS
>>> END # LAYER
>>>=20
>>> How to get working =E2=80=98Point=E2=80=99 style using first method?=

>>> MapServer version: 7.2.1
>>>=20
>>> Thanks!
>>>=20

>>> --
>>> Regards, Vladimir.
>>>=20

>>>=20

>>> _______________________________________________
>>> mapserver-users mailing list
>>> [email protected] <https://www.fastmail.com/compose?To=
=3Dmapserver%[email protected]>
>>> https://lists.osgeo.org/mailman/listinfo/mapserver-users
>>=20
>> _______________________________________________
>>  mapserver-users mailing list
>> [email protected] <https://www.fastmail.com/compose?To=3D=
mapserver%[email protected]>
>> https://lists.osgeo.org/mailman/listinfo/mapserver-users
>=20
>=20
>=20

>=20

>=20

--5eb775346c94456696443beab91b71fc
Content-Type: text/html;charset=utf-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html><html><head><title></title><style type=3D"text/css">

p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div>Hi,<br></d=
iv><div><br></div><div>The following example works for me - 2 styles are=
 in the output Mapfile. Maybe there is an issue elsewhere?<br></div><div=
>Is there a Python error, or is the output not what you are expecting?<b=
r></div><div><br></div><div>import mapscript<br></div><div><br></div><di=
v>m =3D mapscript.fromstring("""<br></div><div>MAP<br></div><div>&nbsp;&=
nbsp;&nbsp; LAYER<br></div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; NAME "test"<br></div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
TYPE POINT<br></div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CLAS=
S<br></div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp; NAME "0"<br></div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp; STYLE<br></div><div>&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COLO=
R 0 0 0<br></div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SYMBOL 1<br></div><div>&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp; SIZE 13<br></div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp; END<br></div><div>&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp; END<br></div><div>&nbsp;&nbsp;&nbsp; END<br></div><div>=
END<br></div><div>""")<br></div><div>lyr =3D m.getLayerByName('test')<br=
></div><div>cls =3D lyr.getClass(0)<br></div><div>style =3D mapscript.st=
yleObj()<br></div><div>style.color.setRGB(0, 0, 0)<br></div><div>style.s=
ymbol =3D 1<br></div><div>style.size =3D 3<br></div><div>cls.insertStyle=
(style)<br></div><div>print(m.convertToString())<br></div><div><br></div=
><div>For Mapfile manipulation in Python you could also try <a href=3D"h=
ttps://pypi.org/project/mappyfile/">https://pypi.org/project/mappyfile/<=
/a><br></div><div>Regards,<br></div><div><br>Seth<br></div><div><br></di=
v><div><br></div><div id=3D"sig62266145"><div class=3D"signature">--<br>=
</div><div class=3D"signature">web:http://geographika.co.uk<br></div><di=
v class=3D"signature">twitter: @geographika<br></div></div><div><br></di=
v><div><br></div><div>On Sat, Nov 23, 2019, at 2:44 PM, Vladimir wrote:<=
br></div><blockquote type=3D"cite" id=3D"qt"><div><div>Hi all again!<br>=
</div><div>&nbsp;<br></div><div><div>Seth, thank you for response.<br></=
div><div> I tried this way with a single Point layer, unfortunately this=
 also does not work.<br></div><div> <br></div><div> --<br></div><div> Re=
gards, Vladimir.<br></div></div><blockquote style=3D"border-left-color:r=
gb(8, 87, 166);border-left-style:solid;border-left-width:1px;margin-top:=
10px;margin-right:10px;margin-bottom:10px;margin-left:10px;padding-top:0=
px;padding-right:0px;padding-bottom:0px;padding-left:10px;"><div>23 2019=
, 2:41 +06:00 =D0=BE=D1=82 Seth G &lt;[email protected]&gt;:<br></=
div><div> &nbsp; <br></div><div id=3D"qt-"><div class=3D"qt-js-helper qt=
-js-readmsg-msg"><div><div id=3D"qt-style_15744552792088220450_BODY"><di=
v class=3D"qt-class_1574531816"><div>Hi Vladimir,<br></div><div>&nbsp;<b=
r></div><div>Could you try the following syntax?<br></div><div>&nbsp;<br=
></div><pre><span class=3D"qt-n_mailru_css_attribute_postfix">new_style<=
/span> <span class=3D"qt-o_mailru_css_attribute_postfix">=3D</span> <spa=
n class=3D"qt-n_mailru_css_attribute_postfix">new</span> <span class=3D"=
qt-n_mailru_css_attribute_postfix">mapscript.styleObj</span><span class=3D=
"qt-p_mailru_css_attribute_postfix">()
</span><span class=3D"qt-n_mailru_css_attribute_postfix">new_style</span=
>.symbolname =3D 'circle'
<span class=3D"qt-n_mailru_css_attribute_postfix">new_style</span>.size =
=3D 10
<span class=3D"qt-n_mailru_css_attribute_postfix">the_class</span><span =
class=3D"qt-o_mailru_css_attribute_postfix">.</span><span class=3D"qt-n_=
mailru_css_attribute_postfix">insertStyle</span><span class=3D"qt-p_mail=
ru_css_attribute_postfix">(</span><span class=3D"qt-n_mailru_css_attribu=
te_postfix">new_style</span><span class=3D"qt-p_mailru_css_attribute_pos=
tfix">)

</span>
<br></pre><div>Also make sure your variables aren't overriding the class=
 names - e.g. maybe use different variable names than classObj.<br></div=
><div>&nbsp;<br></div><div>Regards,<br></div><div>&nbsp;<br></div><div>S=
eth<br></div><div>&nbsp;<br></div><div id=3D"qt-sig62266145_mailru_css_a=
ttribute_postfix"><div class=3D"qt-signature_mailru_css_attribute_postfi=
x">--<br></div><div class=3D"qt-signature_mailru_css_attribute_postfix">=
web:http://geographika.co.uk<br></div><div class=3D"qt-signature_mailru_=
css_attribute_postfix">twitter: @geographika<br></div></div><div>&nbsp;<=
br></div><div>&nbsp;<br></div><div class=3D"qt-mail-quote-collapse"><div=
><span>On Fri, Nov 15, 2019, at 6:12 PM, Vladimir wrote:</span><br></div=
><div><blockquote type=3D"cite" id=3D"qt-qt_mailru_css_attribute_postfix=
"><div><div>Hi all!<br></div><div>&nbsp;<br></div><div>I unsuccessfully =
try to style =E2=80=98Point=E2=80=99 layer with following code:<br></div=
><div>(first)<br></div><div><div>&nbsp; &nbsp; style =3D mapscript.style=
Obj(classObj)<br></div><div>&nbsp; &nbsp; style.symbolname =3D 'circle'<=
br></div><div>&nbsp; &nbsp; style.size =3D 10<br></div><div>&nbsp; &nbsp=
; style.color =3D mapscript.colorObj(255, 0, 0)<br></div></div><div>&nbs=
p;<br></div><div>No error, no picture as result of using this method.<br=
></div><div>But similar approach works for =E2=80=98Line=E2=80=99 and =E2=
=80=98Polygon=E2=80=99 layers.<br></div><div>&nbsp;<br></div><div><div>A=
lso I figured out working method for the =E2=80=98Point=E2=80=99 layer:<=
br></div><div>(second)<br></div><div style=3D"background-color:rgb(255, =
255, 255);color:rgb(0, 0, 0);font-family:&quot;Droid Sans Mono&quot;, &q=
uot;monospace&quot;, monospace, &quot;Droid Sans Fallback&quot;;font-siz=
e:14px;font-weight:normal;line-height:19px;white-space:pre;"><div>classO=
bj.updateFromString("CLASS STYLE COLOR 255 0 0 SIZE 10&nbsp; SYMBOL 'cir=
cle' END END")<br></div></div><div>&nbsp;<br></div><div>O<span style=3D"=
color:rgb(0, 0, 0)" class=3D"colour">utput of =E2=80=98layer.convertToSt=
ring()=E2=80=99 is the same </span>for both methods<span style=3D"color:=
rgb(0, 0, 0)" class=3D"colour">:</span><br></div></div><div><div style=3D=
"background-color:rgb(255, 255, 255);color:rgb(0, 0, 0);font-family:&quo=
t;Droid Sans Mono&quot;, &quot;monospace&quot;, monospace, &quot;Droid S=
ans Fallback&quot;;font-size:14px;font-weight:normal;line-height:19px;wh=
ite-space:pre;"><div><div>LAYER<br></div><div>&nbsp;&nbsp;&nbsp; CONNECT=
ION \"dbname=3D'db' host=3D'db' user=3D'user' password=3D'1'\"<br></div>=
<div>&nbsp;&nbsp;&nbsp; CONNECTIONTYPE POSTGIS &nbsp;<br></div><div>&nbs=
p;&nbsp;&nbsp; DATA \"value FROM (SELECT value FROM points WHERE ST_Inte=
rsects(value, !BOX!)) AS subquery USING UNIQUE id USING srid =3D 3857\"<=
br></div><div>&nbsp;&nbsp;&nbsp; LABELITEM \"name\"<br></div><div>&nbsp;=
&nbsp;&nbsp; NAME \"points\"<br></div><div>&nbsp;&nbsp;&nbsp; STATUS ON<=
br></div><div>&nbsp;&nbsp;&nbsp; TYPE POINT<br></div><div>&nbsp;&nbsp;&n=
bsp; UNITS METERS<br></div><div>&nbsp;&nbsp;&nbsp; CLASS<br></div><div>&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NAME \"points\"<br></div><div>=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STYLE&nbsp;&nbsp;&nbsp; &nbsp=
;<br></div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp; COLOR 255 0 0<br></div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SIZE 10&nbsp;&nbsp;&nbsp; &nbsp;<br></=
div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp; SYMBOL \"circle\"<br></div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp; END # STYLE<br></div><div>&nbsp;&nbsp;&nbsp; END # CLASS<br></div=
><div>END # LAYER<br></div></div><div>&nbsp;<br></div><div>How to get wo=
rking =E2=80=98Point=E2=80=99 style using first method?<br></div><div>Ma=
pServer version: 7.2.1<br></div><div>&nbsp;<br></div><div>Thanks!<br></d=
iv></div></div><div><div><p>&nbsp;<br></p><div>--<br></div><div>Regards,=
 Vladimir.<br></div><p>&nbsp;<br></p><p>&nbsp;<br></p></div></div></div>=
<div>_______________________________________________<br></div><div>mapse=
rver-users mailing list<br></div><div><a href=3D"/compose?To=3Dmapserver=
%[email protected]">[email protected]</a><br></div><=
div><a href=3D"https://lists.osgeo.org/mailman/listinfo/mapserver-users"=
>https://lists.osgeo.org/mailman/listinfo/mapserver-users</a><br></div><=
/blockquote></div></div><div>&nbsp;<br></div></div></div><div><div>_____=
__________________________________________<br></div><div> mapserver-user=
s mailing list<br></div><div> <a href=3D"/compose?To=3Dmapserver%2dusers=
@lists.osgeo.org">[email protected]</a><br></div><div> <a =
href=3D"https://lists.osgeo.org/mailman/listinfo/mapserver-users">https:=
//lists.osgeo.org/mailman/listinfo/mapserver-users</a><br></div></div></=
div></div></div></blockquote><div>&nbsp;<br></div><div>&nbsp;<br></div><=
div><div><p>&nbsp;<br></p><p>&nbsp;<br></p></div></div><div>&nbsp;<br></=
div></div></blockquote><div><br></div></body></html>
--5eb775346c94456696443beab91b71fc--

--===============8446407279640455592==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KbWFwc2VydmVy
LXVzZXJzIG1haWxpbmcgbGlzdAptYXBzZXJ2ZXItdXNlcnNAbGlzdHMub3NnZW8ub3JnCmh0dHBz
Oi8vbGlzdHMub3NnZW8ub3JnL21haWxtYW4vbGlzdGluZm8vbWFwc2VydmVyLXVzZXJz

--===============8446407279640455592==--