Import error from shapely package

pyspark

#1

I imported shapely package and I am calculating intersection area of multipolygons, but I got this error,

ImportError: No module named shapely.geometry.geo

is there any issue with shapely package? how to solve this issue?


#2

@Ravindranath_Edlapat Can you get us the complete code which is your trying?


#3

@annapurna this is the code I am running,

from shapely import *
from shapely.geometry import asShape
from shapely.ops import unary_union

def poly_coord(line):
parsed_line = line.replace(’"’,’’).split(‘POLYGON ‘)[1].replace(’(’,’’).replace(’)’,’’).split(’ ')
float_point = [float(parsed_line[i]) for i in range(0,len(parsed_line))]
coordinates = [[[float_point[i:i+2] for i in range(0,len(float_point),2)]]]
return coordinates
def to_shape(multi_polygon):
def to_multi_polygon_json(multi_polygon_json):
ps = []
for p in multi_polygon_json:
ls = []
for l in p:
cs = []
for c in l:
ds = []
for d in c:
ds.append(d)
cs.append((ds[0], ds[1]))
ls.append(cs)
ps.append(ls)
return {‘type’: ‘MultiPolygon’, ‘coordinates’: ps}
return asShape(to_multi_polygon_json(multi_polygon))

def intersection_area(multi_polygon_a, multi_polygon_b):
a = to_shape(multi_polygon_a)
b = to_shape(multi_polygon_b)
return a.intersection(b).area

line = sc.textFile(’/user/edraviitbig/myrepo/melb_urban_forest_2016.txt’)

uf = line.map(poly_coord)

sa2 = sqlContext.read.json(’/user/edraviitbig/myrepo’)
sa2c = sa2.drop(’_corrupt_record’).dropna()
sa2sub = sa2c.select(sa2c.sa2_name16,sa2c.geometry)
sa2subRDD = sa2sub.map(lambda s: (s[0],s[1].coordinates))

subCartUf = sa2subRDD.cartesian(uf)
suburbGreen = SubCartUf.map(lambda s: (s[0][0], intersection_area(s[0][1],s[1])))

here I am getting the error ,
ImportError: No module named shapely.geometry.geo


#4

You have given variable as SubCartUf instead of subCartUf.


#5

@annapurna I am getting the same error with the variable subCartUf.