Discussion:
[Community] writing dgn-files with fiona
tõnis kärdi
2014-12-31 07:01:52 UTC
Permalink
Hi,

I can't seem to get writing dgn files with fiona to work - it results in
"ValueError: Null layer". The same script works fine for writing shapefiles
and MI tabs.
I managed to create a DGN file using QGIS and then read it using fiona. I
don't know much about CAD files in general so I'm sure there's something
I've missed totally, any pointers much appreciated.

Here's how it goes:

C:\>ogr2ogr --version
GDAL 1.11.0, released 2014/04/16
C:\>python
Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
import fiona
print fiona.__version__
1.1.6
schema and properties read from the file created in QGIS
except for schema['geometry'] which was set manually to LineString
fiona.OrderedDict([(u'Type', 'int:2'), (u'Level', 'int:2'),
(u'GraphicGroup', 'int:4'), (u'ColorIndex', 'int:3'), (u'Weight', 'int:2'),
(u'Style', 'int:1'), (u'EntityNum', 'int'), (u'MSLink', 'int'), (u'Text',
'str')])}
properties = {u'Style': 0, u'ColorIndex': 0, u'Weight': 0, u'Level': 0,
u'Text': None, u'MSLink': None, u'GraphicGroup': 0, u'EntityNum': None,
u'Type': 14}
crs = {'lon_0': 24, 'no_defs': True, 'x_0': 500000, 'lat_2': 58,
'lat_1': 59.33333333333334, 'towgs84': '0,0,0,0,0,0,0', 'ellps': 'GRS80',
'y_0': 6375000, 'proj': 'lcc', 'units': 'm', 'lat_0': 57.51755393055556}
[...]
with fiona.open(
... 'd:/tmp/nna.dgn',
... 'w',
... 'DGN',
... schema=schema,
... crs=crs) as sink:
... sink.write(
... {'geometry': {
... 'type': 'LineString',
... 'coordinates': [
... [658513.3899922734, 6475203.499964565],
... [658467.8400262331, 6475236.229952499],
... [658486.4300012367, 6475258.259991983],
... [658528.96998106, 6475228.000044374],
... [658513.3899922734, 6475203.499964565]]
... },
... 'type': 'Feature',
... 'properties': properties})
...

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
with fiona.open('d:/tmp/nna.dgn', 'w', 'DGN', schema=schema, crs=crs)
as sink:
File "C:\Python27\lib\site-packages\fiona\__init__.py", line 156, in open
encoding=encoding, layer=layer, vsi=vsi, archive=archive)
File "C:\Python27\lib\site-packages\fiona\collection.py", line 132, in
__init__
self.session.start(self, **kwargs)
File "ogrext.pyx", line 960, in fiona.ogrext.WritingSession.start
(src/fiona/ogrext.c:15730)
ValueError: Null layer
All the best,
Tõnis

p.s. tried writing DGN also using osgeo.ogr. For whatever reason the
.CreateLayer(...) method always returns None...
Sean Gillies
2014-12-31 20:02:02 UTC
Permalink
Hi Tõnis,

I don't have much experience with DGN files, but it looks like there are a
bunch of limitations and caveats listed at http://www.gdal.org/drv_dgn.html.
The "seed file" in particular looks like something to investigate. Remember
that creation options can be passed into fiona.open as kwargs like

with fiona.open('example.dgn', 'w', driver='DGN', schema=schema,
crs=crs, seed='seed.dgn') as dst:
...

Hope this helps, and happy new year!
Post by tõnis kärdi
Hi,
I can't seem to get writing dgn files with fiona to work - it results in
"ValueError: Null layer". The same script works fine for writing shapefiles
and MI tabs.
I managed to create a DGN file using QGIS and then read it using fiona. I
don't know much about CAD files in general so I'm sure there's something
I've missed totally, any pointers much appreciated.
C:\>ogr2ogr --version
GDAL 1.11.0, released 2014/04/16
C:\>python
Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
import fiona
print fiona.__version__
1.1.6
schema and properties read from the file created in QGIS
except for schema['geometry'] which was set manually to LineString
fiona.OrderedDict([(u'Type', 'int:2'), (u'Level', 'int:2'),
(u'GraphicGroup', 'int:4'), (u'ColorIndex', 'int:3'), (u'Weight', 'int:2'),
(u'Style', 'int:1'), (u'EntityNum', 'int'), (u'MSLink', 'int'), (u'Text',
'str')])}
0, u'Text': None, u'MSLink': None, u'GraphicGroup': 0, u'EntityNum': None,
u'Type': 14}
crs = {'lon_0': 24, 'no_defs': True, 'x_0': 500000, 'lat_2': 58,
'lat_1': 59.33333333333334, 'towgs84': '0,0,0,0,0,0,0', 'ellps': 'GRS80',
'y_0': 6375000, 'proj': 'lcc', 'units': 'm', 'lat_0': 57.51755393055556}
[...]
with fiona.open(
... 'd:/tmp/nna.dgn',
... 'w',
... 'DGN',
... schema=schema,
... sink.write(
... {'geometry': {
... 'type': 'LineString',
... 'coordinates': [
... [658513.3899922734, 6475203.499964565],
... [658467.8400262331, 6475236.229952499],
... [658486.4300012367, 6475258.259991983],
... [658528.96998106, 6475228.000044374],
... [658513.3899922734, 6475203.499964565]]
... },
... 'type': 'Feature',
... 'properties': properties})
...
File "<stdin>", line 1, in <module>
with fiona.open('d:/tmp/nna.dgn', 'w', 'DGN', schema=schema, crs=crs)
File "C:\Python27\lib\site-packages\fiona\__init__.py", line 156, in open
encoding=encoding, layer=layer, vsi=vsi, archive=archive)
File "C:\Python27\lib\site-packages\fiona\collection.py", line 132, in
__init__
self.session.start(self, **kwargs)
File "ogrext.pyx", line 960, in fiona.ogrext.WritingSession.start
(src/fiona/ogrext.c:15730)
ValueError: Null layer
All the best,
Tõnis
p.s. tried writing DGN also using osgeo.ogr. For whatever reason the
.CreateLayer(...) method always returns None...
_______________________________________________
Community mailing list
http://lists.gispython.org/mailman/listinfo/community
--
Sean Gillies
tõnis kärdi
2015-01-02 07:05:44 UTC
Permalink
Thanks Sean,

Yes, it looks like somewhere along the line my GDAL_DATA environment
variable is lost. As soon as I pass the path to a dgn seed-file in the
creation options everything just magically works. I guess it's a windows
wonderland thing.

Cheerio and a Happy new year!
Tõnis
Post by Sean Gillies
Hi Tõnis,
I don't have much experience with DGN files, but it looks like there are a
bunch of limitations and caveats listed at
http://www.gdal.org/drv_dgn.html. The "seed file" in particular looks
like something to investigate. Remember that creation options can be passed
into fiona.open as kwargs like
with fiona.open('example.dgn', 'w', driver='DGN', schema=schema,
...
Hope this helps, and happy new year!
Post by tõnis kärdi
Hi,
I can't seem to get writing dgn files with fiona to work - it results in
"ValueError: Null layer". The same script works fine for writing shapefiles
and MI tabs.
I managed to create a DGN file using QGIS and then read it using fiona. I
don't know much about CAD files in general so I'm sure there's something
I've missed totally, any pointers much appreciated.
C:\>ogr2ogr --version
GDAL 1.11.0, released 2014/04/16
C:\>python
Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
import fiona
print fiona.__version__
1.1.6
schema and properties read from the file created in QGIS
except for schema['geometry'] which was set manually to LineString
fiona.OrderedDict([(u'Type', 'int:2'), (u'Level', 'int:2'),
(u'GraphicGroup', 'int:4'), (u'ColorIndex', 'int:3'), (u'Weight', 'int:2'),
(u'Style', 'int:1'), (u'EntityNum', 'int'), (u'MSLink', 'int'), (u'Text',
'str')])}
0, u'Text': None, u'MSLink': None, u'GraphicGroup': 0, u'EntityNum': None,
u'Type': 14}
crs = {'lon_0': 24, 'no_defs': True, 'x_0': 500000, 'lat_2': 58,
'lat_1': 59.33333333333334, 'towgs84': '0,0,0,0,0,0,0', 'ellps': 'GRS80',
'y_0': 6375000, 'proj': 'lcc', 'units': 'm', 'lat_0': 57.51755393055556}
[...]
with fiona.open(
... 'd:/tmp/nna.dgn',
... 'w',
... 'DGN',
... schema=schema,
... sink.write(
... {'geometry': {
... 'type': 'LineString',
... 'coordinates': [
... [658513.3899922734, 6475203.499964565],
... [658467.8400262331, 6475236.229952499],
... [658486.4300012367, 6475258.259991983],
... [658528.96998106, 6475228.000044374],
... [658513.3899922734, 6475203.499964565]]
... },
... 'type': 'Feature',
... 'properties': properties})
...
File "<stdin>", line 1, in <module>
with fiona.open('d:/tmp/nna.dgn', 'w', 'DGN', schema=schema, crs=crs)
File "C:\Python27\lib\site-packages\fiona\__init__.py", line 156, in open
encoding=encoding, layer=layer, vsi=vsi, archive=archive)
File "C:\Python27\lib\site-packages\fiona\collection.py", line 132, in
__init__
self.session.start(self, **kwargs)
File "ogrext.pyx", line 960, in fiona.ogrext.WritingSession.start
(src/fiona/ogrext.c:15730)
ValueError: Null layer
All the best,
Tõnis
p.s. tried writing DGN also using osgeo.ogr. For whatever reason the
.CreateLayer(...) method always returns None...
_______________________________________________
Community mailing list
http://lists.gispython.org/mailman/listinfo/community
--
Sean Gillies
_______________________________________________
Community mailing list
http://lists.gispython.org/mailman/listinfo/community
tõnis kärdi
2015-01-02 08:27:39 UTC
Permalink
ok, now I got it. I had GDAL_DATA set pointing to two different
directories: for a PostgreSQL/PostGIS installation which had been set
automatically and separate GDAL installation which I had set manually.
Removed one of them and everything works as expected.

All the best,
Tõnis
Post by tõnis kärdi
Thanks Sean,
Yes, it looks like somewhere along the line my GDAL_DATA environment
variable is lost. As soon as I pass the path to a dgn seed-file in the
creation options everything just magically works. I guess it's a windows
wonderland thing.
Cheerio and a Happy new year!
Tõnis
Post by Sean Gillies
Hi Tõnis,
I don't have much experience with DGN files, but it looks like there are
a bunch of limitations and caveats listed at
http://www.gdal.org/drv_dgn.html. The "seed file" in particular looks
like something to investigate. Remember that creation options can be passed
into fiona.open as kwargs like
with fiona.open('example.dgn', 'w', driver='DGN', schema=schema,
...
Hope this helps, and happy new year!
Post by tõnis kärdi
Hi,
I can't seem to get writing dgn files with fiona to work - it results in
"ValueError: Null layer". The same script works fine for writing shapefiles
and MI tabs.
I managed to create a DGN file using QGIS and then read it using fiona.
I don't know much about CAD files in general so I'm sure there's something
I've missed totally, any pointers much appreciated.
C:\>ogr2ogr --version
GDAL 1.11.0, released 2014/04/16
C:\>python
Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
import fiona
print fiona.__version__
1.1.6
schema and properties read from the file created in QGIS
except for schema['geometry'] which was set manually to LineString
fiona.OrderedDict([(u'Type', 'int:2'), (u'Level', 'int:2'),
(u'GraphicGroup', 'int:4'), (u'ColorIndex', 'int:3'), (u'Weight', 'int:2'),
(u'Style', 'int:1'), (u'EntityNum', 'int'), (u'MSLink', 'int'), (u'Text',
'str')])}
0, u'Text': None, u'MSLink': None, u'GraphicGroup': 0, u'EntityNum': None,
u'Type': 14}
crs = {'lon_0': 24, 'no_defs': True, 'x_0': 500000, 'lat_2': 58,
'lat_1': 59.33333333333334, 'towgs84': '0,0,0,0,0,0,0', 'ellps': 'GRS80',
'y_0': 6375000, 'proj': 'lcc', 'units': 'm', 'lat_0': 57.51755393055556}
[...]
with fiona.open(
... 'd:/tmp/nna.dgn',
... 'w',
... 'DGN',
... schema=schema,
... sink.write(
... {'geometry': {
... 'type': 'LineString',
... 'coordinates': [
... [658513.3899922734, 6475203.499964565],
... [658467.8400262331, 6475236.229952499],
... [658486.4300012367, 6475258.259991983],
... [658528.96998106, 6475228.000044374],
... [658513.3899922734, 6475203.499964565]]
... },
... 'type': 'Feature',
... 'properties': properties})
...
File "<stdin>", line 1, in <module>
with fiona.open('d:/tmp/nna.dgn', 'w', 'DGN', schema=schema,
File "C:\Python27\lib\site-packages\fiona\__init__.py", line 156, in open
encoding=encoding, layer=layer, vsi=vsi, archive=archive)
File "C:\Python27\lib\site-packages\fiona\collection.py", line 132, in
__init__
self.session.start(self, **kwargs)
File "ogrext.pyx", line 960, in fiona.ogrext.WritingSession.start
(src/fiona/ogrext.c:15730)
ValueError: Null layer
All the best,
Tõnis
p.s. tried writing DGN also using osgeo.ogr. For whatever reason the
.CreateLayer(...) method always returns None...
_______________________________________________
Community mailing list
http://lists.gispython.org/mailman/listinfo/community
--
Sean Gillies
_______________________________________________
Community mailing list
http://lists.gispython.org/mailman/listinfo/community
Loading...