question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DOC: add example of simple joining two GeoSeries together (append)

See original GitHub issue

I am writing (extremely basic) script using Geopandas and I am stuck a bit due to missing documentation.

I was happy to fing “merging data” at http://geopandas.org/mergingdata.html because I run into TypeError: unsupported operand type(s) for +: 'GeometryArray' and 'GeometryArray' on attempting to merge data split into two such objects.

Sadly, “Merging Data” docs page is not covering simplest possible way of merging data.

For reference my code:

data = gpd.read_file(in_file)

if "waterway" in data:
    rivers = []
    streams = []
    rivers = data[data["waterway"] == "river"]
    rivers.geometry = rivers['geometry'].buffer(0.000250)
    streams = data[data["waterway"] == "stream"]
    streams.geometry = rivers['geometry'].buffer(0.000025)
    (rivers + streams).to_file(out_file, driver = 'GeoJSON')

EDIT: I asked https://gis.stackexchange.com/questions/340463/merge-two-geometryarray-into-one-one-geometryarray-in-geopandas

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
martinfleiscommented, Nov 1, 2019

You are looking for simple append. Reproducible example:

world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
cities = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
merged = world.geometry.append(cities.geometry)

Your example:

data = gpd.read_file(in_file)

if "waterway" in data:
    rivers = []
    streams = []
    rivers = data[data["waterway"] == "river"]
    rivers.geometry = rivers['geometry'].buffer(0.000250)
    streams = data[data["waterway"] == "stream"]
    streams.geometry = rivers['geometry'].buffer(0.000025)
    rivers.append(streams).to_file(out_file, driver = 'GeoJSON')

But yeah, we might add it to docs.

0reactions
martinfleiscommented, Jan 19, 2020

You can check #524 and #529. But first check what is already included on geopandas.readthedocs.io and in examples folder.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Merging Data — GeoPandas 0.12.2+0.gefcb367.dirty ...
In a Spatial Join, observations from two GeoSeries or GeoDataFrame are combined based on their spatial relationship to one another.
Read more >
GeoPandas Documentation - Read the Docs
There are two ways to combine datasets in geopandas – attribute joins and spatial joins. In an attribute join, a GeoSeries or GeoDataFrame...
Read more >
Joins in Python- Merging, Appending and Aggregating Data
We can use the simple merge() function for merging data in pandas. First, we import the two datasets as sal_data and bonus_data using...
Read more >
Relations and spatial joins with vector data - PySAL
For example, the following plot shows the neighborhoods and listing data ... To join two spatial tables together using a spatial join, you...
Read more >
Merge Data & Dissolve Polygons — Python Open ... - PyGIS
Dataframes are widely used in Python for manipulating data. Recall that a dataframe is essentially an Excel spreadsheet (a 2-D table of rows...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found