Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

django - GeoDjango - DataSource Feature Type Error

I'm trying to import geoJSON into a geodjango database. In the below example, the layer.field_types method returns the correct datatypes. However, when looping through the features the elevation field is converted from a float to a int.

>>> 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'>]

Is it fair to assume this is some sort of geojson driver issue that cannot be fixed in python? Other file types like .shp work as expected.

question from:https://stackoverflow.com/questions/65910800/geodjango-datasource-feature-type-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...