[Geoserver-users] [Re: RE ST Style creation and/or updating]

Nope, I pasted it on my original post on the mailing list (on the Nabble website)… but it has changed in the mean time, so here it is again:

<?xml version="1.0" encoding="ISO-8859-1"?>

<sld:StyledLayerDescriptor xmlns=“http://www.opengis.net/sld” xmlns:sld=“http://www.opengis.net/sld” xmlns:ogc=“http://www.opengis.net/ogc” xmlns:gml=“http://www.opengis.net/gml” version=“1.0.0”>
sld:NamedLayer
sld:NameCON-Test-style</sld:Name>
sld:UserStyle
sld:TitleStyle for Test-style</sld:Title>
sld:AbstractStyle definition for all features linked to entity Test-style</sld:Abstract>
sld:FeatureTypeStyle

sld:Rule
sld:NameWORKING Rule</sld:Name>
sld:TitleWORKING Ducts</sld:Title>
sld:AbstractWORKING Ducts</sld:Abstract>
ogc:Filter
ogc:And
ogc:PropertyIsEqualTo
ogc:PropertyNameEA1</ogc:PropertyName>
ogc:LiteralWORKING</ogc:Literal>
</ogc:PropertyIsEqualTo>
ogc:Or
ogc:PropertyIsEqualTo
ogc:PropertyNameNAME</ogc:PropertyName>
ogc:LiteralGH 00233</ogc:Literal>
</ogc:PropertyIsEqualTo>
ogc:PropertyIsEqualTo
ogc:PropertyNameNAME</ogc:PropertyName>
ogc:LiteralGH 00234</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Or>
</ogc:And>
</ogc:Filter>

sld:LineSymbolizer
sld:Stroke
<sld:CssParameter name=“stroke”>
ogc:Literal#00FF00</ogc:Literal>
</sld:CssParameter>
<sld:CssParameter name=“stroke-width”>
ogc:Literal2</ogc:Literal>
</sld:CssParameter>
</sld:Stroke>
</sld:LineSymbolizer>
sld:PointSymbolizer
sld:Graphic
sld:Mark
sld:Fill
<sld:CssParameter name=“fill-opacity”>0</sld:CssParameter>
</sld:Fill>
</sld:Mark>
</sld:Graphic>
</sld:PointSymbolizer>
</sld:Rule>

sld:Rule
sld:NameDown Rule</sld:Name>
sld:TitleDOWN Ducts</sld:Title>
sld:AbstractDOWN Ducts</sld:Abstract>
ogc:Filter
ogc:And
ogc:PropertyIsEqualTo
ogc:PropertyNameEA1</ogc:PropertyName>
ogc:LiteralDOWN</ogc:Literal>
</ogc:PropertyIsEqualTo>
ogc:Or
ogc:PropertyIsEqualTo
ogc:PropertyNameNAME</ogc:PropertyName>
ogc:LiteralGH 00233</ogc:Literal>
</ogc:PropertyIsEqualTo>
ogc:PropertyIsEqualTo
ogc:PropertyNameNAME</ogc:PropertyName>
ogc:LiteralGH 00234</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Or>
</ogc:And>
</ogc:Filter>

sld:LineSymbolizer
sld:Stroke
<sld:CssParameter name=“stroke”>
ogc:Literal#FF0000</ogc:Literal>
</sld:CssParameter>
<sld:CssParameter name=“stroke-width”>
ogc:Literal4</ogc:Literal>
</sld:CssParameter>
</sld:Stroke>
</sld:LineSymbolizer>
sld:PointSymbolizer
sld:Graphic
sld:Mark
sld:Fill
<sld:CssParameter name=“fill-opacity”>0</sld:CssParameter>
</sld:Fill>
</sld:Mark>
</sld:Graphic>
</sld:PointSymbolizer>
</sld:Rule>

sld:Rule
sld:NameUnknown Rule</sld:Name>
sld:TitleUNKNOWN Ducts</sld:Title>
sld:AbstractUNKNOWN Ducts</sld:Abstract>
ogc:Filter
ogc:And
ogc:PropertyIsEqualTo
ogc:PropertyNameEA1</ogc:PropertyName>
ogc:LiteralUNKNOWN</ogc:Literal>
</ogc:PropertyIsEqualTo>
ogc:Or
ogc:PropertyIsEqualTo
ogc:PropertyNameNAME</ogc:PropertyName>
ogc:LiteralGH 00233</ogc:Literal>
</ogc:PropertyIsEqualTo>
ogc:PropertyIsEqualTo
ogc:PropertyNameNAME</ogc:PropertyName>
ogc:LiteralGH 00234</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Or>
</ogc:And>
</ogc:Filter>

sld:LineSymbolizer
sld:Stroke
<sld:CssParameter name=“stroke”>
ogc:Literal#FFFF00</ogc:Literal>
</sld:CssParameter>
<sld:CssParameter name=“stroke-width”>
ogc:Literal3</ogc:Literal>
</sld:CssParameter>
</sld:Stroke>
</sld:LineSymbolizer>
sld:PointSymbolizer
sld:Graphic
sld:Mark
sld:Fill
<sld:CssParameter name=“fill-opacity”>0</sld:CssParameter>
</sld:Fill>
</sld:Mark>
</sld:Graphic>
</sld:PointSymbolizer>
</sld:Rule>
</sld:FeatureTypeStyle>
</sld:UserStyle>
</sld:NamedLayer>
</sld:StyledLayerDescriptor>

PS: Apologies for the re-send Justin, forgot to Reply-All :slight_smile:

Justin Deoliveira wrote:

···


Reinhardt Bron
Solution Architect
t: +27 82 445 4546
f: +27 86 665 5545
e: reinhardt.bron@anonymised.com

SSG Consulting
t: +27 12 345 6779
Unit 2
Vallei Forum
c/o Kort & Piering str.
Elardus Park
0181

Sorry I missed it, I must be blind :slight_smile:

So I tried uploading this style with a POST and it worked ok. Using curl I executed the command:

curl -u admin:geoserver -XPOST -d @reinhardt.sld -H 'Content-type: application/vnd.ogc.sld+xml' http://localhost:8080/geoserver/rest/styles

The new style is created with the name "Default Styler". The space in the name throws things off, so i specified the name parameter:

curl -u admin:geoserver -XPOST -d @foo.sld -H 'Content-type: application/vnd.ogc.sld+xml' "http://localhost:8080/geoserver/rest/styles?name=reinhardt&quot;

And it works. Doing a get for that style:

curl -G http://localhost:8080/geoserver/rest/styles/reinhardt.sld

I get the style back.

Reinhardt Bron wrote:

Nope, I pasted it on my original post on the mailing list (on the Nabble website)... but it has changed in the mean time, so here it is again:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- edited with XMLSpy v2008 rel. 2 sp2 (http://www.altova.com) by Reinhardt (EMBRACE) -->
<sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld&quot; xmlns:sld="http://www.opengis.net/sld&quot; xmlns:ogc="http://www.opengis.net/ogc&quot; xmlns:gml="http://www.opengis.net/gml&quot; version="1.0.0">
    <sld:NamedLayer>
        <sld:Name>CON-Test-style</sld:Name>
        <sld:UserStyle>
            <sld:Title>Style for Test-style</sld:Title>
            <sld:Abstract>Style definition for all features linked to entity Test-style</sld:Abstract>
            <sld:FeatureTypeStyle>
                <!--********************************************************-->
                <!-- Drawing 'WORKING' Ducts -->
                <sld:Rule>
                    <sld:Name>WORKING Rule</sld:Name>
                    <sld:Title>WORKING Ducts</sld:Title>
                    <sld:Abstract>WORKING Ducts</sld:Abstract>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsEqualTo>
                                <ogc:PropertyName>EA1</ogc:PropertyName>
                                <ogc:Literal>WORKING</ogc:Literal>
                            </ogc:PropertyIsEqualTo>
                            <ogc:Or>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00233</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00234</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                            </ogc:Or>
                        </ogc:And>
                    </ogc:Filter>
                    <!-- like a linesymbolizer but with a fill too -->
                    <sld:LineSymbolizer>
                        <sld:Stroke>
                            <sld:CssParameter name="stroke">
                                <ogc:Literal>#00FF00</ogc:Literal>
                            </sld:CssParameter>
                            <sld:CssParameter name="stroke-width">
                                <ogc:Literal>2</ogc:Literal>
                            </sld:CssParameter>
                        </sld:Stroke>
                    </sld:LineSymbolizer>
                    <sld:PointSymbolizer>
                        <sld:Graphic>
                            <sld:Mark>
                                <sld:Fill>
                                    <sld:CssParameter name="fill-opacity">0</sld:CssParameter>
                                </sld:Fill>
                            </sld:Mark>
                        </sld:Graphic>
                    </sld:PointSymbolizer>
                </sld:Rule>
                <!--********************************************************-->
                <!-- Drawing 'DOWN' Ducts -->
                <sld:Rule>
                    <sld:Name>Down Rule</sld:Name>
                    <sld:Title>DOWN Ducts</sld:Title>
                    <sld:Abstract>DOWN Ducts</sld:Abstract>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsEqualTo>
                                <ogc:PropertyName>EA1</ogc:PropertyName>
                                <ogc:Literal>DOWN</ogc:Literal>
                            </ogc:PropertyIsEqualTo>
                            <ogc:Or>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00233</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00234</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                            </ogc:Or>
                        </ogc:And>
                    </ogc:Filter>
                    <!-- like a linesymbolizer but with a fill too -->
                    <sld:LineSymbolizer>
                        <sld:Stroke>
                            <sld:CssParameter name="stroke">
                                <ogc:Literal>#FF0000</ogc:Literal>
                            </sld:CssParameter>
                            <sld:CssParameter name="stroke-width">
                                <ogc:Literal>4</ogc:Literal>
                            </sld:CssParameter>
                        </sld:Stroke>
                    </sld:LineSymbolizer>
                    <sld:PointSymbolizer>
                        <sld:Graphic>
                            <sld:Mark>
                                <sld:Fill>
                                    <sld:CssParameter name="fill-opacity">0</sld:CssParameter>
                                </sld:Fill>
                            </sld:Mark>
                        </sld:Graphic>
                    </sld:PointSymbolizer>
                </sld:Rule>
                <!--********************************************************-->
                <!-- Drawing 'UNKNOWN' Ducts -->
                <sld:Rule>
                    <sld:Name>Unknown Rule</sld:Name>
                    <sld:Title>UNKNOWN Ducts</sld:Title>
                    <sld:Abstract>UNKNOWN Ducts</sld:Abstract>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsEqualTo>
                                <ogc:PropertyName>EA1</ogc:PropertyName>
                                <ogc:Literal>UNKNOWN</ogc:Literal>
                            </ogc:PropertyIsEqualTo>
                            <ogc:Or>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00233</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00234</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                            </ogc:Or>
                        </ogc:And>
                    </ogc:Filter>
                    <!-- like a linesymbolizer but with a fill too -->
                    <sld:LineSymbolizer>
                        <sld:Stroke>
                            <sld:CssParameter name="stroke">
                                <ogc:Literal>#FFFF00</ogc:Literal>
                            </sld:CssParameter>
                            <sld:CssParameter name="stroke-width">
                                <ogc:Literal>3</ogc:Literal>
                            </sld:CssParameter>
                        </sld:Stroke>
                    </sld:LineSymbolizer>
                    <sld:PointSymbolizer>
                        <sld:Graphic>
                            <sld:Mark>
                                <sld:Fill>
                                    <sld:CssParameter name="fill-opacity">0</sld:CssParameter>
                                </sld:Fill>
                            </sld:Mark>
                        </sld:Graphic>
                    </sld:PointSymbolizer>
                </sld:Rule>
            </sld:FeatureTypeStyle>
        </sld:UserStyle>
    </sld:NamedLayer>
</sld:StyledLayerDescriptor>

PS: Apologies for the re-send Justin, forgot to Reply-All :slight_smile:

Justin Deoliveira wrote:

Hmmm... i don't see the SLD. Did you include it as an attachment?

Reinhardt Bron wrote:

Hi Justin,

As I said in my previous e-mail, the updating works perfectly, it's the creation of a style that I'm having difficulty with!

My SLD looks exactly the same as it does in the inital post - only with a different value in the Name tag, which obviously doesn't exist on the GeoServer yet.

I could hack out my C# code to post that to you too if that would help.

Thanks again,
Reinhardt

Justin Deoliveira wrote:

Hi Reinhardt,

It is appreciated if you can keep your questions on the public list. Thanks.

Reinhardt Bron wrote:

Hi Justin,

"Content-type: application/vnd.ogc.sld+xml"

That line did it - I've been struggling the whole day and last night with this issue, and have very little hair left!!! Thank you!!!! What baffles me is that that isn't specified anywhere in the documentation...? OK, now that I've searched the document, I find it - but not where you'd expect to find it...

Apologies, it is indeed not very evident. I just updated the documentation.

But anyway, so I am now successfully updating styles on the GeoServer from my application - <BIG sigh of relief!>. Final hurdle is the creation - which isn't quite working yet. I'm getting a 403 (Forbidden) error, but I suspect this might be because of the way I am requesting the SLD to be created.

Once again, the details of my request are as follows:
URL: http://localhost:8080/geoserver/rest/styles/
Content Type: application/vnd.ogc.sld+xml
Request Type: POST

Hmmm... everything looks ok. A 403 seems wierd to me... does the style already exist? If so you should use a PUT if you want to update it, rather than a POST.

Could you include the SLD? It would be helpful if I could try it out over here.

Style is valid, accepted by GeoServer when input manually, and has a <sld:Name> tag defined under the <sld:NamedStyle> tag. Would GeoServer infer the name from the SLD correctly, or would I have to send the name of the style through as a request parameter?

In the documentation, style creation is documented as follows:
Method = POST
Response = 201 with Location header
Formats = SLD, XML, JSON
Parameter = /name

/and then "The name parameter specifies the name to be given to the style. This option is most useful when POSTing
a style in SLD format, and an appropriate name can be not be inferred from the SLD itself."

Any pointers would, again, be greatly appreciated!

Depends on your SLD, there are multiple places a Name can show up. If you can supply your SLD I can tell you. But yes, the "name" parameter will be respected before anything in the SLD if specified.

-Justin

Thanks,
Reinhardt

Justin Deoliveira wrote:

Hi Reinhardt,

Could you perhaps share the code snippet that you are using to do the upload. One thing to do is make sure the Content-type header:

Content-type: application/vnd.ogc.sld+xml

Also, are you getting any errors on the server side. If you turn up logging to GEOSERVER_DEVELOPER_LOGGING (to go the UI and go to Config - > Server), and then execute the request you might see some errors in the log.

It might also help to have the code snippet you are using to upload the style.

Thanks,

-Justin

SouthAfrican wrote:

Hi all,

I'm trying to create styles programmatically on GeoServer (1.7.4 - latest
REST plugin installed).

The styles are generated in code, and I have tested that the generated style
can be added in GeoServer manually through the config interface.

My trouble is obviously with the HTTP request that I'm using - this is all
through C# by the way. I have found conflicting information in connection
with the specification of what the REST interface expects with regards to
styles.

For a style creation, I am writing the SDL into my web request, and sending
it to the URL http://localhost:8080/geoserver/rest/styles with a POST
request. Is this correct? Am I supposed to send through the 'name'
parameter in the URL (as in ...rest/styles?name=myNewStyle, or
...?myNewStyle.sld) or should I write the parameter into my request as here:
http://vinothnat.blogspot.com/2007/09/httpwebrequest-post-method.html (I've
tried both, to no avail)...

Any pointers?

Thanks in advance,
Reinhardt

--
------------------------------------------------------------------------
*Reinhardt Bron*
Solution Architect
t: +27 82 445 4546
f: +27 86 665 5545
e: reinhardt.bron@anonymised.com

*SSG Consulting*
t: +27 12 345 6779
Unit 2
Vallei Forum
c/o Kort & Piering str.
Elardus Park
0181

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

Thanks Justin,

The problem is obviously that I am not specifying a name for the style in the HttpWebRequest, hoping that GeoServer will resolve the name from the SLD itself :expressionless:

How well do you know C#? :wink:

Will figure it out and post my solution here once working.

Thank you so much for the direction - lost in the deep dark ocean to enlightened and on the right track in the space of 5 e-mails - thank you!

Cheers,
R

Justin Deoliveira wrote:

···


Reinhardt Bron
Solution Architect
t: +27 82 445 4546
f: +27 86 665 5545
e: reinhardt.bron@anonymised.com

SSG Consulting
t: +27 12 345 6779
Unit 2
Vallei Forum
c/o Kort & Piering str.
Elardus Park
0181

Hi Justin,

The create is working, all it needed was to specify the name parameter in the URL: …rest/styles?name=myNewStyle

Then, one last question: once the style has been added successfully to the GeoServer, I have to click the Load button on the GeoServer config side, before it displays in the styles list of Styles in GeoServer config, but it does however display in the list at …rest/styles. Should I worry about it? These styles are being generated on the fly, for consumption via Google Earth, and thus need to be available immediately.

Thanks!

Reinhardt Bron wrote:

···


Reinhardt Bron
Solution Architect
t: +27 82 445 4546
f: +27 86 665 5545
e: reinhardt.bron@anonymised.com

SSG Consulting
t: +27 12 345 6779
Unit 2
Vallei Forum
c/o Kort & Piering str.
Elardus Park
0181

Reinhardt Bron wrote:

Thanks Justin,

The problem is obviously that I am not specifying a name for the style in the HttpWebRequest, hoping that GeoServer will resolve the name from the SLD itself :expressionless:

How well do you know C#? :wink:

Will figure it out and post my solution here once working.

Thank you so much for the direction - lost in the deep dark ocean to enlightened and on the right track in the space of 5 e-mails - thank you!

Your very welcome :slight_smile:

Cheers,
R

Justin Deoliveira wrote:

Sorry I missed it, I must be blind :slight_smile:

So I tried uploading this style with a POST and it worked ok. Using curl I executed the command:

curl -u admin:geoserver -XPOST -d @reinhardt.sld -H 'Content-type: application/vnd.ogc.sld+xml' http://localhost:8080/geoserver/rest/styles

The new style is created with the name "Default Styler". The space in the name throws things off, so i specified the name parameter:

curl -u admin:geoserver -XPOST -d @foo.sld -H 'Content-type: application/vnd.ogc.sld+xml' "http://localhost:8080/geoserver/rest/styles?name=reinhardt&quot;

And it works. Doing a get for that style:

curl -G http://localhost:8080/geoserver/rest/styles/reinhardt.sld

I get the style back.

Reinhardt Bron wrote:

Nope, I pasted it on my original post on the mailing list (on the Nabble website)... but it has changed in the mean time, so here it is again:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- edited with XMLSpy v2008 rel. 2 sp2 (http://www.altova.com) by Reinhardt (EMBRACE) -->
<sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld&quot; xmlns:sld="http://www.opengis.net/sld&quot; xmlns:ogc="http://www.opengis.net/ogc&quot; xmlns:gml="http://www.opengis.net/gml&quot; version="1.0.0">
    <sld:NamedLayer>
        <sld:Name>CON-Test-style</sld:Name>
        <sld:UserStyle>
            <sld:Title>Style for Test-style</sld:Title>
            <sld:Abstract>Style definition for all features linked to entity Test-style</sld:Abstract>
            <sld:FeatureTypeStyle>
                <!--********************************************************-->
                <!-- Drawing 'WORKING' Ducts -->
                <sld:Rule>
                    <sld:Name>WORKING Rule</sld:Name>
                    <sld:Title>WORKING Ducts</sld:Title>
                    <sld:Abstract>WORKING Ducts</sld:Abstract>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsEqualTo>
                                <ogc:PropertyName>EA1</ogc:PropertyName>
                                <ogc:Literal>WORKING</ogc:Literal>
                            </ogc:PropertyIsEqualTo>
                            <ogc:Or>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00233</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00234</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                            </ogc:Or>
                        </ogc:And>
                    </ogc:Filter>
                    <!-- like a linesymbolizer but with a fill too -->
                    <sld:LineSymbolizer>
                        <sld:Stroke>
                            <sld:CssParameter name="stroke">
                                <ogc:Literal>#00FF00</ogc:Literal>
                            </sld:CssParameter>
                            <sld:CssParameter name="stroke-width">
                                <ogc:Literal>2</ogc:Literal>
                            </sld:CssParameter>
                        </sld:Stroke>
                    </sld:LineSymbolizer>
                    <sld:PointSymbolizer>
                        <sld:Graphic>
                            <sld:Mark>
                                <sld:Fill>
                                    <sld:CssParameter name="fill-opacity">0</sld:CssParameter>
                                </sld:Fill>
                            </sld:Mark>
                        </sld:Graphic>
                    </sld:PointSymbolizer>
                </sld:Rule>
                <!--********************************************************-->
                <!-- Drawing 'DOWN' Ducts -->
                <sld:Rule>
                    <sld:Name>Down Rule</sld:Name>
                    <sld:Title>DOWN Ducts</sld:Title>
                    <sld:Abstract>DOWN Ducts</sld:Abstract>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsEqualTo>
                                <ogc:PropertyName>EA1</ogc:PropertyName>
                                <ogc:Literal>DOWN</ogc:Literal>
                            </ogc:PropertyIsEqualTo>
                            <ogc:Or>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00233</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00234</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                            </ogc:Or>
                        </ogc:And>
                    </ogc:Filter>
                    <!-- like a linesymbolizer but with a fill too -->
                    <sld:LineSymbolizer>
                        <sld:Stroke>
                            <sld:CssParameter name="stroke">
                                <ogc:Literal>#FF0000</ogc:Literal>
                            </sld:CssParameter>
                            <sld:CssParameter name="stroke-width">
                                <ogc:Literal>4</ogc:Literal>
                            </sld:CssParameter>
                        </sld:Stroke>
                    </sld:LineSymbolizer>
                    <sld:PointSymbolizer>
                        <sld:Graphic>
                            <sld:Mark>
                                <sld:Fill>
                                    <sld:CssParameter name="fill-opacity">0</sld:CssParameter>
                                </sld:Fill>
                            </sld:Mark>
                        </sld:Graphic>
                    </sld:PointSymbolizer>
                </sld:Rule>
                <!--********************************************************-->
                <!-- Drawing 'UNKNOWN' Ducts -->
                <sld:Rule>
                    <sld:Name>Unknown Rule</sld:Name>
                    <sld:Title>UNKNOWN Ducts</sld:Title>
                    <sld:Abstract>UNKNOWN Ducts</sld:Abstract>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsEqualTo>
                                <ogc:PropertyName>EA1</ogc:PropertyName>
                                <ogc:Literal>UNKNOWN</ogc:Literal>
                            </ogc:PropertyIsEqualTo>
                            <ogc:Or>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00233</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00234</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                            </ogc:Or>
                        </ogc:And>
                    </ogc:Filter>
                    <!-- like a linesymbolizer but with a fill too -->
                    <sld:LineSymbolizer>
                        <sld:Stroke>
                            <sld:CssParameter name="stroke">
                                <ogc:Literal>#FFFF00</ogc:Literal>
                            </sld:CssParameter>
                            <sld:CssParameter name="stroke-width">
                                <ogc:Literal>3</ogc:Literal>
                            </sld:CssParameter>
                        </sld:Stroke>
                    </sld:LineSymbolizer>
                    <sld:PointSymbolizer>
                        <sld:Graphic>
                            <sld:Mark>
                                <sld:Fill>
                                    <sld:CssParameter name="fill-opacity">0</sld:CssParameter>
                                </sld:Fill>
                            </sld:Mark>
                        </sld:Graphic>
                    </sld:PointSymbolizer>
                </sld:Rule>
            </sld:FeatureTypeStyle>
        </sld:UserStyle>
    </sld:NamedLayer>
</sld:StyledLayerDescriptor>

PS: Apologies for the re-send Justin, forgot to Reply-All :slight_smile:

Justin Deoliveira wrote:

Hmmm... i don't see the SLD. Did you include it as an attachment?

Reinhardt Bron wrote:

Hi Justin,

As I said in my previous e-mail, the updating works perfectly, it's the creation of a style that I'm having difficulty with!

My SLD looks exactly the same as it does in the inital post - only with a different value in the Name tag, which obviously doesn't exist on the GeoServer yet.

I could hack out my C# code to post that to you too if that would help.

Thanks again,
Reinhardt

Justin Deoliveira wrote:

Hi Reinhardt,

It is appreciated if you can keep your questions on the public list. Thanks.

Reinhardt Bron wrote:

Hi Justin,

"Content-type: application/vnd.ogc.sld+xml"

That line did it - I've been struggling the whole day and last night with this issue, and have very little hair left!!! Thank you!!!! What baffles me is that that isn't specified anywhere in the documentation...? OK, now that I've searched the document, I find it - but not where you'd expect to find it...

Apologies, it is indeed not very evident. I just updated the documentation.

But anyway, so I am now successfully updating styles on the GeoServer from my application - <BIG sigh of relief!>. Final hurdle is the creation - which isn't quite working yet. I'm getting a 403 (Forbidden) error, but I suspect this might be because of the way I am requesting the SLD to be created.

Once again, the details of my request are as follows:
URL: http://localhost:8080/geoserver/rest/styles/
Content Type: application/vnd.ogc.sld+xml
Request Type: POST

Hmmm... everything looks ok. A 403 seems wierd to me... does the style already exist? If so you should use a PUT if you want to update it, rather than a POST.

Could you include the SLD? It would be helpful if I could try it out over here.

Style is valid, accepted by GeoServer when input manually, and has a <sld:Name> tag defined under the <sld:NamedStyle> tag. Would GeoServer infer the name from the SLD correctly, or would I have to send the name of the style through as a request parameter?

In the documentation, style creation is documented as follows:
Method = POST
Response = 201 with Location header
Formats = SLD, XML, JSON
Parameter = /name

/and then "The name parameter specifies the name to be given to the style. This option is most useful when POSTing
a style in SLD format, and an appropriate name can be not be inferred from the SLD itself."

Any pointers would, again, be greatly appreciated!

Depends on your SLD, there are multiple places a Name can show up. If you can supply your SLD I can tell you. But yes, the "name" parameter will be respected before anything in the SLD if specified.

-Justin

Thanks,
Reinhardt

Justin Deoliveira wrote:

Hi Reinhardt,

Could you perhaps share the code snippet that you are using to do the upload. One thing to do is make sure the Content-type header:

Content-type: application/vnd.ogc.sld+xml

Also, are you getting any errors on the server side. If you turn up logging to GEOSERVER_DEVELOPER_LOGGING (to go the UI and go to Config - > Server), and then execute the request you might see some errors in the log.

It might also help to have the code snippet you are using to upload the style.

Thanks,

-Justin

SouthAfrican wrote:

Hi all,

I'm trying to create styles programmatically on GeoServer (1.7.4 - latest
REST plugin installed).

The styles are generated in code, and I have tested that the generated style
can be added in GeoServer manually through the config interface.

My trouble is obviously with the HTTP request that I'm using - this is all
through C# by the way. I have found conflicting information in connection
with the specification of what the REST interface expects with regards to
styles.

For a style creation, I am writing the SDL into my web request, and sending
it to the URL http://localhost:8080/geoserver/rest/styles with a POST
request. Is this correct? Am I supposed to send through the 'name'
parameter in the URL (as in ...rest/styles?name=myNewStyle, or
...?myNewStyle.sld) or should I write the parameter into my request as here:
http://vinothnat.blogspot.com/2007/09/httpwebrequest-post-method.html (I've
tried both, to no avail)...

Any pointers?

Thanks in advance,
Reinhardt

--
------------------------------------------------------------------------
*Reinhardt Bron*
Solution Architect
t: +27 82 445 4546
f: +27 86 665 5545
e: reinhardt.bron@anonymised.com

*SSG Consulting*
t: +27 12 345 6779
Unit 2
Vallei Forum
c/o Kort & Piering str.
Elardus Park
0181

--
------------------------------------------------------------------------
*Reinhardt Bron*
Solution Architect
t: +27 82 445 4546
f: +27 86 665 5545
e: reinhardt.bron@anonymised.com

*SSG Consulting*
t: +27 12 345 6779
Unit 2
Vallei Forum
c/o Kort & Piering str.
Elardus Park
0181

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

Reinhardt Bron wrote:

Hi Justin,

The create is working, all it needed was to specify the name parameter in the URL: ...rest/styles?name=myNewStyle

Awesome, glad that worked.

Then, one last question: once the style has been added successfully to the GeoServer, I have to click the Load button on the GeoServer config side, before it displays in the styles list of Styles in GeoServer config, but it does however display in the list at ...rest/styles. Should I worry about it? These styles are being generated on the fly, for consumption via Google Earth, and thus need to be available immediately.

Yeah, this is a known issue. And one that will be fixed for the upcoming 1.7.5 release. Here is the bug report for it:

http://jira.codehaus.org/browse/GEOS-3112

That said, everything else should see the style. Rest calls, any WMS calls you make, etc... So you *should* be able to seem them in google earth without reloading. If not let me know.

-Justin

Thanks!

Reinhardt Bron wrote:

Thanks Justin,

The problem is obviously that I am not specifying a name for the style in the HttpWebRequest, hoping that GeoServer will resolve the name from the SLD itself :expressionless:

How well do you know C#? :wink:

Will figure it out and post my solution here once working.

Thank you so much for the direction - lost in the deep dark ocean to enlightened and on the right track in the space of 5 e-mails - thank you!

Cheers,
R

Justin Deoliveira wrote:

Sorry I missed it, I must be blind :slight_smile:

So I tried uploading this style with a POST and it worked ok. Using curl I executed the command:

curl -u admin:geoserver -XPOST -d @reinhardt.sld -H 'Content-type: application/vnd.ogc.sld+xml' http://localhost:8080/geoserver/rest/styles

The new style is created with the name "Default Styler". The space in the name throws things off, so i specified the name parameter:

curl -u admin:geoserver -XPOST -d @foo.sld -H 'Content-type: application/vnd.ogc.sld+xml' "http://localhost:8080/geoserver/rest/styles?name=reinhardt&quot;

And it works. Doing a get for that style:

curl -G http://localhost:8080/geoserver/rest/styles/reinhardt.sld

I get the style back.

Reinhardt Bron wrote:

Nope, I pasted it on my original post on the mailing list (on the Nabble website)... but it has changed in the mean time, so here it is again:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- edited with XMLSpy v2008 rel. 2 sp2 (http://www.altova.com) by Reinhardt (EMBRACE) -->
<sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld&quot; xmlns:sld="http://www.opengis.net/sld&quot; xmlns:ogc="http://www.opengis.net/ogc&quot; xmlns:gml="http://www.opengis.net/gml&quot; version="1.0.0">
    <sld:NamedLayer>
        <sld:Name>CON-Test-style</sld:Name>
        <sld:UserStyle>
            <sld:Title>Style for Test-style</sld:Title>
            <sld:Abstract>Style definition for all features linked to entity Test-style</sld:Abstract>
            <sld:FeatureTypeStyle>
                <!--********************************************************-->
                <!-- Drawing 'WORKING' Ducts -->
                <sld:Rule>
                    <sld:Name>WORKING Rule</sld:Name>
                    <sld:Title>WORKING Ducts</sld:Title>
                    <sld:Abstract>WORKING Ducts</sld:Abstract>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsEqualTo>
                                <ogc:PropertyName>EA1</ogc:PropertyName>
                                <ogc:Literal>WORKING</ogc:Literal>
                            </ogc:PropertyIsEqualTo>
                            <ogc:Or>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00233</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00234</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                            </ogc:Or>
                        </ogc:And>
                    </ogc:Filter>
                    <!-- like a linesymbolizer but with a fill too -->
                    <sld:LineSymbolizer>
                        <sld:Stroke>
                            <sld:CssParameter name="stroke">
                                <ogc:Literal>#00FF00</ogc:Literal>
                            </sld:CssParameter>
                            <sld:CssParameter name="stroke-width">
                                <ogc:Literal>2</ogc:Literal>
                            </sld:CssParameter>
                        </sld:Stroke>
                    </sld:LineSymbolizer>
                    <sld:PointSymbolizer>
                        <sld:Graphic>
                            <sld:Mark>
                                <sld:Fill>
                                    <sld:CssParameter name="fill-opacity">0</sld:CssParameter>
                                </sld:Fill>
                            </sld:Mark>
                        </sld:Graphic>
                    </sld:PointSymbolizer>
                </sld:Rule>
                <!--********************************************************-->
                <!-- Drawing 'DOWN' Ducts -->
                <sld:Rule>
                    <sld:Name>Down Rule</sld:Name>
                    <sld:Title>DOWN Ducts</sld:Title>
                    <sld:Abstract>DOWN Ducts</sld:Abstract>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsEqualTo>
                                <ogc:PropertyName>EA1</ogc:PropertyName>
                                <ogc:Literal>DOWN</ogc:Literal>
                            </ogc:PropertyIsEqualTo>
                            <ogc:Or>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00233</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00234</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                            </ogc:Or>
                        </ogc:And>
                    </ogc:Filter>
                    <!-- like a linesymbolizer but with a fill too -->
                    <sld:LineSymbolizer>
                        <sld:Stroke>
                            <sld:CssParameter name="stroke">
                                <ogc:Literal>#FF0000</ogc:Literal>
                            </sld:CssParameter>
                            <sld:CssParameter name="stroke-width">
                                <ogc:Literal>4</ogc:Literal>
                            </sld:CssParameter>
                        </sld:Stroke>
                    </sld:LineSymbolizer>
                    <sld:PointSymbolizer>
                        <sld:Graphic>
                            <sld:Mark>
                                <sld:Fill>
                                    <sld:CssParameter name="fill-opacity">0</sld:CssParameter>
                                </sld:Fill>
                            </sld:Mark>
                        </sld:Graphic>
                    </sld:PointSymbolizer>
                </sld:Rule>
                <!--********************************************************-->
                <!-- Drawing 'UNKNOWN' Ducts -->
                <sld:Rule>
                    <sld:Name>Unknown Rule</sld:Name>
                    <sld:Title>UNKNOWN Ducts</sld:Title>
                    <sld:Abstract>UNKNOWN Ducts</sld:Abstract>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsEqualTo>
                                <ogc:PropertyName>EA1</ogc:PropertyName>
                                <ogc:Literal>UNKNOWN</ogc:Literal>
                            </ogc:PropertyIsEqualTo>
                            <ogc:Or>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00233</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                                <ogc:PropertyIsEqualTo>
                                    <ogc:PropertyName>NAME</ogc:PropertyName>
                                    <ogc:Literal>GH 00234</ogc:Literal>
                                </ogc:PropertyIsEqualTo>
                            </ogc:Or>
                        </ogc:And>
                    </ogc:Filter>
                    <!-- like a linesymbolizer but with a fill too -->
                    <sld:LineSymbolizer>
                        <sld:Stroke>
                            <sld:CssParameter name="stroke">
                                <ogc:Literal>#FFFF00</ogc:Literal>
                            </sld:CssParameter>
                            <sld:CssParameter name="stroke-width">
                                <ogc:Literal>3</ogc:Literal>
                            </sld:CssParameter>
                        </sld:Stroke>
                    </sld:LineSymbolizer>
                    <sld:PointSymbolizer>
                        <sld:Graphic>
                            <sld:Mark>
                                <sld:Fill>
                                    <sld:CssParameter name="fill-opacity">0</sld:CssParameter>
                                </sld:Fill>
                            </sld:Mark>
                        </sld:Graphic>
                    </sld:PointSymbolizer>
                </sld:Rule>
            </sld:FeatureTypeStyle>
        </sld:UserStyle>
    </sld:NamedLayer>
</sld:StyledLayerDescriptor>

PS: Apologies for the re-send Justin, forgot to Reply-All :slight_smile:

Justin Deoliveira wrote:

Hmmm... i don't see the SLD. Did you include it as an attachment?

Reinhardt Bron wrote:

Hi Justin,

As I said in my previous e-mail, the updating works perfectly, it's the creation of a style that I'm having difficulty with!

My SLD looks exactly the same as it does in the inital post - only with a different value in the Name tag, which obviously doesn't exist on the GeoServer yet.

I could hack out my C# code to post that to you too if that would help.

Thanks again,
Reinhardt

Justin Deoliveira wrote:

Hi Reinhardt,

It is appreciated if you can keep your questions on the public list. Thanks.

Reinhardt Bron wrote:

Hi Justin,

"Content-type: application/vnd.ogc.sld+xml"

That line did it - I've been struggling the whole day and last night with this issue, and have very little hair left!!! Thank you!!!! What baffles me is that that isn't specified anywhere in the documentation...? OK, now that I've searched the document, I find it - but not where you'd expect to find it...

Apologies, it is indeed not very evident. I just updated the documentation.

But anyway, so I am now successfully updating styles on the GeoServer from my application - <BIG sigh of relief!>. Final hurdle is the creation - which isn't quite working yet. I'm getting a 403 (Forbidden) error, but I suspect this might be because of the way I am requesting the SLD to be created.

Once again, the details of my request are as follows:
URL: http://localhost:8080/geoserver/rest/styles/
Content Type: application/vnd.ogc.sld+xml
Request Type: POST

Hmmm... everything looks ok. A 403 seems wierd to me... does the style already exist? If so you should use a PUT if you want to update it, rather than a POST.

Could you include the SLD? It would be helpful if I could try it out over here.

Style is valid, accepted by GeoServer when input manually, and has a <sld:Name> tag defined under the <sld:NamedStyle> tag. Would GeoServer infer the name from the SLD correctly, or would I have to send the name of the style through as a request parameter?

In the documentation, style creation is documented as follows:
Method = POST
Response = 201 with Location header
Formats = SLD, XML, JSON
Parameter = /name

/and then "The name parameter specifies the name to be given to the style. This option is most useful when POSTing
a style in SLD format, and an appropriate name can be not be inferred from the SLD itself."

Any pointers would, again, be greatly appreciated!

Depends on your SLD, there are multiple places a Name can show up. If you can supply your SLD I can tell you. But yes, the "name" parameter will be respected before anything in the SLD if specified.

-Justin

Thanks,
Reinhardt

Justin Deoliveira wrote:

Hi Reinhardt,

Could you perhaps share the code snippet that you are using to do the upload. One thing to do is make sure the Content-type header:

Content-type: application/vnd.ogc.sld+xml

Also, are you getting any errors on the server side. If you turn up logging to GEOSERVER_DEVELOPER_LOGGING (to go the UI and go to Config - > Server), and then execute the request you might see some errors in the log.

It might also help to have the code snippet you are using to upload the style.

Thanks,

-Justin

SouthAfrican wrote:

Hi all,

I'm trying to create styles programmatically on GeoServer (1.7.4 - latest
REST plugin installed).

The styles are generated in code, and I have tested that the generated style
can be added in GeoServer manually through the config interface.

My trouble is obviously with the HTTP request that I'm using - this is all
through C# by the way. I have found conflicting information in connection
with the specification of what the REST interface expects with regards to
styles.

For a style creation, I am writing the SDL into my web request, and sending
it to the URL http://localhost:8080/geoserver/rest/styles with a POST
request. Is this correct? Am I supposed to send through the 'name'
parameter in the URL (as in ...rest/styles?name=myNewStyle, or
...?myNewStyle.sld) or should I write the parameter into my request as here:
http://vinothnat.blogspot.com/2007/09/httpwebrequest-post-method.html (I've
tried both, to no avail)...

Any pointers?

Thanks in advance,
Reinhardt

--
------------------------------------------------------------------------

*Reinhardt Bron*
Solution Architect
t: +27 82 445 4546
f: +27 86 665 5545
e: reinhardt.bron@anonymised.com

*SSG Consulting*
t: +27 12 345 6779
Unit 2
Vallei Forum
c/o Kort & Piering str.
Elardus Park
0181

--
------------------------------------------------------------------------
*Reinhardt Bron*
Solution Architect
t: +27 82 445 4546
f: +27 86 665 5545
e: reinhardt.bron@anonymised.com

*SSG Consulting*
t: +27 12 345 6779
Unit 2
Vallei Forum
c/o Kort & Piering str.
Elardus Park
0181

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.