I don't understand the difference between OGR and Geopandas librairies. I have checked the documentation of GDAL as well as http://geopandas.org/ but I still don't get it. I just started learning about them and for now I'm trying to write some scripts in python using Geopandas.

My goal is to select features from a shapefile where field="value", then export the selected features to a shapefile. The second step would be to add another field to the output shapefile(with only the selected features from the first shapefile) and set it to a certain value. Doing the second part with OGR seems easy. This is how I've done it :

from osgeo import ogr
driver = ogr.GetDriverByName('ESRI Shapefile')
dataSrc = driver.Open("myshp.shp", 1)
fld = ogr.FieldDefn('City', ogr.OFTString)
lyr = dataSrc.GetLayer()
for feature in lyr:
    feature.SetField("Not Found", fld)
dataSrc= None

However I don't see how I can do the same thing using Geopandas. I might be missing the point though that's why I'm confused between the use of the two librairies.

I know that this is easily done using QGIS or ArcGIS manually, but as of now I'm trying to learn how to use python with Geopandas.

How can I achieve my goal explained above using Geopandas?

  • I think you should focus your question on how to achieve that one specific goal instead of asking a broad question about differences.
    – PolyGeo
    Commented Jul 19, 2016 at 20:56
  • @PolyGeo My main concern is to know the use of each library and therefore the difference between them. By knowing that I might know if that goal is achievable in the first place or not. I don't know how specific I can be?
    – GeoSal
    Commented Jul 20, 2016 at 0:14
  • 1
    I've edited to show how. It now asks a single specific question rather than two questions (one specific and one broad).
    – PolyGeo
    Commented Jul 20, 2016 at 0:18

1 Answer 1


I didn't knew geopandas, it is very easy to add a field, a great library indeed. You just need to read your file add it and save.

dataSrc = gpd.read_file('my_shp.shp')
dataSrc['new_field'] = 1

Selecting is also straightforward:

dataSrc = gpd.read_file('my_shp.shp')
  • Thank u so much @caiohamamura! It works. I am still confused though about the use of OGR and Geopandas. Can u clarify this point for me please?
    – GeoSal
    Commented Jul 20, 2016 at 1:23
  • 1
    They are just different libraries, as I said I don't know geopandas, looks like a new library (version is still 0.2). OGR is very mature. I think geopandas still won't have many options to access things OGR already does, but for what I've already seen geopandas is FAR easier. But usually there's a tradeoff between easy and access to advanced features. Commented Jul 20, 2016 at 1:26
  • 2
    Also another difference is that OGR is directly wrapped to C++ OGR libraries, while geopandas uses other python libraries such as fiona which uses OGR wrapper, so you have many layers between python code and C++ code, this usually will lead to worse performance. Commented Jul 20, 2016 at 1:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.