如何解决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,[ 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 等其他文件类型按预期工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。