I have a number of WKB strings, couple of examples given below: I want to convert them to WKT or GeoJSON type as I am able to do using the following online tool: https://rodic.fr/blog/online-conversion-between-geometric-formats/ Is there a way for me to do the same on Python? Answer You can use shapely for this:
Tag: shapely
Why do I get an error when trying to read a file in geopanda’s included datasets?
I’ve just installed Anaconda in my new laptop, and created an environment with geopandas installed in it. I’ve tried to upload the world map that comes with geopandas through the following code: But I obtain the following error message: Since this error has never appeared in my old laptop, I guess it is related to some problem during installation, but
When do I need to use a GeoSeries when creating a GeoDataFrame, and when is a list enough?
I define a polygon: and create a list of random points: I want to know which points are within the polygon. I create a GeoDataFrame with a column called points, by first converting the points list to GeoSeries: Then simply do: which returns a pandas.core.series.Series of booleans, indicating which points are within the polygon. However, if I don’t create the
Converting a list of coordinates to point geometry
My geopandas df looks like this: As you can see, the geometry column is a list containing longitude and latitude values. Is there an efficient way to convert them to points? This works but is very inefficient: When I put this in a loop I get TypeError: len() of unsized object Basically I need the inverse of this question. Reproducible
Difference between wkt and str
I have a shapely Polygon. What is the difference between converting it to wkt and converting it to string: Is the result always the same? And can these two be used interchangeably? Answer They are the same. Looking at the source code BaseGeometry.__str__() method returns self.wkt. So with P.wkt or str(P) you get the same Well Known Text (WKT) representation.
Delete polygons that have one or more side parts in common
I am trying to solve a particular case of comparison of polygons to others. I have five polygons distributed as in the figure below. The black polygon is the one with the largest area. There may be other similar cases, the main rule is to remove the smallest polygons among all those that have one or more side portions in
How do I plot Shapely polygons and objects using Matplotlib?
I want to use Shapely for my computational geometry project. I need to be able to visualize and display polygons, lines, and other geometric objects for this. I’ve tried to use Matplotlib for this but I am having trouble with it. I would like to be able to display this polygon in a plot. How would I change my code
How to calculate the center of gravity with shapely in python?
I discovered shapely but I did not find how to calculated the center of gravity of a polygon! Does someone have the solution? Answer If your polygon has a uniform density, its center of mass coincides with its centroid. In shapely, the centroid can be directly calculated as:
Remove a Polygon from a MultiPolygon with shapely in Python
I am working with spatial objects in Python using the shapely library. Given a MultiPolygon, I want to remove from it the Polygons which don’t contain an obstacle. However, I haven’t found a way to do this, even though I can get the coordinates from the MultiPolygon just by using the mapping function. I already know which Polygons I want
Import mssql spatial fields into geopandas/shapely geometry
I cannot seem to be able to directly import mssql spatial fields into geopandas. I can import normal mssql tables into pandas with Pymssql without problems, but I cannot figure out a way to import the spatial fields into shapely geometry. I know that the OGR driver for mssql should be able to handle it, but I’m not skilled enough