0

I'm trying gpxpy lib and its probably working, but I can't create PointField... Can't find documentation on it.

Also, how can I create a set of PointFields with GDAL from gpx track?

Here is my code in case you need it.

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
user1685095
  • 5,787
  • 9
  • 51
  • 100

1 Answers1

0

In case you still didn't figure it out I think this is exactly what you are looking for. http://ipasic.com/article/uploading-parsing-and-saving-gpx-data-postgis-geodjango/

I hope it will help!

ivan.zd
  • 674
  • 9
  • 13