Hi Lee Wai See,
2. The sld can be declared in a number of ways. In my case the
BoundingBox element is created dynamically from servlet input parameters so
I just build it in the simplest possible manner as a new StringBuffer
instance:
StringBuffer sld = new StringBuffer();
sld.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
sld.append("<ogc:GetMap\n");
sld.append(" xmlns:ogc=\"http://www.opengis.net/ows\\"\\n"\);
sld.append(" xmlns:gml=\"http://www.opengis.net/gml\\"\\n"\);
sld.append(" version=\"1.1.1\" service=\"WMS\">\n");
sld.append(" <StyledLayerDescriptor version=\"1.0.0\">\n");
.
.
A more sophisticated approach would be to create the xml using
perhaps Xerces or Jdom before writing it to the geocon connection.
In some cases it might be useful to read the sld from the
filesystem. In other cases it is useful to load an sld file as a xml
template and change specific elements as needed. The sld example I indicated
is just a specific instance for a client selected bounding box.
1. The display image/jpeg can be returned directly as the servlet response
output stream.
If you are just using html or jsp you could call the servlet to build your
WMS image from an img src:
<html>
<body>
<img height="100%" width="100%"
src="http://ims.cr.usgs.gov/servlet19/com.esri.wms.Esrimap/USGS_EDC_National
_Atlas?Service=WMS&Version=1.1.1&request=GetMap&layers=ATLAS_ROADS_INTERSTAT
E&format=image/png&transparent=TRUE&srs=EPSG:4326&bbox=-109.59893035888672,3
6.71657752990723,-101.73796844482422,41.28876972198486&WIDTH=1000&HEIGHT=582
"/>
</html>
</body>
Or
If the calling servlet is from svg, as in my case, I simply call the servlet
from the image element xlink:href using multiple overlapping png image
elements with transparent set to true. (With many thanks to a hint from
cholmes)
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN"
"http://www.w3.org/TR/SVG/DTD/svg10.dtd" >
<svg preserveAspectRatio="xMinYMin"
viewBox="-109.59893035888672 -41.28876972198486 7.8609619140625
4.572192192077637"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
zoomAndPan="magnify">
<g id="canvas">
<rect x="-113.52941131591797" y="-45.21925067901611" width="31.44384765625"
height="31.44384765625" style="fill:none"/>
<g id="WMSGeothermal">
<image id="img" x="-109.59893035888672" y="-41.28876972198486"
width="7.8609619140625" height="4.572192192077637"
xlink:href="http://localhost/geoserver/wms?request=GetMap&layers=geo:cou
nty&styles=county&format=image/png&transparent=TRUE&srs=EPSG
:4326&bbox=-109.59893035888672,36.71657752990723,-101.73796844482422,41.
28876972198486&WIDTH=1000&HEIGHT=582">
</image>
</g>
<g id="WMSUSGS_Atlas">
<image id="img" x="-109.59893035888672" y="-41.28876972198486"
width="7.8609619140625" height="4.572192192077637"
xlink:href="http://ims.cr.usgs.gov/servlet19/com.esri.wms.Esrimap/USGS_EDC_N
ational_Atlas?Service=WMS&Version=1.1.1&request=GetMap&layers=AT
LAS_ROADS_INTERSTATE&format=image/png&transparent=TRUE&srs=EPSG:
4326&bbox=-109.59893035888672,36.71657752990723,-101.73796844482422,41.2
8876972198486&WIDTH=1000&HEIGHT=582">
</image>
</g>
</g><!-- canvas -->
</svg>
Hopefully I'm answering the right questions.
rkgeorge
-----Original Message-----
From: geoserver-users-admin@lists.sourceforge.net
[mailto:geoserver-users-admin@lists.sourceforge.net] On Behalf Of
leewse@anonymised.com
Sent: Sunday, February 26, 2006 2:16 AM
To: Randy George
Cc: geoserver-users@lists.sourceforge.net
Subject: RE: [Geoserver-users] RE: Adding the SLD body dynamically
Hi Randy George,
Thanks for the information given. They should be useful for me. However, I
still have some doubts, which I hope you can clear them for me:
1. With respect to the java code snippet to feed a custom SLD to a
wms/GetMap post, after getting back the response as an image file, how do
i display this image on my jsp page?
2. Again, with respect to the java code snippet, what is the sld declared?
Thank you.
Regards,
Lee Wai See
Hi Lee Wai See,
I have recently been working with this as well. Alex Petkov has a
nice example: http://docs.codehaus.org/display/GEOSDOC/SLD+SnippetsLook at the bottom. If you take out the first named layer it will work
directly with the geoserver1.3.war demo/sampleRequest/ using the
TestWfsPostAlso add the topp: prefix to states => topp:states
url:
http://localhost:8080/geoserver/wms/GetNapbody:
<?xml version="1.0" encoding="UTF-8"?>
<ogc:GetMap
xmlns:ogc="http://www.opengis.net/ows"
xmlns:gml="http://www.opengis.net/gml"
version="1.1.1" service="WMS">
<StyledLayerDescriptor version="1.0.0">
<NamedLayer>
<Name>topp:states</Name>
<NamedStyle>
<Name>population</Name>
</NamedStyle>
</NamedLayer>
</StyledLayerDescriptor>
<BoundingBox srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:coord>
<gml:X>-130.0</gml:X>
<gml:Y>24.0</gml:Y>
</gml:coord>
<gml:coord>
<gml:X>-66.0</gml:X>
<gml:Y>50.0</gml:Y>
</gml:coord>
</BoundingBox>
<Output><Format>image/png</Format>
<Size>
<Width>600</Width>
<Height>320</Height>
</Size>
</Output>
<Exceptions>application/vnd.ogc.se+xml</Exceptions>
</ogc:GetMap>I don't know the way mapbuilder works but here is a sample code for using
java to feed a custom sld to a wms/GetMap PostSnippet:
try {
URL u = new URL("http://www.web-demographics.com/geoserver/wms/GetMap"\);
HttpURLConnection geocon = (HttpURLConnection)u.openConnection();
geocon.setAllowUserInteraction(false);
geocon.setRequestMethod("POST");
geocon.setRequestProperty("Content-Type", "application/xml");
geocon.setDoOutput(true);
geocon.setDoInput(true);
geocon.setUseCaches(false);
System.out.println("GetImage\n"+sld.toString());
xmlOut = new PrintWriter(new BufferedWriter(new
OutputStreamWriter(geocon.getOutputStream())));
xmlOut.write(sld.toString());
xmlOut.flush();
xmlOut.close();
response.setHeader("Cache-Control", "no-store, no-cache,
must-revalidate");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.setHeader("Pragma", "no-cache");
response.setContentType("image/jpeg");
OutputStream outsld = response.getOutputStream();
int c;
InputStream in = geocon.getInputStream();
while ((c = in.read()) != -1) outsld.write(c);
in.close();
outsld.close();} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
System.out.println("WMSFeature: "+e.toString());
}Here is another example sld for filtering by bounding box and parameter
value:
<?xml version="1.0" encoding="UTF-8"?>
<ogc:GetMap
xmlns:ogc="http://www.opengis.net/ows"
xmlns:gml="http://www.opengis.net/gml"
version="1.1.1" service="WMS">
<StyledLayerDescriptor version="1.0.0">
<NamedLayer>
<Name>geo:USGS_Quat_Faults</Name>
<UserStyle>
<Name>geothermalgeo:USGS_Quat_Faults</Name>
<Title>Geothermal</Title>
<Abstract>Geothermal filters</Abstract>
<FeatureTypeStyle>
<Rule>
<!-- Theme 1 -->
<ogc:Filter xmlns:gml="http://www.opengis.net/gml">
<ogc:PropertyIsBetween>
<ogc:PropertyName>SLIPRATE</ogc:PropertyName>
<ogc:LowerBoundary>
<ogc:Literal>0.001</ogc:Literal>
</ogc:LowerBoundary>
<ogc:UpperBoundary>
<ogc:Literal>17.5005</ogc:Literal>
</ogc:UpperBoundary>
</ogc:PropertyIsBetween>
</ogc:Filter>
<LineSymbolizer>
<Stroke>
<CssParameter name="stroke">
<ogc:Literal>#0000FF</ogc:Literal>
</CssParameter>
<CssParameter name="stroke-width">
<ogc:Literal>2</ogc:Literal>
</CssParameter>
</Stroke>
</LineSymbolizer>
</Rule>
<Rule>
<!-- Theme 2 -->
<ogc:Filter xmlns:gml="http://www.opengis.net/gml">
<ogc:PropertyIsBetween>
<ogc:PropertyName>SLIPRATE</ogc:PropertyName>
<ogc:LowerBoundary>
<ogc:Literal>17.5005</ogc:Literal>
</ogc:LowerBoundary>
<ogc:UpperBoundary>
<ogc:Literal>35</ogc:Literal>
</ogc:UpperBoundary>
</ogc:PropertyIsBetween>
</ogc:Filter>
<LineSymbolizer>
<Stroke>
<CssParameter name="stroke">
<ogc:Literal>#FF0000</ogc:Literal>
</CssParameter>
<CssParameter name="stroke-width">
<ogc:Literal>2</ogc:Literal>
</CssParameter>
</Stroke>
</LineSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
<BoundingBox srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:coord>
<gml:X>-116.01796340942383</gml:X>
<gml:Y>36.40119743347168</gml:Y>
</gml:coord>
<gml:coord>
<gml:X>-114.8682632446289</gml:X>
<gml:Y>37.33532905578613</gml:Y>
</gml:coord>
</BoundingBox>
<Output><Format>image/jpeg</Format>
<Size>
<Width>1000</Width>
<Height>813</Height>
</Size>
</Output>
<Exceptions>application/vnd.ogc.se+xml</Exceptions>
</ogc:GetMap>Hope this helps
Rkgeorge-----Original Message-----
From: geoserver-users-admin@lists.sourceforge.net
[mailto:geoserver-users-admin@lists.sourceforge.net] On Behalf Of Lee Wai
See
Sent: Friday, February 24, 2006 12:35 AM
To: 'Brent Owens'
Cc: geoserver-users@lists.sourceforge.net
Subject: RE: [Geoserver-users] RE: Adding the SLD body dynamicallyHi Brent,
Thank you for your reply. Pardon me, but the SLD-POST link under the URL
you
have given to me does not contain any information. Could you please point
out to me where I can get relevant information to help in the
implementation
of my desired feature as described? Thank you.Regards,
Lee Wai See
ST Electronics (Info-Software Systems) Pte Ltd-----Original Message-----
From: geoserver-users-admin@lists.sourceforge.net
[mailto:geoserver-users-admin@lists.sourceforge.net] On Behalf Of Brent
Owens
Sent: Friday, February 24, 2006 3:24 PM
To: Lee Wai See
Cc: geoserver-users@lists.sourceforge.net
Subject: Re: [Geoserver-users] RE: Adding the SLD body dynamicallyYou should be able to do something like that using SLD-POST. There is
some information on SLDs here:
http://docs.codehaus.org/display/GEOSDOC/SLD%20Explanations%20and%20Samples
It is a good starting point.
Brent Owens
(The Open Planning Project)Lee Wai See wrote:
Hi,
I want to add the SLD body of the map dynamically rather than
statically through the context.xml file. That is, I want to display
not all, but only some of the features, of a map layer depending on
the input from the user. Can anyone be kind enough to give advice on
how this can be done in GeoServer ands MapBuilder?Hope I am clear in my question. Thanks.
Regards,
Lee Wai See
ST Electronics (Info-Software Systems) Pte Ltd[This e-mail is confidential and may be priviledged. If you are not the
intended recipient, please kindly notify us immediately and delete themessage
from your system; please do not copy or use it for any purpose, nor
disclose
its contents to any other person. Thank you.]
---ST Electronics Group----------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting
language
that extends applications into web and mobile media. Attend the live
webcast
and join the prime developer group breaking into this new coding
territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting
language
that extends applications into web and mobile media. Attend the live
webcast
and join the prime developer group breaking into this new coding
territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting
language
that extends applications into web and mobile media. Attend the live
webcast
and join the prime developer group breaking into this new coding
territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users