mapnik / mapnik-support

Use the issues queue here to ask questions and offer help on using Mapnik (maybe if this works well we can retire the mailing list at http://mapnik.org/contact/?)
6 stars 6 forks source link

mapnik.Feature attribute error: no attribute "add_geometries_from_wkt" #108

Closed giantchen2012 closed 6 years ago

giantchen2012 commented 6 years ago

hi, guys, I use memorydatasource mapnik 3 and python 3, then result the problem as described in the title -- mapnik.Feature attribute error: no attribute "add_geometries_from_wkt", and also this post in stackoverflow. And more details in my code and my command lines as following:

if points != None:
    memoryDatasource = mapnik.MemoryDatasource()
    context = mapnik.Context()
    context.push("name")
    next_id = 1
    for long,lat,name in points:
        wkt = "POINT (%0.8f %0.8f)" % (long,lat)
        feature = mapnik.Feature(context, next_id)
        feature['name'] = name
        feature.add_geometries_from_wkt(wkt)
        next_id = next_id + 1
        memoryDatasource.add_feature(feature)

    layer = mapnik.Layer("Points")
    layer.datasource = memoryDatasource

output from commandline:

    b'Traceback (most recent call last):\r\n  File "path\\to\\showResults.py", line 96, in <module>\r\n    points=points)\r\n  File "path\\to \\mapGenerator.py", line 79, in generateMap\r\n    feature.add_geometries_from_wkt(wkt)\r\nAttributeError: \'Feature\' object has no attribute \'add_geometries_from_wkt\'\r\n'
talaj commented 6 years ago

mapnik.Feature doesn't have the method add_geometries_from_wkt(). See https://github.com/mapnik/python-mapnik/blob/8481096ebaa94e907a505c1dc6bebec4294ab19f/src/mapnik_feature.cpp#L213-L232

Try to use

geom = mapnik.Geometry.from_wkt(wkt)

instead, according to this test: https://github.com/mapnik/python-mapnik/blob/8481096ebaa94e907a505c1dc6bebec4294ab19f/test/python_tests/geometry_io_test.py#L310

giantchen2012 commented 6 years ago

alright, it works like a charm.

and i can made feature from geom by assign it to the geometry attribute of Feature