You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sedona.apache.org by "egorov-viadukt (via GitHub)" <gi...@apache.org> on 2023/11/20 23:40:34 UTC

[I] Unable to read GeoJson with Polygons and Multipolygons [sedona]

egorov-viadukt opened a new issue, #1126:
URL: https://github.com/apache/sedona/issues/1126

   Within my scenario, I am trying to reproduce one of the already running use-cases in our company. For this, we use GeoPandas to import GeoJson files. It worked well following the examples in Sedona documentation. However, when I tried to import a file with different geometry types, I find that Spark can't handle different types out of json.
   
   I would be very thankful for your help.
   
   ## Expected behavior
   
   Following [this example](https://sedona.apache.org/1.5.0/tutorial/sql/#load-geojson-using-spark-json-data-source ), I was expecting to retrieve "similar" outcome as in GeoPandas.
   
   ## Actual behavior
   
   Following the above tutorial, I get back an empty dataframe.
   
   ## Steps to reproduce the problem
   
   Code that I use here:
   
   ```
   schema = "type string, name string, features array<struct<type string, geometry string, properties map<string, string>>>"
   (sedona.read.json(geojson_path, schema=schema) 
       .selectExpr("explode(features) as features") # Explode the envelope to get one feature per row.
       .select("features.*") # Unpack the features struct.
       .withColumn("geometry", F.expr("ST_GeomFromGeoJSON(geometry)")) # Convert the geometry string.
       .show())
   ```
   
   You can try importing the following example/excerpt:
   
   ```
   {
   	"type" : "FeatureCollection",
   	"name" : "Gebaeude_EPSG4326_JSON",
   	"features" : [
   		{
   			"type" : "Feature",
   			"geometry" : {
   				"type" : "Polygon",
   				"coordinates" : [
   					[
   						[ 7.2746115909, 51.2778283936 ],
   						[ 7.2747184496, 51.2778641239 ],
   						[ 7.2746658893, 51.2779260031 ],
   						[ 7.2745578156, 51.2778897872 ],
   						[ 7.2745763052, 51.2778681619 ],
   						[ 7.2746105856, 51.277828055 ],
   						[ 7.2746115909, 51.2778283936 ]
   					]
   				]
   			},
   			"properties" : {
   				"UUID" : "DENW29AL1K70001n",
   				"GEB_TYP" : "Hauptgebäude",
   				"GEB_FKT" : "Wohnhaus",
   				"GEB_NAME" : "",
   				"BAUWEISE" : "",
   				"DACHFORM" : "",
   				"GEB_ZUS" : "",
   				"GRUNDFL" : "67",
   				"FLAECHE" : 66.6,
   				"OEFFENTL" : "nein",
   				"LAGE" : ""
   			}
   		},
   		{
   			"type" : "Feature",
   			"geometry" : {
   				"type" : "Polygon",
   				"coordinates" : [
   					[
   						[ 7.2746115909, 51.2778283936 ],
   						[ 7.2747184496, 51.2778641239 ],
   						[ 7.2746658893, 51.2779260031 ],
   						[ 7.2745578156, 51.2778897872 ],
   						[ 7.2745763052, 51.2778681619 ],
   						[ 7.2746105856, 51.277828055 ],
   						[ 7.2746115909, 51.2778283936 ]
   					]
   				]
   			},
   			"properties" : {
   				"UUID" : "DENW29AL1K70001n",
   				"GEB_TYP" : "Hauptgebäude",
   				"GEB_FKT" : "Wohnhaus",
   				"GEB_NAME" : "",
   				"BAUWEISE" : "",
   				"DACHFORM" : "",
   				"GEB_ZUS" : "",
   				"GRUNDFL" : "67",
   				"FLAECHE" : 66.6,
   				"OEFFENTL" : "nein",
   				"LAGE" : ""
   			}
   		},
   		{
   			"type" : "Feature",
   			"geometry" : {
   				"type" : "MultiPolygon",
   				"coordinates" : [
   					[
   						[
   							[ 7.1199865419, 51.2762210321 ],
   							[ 7.119988913, 51.2762184442 ],
   							[ 7.1199865563, 51.2762210323 ],
   							[ 7.1199865419, 51.2762210321 ]
   						]
   					],
   					[
   						[
   							[ 7.1199865419, 51.2762210321 ],
   							[ 7.1199159896, 51.276298148 ],
   							[ 7.1198254916, 51.2762646788 ],
   							[ 7.11981461, 51.2762765908 ],
   							[ 7.1197230484, 51.2762424839 ],
   							[ 7.1198144632, 51.2761421862 ],
   							[ 7.1198779945, 51.276165033 ],
   							[ 7.1198664749, 51.2761771236 ],
   							[ 7.1199865419, 51.2762210321 ]
   						]
   					]
   				]
   			},
   			"properties" : {
   				"UUID" : "DENW29AL1000Fprz",
   				"GEB_TYP" : "Hauptgebäude",
   				"GEB_FKT" : "Wohnhaus",
   				"GEB_NAME" : "",
   				"BAUWEISE" : "Reihenhaus",
   				"DACHFORM" : "",
   				"GEB_ZUS" : "",
   				"GRUNDFL" : "nicht belegt",
   				"FLAECHE" : 164.7,
   				"OEFFENTL" : "nein",
   				"LAGE" : ""
   			}
   		},
   		{
   			"type" : "Feature",
   			"geometry" : {
   				"type" : "MultiPolygon",
   				"coordinates" : [
   					[
   						[
   							[ 7.1199865419, 51.2762210321 ],
   							[ 7.119988913, 51.2762184442 ],
   							[ 7.1199865563, 51.2762210323 ],
   							[ 7.1199865419, 51.2762210321 ]
   						]
   					],
   					[
   						[
   							[ 7.1199865419, 51.2762210321 ],
   							[ 7.1199159896, 51.276298148 ],
   							[ 7.1198254916, 51.2762646788 ],
   							[ 7.11981461, 51.2762765908 ],
   							[ 7.1197230484, 51.2762424839 ],
   							[ 7.1198144632, 51.2761421862 ],
   							[ 7.1198779945, 51.276165033 ],
   							[ 7.1198664749, 51.2761771236 ],
   							[ 7.1199865419, 51.2762210321 ]
   						]
   					]
   				]
   			},
   			"properties" : {
   				"UUID" : "DENW29AL1000Fprz",
   				"GEB_TYP" : "Hauptgebäude",
   				"GEB_FKT" : "Wohnhaus",
   				"GEB_NAME" : "",
   				"BAUWEISE" : "Reihenhaus",
   				"DACHFORM" : "",
   				"GEB_ZUS" : "",
   				"GRUNDFL" : "nicht belegt",
   				"FLAECHE" : 164.7,
   				"OEFFENTL" : "nein",
   				"LAGE" : ""
   			}
   		}
   	]
   }
   ```
   
   ## Settings
   
   I use the docker image with latest sedona version.
   
   Environment = Standalone
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sedona.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Unable to read GeoJson with Polygons and Multipolygons [sedona]

Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on issue #1126:
URL: https://github.com/apache/sedona/issues/1126#issuecomment-1823743933

   @egorov-viadukt We should improve Sedona doc for reading GeoJSON actually. The reader that you use does not enable `multi-line`, which is critical for multi-line geojson. Wherobots doc website has a more comprehensive explanation on this: https://docs.wherobots.services/1.2.0/tutorials/sedonadb/vector-data/vector-load/#load-multiline-geojson-featurecollection


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Unable to read GeoJson with Polygons and Multipolygons [sedona]

Posted by "Kontinuation (via GitHub)" <gi...@apache.org>.
Kontinuation commented on issue #1126:
URL: https://github.com/apache/sedona/issues/1126#issuecomment-1823777254

   You may want to use `option("multiLine", True)` option to read a multi-line GeoJSON file.
   
   ```
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Unable to read GeoJson with Polygons and Multipolygons [sedona]

Posted by "egorov-viadukt (via GitHub)" <gi...@apache.org>.
egorov-viadukt commented on issue #1126:
URL: https://github.com/apache/sedona/issues/1126#issuecomment-1825383766

   @jiayuasu thanks for the response. I though I actually activated multiline option, but probably I did it at some other point. Now it seems to work. However, only Scala example has this option present, while Java and Python do not. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Unable to read GeoJson with Polygons and Multipolygons [sedona]

Posted by "egorov-viadukt (via GitHub)" <gi...@apache.org>.
egorov-viadukt closed issue #1126: Unable to read GeoJson with Polygons and Multipolygons
URL: https://github.com/apache/sedona/issues/1126


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sedona.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org