I have the usual US census states shapefile for the 48 contiguous states. I am trying to select a state of interest from that shapefile then save that shapefile and display. I want to use GeoPandas, Shapely, Fiona to do this.

Any ideas on how this could be done?

  • GeoPandas use Shapely and Fiona
    – gene
    Nov 20, 2018 at 17:49

1 Answer 1


Hard to say without more info but like this:

import geopandas as gpd

states = gpd.read_file(path_to_shape)

#select alaska if column name is "State"
ak = states[states['State'] == 'Alaska'])


ak.to_file(driver = 'ESRI Shapefile', filename = out_path)
  • Perfect! Thank you so much! Only thing I am trying to do now is created an outpath to my desktop. Not sure what to_file(out_path) means exactly. I created a variable called out_path like so: out_path = r"C:\Users\new\Desktop\selection_state.shp"....and then at the end of that code snippet I wrote: selection.to_file(out_path). Gives me a RuntimeError and says Failed to open C:\Users\new\Desktop\selection_state.shp
    – yuen2
    Nov 20, 2018 at 18:03
  • try selection.to_file(driver = 'ESRI Shapefile', filename = out_path), I suggest you read geopandas.org as all your questions are answered in the documentation Nov 20, 2018 at 18:13
  • If it's not asking too much. I have a related question. Would this be correct way to reproject that shapefile data to another projection? ak.crs = ({'init' :'epsg:3395'}), I want to put it in the best UTM but I don't think GeoPandas offers the option to input UTM projections like for example UTM 10 for California.
    – yuen2
    Nov 20, 2018 at 18:53
  • Everything has an EPSG, spatialreference.org/ref/epsg/wgs-84-utm-zone-10n is the one you want. What you have listed there is defining the projection, be careful that you don't actually need to reproject which would be ak = ak.to_crs({'init': 'epsg:3395'}), once again, this is in the documentation, geopandas.org/projections.html, please read. Nov 20, 2018 at 19:30
  • Thanks once more. What I have has defined the projection, that means that my California shapefile is not in epsg: 3395 projection? Is defining the projection the same thing as reprojecting the shapefile?
    – yuen2
    Nov 20, 2018 at 20:06

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