GML可视化学习(一)

  学习了两周,今天总算实现了gml到svg的简单转换,成功的第一步,还有待继续学习。将代码写下:

 

 

ContractedBlock.gif ExpandedBlockStart.gif 1.xml代码
 
   
1 <? xml version="1.0" encoding="UTF-8" ?>
2   <? xml-stylesheet type="text/xsl" href="1.xsl" ?>
3   <!-- 编辑使用 XMLSpy v2006 U (http://www.altova.com) 由 any (any) -->
4   < City xmlns ="http://www.ukusa.org/app" xmlns:gml ="http://www.opengis.net/gml" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation ="http://www.ukusa.org/app
5 E:\XML\exc\1.xsd" >
6 < gml:boundedBy >
7 < gml:Envelope >
8 < gml:lowerCorner > 0 0 </ gml:lowerCorner >
9 < gml:upperCorner > 100 200 </ gml:upperCorner >
10 </ gml:Envelope >
11 </ gml:boundedBy >
12 < gml:featureMember >
13 < Bridge >
14 < span > 100 </ span >
15 < height > 200 </ height >
16 < gml:centerLineOf >
17 < gml:LineString >
18 < gml:coordinates > 0,0 100,200 </ gml:coordinates >
19 </ gml:LineString >
20 </ gml:centerLineOf >
21 < mobility > DrawBridge </ mobility >
22 < spans >
23 < Gorge >
24 < width > 100 </ width >
25 < depth > 50 </ depth >
26 < gml:centerLineOf >
27 < gml:LineString >
28 < gml:coordinates > 100,0 0,200 </ gml:coordinates >
29 </ gml:LineString >
30 </ gml:centerLineOf >
31 </ Gorge >
32 </ spans >
33 </ Bridge >
34 </ gml:featureMember >
35   </ City >
36  

 

ContractedBlock.gif ExpandedBlockStart.gif 1.xsd代码
 
   
1 <? xml version="1.0" encoding="UTF-8" ?>
2   <!-- 编辑使用 XMLSpy v2006 U (http://www.altova.com) 由 any (any) -->
3   <!-- 编辑使用 XMLSpy v2006 U (http://www.altova.com) 由 any (any) -->
4   <!-- 编辑使用 XMLSpy v2006 U (http://www.altova.com) 由 any (any) -->
5   < xs:schema xmlns:app ="http://www.ukusa.org/app" xmlns:xs ="http://www.w3.org/2001/XMLSchema" xmlns:gml ="http://www.opengis.net/gml" targetNamespace ="http://www.ukusa.org/app" elementFormDefault ="qualified" attributeFormDefault ="unqualified" >
6 < xs:import namespace ="http://www.opengis.net/gml" schemaLocation ="E:\XML\GML\03-105r1_GML_3.1.1\GML-3.1.1\base\feature.xsd" />
7 < xs:import namespace ="http://www.opengis.net/gml" schemaLocation ="E:\XML\GML\03-105r1_GML_3.1.1\GML-3.1.1\base\geometryBasic0d1d.xsd" />
8 < xs:element name ="City" substitutionGroup ="gml:_FeatureCollection" >
9 < xs:annotation >
10 < xs:documentation > Comment describing your root element </ xs:documentation >
11 </ xs:annotation >
12 < xs:complexType >
13 < xs:complexContent >
14 < xs:extension base ="gml:AbstractFeatureCollectionType" />
15 </ xs:complexContent >
16 </ xs:complexType >
17 </ xs:element >
18 < xs:element name ="Bridge" type ="app:BridgeType" substitutionGroup ="gml:_Feature" />
19 < xs:element name ="mobility" type ="app:MobilityType" />
20 < xs:simpleType name ="MobilityType" >
21 < xs:restriction base ="xs:string" />
22 </ xs:simpleType >
23 < xs:complexType name ="BridgeType" >
24 < xs:complexContent >
25 < xs:extension base ="gml:AbstractFeatureType" >
26 < xs:sequence >
27 < xs:element name ="span" type ="xs:integer" />
28 < xs:element name ="height" type ="xs:integer" />
29 < xs:element ref ="gml:centerLineOf" />
30 < xs:element ref ="app:mobility" />
31 < xs:element ref ="app:spans" />
32 </ xs:sequence >
33 </ xs:extension >
34 </ xs:complexContent >
35 </ xs:complexType >
36 < xs:element name ="Gorge" substitutionGroup ="gml:_Feature" >
37 < xs:complexType >
38 < xs:complexContent >
39 < xs:extension base ="app:GorgeType" />
40 </ xs:complexContent >
41 </ xs:complexType >
42 </ xs:element >
43 < xs:complexType name ="GorgeType" >
44 < xs:complexContent >
45 < xs:extension base ="gml:AbstractFeatureType" >
46 < xs:sequence >
47 < xs:element name ="width" type ="xs:integer" />
48 < xs:element name ="depth" type ="xs:integer" />
49 < xs:element ref ="gml:centerLineOf" />
50 </ xs:sequence >
51 </ xs:extension >
52 </ xs:complexContent >
53 </ xs:complexType >
54 < xs:element name ="spans" type ="app:GorgePropertyType" />
55 < xs:complexType name ="GorgePropertyType" >
56 < xs:sequence >
57 < xs:element ref ="app:Gorge" />
58 </ xs:sequence >
59 < xs:attributeGroup ref ="gml:AssociationAttributeGroup" />
60 </ xs:complexType >
61   </ xs:schema >
62  

 

ContractedBlock.gif ExpandedBlockStart.gif 1.xslt代码
 
   
1 <? xml version="1.0" encoding="UTF-8" ?>
2   <!-- 编辑使用 XMLSpy v2006 U (http://www.altova.com) 由 any (any) -->
3   < xsl:stylesheet version ="1.0" xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" xmlns:gml ="http://www.opengis.net/gml" xmlns:xlink ="http://www.w3.org/1999/xlink" >
4 < xsl:output method ="xml" version ="1.0" encoding ="UTF-8" indent ="yes" />
5 < xsl:preserve-space elements ="*" />
6 < xsl:template match ="/" >
7 < xsl:element name ="svg" >
8 < xsl:attribute name ="width" > 800 </ xsl:attribute >
9 < xsl:attribute name ="height" > 600 </ xsl:attribute >
10 < xsl:apply-templates select ="//gml:coordinates" />
11 </ xsl:element >
12 </ xsl:template >
13 < xsl:template name ="transform-x" >
14 < xsl:param name ="coordinate-pair" />
15 < xsl:value-of select ="substring-before($coordinate-pair,',')" />
16 </ xsl:template >
17 < xsl:template name ="transform-y" >
18 < xsl:param name ="coordinate-pair" />
19 < xsl:value-of select ="substring-after($coordinate-pair,',') * ( -1 ) + 600" />
20 </ xsl:template >
21 < xsl:template match ="gml:coordinates" >
22 < xsl:call-template name ="Path" >
23 < xsl:with-param name ="list" select ="." />
24 </ xsl:call-template >
25 </ xsl:template >
26 < xsl:template name ="Path" >
27 < xsl:param name ="list" />
28 < xsl:variable name ="first" select ="substring-before($list,' ')" />
29 < xsl:variable name ="last" select ="substring-after($list,' ')" />
30 < xsl:variable name ="x1" >
31 < xsl:call-template name ="transform-x" >
32 < xsl:with-param name ="coordinate-pair" select ="$first" />
33 </ xsl:call-template >
34 </ xsl:variable >
35 < xsl:variable name ="y1" >
36 < xsl:call-template name ="transform-y" >
37 < xsl:with-param name ="coordinate-pair" select ="$first" />
38 </ xsl:call-template >
39 </ xsl:variable >
40 < xsl:variable name ="x2" >
41 < xsl:call-template name ="transform-x" >
42 < xsl:with-param name ="coordinate-pair" select ="$last" />
43 </ xsl:call-template >
44 </ xsl:variable >
45 < xsl:variable name ="y2" >
46 < xsl:call-template name ="transform-y" >
47 < xsl:with-param name ="coordinate-pair" select ="$last" />
48 </ xsl:call-template >
49 </ xsl:variable >
50 < xsl:element name ="line" >
51 < xsl:attribute name ="x1" >< xsl:value-of select ="$x1" /></ xsl:attribute >
52 < xsl:attribute name ="y1" >< xsl:value-of select ="$y1" /></ xsl:attribute >
53 < xsl:attribute name ="x2" >< xsl:value-of select ="$x2" /></ xsl:attribute >
54 < xsl:attribute name ="y2" >< xsl:value-of select ="$y2" /></ xsl:attribute >
55 < xsl:attribute name ="style" > stroke:red </ xsl:attribute >
56 </ xsl:element >
57 < xsl:element name ="path" >
58 < xsl:attribute name ="d" >< xsl:value-of select ="concat('M',$x1 + 10,' ', $y1,' ','L',$x2 + 10,' ', $y2)" /></ xsl:attribute >
59 < xsl:attribute name ="style" > stroke:blue </ xsl:attribute >
60 </ xsl:element >
61 </ xsl:template >
62   </ xsl:stylesheet >
63  

 

 

转成的svg代码和图形如下:

ContractedBlock.gif ExpandedBlockStart.gif 1.svg代码
 
   
1 <? xml version="1.0" encoding="UTF-8" ?>
2   < svg width ="800" height ="600" >
3 < line x1 ="0" y1 ="600" x2 ="100" y2 ="400" style ="stroke:red" />
4 < path d ="M10 600 L110 400" style ="stroke:blue" />
5 < line x1 ="100" y1 ="600" x2 ="0" y2 ="400" style ="stroke:red" />
6 < path d ="M110 600 L10 400" style ="stroke:blue" />
7   </ svg >

2010040223535718.jpg

 

转载于:https://www.cnblogs.com/Geo-Web/archive/2010/04/02/1703483.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值