GeoDjango - 数据源特征类型错误

时间:2021-01-26 23:31:05

标签: django gdal geodjango

我正在尝试将 geoJSON 导入 geodjango 数据库。在下面的示例中, layer.field_types 方法返回正确的数据类型。但是,当循环遍历要素时,高程字段会从浮点数转换为整数。

>>> from django.contrib.gis.gdal import DataSource
>>> a = '{"type": "FeatureCollection","name": "minContours","crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::6527" } },"features": [{ "type": "Feature", "properties": { "ID": 2, "Elevation": 41.5 }, "geometry": { "type": "MultiLineString", "coordinates": [ [ [ 589193.655952385859564, 768634.955786595470272, 41.5 ], [ 589193.4616099999985, 768634.944451080053113, 41.5 ], [ 589192.966033526696265, 768635.120235103997402, 41.5 ] ] ] } }]}'
>>> ds = DataSource(a)
>>> lyr = ds[0]
>>> print(lyr.field_types)
>>> features = [f for f in lyr]
>>> print([type(features[0]['ID']),type(features[0]['Elevation'])])

[<class 'django.contrib.gis.gdal.field.OFTInteger'>, <class 'django.contrib.gis.gdal.field.OFTReal'>]
[<class 'django.contrib.gis.gdal.field.OFTInteger'>, <class 'django.contrib.gis.gdal.field.OFTInteger'>]

假设这是某种无法在 python 中修复的 geojson 驱动程序问题是否公平? .shp 等其他文件类型按预期工作。

0 个答案:

没有答案