Shapely point geometry in geopandas df to lat/lon columns

If you have the latest version of geopandas (0.3.0 as of writing), and the if df is a GeoDataFrame, you can use the x and y attributes on the geometry column: df[‘lon’] = df.point_object.x df[‘lat’] = df.point_object.y In general, if you have a column of shapely objects, you can also use apply to do what … Read more

Geopandas: how to read a csv and convert to a geopandas dataframe with polygons?

Geopandas seems to be unable to convert a geometry column from a pandas dataframe. Solution number 2 Try applying the shapely wkt.loads function on your column before converting your dataframe to a geodataframe. from shapely import wkt df[‘geometry’] = df[‘geometry’].apply(wkt.loads) gdf = gpd.GeoDataFrame(df, crs=”epsg:4326″) Good luck! Do not use – crashes spyder and jupyter kernel … Read more

Which geopandas datasets (maps) are available?

As written in the geopandas.datasets.get_path(…) documentation, one has to execute >>> geopandas.datasets.available [‘naturalearth_lowres’, ‘naturalearth_cities’, ‘nybb’] Where naturalearth_lowres: contours of countries naturalearth_cities: positions of cities nybb: maybe New York? Other data sources Searching for “germany shapefile” gave an arcgis.com url which used the “Bundesamt für Kartographie und Geodäsie” as a source. The result of using vg2500_geo84/vg2500_krs.shp … Read more

geopandas point in polygon

Not really clear what kind of data structures you actually have. Also, all your expected results are False, so that’s kind of hard to check. Assuming GeoSeries and GeoDataFrames, I would do this: from shapely.geometry import Point, Polygon import geopandas polys = geopandas.GeoSeries({ ‘foo’: Polygon([(5, 5), (5, 13), (13, 13), (13, 5)]), ‘bar’: Polygon([(10, 10), … Read more

Convert geopandas shapely polygon to geojson

If you don’t want to create this dict manually, you can also rely on geopandas creating it: In [1]: import shapely.geometry In [2]: import geopandas In [3]: shapely_polygon = shapely.geometry.Polygon([(0, 0), (0, 1), (1, 0)]) In [4]: geopandas.GeoSeries([shapely_polygon]).__geo_interface__ Out[4]: {‘bbox’: (0.0, 0.0, 1.0, 1.0), ‘features’: [{‘bbox’: (0.0, 0.0, 1.0, 1.0), ‘geometry’: {‘coordinates’: (((0.0, 0.0), (0.0, … Read more

GeoPandas Set CRS on Points

Geopandas API got cleaned up, and now works without surprises. Make sure to use the lastest stable version and read the docs. Setting the CRS on a GeoDataFrame using its EPSG code is as simple as gdf.set_crs(epsg=4326, inplace=True) where gdf is a geopandas.geodataframe.GeoDataFrame. Watch out for the explicit inplace! So in the example above it … Read more

how to successfully install pyproj and geopandas?

Thanks to the conda-forge community, geopandas is actually pretty easy to install on all platforms using the conda package manager (or: its dependencies, as this is the difficulty). If you have conda, it is just: conda install -c conda-forge geopandas To install conda, you can install the Anaconda python distribution or miniconda: http://conda.pydata.org/docs/download.html See the … Read more

GeoPandas Label Polygons

c[‘geometry’] is a series comprised of shapely.geometry.polygon.Polygon objects. You can verify this by checking In [23]: type(c.ix[23, ‘geometry’]) Out[23]: shapely.geometry.polygon.Polygon From the Shapely docs there is a method representative_point() that Returns a cheaply computed point that is guaranteed to be within the geometric object. Sounds ideal for a situation in which you need to label … Read more

Make a union of polygons in GeoPandas, or Shapely (into a single geometry)

Note: cascaded_union mentioned in the answer below is superceded by unary_union if GEOS 3.2+ is used – this allows unions on different geometry types, not only polygons. To check your version, >>> shapely.geos.geos_version (3, 5, 1) From the question/answer here, it seems this is called a cascaded_union within shapely: from shapely.ops import cascaded_union polygons = … Read more