Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add read geojson capability #246

Open
1 task
ncgl-syngenta opened this issue Jun 13, 2022 · 1 comment
Open
1 task

Add read geojson capability #246

ncgl-syngenta opened this issue Jun 13, 2022 · 1 comment

Comments

@ncgl-syngenta
Copy link

Describe the feature request

Looking for the ability to easily read a geojson file into the Reader.

Contributions

  • I am interested in implementing the described feature request and submit as a PR.
@karimbahgat
Copy link
Collaborator

karimbahgat commented Jan 10, 2023

Directly reading the contents of a geojson file is a bit outside the scope of this library, but there are convenience methods for writing shapes from geojson dicts, which can then be opened with a Reader. Perhaps something like this:

import shapefile
import json

geoj = json.loads(open('fromfile.geojson').read())
w = shapefile.Writer('tofile.shp')
for feat in geoj['features']:
    w.shape(feat['geometry'])
w.close()

r = shapefile.Reader('tofile.shp')

Some more work required to add fields and records, and detecting the correct field types, depending on your use-case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants