今天会用TextSymbolizer来显示文字。
数据源geo_first_class_city_point 结构如下:
gid: int
area: double
perimeter: double
res1_4m_: long
res1_4m_id: long
gbcode: int
name: string
adcode93: int
adcode99: int
adclass: int
pinyin: string
the_geom: pointProperty
该层所采用的sld文件:
<
FeatureTypeStyle
>
<
FeatureTypeName
>
feature
</
FeatureTypeName
>
<
Rule
>
<
TextSymbolizer
>
<
Geometry
>
<
ogc:PropertyName
>
the_geom
</
ogc:PropertyName
>
</
Geometry
>
<
Label
>
<
ogc:PropertyName
>
name
</
ogc:PropertyName
>
</
Label
>
<
Font
>
<
CssParameter
name
="font-family"
>
宋体
</
CssParameter
>
<
CssParameter
name
="font-style"
>
italic
</
CssParameter
>
<
CssParameter
name
="font-Size"
>
<
literal
>
10
</
literal
>
</
CssParameter
>
</
Font
>
<
LabelPlacement
>
<
PointPlacement
>
<
AnchorPoint
>
<
AnchorPointX
>
0
</
AnchorPointX
>
<
AnchorPointY
>
0
</
AnchorPointY
>
</
AnchorPoint
>
</
PointPlacement
>
</
LabelPlacement
>
<
Fill
>
<
CssParameter
name
="fill"
>
#000000
</
CssParameter
>
</
Fill
>
<
Halo
/>
</
TextSymbolizer
>
<
PointSymbolizer
>
<
Geometry
>
<
ogc:PropertyName
>
the_geom
</
ogc:PropertyName
>
</
Geometry
>
<
graphic
>
<
size
>
6
</
size
>
<
mark
>
<
wellknownname
>
circle
</
wellknownname
>
<
Fill
>
<
CssParameter
name
="fill"
>
#FF0000
</
CssParameter
>
<
CssParameter
name
="fill-opacity"
>
0.8
</
CssParameter
>
</
Fill
>
</
mark
>
</
graphic
>
</
PointSymbolizer
>
</
Rule
>
</
FeatureTypeStyle
>
<?
xml version="1.0" encoding="UTF-8"
?>
-
<
wfs:FeatureCollection
xmlns:wfs
="http://www.opengis.net/wfs"
xmlns:topp
="http://www.openplans.org/topp"
xmlns:gml
="http://www.opengis.net/gml"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://www.openplans.org/topp http://localhost:80/geoserver/wfs/DescribeFeatureType?typeName=topp:geo_first_class_city_point http://www.opengis.net/wfs http://localhost:80/geoserver/data/capabilities/wfs/1.0.0/WFS-basic.xsd"
>
-
<
gml:boundedBy
>
-
<
gml:Box
srsName
="http://www.opengis.net/gml/srs/epsg.xml#4326"
>
<
gml:coordinates
decimal
="."
cs
=","
ts
=""
>
101.7874527,28.20082474 118.77278137,40.82094193
</
gml:coordinates
>
</
gml:Box
>
</
gml:boundedBy
>
-
<
gml:featureMember
>
-
<
topp:geo_first_class_city_point
fid
="geo_first_class_city_point.83613"
>
<
topp:gid
>
0
</
topp:gid
>
<
topp:area
>
0.0
</
topp:area
>
<
topp:perimeter
>
0.0
</
topp:perimeter
>
<
topp:res1_4m_
>
1
</
topp:res1_4m_
>
<
topp:res1_4m_id
>
61
</
topp:res1_4m_id
>
<
topp:gbcode
>
31010
</
topp:gbcode
>
<
topp:name
>
北京
</
topp:name
>
<
topp:adcode93
>
110100
</
topp:adcode93
>
<
topp:adcode99
>
110100
</
topp:adcode99
>
<
topp:adclass
>
1
</
topp:adclass
>
<
topp:pinyin
>
Beijing
</
topp:pinyin
>
-
<
topp:the_geom
>
-
<
gml:Point
srsName
="http://www.opengis.net/gml/srs/epsg.xml#4326"
>
<
gml:coordinates
decimal
="."
cs
=","
ts
=""
>
116.3809433,39.9236145
</
gml:coordinates
>
</
gml:Point
>
</
topp:the_geom
>
</
topp:geo_first_class_city_point
>
</
gml:featureMember
>
-
<
gml:featureMember
>
……
</
gml:featureMember
>
</
wfs:FeatureCollection
>
这样我可以在客户端解析wfs返回的数据,想怎么显示怎么显示。
数据源geo_first_class_city_point 结构如下:
gid: int
area: double
perimeter: double
res1_4m_: long
res1_4m_id: long
gbcode: int
name: string
adcode93: int
adcode99: int
adclass: int
pinyin: string
the_geom: pointProperty
该层所采用的sld文件:
<
FeatureTypeStyle
>
<
FeatureTypeName
>
feature
</
FeatureTypeName
>
<
Rule
>
<
TextSymbolizer
>
<
Geometry
>
<
ogc:PropertyName
>
the_geom
</
ogc:PropertyName
>
</
Geometry
>
<
Label
>
<
ogc:PropertyName
>
name
</
ogc:PropertyName
>
</
Label
>
<
Font
>
<
CssParameter
name
="font-family"
>
宋体
</
CssParameter
>
<
CssParameter
name
="font-style"
>
italic
</
CssParameter
>
<
CssParameter
name
="font-Size"
>
<
literal
>
10
</
literal
>
</
CssParameter
>
</
Font
>
<
LabelPlacement
>
<
PointPlacement
>
<
AnchorPoint
>
<
AnchorPointX
>
0
</
AnchorPointX
>
<
AnchorPointY
>
0
</
AnchorPointY
>
</
AnchorPoint
>
</
PointPlacement
>
</
LabelPlacement
>
<
Fill
>
<
CssParameter
name
="fill"
>
#000000
</
CssParameter
>
</
Fill
>
<
Halo
/>
</
TextSymbolizer
>
<
PointSymbolizer
>
<
Geometry
>
<
ogc:PropertyName
>
the_geom
</
ogc:PropertyName
>
</
Geometry
>
<
graphic
>
<
size
>
6
</
size
>
<
mark
>
<
wellknownname
>
circle
</
wellknownname
>
<
Fill
>
<
CssParameter
name
="fill"
>
#FF0000
</
CssParameter
>
<
CssParameter
name
="fill-opacity"
>
0.8
</
CssParameter
>
</
Fill
>
</
mark
>
</
graphic
>
</
PointSymbolizer
>
</
Rule
>
</
FeatureTypeStyle
>
这里就不一项项解释上面各项含意了。不清楚的话请看OGC SLD规范。
得到图:

现在文字出来了,就是不好看。要弄好看点,可能需要进行坐标变换。看了看geoserver文档,当前geoserver对坐标变换支持不够。那怎么办呢?干脆通过WFS把数据调到客户端,到时候想怎么办就怎么办,想怎么显示就怎么显示,还可以加上超链接。
WFS调用格式举例如下:
typeName就是你的数据层的名字,BBOX是查询范围。返回结果:
<?
xml version="1.0" encoding="UTF-8"
?>
-
<
wfs:FeatureCollection
xmlns:wfs
="http://www.opengis.net/wfs"
xmlns:topp
="http://www.openplans.org/topp"
xmlns:gml
="http://www.opengis.net/gml"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://www.openplans.org/topp http://localhost:80/geoserver/wfs/DescribeFeatureType?typeName=topp:geo_first_class_city_point http://www.opengis.net/wfs http://localhost:80/geoserver/data/capabilities/wfs/1.0.0/WFS-basic.xsd"
>
-
<
gml:boundedBy
>
-
<
gml:Box
srsName
="http://www.opengis.net/gml/srs/epsg.xml#4326"
>
<
gml:coordinates
decimal
="."
cs
=","
ts
=""
>
101.7874527,28.20082474 118.77278137,40.82094193
</
gml:coordinates
>
</
gml:Box
>
</
gml:boundedBy
>
-
<
gml:featureMember
>
-
<
topp:geo_first_class_city_point
fid
="geo_first_class_city_point.83613"
>
<
topp:gid
>
0
</
topp:gid
>
<
topp:area
>
0.0
</
topp:area
>
<
topp:perimeter
>
0.0
</
topp:perimeter
>
<
topp:res1_4m_
>
1
</
topp:res1_4m_
>
<
topp:res1_4m_id
>
61
</
topp:res1_4m_id
>
<
topp:gbcode
>
31010
</
topp:gbcode
>
<
topp:name
>
北京
</
topp:name
>
<
topp:adcode93
>
110100
</
topp:adcode93
>
<
topp:adcode99
>
110100
</
topp:adcode99
>
<
topp:adclass
>
1
</
topp:adclass
>
<
topp:pinyin
>
Beijing
</
topp:pinyin
>
-
<
topp:the_geom
>
-
<
gml:Point
srsName
="http://www.opengis.net/gml/srs/epsg.xml#4326"
>
<
gml:coordinates
decimal
="."
cs
=","
ts
=""
>
116.3809433,39.9236145
</
gml:coordinates
>
</
gml:Point
>
</
topp:the_geom
>
</
topp:geo_first_class_city_point
>
</
gml:featureMember
>
-
<
gml:featureMember
>
……
</
gml:featureMember
>
</
wfs:FeatureCollection
>
这样我可以在客户端解析wfs返回的数据,想怎么显示怎么显示。
实际上Geoserver+Geotools已经实现了大部分webgis的功能,只要理解了OGC规范,不难开发出复杂的应用。
本文转自xiaotie博客园博客,原文链接http://www.cnblogs.com/xiaotie/archive/2005/08/19/218509.html如需转载请自行联系原作者
xiaotie 集异璧实验室(GEBLAB)