在XML中给出一个数组(坐标),寻求有关如何计算GML Envelope中lowerCorner和upperCorner的建议。注意我已经大大减少了坐标列表以保持简短。
意识到我需要迭代<coordinates>
元素,但不确定最有效的方法来计算lowerCorner和upperCorner对,最终映射到GML Envelope。
XML示例
<?xml version="1.0" encoding="UTF-8"?>
<Extract>
<n1:XMLExtract xmlns:n1="urn:com:aaa">
<regionId>4671</regionId>
<coordinates>151.344553 -33.4123250000193, 151.346606 -33.4126370000193, 151.347188 -33.4127280000193, 151.347707 -33.4127990000193, 151.347858 -33.4121160000193, 151.34931 -33.4123270000192, 151.349253 -33.4125910000192, 151.349693 -33.4126610000193, 151.34963 -33.4129810000192, 151.351338 -33.4132280000193, 151.351393 -33.4129550000193, 151.352038 -33.4130480000192, 151.352169 -33.4128100000193, 151.352355 -33.4128370000193, 151.35249 -33.4128910000193, 151.352585 -33.4129170000193, 151.352913 -33.4130080000193, 151.35294 -33.4131310000193, 151.355307 -33.4134860000192, 151.355315 -33.4134470000193, 151.355764 -33.4135020000193, 151.355757 -33.4135590000193, 151.356196 -33.4136240000192, 151.356229 -33.4134890000192, 151.356342 -33.4136260000193, 151.358407 -33.4139280000192, 151.358335 -33.4142510000192, 151.358465 -33.4143660000193, 151.359572 -33.4145260000194, 151.359936 -33.4144860000193, 151.360146 -33.4146080000193, 151.360627 -33.4146790000192, 151.360619 -33.4146980000193, 151.362603 -33.4149980000193, 151.362996 -33.4150940000193, 151.363655 -33.4158080000193, 151.364236 -33.4161380000194, 151.365691 -33.4163460000193, 151.366212 -33.4164920000193, 151.367333 -33.4170870000193, 151.368456 -33.4180250000193, 151.368481 -33.4180200000193, 151.368888 -33.4183130000193, 151.371305 -33.4187840000193, 151.373106 -33.4187890000193, 151.374004 -33.4189970000194, 151.374994 -33.4194460000193, 151.376513 -33.4199650000193, 151.378063 -33.4197680000193, 151.379519 -33.4185780000193, 151.383555 -33.4161210000193, 151.393929 -33.4059400000192, 151.396063 -33.4062720000193, 151.396727 -33.4051740000192, 151.39785 -33.4032380000193, 151.397122 -33.4027200000192, 151.396761 -33.4022700000193, 151.396541 -33.4008350000192, 151.397496 -33.3995910000192, 151.397788 -33.3990280000193, 151.397788 -33.3990100000192, 151.397773 -33.3990000000192, </coordinates>
<interactionId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="1" />
<interactionTypeId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="1" />
<refNumber/>
<incidentNumber/>
<payloadId>20002065</payloadId>
<filename/>
<url/>
</n1:XMLExtract>
</Extract>
所需的输出如下:
<gml:boundedBy>
<gml:Envelope srsDimension="2" srsName="EPSG:4283">
<gml:lowerCorner>-30.511985 151.63592</gml:lowerCorner>
<gml:upperCorner>-30.49207 151.669169</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
答案 0 :(得分:0)
假设您要查找包围多边形的矩形的坐标,并假设您的处理器支持EXSLT扩展函数str:split()
,math:min()
和math:max()
(IOW,您正在使用libxslt或Xalan),你可以这样做:
XSLT 1.0 + EXSLT
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:n1="urn:com:aaa"
xmlns:exsl="http://exslt.org/common"
xmlns:math="http://exslt.org/math"
xmlns:str="http://exslt.org/strings"
extension-element-prefixes="exsl math str"
exclude-result-prefixes="n1">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/Extract">
<xsl:variable name="vertices-rtl">
<xsl:for-each select="str:split(n1:XMLExtract/coordinates, ', ')">
<v x="{substring-before(., ' ')}" y="{substring-after(., ' ')}"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="vertices" select="exsl:node-set($vertices-rtl)/v" />
<output>
<lowerLeft>
<xsl:value-of select="math:min($vertices/@x)" />
<xsl:text> </xsl:text>
<xsl:value-of select="math:min($vertices/@y)" />
</lowerLeft>
<upperRight>
<xsl:value-of select="math:max($vertices/@x)" />
<xsl:text> </xsl:text>
<xsl:value-of select="math:max($vertices/@y)" />
</upperRight>
</output>
</xsl:template>
</xsl:stylesheet>
应用于您的示例输入,结果将是:
<?xml version="1.0" encoding="UTF-8"?>
<output>
<lowerLeft>151.344553 -33.4199650000193</lowerLeft>
<upperRight>151.39785 -33.3990000000192</upperRight>
</output>