Reputation: 80
I am using geopandas for some spatial analysis and am running into an error when using the points_from_xy function. I have the following line of code:
MW = gp.GeoDataFrame(mw_coordinates,
geometry=gp.points_from_xy(x=mw_coordinates['x'],
y=mw_coordinates['y'], crs=crs))
Which results in this error:
AttributeError: module 'shapely' has no attribute 'geometry'
I am using MacOS and installed Geopandas with all dependencies via Conda Forge, and the following command does work to import geometry from Shapely manually:
import shapely.geometry
Any help would be appreciated, thanks.
Upvotes: 2
Views: 1416
Reputation: 80
Thanks all for the responses. I was able to resolve this error by starting over in a new conda environment and reinstalling Geopandas from conda forge. I am not sure what the cause was initially as I was also in a fresh environment when I ran into it.
In response to Rob, mw_coordinates is a DataFrame with well names and x-y-z corrdinates:
MW x y z
1.0 1.948293e+06 625635.615173 20.027135
2.0 1.948294e+06 625479.944974 19.999499
3.0 1.948294e+06 625295.156011 19.959875
4.0 1.948134e+06 625177.900975 19.438464
5.0 1.948135e+06 625053.886085 19.554898
6.0 1.947928e+06 625486.354308 19.891194
7.0 1.947928e+06 625388.739060 19.841715
8.0 1.947928e+06 625290.605652 19.962517
9.0 1.947907e+06 625147.859278 19.431860
10.0 1.947907e+06 625052.148115 19.435924
11.0 1.947704e+06 625516.932454 19.277022
12.0 1.947705e+06 625407.428177 19.268081
13.0 1.947699e+06 625296.353875 19.280984
14.0 1.947697e+06 625149.441190 19.254162
15.0 1.947701e+06 625031.845387 19.125739
16.0 1.947526e+06 625516.064688 19.326399
17.0 1.947527e+06 625406.695742 19.288706
18.0 1.947537e+06 625295.598276 19.107959
19.0 1.947529e+06 625148.770325 19.064983
20.0 1.947533e+06 625030.705130 19.097495
With crs equal to the following:
crs = "+proj=lcc +lat_1=37.06666666666667 +lat_2=38.43333333333333 +lat_0=36.5 +lon_0=-120.5 +x_0=2000000 +y_0=500000.0000000002 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs"
And geopandas imported via:
import geopandas as gp
Upvotes: 1
Reputation: 31146
As per comment, without a full minimum example it's not possible to resolve your error. Have synthesized this.
mw_coordinates
is. It looks like a dataframe, could be a dictimport geopandas as gp
import pandas as pd
mw_coordinates = pd.DataFrame(
columns=["name", "x", "y"],
data=[
["Tegucigalpa", -87.2194751979415, 14.103990759076396],
["Belmopan", -88.76707299981655, 17.252033507246892],
["Podgorica", 19.266306924118226, 42.465972512881706],
["Gaborone", 25.91194779328538, -24.646313457438907],
["Male", 73.499947467955, 4.1667081898118],
["Juba", 31.580025592787308, 4.829975198277964],
["Sao Tome", 6.733325153234773, 0.3334021188329075],
["Bern", 7.466975462482424, 46.91668275866772],
["Paramaribo", -55.16703088542437, 5.835030129922586],
["San Marino", 12.441770157800141, 43.936095834768004],
],
)
crs = "epsg:4386"
MW = gp.GeoDataFrame(
mw_coordinates,
geometry=gp.points_from_xy(x=mw_coordinates["x"], y=mw_coordinates["y"], crs=crs),
)
Upvotes: 1