Rasterize a shapefile with Geopandas or fiona - python

المشرف العام

Administrator
طاقم الإدارة
I need to rasterize a really simple shapefile a bit like this http://tinyurl.com/odfbanu. Which is just a shapefile coutaining counties in the US.

So my goal is to rasterize it and assign a value to every polygon sharing a comon value, LSAD in the exempe. I know that GDAL can do that but I would rather not use system command in that script and I heard that either fiona or Geopandas can do it. I just began messing with Python and so I need your help

So I wrote the beginning of the code inspired by shongololo in the thread :Dissolve polygons based on attributes with Python (shapely - fiona).

from geopandas import GeoDataFramename_in = 'cb_2013_us_county_20m.shp'#Open the file with geopandascounties = GeoDataFrame.from_file(name_in)#Add a column to the Geodataframe containing the new valuefor i in range (len(counties)): LSAD = counties.at[i,'LSAD'] if LSAD == 00 : counties['LSAD_NUM'] == 'A' elif LSAD == 03 : counties['LSAD_NUM'] == 'B' elif LSAD == 04 : counties['LSAD_NUM'] == 'C' elif LSAD == 05 : counties['LSAD_NUM'] == 'D' elif LSAD == 06 : counties['LSAD_NUM'] == 'E' elif LSAD == 13 : counties['LSAD_NUM'] == 'F' elif LSAD == 15 : counties['LSAD_NUM'] == 'G' elif LSAD == 25 : counties['LSAD_NUM'] == 'I' else : counties['LSAD_NUM'] == 'NA'Really easy stuff so now I am wondering how can I actually write those shapes to a tiff. I began working with Geopandas as I believed that was the best option but if you have an fiona suggestion I am up for it too.



أكثر...
 
أعلى