Skip to main content
Responding to @Mathew 's edit
Source Link
Alex Kerney
  • 1.1k
  • 8
  • 6

Since you've already got a list of dicts, you can use Shapely (to manage the geometry) and Fiona (to write the shape file).

from shapely.geometry import mapping
from shapely.wkt import loads
from fiona import collection

schema = {'geometry': 'Point', 'properties': {'atribute1':'value', 'atribute2':'value'}}

with collection("output.shp", "w", "ESRI Shapefile", schema) as output:
    for point in points:
        geometry = loads(point['wkt'])
        output.write({'properties':{'atribute1': point['atribute1'],
                                    'atribute2': point['atribute2']},
                      'geometry': mapping(geometry)

Largely cribbed from GIS with Python, Shapely, and Fiona by Tom MacWright, but I found the Shapely WKT info in the Shapely docs

Edit in response to @Mathew edit in original question: There are three different errors that I find I'm getting, and your version of Fiona may be calling them slightly different.

  1. If 'datetime.datetime' is used instead of 'datetime' I get a 'ValueError' as 'datetime.datetime' is not in the list of valid property types.
  2. If I'm trying to write somewhere outside my working directory, I'll get ERROR:Fiona:OGR Error 1: Failed to create file .shp file. Try without specifying a directory in the file path.
  3. I'm getting a Warning:Fiona:OGR Error 6: Field time create as date field, though DateTime requested. Which looks to be because shapefiles don't specifically allow a datetime fieldallow a datetime field. You can split it upseparate out the datetimes into a date and2 separate properties, or write them as a time field thoughstring.

Since you've already got a list of dicts, you can use Shapely (to manage the geometry) and Fiona (to write the shape file).

from shapely.geometry import mapping
from shapely.wkt import loads
from fiona import collection

schema = {'geometry': 'Point', 'properties': {'atribute1':'value', 'atribute2':'value'}}

with collection("output.shp", "w", "ESRI Shapefile", schema) as output:
    for point in points:
        geometry = loads(point['wkt'])
        output.write({'properties':{'atribute1': point['atribute1'],
                                    'atribute2': point['atribute2']},
                      'geometry': mapping(geometry)

Largely cribbed from GIS with Python, Shapely, and Fiona by Tom MacWright, but I found the Shapely WKT info in the Shapely docs

Edit in response to @Mathew edit in original question: There are three different errors that I find I'm getting, and your version of Fiona may be calling them slightly different.

  1. If 'datetime.datetime' is used instead of 'datetime' I get a 'ValueError' as 'datetime.datetime' is not in the list of valid property types.
  2. If I'm trying to write somewhere outside my working directory, I'll get ERROR:Fiona:OGR Error 1: Failed to create file .shp file. Try without specifying a directory in the file path.
  3. I'm getting a Warning:Fiona:OGR Error 6: Field time create as date field, though DateTime requested. Which looks to be because shapefiles don't specifically allow a datetime field. You can split it up into a date and a time field though.

Since you've already got a list of dicts, you can use Shapely (to manage the geometry) and Fiona (to write the shape file).

from shapely.geometry import mapping
from shapely.wkt import loads
from fiona import collection

schema = {'geometry': 'Point', 'properties': {'atribute1':'value', 'atribute2':'value'}}

with collection("output.shp", "w", "ESRI Shapefile", schema) as output:
    for point in points:
        geometry = loads(point['wkt'])
        output.write({'properties':{'atribute1': point['atribute1'],
                                    'atribute2': point['atribute2']},
                      'geometry': mapping(geometry)

Largely cribbed from GIS with Python, Shapely, and Fiona by Tom MacWright, but I found the Shapely WKT info in the Shapely docs

Edit in response to @Mathew edit in original question: There are three different errors that I find I'm getting, and your version of Fiona may be calling them slightly different.

  1. If 'datetime.datetime' is used instead of 'datetime' I get a 'ValueError' as 'datetime.datetime' is not in the list of valid property types.
  2. If I'm trying to write somewhere outside my working directory, I'll get ERROR:Fiona:OGR Error 1: Failed to create file .shp file. Try without specifying a directory in the file path.
  3. I'm getting a Warning:Fiona:OGR Error 6: Field time create as date field, though DateTime requested. Which looks to be because shapefiles don't specifically allow a datetime field. You can separate out the datetimes into 2 separate properties, or write them as a string.
Responding to @Mathew 's edit
Source Link
Alex Kerney
  • 1.1k
  • 8
  • 6

Since you've already got a list of dicts, you can use Shapely (to manage the geometry) and Fiona (to write the shape file).

from shapely.geometry import mapping
from shapely.wkt import loads
from fiona import collection

schema = {'geometry': 'Point', 'properties': {'atribute1':'value', 'atribute2':'value'}}

with collection("output.shp", "w", "ESRI Shapefile", schema) as output:
    for point in points:
        geometry = loads(point['wkt'])
        output.write({'properties':{'atribute1': point['atribute1'],
                                    'atribute2': point['atribute2']},
                      'geometry': mapping(geometry)

Largely cribbed from GIS with Python, Shapely, and Fiona by Tom MacWright, but I found the Shapely WKT info in the Shapely docs

Edit in response to @Mathew edit in original question: There are three different errors that I find I'm getting, and your version of Fiona may be calling them slightly different.

  1. If 'datetime.datetime' is used instead of 'datetime' I get a 'ValueError' as 'datetime.datetime' is not in the list of valid property types.
  2. If I'm trying to write somewhere outside my working directory, I'll get ERROR:Fiona:OGR Error 1: Failed to create file .shp file. Try without specifying a directory in the file path.
  3. I'm getting a Warning:Fiona:OGR Error 6: Field time create as date field, though DateTime requested. Which looks to be because shapefiles don't specifically allow a datetime field. You can split it up into a date and a time field though.

Since you've already got a list of dicts, you can use Shapely (to manage the geometry) and Fiona (to write the shape file).

from shapely.geometry import mapping
from shapely.wkt import loads
from fiona import collection

schema = {'geometry': 'Point', 'properties': {'atribute1':'value', 'atribute2':'value'}}

with collection("output.shp", "w", "ESRI Shapefile", schema) as output:
    for point in points:
        geometry = loads(point['wkt'])
        output.write({'properties':{'atribute1': point['atribute1'],
                                    'atribute2': point['atribute2']},
                      'geometry': mapping(geometry)

Largely cribbed from GIS with Python, Shapely, and Fiona by Tom MacWright, but I found the Shapely WKT info in the Shapely docs

Since you've already got a list of dicts, you can use Shapely (to manage the geometry) and Fiona (to write the shape file).

from shapely.geometry import mapping
from shapely.wkt import loads
from fiona import collection

schema = {'geometry': 'Point', 'properties': {'atribute1':'value', 'atribute2':'value'}}

with collection("output.shp", "w", "ESRI Shapefile", schema) as output:
    for point in points:
        geometry = loads(point['wkt'])
        output.write({'properties':{'atribute1': point['atribute1'],
                                    'atribute2': point['atribute2']},
                      'geometry': mapping(geometry)

Largely cribbed from GIS with Python, Shapely, and Fiona by Tom MacWright, but I found the Shapely WKT info in the Shapely docs

Edit in response to @Mathew edit in original question: There are three different errors that I find I'm getting, and your version of Fiona may be calling them slightly different.

  1. If 'datetime.datetime' is used instead of 'datetime' I get a 'ValueError' as 'datetime.datetime' is not in the list of valid property types.
  2. If I'm trying to write somewhere outside my working directory, I'll get ERROR:Fiona:OGR Error 1: Failed to create file .shp file. Try without specifying a directory in the file path.
  3. I'm getting a Warning:Fiona:OGR Error 6: Field time create as date field, though DateTime requested. Which looks to be because shapefiles don't specifically allow a datetime field. You can split it up into a date and a time field though.
Source Link
Alex Kerney
  • 1.1k
  • 8
  • 6

Since you've already got a list of dicts, you can use Shapely (to manage the geometry) and Fiona (to write the shape file).

from shapely.geometry import mapping
from shapely.wkt import loads
from fiona import collection

schema = {'geometry': 'Point', 'properties': {'atribute1':'value', 'atribute2':'value'}}

with collection("output.shp", "w", "ESRI Shapefile", schema) as output:
    for point in points:
        geometry = loads(point['wkt'])
        output.write({'properties':{'atribute1': point['atribute1'],
                                    'atribute2': point['atribute2']},
                      'geometry': mapping(geometry)

Largely cribbed from GIS with Python, Shapely, and Fiona by Tom MacWright, but I found the Shapely WKT info in the Shapely docs