Commit 51aa25ac authored by Kim Mortimer's avatar Kim Mortimer
Browse files

Extending bounding box to handle multipolygon

parent 523717c4
......@@ -669,83 +669,125 @@
</xsl:for-each>
<!-- TODO: index bounding polygon -->
<xsl:for-each select=".//gmd:EX_GeographicBoundingBox[
./gmd:westBoundLongitude/gco:Decimal castable as xs:decimal and
./gmd:eastBoundLongitude/gco:Decimal castable as xs:decimal and
./gmd:northBoundLatitude/gco:Decimal castable as xs:decimal and
./gmd:southBoundLatitude/gco:Decimal castable as xs:decimal
]">
<xsl:variable name="format" select="'#0.000000'"></xsl:variable>
<xsl:variable name="w"
select="format-number(./gmd:westBoundLongitude/gco:Decimal/text(), $format)"/>
<xsl:variable name="e"
select="format-number(./gmd:eastBoundLongitude/gco:Decimal/text(), $format)"/>
<xsl:variable name="n"
select="format-number(./gmd:northBoundLatitude/gco:Decimal/text(), $format)"/>
<xsl:variable name="s"
select="format-number(./gmd:southBoundLatitude/gco:Decimal/text(), $format)"/>
<!-- Example: ENVELOPE(-10, 20, 15, 10) which is minX, maxX, maxY, minY order
http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4
https://cwiki.apache.org/confluence/display/solr/Spatial+Search
bbox field type limited to one. TODO
<xsl:if test="position() = 1">
<bbox>
<xsl:text>ENVELOPE(</xsl:text>
<xsl:value-of select="$w"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$e"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$n"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$s"/>
<xsl:text>)</xsl:text>
</field>
</xsl:if>
-->
<xsl:choose>
<xsl:when test="-180 &lt;= number($e) and number($e) &lt;= 180 and
-180 &lt;= number($w) and number($w) &lt;= 180 and
-90 &lt;= number($s) and number($s) &lt;= 90 and
-90 &lt;= number($n) and number($n) &lt;= 90">
<xsl:if test="count(.//gmd:EX_GeographicBoundingBox)">
<geojson>
<xsl:variable name="isMulti">
<xsl:choose>
<xsl:when test="$e = $w and $s = $n">
<location><xsl:value-of select="concat($s, ',', $w)"/></location>
</xsl:when>
<xsl:when
test="($e = $w and $s != $n) or ($e != $w and $s = $n)">
<!-- Probably an invalid bbox indexing a point only -->
<location><xsl:value-of select="concat($s, ',', $w)"/></location>
<xsl:when test="count(.//gmd:EX_GeographicBoundingBox) = 1">
<xsl:text>false</xsl:text>
</xsl:when>
<xsl:otherwise>
<geojson>
<xsl:text>{"type": "polygon",</xsl:text>
<xsl:text>"coordinates": [[</xsl:text>
<xsl:value-of select="concat('[', $w, ',', $s, ']')"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="concat('[', $e, ',', $s, ']')"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="concat('[', $e, ',', $n, ']')"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="concat('[', $w, ',', $n, ']')"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="concat('[', $w, ',', $s, ']')"/>
<xsl:text>]]}</xsl:text>
</geojson>
<location><xsl:value-of select="concat(
(number($s) + number($n)) div 2,
',',
(number($w) + number($e)) div 2)"/></location>
<xsl:text>true</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
<!--<xsl:value-of select="($e + $w) div 2"/>,<xsl:value-of select="($n + $s) div 2"/></field>-->
</xsl:for-each>
</xsl:variable>
<xsl:choose>
<xsl:when test="count(.//gmd:EX_GeographicBoundingBox) = 1">
<xsl:text>{"type": "Polygon",</xsl:text>
<xsl:text>"coordinates": [
</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>{"type": "MultiPolygon",</xsl:text>
<xsl:text>"coordinates": [ <!-- curly brace opened, 1 square brackets opened -->
</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select=".//gmd:EX_GeographicBoundingBox[
./gmd:westBoundLongitude/gco:Decimal castable as xs:decimal and
./gmd:eastBoundLongitude/gco:Decimal castable as xs:decimal and
./gmd:northBoundLatitude/gco:Decimal castable as xs:decimal and
./gmd:southBoundLatitude/gco:Decimal castable as xs:decimal
]">
<xsl:variable name="format" select="'#0.000000'"></xsl:variable>
<xsl:variable name="w"
select="format-number(./gmd:westBoundLongitude/gco:Decimal/text(), $format)"/>
<xsl:variable name="e"
select="format-number(./gmd:eastBoundLongitude/gco:Decimal/text(), $format)"/>
<xsl:variable name="n"
select="format-number(./gmd:northBoundLatitude/gco:Decimal/text(), $format)"/>
<xsl:variable name="s"
select="format-number(./gmd:southBoundLatitude/gco:Decimal/text(), $format)"/>
<!-- Example: ENVELOPE(-10, 20, 15, 10) which is minX, maxX, maxY, minY order
http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4
https://cwiki.apache.org/confluence/display/solr/Spatial+Search
bbox field type limited to one. TODO
<xsl:if test="position() = 1">
<bbox>
<xsl:text>ENVELOPE(</xsl:text>
<xsl:value-of select="$w"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$e"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$n"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="$s"/>
<xsl:text>)</xsl:text>
</field>
</xsl:if>
-->
<xsl:if test="$isMulti = 'true'">
<xsl:text>[</xsl:text> <!-- wraps the entire polygon component in a square bracket -->
</xsl:if>
<xsl:text>[</xsl:text> <!-- wraps exterior -->
<xsl:value-of select="concat('[', $w, ',', $s, ']')"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="concat('[', $e, ',', $s, ']')"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="concat('[', $e, ',', $n, ']')"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="concat('[', $w, ',', $n, ']')"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="concat('[', $w, ',', $s, ']')"/>
<xsl:text>]</xsl:text><!-- closes the exterior -->
<xsl:if test="$isMulti = 'true'">
<xsl:text>]</xsl:text> <!-- closes the wrapping -->
</xsl:if>
<xsl:if test="position() != last() and $isMulti = 'true'">
<xsl:text>,</xsl:text> <!-- adds a comma to allow the next polygon -->
</xsl:if>
<!--<xsl:value-of select="($e + $w) div 2"/>,<xsl:value-of select="($n + $s) div 2"/></field>-->
<xsl:text>]}</xsl:text>
</xsl:for-each>
</geojson>
<xsl:for-each select=".//gmd:EX_GeographicBoundingBox[
./gmd:westBoundLongitude/gco:Decimal castable as xs:decimal and
./gmd:eastBoundLongitude/gco:Decimal castable as xs:decimal and
./gmd:northBoundLatitude/gco:Decimal castable as xs:decimal and
./gmd:southBoundLatitude/gco:Decimal castable as xs:decimal
]">
<xsl:variable name="format" select="'#0.000000'"></xsl:variable>
<xsl:variable name="w"
select="format-number(./gmd:westBoundLongitude/gco:Decimal/text(), $format)"/>
<xsl:variable name="e"
select="format-number(./gmd:eastBoundLongitude/gco:Decimal/text(), $format)"/>
<xsl:variable name="n"
select="format-number(./gmd:northBoundLatitude/gco:Decimal/text(), $format)"/>
<xsl:variable name="s"
select="format-number(./gmd:southBoundLatitude/gco:Decimal/text(), $format)"/>
<xsl:choose>
<xsl:when test="$e = $w and $s = $n">
<location><xsl:value-of select="concat($s, ',', $w)"/></location>
</xsl:when>
<xsl:when
test="($e = $w and $s != $n) or ($e != $w and $s = $n)">
<!-- Probably an invalid bbox indexing a point only -->
<location><xsl:value-of select="concat($s, ',', $w)"/></location>
</xsl:when>
<xsl:otherwise>
<location><xsl:value-of select="concat(
(number($s) + number($n)) div 2,
',',
(number($w) + number($e)) div 2)"/></location>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:if>
<xsl:if test="count(.//gmd:EX_BoundingPolygon/gmd:polygon/gml:Polygon)>0 and count(.//gmd:EX_BoundingPolygon/gmd:polygon/gml:Point)=0">
<geojson>
<xsl:variable name="isMulti">
......@@ -766,7 +808,7 @@
</xsl:when>
<xsl:otherwise>
<xsl:text>{"type": "MultiPolygon",</xsl:text>
<xsl:text>"coordinates": [ <!-- curly brace opened, 1 or 2 square brackets opened -->
<xsl:text>"coordinates": [ <!-- curly brace opened, 1 square brackets opened -->
</xsl:text>
</xsl:otherwise>
</xsl:choose>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment