0

I have a xml file that keeps the edges of a polygon designed in map like this:

<polygons>
    <polygon>
        <point x="23.40637" y="38.20176"/>
        <point x="23.45169" y="38.11011"/>
        <point x="23.43383" y="38.20284"/>
        <point x="23.52722" y="38.27285"/>
        <point x="23.41323" y="38.25023"/>
        <point x="23.40774" y="38.20068"/>
        <point x="23.41598" y="38.18020"/>
    </polygon>
</polygons>

My problem is that I need to get a number of inner points of the polygon in a new xml file. I tried to implement something in Javascript to generate random points inside the polygon, but it turned to a disaster when i tried to include it in an xsl. What actually I was trying to do is to feed a function with a list of objects that contains my initial x,y points and return a random x and y from inside the polygon.

Does anyone have any idea how to do it?

Note: I do not care about overlapping polygons

  • Do you need a [Convex hull](https://en.wikipedia.org/wiki/Convex_hull)? – zx485 Feb 12 '18 at 17:29
  • What XSLT processor are you using, exactly and are you limited to implementing this in XSLT? – Tomalak Feb 12 '18 at 17:40
  • When you say "random", how random does it have to be? Do you require that all points within the polygon have an equal chance of being selected, for example? – Michael Kay Feb 12 '18 at 22:52
  • "It turned into a disaster". We solve problems on this site by studying the symptoms. If you don't tell us what the disaster looked like, we can't tell you why it happened. – Michael Kay Feb 12 '18 at 23:04
  • I use the standard XSLT1 processors. – Andrew Karras Feb 13 '18 at 13:16
  • about the random points in the polygon, each point has an equal chance of being selected and the accuracy of the functionality will be accomplished by the number of the random points that will be created. – Andrew Karras Feb 13 '18 at 13:21

1 Answers1

0

A quick search reveals a number of algorithms for generating a "random" point within the interior of a polygon, for example:

https://gis.stackexchange.com/questions/6412/generate-points-that-lie-inside-polygon

https://codereview.stackexchange.com/questions/69833/generate-sample-coordinates-inside-a-polygon

How to get a random point on the interior of an irregular polygon?

The only problem with these answers is that they are in the wrong programming language. However, translating them into XSLT doesn't look particularly difficult. Some of them rely on a random number generator: you don't get that in the standard function library until XSLT 3.0 (fn:random-number-generator), but some XSLT 1.0 and XSLT 2.0 processors offer the exslt:random extension function from the EXSLT library.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164