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

Support shapefiles (SHP and GeoJSON) #343

Open
turicas opened this issue Mar 24, 2020 · 0 comments
Open

Support shapefiles (SHP and GeoJSON) #343

turicas opened this issue Mar 24, 2020 · 0 comments

Comments

@turicas
Copy link
Owner

turicas commented Mar 24, 2020

It woud be awesome to read/write from/to SHP and GeoJSON formats, so we can convert between SHP to GeoJSON, SHP to CSV, CSV to GeoJSON, CSV do SHP etc.

It's not that difficult: libraries such as fiona and shapely make the work easier - example from this post:

import csv
from shapely.geometry import Point, mapping
from fiona import collection

schema = { 'geometry': 'Point', 'properties': { 'name': 'str' } }
with collection(
    "some.shp", "w", "ESRI Shapefile", schema) as output:
    with open('some.csv', 'rb') as f:
        reader = csv.DictReader(f)
        for row in reader:
            point = Point(float(row['lon']), float(row['lat']))
            output.write({
                'properties': {
                    'name': row['name']
                },
                'geometry': mapping(point)
            })
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

1 participant