1

I have some coordinates from which I am creating a shapefile.

tafo_boundary_coords = [(652316, 742792), (652161, 742920), (651897, 743166), (652210, 743477), (652298, 743448),(652375, 743458), (652459, 743518), (652540, 743509), (652596, 743471), (652582, 743420), (652532, 743078)]
muslims1_coords = [(652582, 743420), (652540, 743441), (652486, 743401), (652472, 743414), (652298, 743448), (652375, 743458), (652459, 743518), (652540, 743509), (652596, 743471)]
muslims2_coords = [(652161, 742920), (652180, 742950),(652261.8897, 743099.2634), (652289.2631, 743187),(652307.0113, 743339.2470), (652298, 743448), (652210, 743477), (651897, 743166)]

I went ahead to create an empty GeoDataFrame and added the geometries to it. I also added the CRS information using Fiona.

tafo_cem = gpd.GeoDataFrame()
tafo_boundary_poly = Polygon(tafo_boundary_coords)
tafo_cem.loc[0, 'geometry'] = tafo_boundary_poly
tafo_cem.crs = from_epsg(32630)
muslims_one = LineString(muslims1_coords)
muslims_two = LineString(muslims2_coords)
tafo_cem.loc[1, 'geometry'] = muslims_one
tafo_cem.loc[2, 'geometry'] = muslims_two
print(tafo_cem)
tafo_cem.plot(edgecolor = 'brown',linewidth = 2,  figsize = (9, 9))

I also provide the information for the output filepath:

outfilepath = r"C:\\Users\\...\\tafo.shp"

And finally save it to that filepath. The polygon gets saved alright but the linestrings don't get saved.

I get this error:

"RuntimeError: Failed to write record: {'id': '1', 'type': 'Feature', 'properties': {}, 'geometry': {'type': 'LineString', 'coordinates': ((652582.0, 743420.0), (652540.0, 743441.0), (652486.0, 743401.0), (652472.0, 743414.0), (652298.0, 743448.0), (652375.0, 743458.0), (652459.0, 743518.0), (652540.0, 743509.0), (652596.0, 743471.0))}}"

How can I fix this?

  • 3
    You can't mix geometries in a shapefile (polygons and linestrings) – gene Mar 4 at 20:07
  • Thank you for the feedback. – Algpspatial Mar 7 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.