我正在尝试gpxpy lib并且它可能正常工作,但我无法创建PointField ... 找不到文档。
另外,如何从gpx track创建一组带有GDAL的PointField?
以下是我需要的代码。
def upload(request):
'Upload waypoints'
# If the form contains an upload,
if 'gpx' in request.FILES:
# Get
gpxFile = request.FILES['gpx']
track = FiberTrack(name=request.POST.get('track_name'))
track.save()
#parse_gpx(gpxFile, track)
# Save
targetPath = tempfile.mkstemp()[1]
destination = open(targetPath, 'wt')
for chunk in gpxFile.chunks():
destination.write(chunk)
destination.close()
# Parse
dataSource = DataSource(targetPath)
print(dataSource)
layer = dataSource[0]
waypointNames = layer.get_fields('name')
waypointGeometries = layer.get_geoms()
for waypointName, waypointGeometry in itertools.izip(waypointNames, waypointGeometries):
vertex = FiberTrackVertex(track = track, number=5, point=waypointGeometry.wkt)
vertex.save()
# Clean up
os.remove(targetPath)
# Redirect
return HttpResponseRedirect(reverse(edit_map))
def parse_gpx(file, fiber_track):
Point.set_coords()
gpx = gpxpy.parse(file)
for segment in gpx.tracks[0].segments:
for point in segment.points:
vertex = FiberTrackVertex(track=fiber_track, number=5, point=point)
vertex.save()
return
def toGeoDjangoPoint(point):
to_point = gismodels.PointField
to_point.geography
答案 0 :(得分:0)
如果您还没弄明白,我认为这正是您正在寻找的。 http://ipasic.com/article/uploading-parsing-and-saving-gpx-data-postgis-geodjango/
我希望它会有所帮助!