1

I have a polygon that looks like this:

enter image description here

I am trying to get the integer coordinates of the inside. I tried to use this to get the interior and exterior coords: (from https://stackoverflow.com/a/21922058/5666087)

def extract_poly_coords(geom):
    if geom.type == 'Polygon':
        exterior_coords = geom.exterior.coords[:]
        interior_coords = []
        for interior in geom.interiors:
            interior_coords += interior.coords[:]
    elif geom.type == 'MultiPolygon':
        exterior_coords = []
        interior_coords = []
        for part in geom:
            epc = extract_poly_coords(part)  # Recursive call
            exterior_coords += epc['exterior_coords']
            interior_coords += epc['interior_coords']
    else:
        raise ValueError('Unhandled geometry type: ' + repr(geom.type))
    return {'exterior_coords': exterior_coords,
            'interior_coords': interior_coords}

extract_poly_coords(polygon)

However, all I get is:

{'exterior_coords': [(98.12195640044152, 100.0),
  (90.43547199174871, 75.85239190885227),
  (83.48863255531036, 62.6409875154827),
  (79.159462374665, 60.63421969938672),
  (79.82352166320345, 91.73874935769751),
  (84.03091398055854, 100.0),
  (98.12195640044152, 100.0)],
 'interior_coords': []}

Why are the interior coords empty?
Is there any way to get the interior coords?

jkr
  • 17,119
  • 2
  • 42
  • 68
vftw
  • 1,547
  • 3
  • 22
  • 51
  • 1
    Your polygon has no interiors (holes), that's why the interiors coords list is empty, see https://shapely.readthedocs.io/en/latest/manual.html#Polygon – Stef May 27 '20 at 20:28
  • Oh, I see. Thank you. Is there any 'easy' way, to create the exact same polyon with holes? – vftw May 27 '20 at 20:30
  • I think you should pass the holes' coords in the contructor as shown in the link. – Stef May 27 '20 at 20:32
  • see also https://stackoverflow.com/questions/48770822/how-to-make-holes-in-a-polygon-in-shapely-python-having-polygons – Stef May 27 '20 at 20:33
  • The problem is that I don't have the inners for my polygon. I am creating a polygon from Voronoi regions' vertices. I am in a pickle, I guess. https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.spatial.Voronoi.html – vftw May 27 '20 at 20:38
  • I don't really understand the question. What result did you actually expect to get? – Georgy May 27 '20 at 20:40
  • I thought there would be some way to get the inner points of a polygon, @Georgy. Since I have the vertices, I was asking for advice on how to get the inside coords. – vftw May 27 '20 at 20:44
  • Yes, but what do you mean exactly by "inside coordinates"? There is an infinite number of points inside a polygon, so I'm not sure which kind of result you expected. – Georgy May 27 '20 at 21:12
  • yes, you're right. The integers coords inside the polygon. Does it sound better? – vftw May 27 '20 at 22:10
  • 1
    Does this answer your question? [Get all lattice points lying inside a Shapely polygon](https://stackoverflow.com/questions/44399749/get-all-lattice-points-lying-inside-a-shapely-polygon) – Georgy May 28 '20 at 21:02

0 Answers0