I need help to use pyspark with GeoSpark
Hi there! I trying to make a python wrapper for GeoSpark because I want to process geospatial data using SparkSQL, I created these lines below:
spark.conf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
spark.conf.set("spark.kryo.registrator", "org.datasyslab.geospark.serde.GeoSparkKryoRegistrator")
sc._jvm.org.datasyslab.geosparksql.utils.GeoSparkSQLRegistrator.registerAll(sc._jvm.SQLContext(sc._jsc.sc()))
sqlContext.sql("SELECT ST_GeomFromWKT('POINT(-46.23 -23.46)','4326') as x").show() #this works fine
df = sqlContext.sql("SELECT ST_GeomFromWKT('POINT(-46.23 -23.46)','4326') as x") #raise exception
The exception is:
Py4JException: An exception was raised by the Python Proxy. Return Message: x
py4j.Py4JException: An exception was raised by the Python Proxy. Return Message: x
at py4j.Protocol.getReturnValue(Protocol.java:438)
at py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:105)
at com.sun.proxy.$Proxy60.getNewDatasetInfosJson(Unknown Source)
How I can bind sqlContext to variable?
Thanks
@devlucasc This is very interesting. We haven't try to use GeoSpark in Python yet. I don't even think it can work like this way.
@zongsizhang You have done some research on converting GeoSpark to Python. Any ideas about this? If we only expose GeoSpark SQL API to Python instead of the RDD API, will it be possible?
@devlucasc Hi, thanks for your feedback. As you may know py4j can only automatically handle primitive type like int and string when retrieve java object and "x" in your code is absolutely a its.geom.Point object. Python code can't understand this object so it can't be manipulated in python. And that's the greatest reason why we don't support pyspark. As to this problem, I'm not 100% sure about the reason, can you please give me the whole demo so that I can debug it and give you further explanation?
Has anybody an insight on how much time it would cost to enable pyspark support? What would be the best approach to tackle this? We really need performant spatial joins and pyspark, and it seems like there is no tool yet that can do this out of the box?
@BCarette There is no technical difficulty to implement this. The basic idea is use python shapely to send/receive the geometry data and communicate with GeoSpark RDD/SQL.
The only issue is that we are short of manpower. I am a PhD student who is busy at my other research projects. We need lots of help from the community to implement all these exciting features. This is why I label this issue as help wanted.
We are looking for someone to help us implement a prototype of the Python API. Any contribution will be greatly appreciated.
@BCarette There is no technical difficulty to implement this. The basic idea is use python shapely to send/receive the geometry data and communicate with GeoSpark RDD/SQL.
The only issue is that we are short of manpower. I am a PhD student who is busy at my other research projects. We need lots of help from the community to implement all these exciting features. This is why I label this issue as
help wanted.We are looking for someone to help us implement a prototype of the Python API. Any contribution will be greatly appreciated.
Very interested in if shapely objects can be stored in a pyspark dataframe. Looking over the docs I'm not sure how to accomplish this. Maybe as a UDT?
https://spark.apache.org/docs/2.1.2/api/python/_modules/pyspark/sql/types.html
@BCarette There is no technical difficulty to implement this. The basic idea is use python shapely to send/receive the geometry data and communicate with GeoSpark RDD/SQL.
The only issue is that we are short of manpower. I am a PhD student who is busy at my other research projects. We need lots of help from the community to implement all these exciting features. This is why I label this issue as
help wanted.We are looking for someone to help us implement a prototype of the Python API. Any contribution will be greatly appreciated.
Willing to try this, will let you know
@BCarette There is no technical difficulty to implement this. The basic idea is use python shapely to send/receive the geometry data and communicate with GeoSpark RDD/SQL.
The only issue is that we are short of manpower. I am a PhD student who is busy at my other research projects. We need lots of help from the community to implement all these exciting features. This is why I label this issue as
help wanted.We are looking for someone to help us implement a prototype of the Python API. Any contribution will be greatly appreciated.
Happy to help too!
I created Python wrapper for GeoSparkSQL API. It is available at https://github.com/Imbruced/geo_pyspark. It allows to use all GeoSparkSQL funcionality, also it is possible to transform geoapandas dataframe and shapely objects to GeoSpark and reverse. Supported versions Spark 2.2, 2.3, 2.4 GeoSpark 1.2.0 Python 3.6 (I ll test if 3.7 works as soon as possible) Currently I am creating documentation in sphinx. Any help with maintenance and development will be greatly appreciated.
@jiayuasu can we close this issue ?