0

我正在尝试 gpxpy lib,它可能正在工作,但我无法创建 PointField... 找不到关于它的文档。

另外,如何从 gpx 轨道创建一组带有 GDAL 的 PointFields?

这是我的代码,以备不时之需。

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
4

1 回答 1

0

如果您仍然没有弄清楚,我认为这正是您正在寻找的。 http://ipasic.com/article/uploading-parsing-and-saving-gpx-data-postgis-geodjango/

我希望它会有所帮助!

于 2013-12-08T13:46:46.470 回答