-1

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.

EDIT 1:

I am writing a PHP program.

Andy
  • 1,365
  • 9
  • 16
  • See https://gis.stackexchange.com/questions/76498/how-is-st-pointonsurface-calculated – Marc Pfister Jan 02 '19 at 14:16
  • 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 02 '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 02 '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 02 '19 at 15:16
  • 1
    QGIS has the algorithm Random points inside polygons. – csk Jan 02 '19 at 20:44
  • @MarkIreland, please review my edit. – Zeinab Abbasimazar Jan 04 '19 at 19:09
  • It's probably not enough to convince people to reopen the question, since you don't have any code and this site really likes to see code samples, not make broad suggestions. So I would try and find a library that you can use with PHP to carry out spatial analyses and ask a new question once you've tried that, if you're still having problems. For example, a quick search shows me GeoPHP, which can read KML and do spatial actions on it. So I'd try something like that if possible. – Mark Ireland Jan 04 '19 at 19:40
  • @MarkIreland, thanks for your feedback. I will search and try. – Zeinab Abbasimazar Jan 04 '19 at 20:15
  • @MarkIreland, would you please review my new question? – Zeinab Abbasimazar Jan 04 '19 at 21:19

1 Answers1

1

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.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Marc Pfister
  • 4,097
  • 17
  • 11