Ari Simmons
2014-02-17 08:29:44 UTC
Hi all,
I am new to Shapely (but enthusiastic about it), and recently I've
discovered a bit of a road bump.
I have a polygon shapefile that I am reading in via Fiona. This shapefile
contains BOTH polygon and multipolygon items and I need to build an array
for each feature of all the coordinates within it (i.e. both exterior
and/or interior). Notably, two of the polygon items have interior rings
(and they are valid).
I seem to have no problem accessing the exterior coordinates of the
polygon(s)/multipolygon(s) ... but I am not pulling anything for the
interior coordinates.
Do I need to take a new approach here (i.e. LinearRings)...?
Here is my function if it helps...I can send my test file (it is
small)...if you want to see what I mean...
import fiona
from numpy import asarray
from shapely.geometry import shape, Polygon, MultiPolygon
def convert_polygons(inFile):
for polys in fiona.open(inFile):
myShape = shape(polys['geometry'])
exterior_poly = 0
interior_poly = 0
if isinstance(myShape, Polygon):
print "yes, I am a polygon"
# count how many points for each interior polygon
try:
interior_poly += len(myShape.interior.coords)
except:
pass
# count how many points for each exterior polygon
exterior_poly += len(myShape.exterior.coords)
geomArray = asarray(myShape.exterior)
print geomArray
print "number of interior points in polygon " +
str(interior_poly)
print "number of exterior points in polygon " +
str(exterior_poly)
elif isinstance(myShape, MultiPolygon):
print "yes, I am a MultiPolygon"
# count how many points for each interior polygon
try:
interior_poly += len(myShape.interior.coords)
except:
pass
try:
# count how many points for each exterior polygon
exterior_poly += len(myShape.exterior.coords)
except:
pass
try:
geomArray = asarray(myShape.interior)
except:
pass
try:
geomArray = asarray(myShape.exterior)
except:
pass
print geomArray
print "number of interior points in polygon " +
str(interior_poly)
print "number of exterior points in polygon " +
str(exterior_poly)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20140217/6e6be42e/attachment.htm>
I am new to Shapely (but enthusiastic about it), and recently I've
discovered a bit of a road bump.
I have a polygon shapefile that I am reading in via Fiona. This shapefile
contains BOTH polygon and multipolygon items and I need to build an array
for each feature of all the coordinates within it (i.e. both exterior
and/or interior). Notably, two of the polygon items have interior rings
(and they are valid).
I seem to have no problem accessing the exterior coordinates of the
polygon(s)/multipolygon(s) ... but I am not pulling anything for the
interior coordinates.
Do I need to take a new approach here (i.e. LinearRings)...?
Here is my function if it helps...I can send my test file (it is
small)...if you want to see what I mean...
import fiona
from numpy import asarray
from shapely.geometry import shape, Polygon, MultiPolygon
def convert_polygons(inFile):
for polys in fiona.open(inFile):
myShape = shape(polys['geometry'])
exterior_poly = 0
interior_poly = 0
if isinstance(myShape, Polygon):
print "yes, I am a polygon"
# count how many points for each interior polygon
try:
interior_poly += len(myShape.interior.coords)
except:
pass
# count how many points for each exterior polygon
exterior_poly += len(myShape.exterior.coords)
geomArray = asarray(myShape.exterior)
print geomArray
print "number of interior points in polygon " +
str(interior_poly)
print "number of exterior points in polygon " +
str(exterior_poly)
elif isinstance(myShape, MultiPolygon):
print "yes, I am a MultiPolygon"
# count how many points for each interior polygon
try:
interior_poly += len(myShape.interior.coords)
except:
pass
try:
# count how many points for each exterior polygon
exterior_poly += len(myShape.exterior.coords)
except:
pass
try:
geomArray = asarray(myShape.interior)
except:
pass
try:
geomArray = asarray(myShape.exterior)
except:
pass
print geomArray
print "number of interior points in polygon " +
str(interior_poly)
print "number of exterior points in polygon " +
str(exterior_poly)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20140217/6e6be42e/attachment.htm>