I have a KML file which defines an area. I want to get coordinates of some points inside that area using my KML file.

I googled a lot, but I only found codes to check if a point is inside. My issue is that I am blind about the internal points and I want to get some sample points.

Any API or code sample would help.


I am writing a PHP program.

  • hi, maybe completly dumb, but when i was working with .kml data, i used google earth to look the location of the data. maybe it could help, you just have to drag and drop the file on google earth and it will show you the extent. then you just pick point from what you see ? – Maximilien jaffrès Jan 2 '19 at 14:16
  • @Maximilienjaffrès, it's not just one file. There are about 30 files which I need to get at least 20 points for each. Therefore, I really need to automate the stuff. – Zeinab Abbasimazar Jan 2 '19 at 14:41
  • 1
    What software are you using - or what code are you writing? It's hard to give an answer without knowing that. – Mark Ireland Jan 2 '19 at 15:16
  • 1
    QGIS has the algorithm Random points inside polygons. – csk Jan 2 '19 at 20:44

In PostGIS there's the ST_PointOnSurface() query which returns a point that is always inside the polygon. There's good information in How is ST_PointOnSurface calculated?, which explains how the algorithm works:

The horizontal bisector is found, then the midpoint of the widest intersection is used.

So to create multiple points you could find other ways to generate lines across the polygon and then take their midpoints.

Not the answer you're looking for? Browse other questions tagged or ask your own question.