roelderickx / ogr2osm

A tool for converting ogr-readable files like shapefiles into .pbf or .osm data
https://pypi.org/project/ogr2osm/
MIT License
59 stars 14 forks source link

Translation failing 'filter_layer()' #47

Closed Bandit253 closed 9 months ago

Bandit253 commented 9 months ago

When I try my translation file I get TypeError: TranslationBase.filter_layer() missing 1 required positional argument: 'layer'

but it works without error when I use the base class, I have tried to copy the base class def of filter_layer to mine and still fails.

from DTP_OSM import InitialMatch
infile = r'match_result.shp'
outfile = r'match_result.osm.pbf'

translation_object = InitialMatch
# translation_object = ogr2osm.TranslationBase()

datasource = ogr2osm.OgrDatasource(translation_object)
datasource.open_datasource(infile)
osmdata = ogr2osm.OsmData(translation_object)
osmdata.process(datasource)  # <<<--- Error here
datawriter = ogr2osm.OsmDataWriter(outfile)
osmdata.output(datawriter)

the above code is pretty much exactly the example.

This is my Translation file

import ogr2osm

class InitialMatch(ogr2osm.TranslationBase):

    def filter_tags(self, attrs):

        if not attrs:
            return
        tags = {}

        if 'EZI_ROAD_NAME_LABLE' in attrs:
            tags['name'] = attrs['EZI_ROAD_NAME_LABLE'].title()
        if 'road_class' in attrs:
            tags['highway'] = attrs['road_class']
       return tags
roelderickx commented 9 months ago

Hi,

I think the error message is a bit misleading. The problem is that there is no instance of your translation class, as such translation_object is a class in stead of an object.

Try changing translation_object = InitialMatch into translation_object = InitialMatch().

Bandit253 commented 9 months ago

Thanks so much, such a noob mistake.