roelderickx/ogr2osm

module 'ogr2osm' has no attribute 'TranslationBase'

nevw opened this issue · 11 comments

nevw commented

Hi
I have the following error...
[using iMac 12.0.1 macOS Monterey]
I was having syntax errors but seemed to have solved those but with the following I am not able to proceed...

running with lxml.etree
Traceback (most recent call last):
File "/Users/Nn/ogr2osm/ogr2osm.py", line 772, in
main()
File "/Users/Nn/ogr2osm/ogr2osm.py", line 712, in main
TRANSLATIONS = import(OPTIONS.translationMethod, fromlist = [''])
File "/Volumes/Samsung SSD/GIS Resources/OGR2OSM_tag_translations_roelderickx_version/Dedicated_IPA_2020_tags.py", line 4, in
class Dedicated_IPA_2020_tagsTranslation(ogr2osm.TranslationBase):
AttributeError: module 'ogr2osm' has no attribute 'TranslationBase'

This is the text of my fairly simple Dedicated_IPA_2020_tags.py ...

import ogr2osm

class Dedicated_IPA_2020_tagsTranslation(ogr2osm.TranslationBase):

def filter_tags(self, attrs):
	if not attrs:
		return
	tags = {}

	if "NAME" in attrs:
		tags.update({"name": attrs["NAME"].strip(" ") + " " + attrs["TYPE"].strip(" ")})

	if "IUCN_CODE" in attrs:
		tags.update({"iucn_level": attrs["IUCN_CODE"].replace(",", ";").strip(" ")})

	if "IUCN_CODE" in attrs:
		if attrs["IUCN_CODE"].strip() == "II":
			tags["protect_class"] = "2"
		elif attrs["IUCN"].strip() == "II,VI":
			tags["protect_class"] = "2;6"
		elif attrs["IUCN"].strip() == "III,IV,V":
			tags["protect_class"] = "3;4;5"
		elif attrs["IUCN"].strip() == "III,IV,V,VI":
			tags["protect_class"] = "3;4;5;6"
		elif attrs["IUCN"].strip() == "III,IV,VI":
			tags["protect_class"] = "3;4;6"
		elif attrs["IUCN"].strip() == "III,V":
			tags["protect_class"] = "3;5"
		elif attrs["IUCN"].strip() == "III,VI":
			tags["protect_class"] = "3;6"
		elif attrs["IUCN"].strip() == "IV":
			tags["protect_class"] = "4"
		elif attrs["IUCN"].strip() == "IV,V":
			tags["protect_class"] = "4;5"
		elif attrs["IUCN"].strip() == "IV,VI":
			tags["protect_class"] = "4;6"
		elif attrs["IUCN"].strip() == "V":
			tags["protect_class"] = "5"
		elif attrs["IUCN"].strip() == "V,VI":
			tags["protect_class"] = "5;6"
		elif attrs["IUCN"].strip() == "VI":
			tags["protect_class"] = "6"

	if "AUTHORITY" in attrs:
		if attrs["AUTHORITY"].strip() == "IMG":
			tags["operator"] = "Indigenous Management Group"
		elif attrs["AUTHORITY"].strip() == "LILC":
			tags["operator"] = "Local Indigenous Land Council"
		elif attrs["AUTHORITY"].strip() == "TSRA":
			tags["operator"] = "Torres Strait Regional Authority"

	if "NAME" in attrs:
		tags.update({"wikipedia": "en:" + attrs["NAME"].strip(" ") + " " + attrs["TYPE"].strip(" ")})

	tags["leisure"] = "nature_reserve"

	tags["access"] = "private"

	tags["source"] = "Dedicated Indigenous Protected Areas 2020"

	tags["type"] = "boundary"

	tags["boundary"] = "protected_area"

	return tags

Hello,

At first sight it seems you did not install ogr2osm. That's fine, but then you should run it as a module.

From your output I assume the directory /Users/Nn/ogr2osm contains the complete content of https://github.com/roelderickx/ogr2osm/tree/main/ogr2osm. In that case change the directory to /Users/Nn and run python -m ogr2osm [parameters]

nevw commented

Here is my ogr2osm dir...
Screen Shot 2021-11-25 at 5 25 34 pm
I followed https://wiki.openstreetmap.org/wiki/Ogr2osm for the install
and was then able to run...
/Users/Nn/ogr2osm/ogr2osm.py /Volumes/Samsung\ SSD/GIS\ Resources/Dedicated\ Indigenous\ Protected\ Areas\ 2020/As_downloaded/ipa_dedicated_public.shp --translation=/Volumes/Samsung\ SSD/GIS\ Resources/OGR2OSM_tag_translations_roelderickx_version/Dedicated_IPA_2020_tags.py --never-upload --output=/Volumes/Samsung\ SSD/GIS\ Resources/Dedicated\ Indigenous\ Protected\ Areas\ 2020/As_downloaded/ipa_dedicated_public.osm

which produced the mentioned error.

I just tried as you suggested...
python -m ogr2osm /Volumes/Samsung\ SSD/GIS\ Resources/Dedicated\ Indigenous\ Protected\ Areas\ 2020/As_downloaded/ipa_dedicated_public.shp --translation=/Volumes/Samsung\ SSD/GIS\ Resources/OGR2OSM_tag_translations_roelderickx_version/Dedicated_IPA_2020_tags.py --never-upload --output=/Volumes/Samsung\ SSD/GIS\ Resources/Dedicated\ Indigenous\ Protected\ Areas\ 2020/As_downloaded/ipa_dedicated_public.osm

and have this error...

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ogr2osm.py", line 772, in
main()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ogr2osm.py", line 712, in main
TRANSLATIONS = import(OPTIONS.translationMethod, fromlist = [''])
File "/Volumes/Samsung SSD/GIS Resources/OGR2OSM_tag_translations_roelderickx_version/Dedicated_IPA_2020_tags.py", line 4, in
class Dedicated_IPA_2020_tagsTranslation(ogr2osm.TranslationBase):
AttributeError: module 'ogr2osm' has no attribute 'TranslationBase'

Also....
I just tried "Nn$ pip install --upgrade ogr2osm
and this warning has come up, so perhaps I still have a python problem...

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting ogr2osm
ERROR: Could not find a version that satisfies the requirement ogr2osm (from versions: none)
ERROR: No matching distribution found for ogr2osm
WARNING: You are using pip version 19.1.1, however version 20.3.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command."

You need at least python 3.7 for ogr2osm to run, that requirement seems fulfilled if you run python -m ogr2osm. However, the screenshot implies you have downloaded pnorman's version, this version indeed does not contain a definition for TranslationBase.
Can you try with the version from this repository?

The version from PyPI should also work, but your installation of pip tries to install the package for python 2.7. This will not work.

nevw commented

Just managed to upgrade using pip3.9 install --upgrade ogr2osm
and now have ogr2osm-1.1.1 so all looks better now but still an error regarding "no attribute 'TranslationBase'"

-iMac:~ Nn$ /Library/Frameworks/Python.framework/Versions/3.9/bin/pip3.9 install --upgrade ogr2osm
Requirement already satisfied: ogr2osm in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (0.1)
Collecting ogr2osm
Downloading ogr2osm-1.1.1-py3-none-any.whl (31 kB)
Requirement already satisfied: lxml>=4.3.0 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from ogr2osm) (4.6.4)
Requirement already satisfied: GDAL>=3.0.0 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from ogr2osm) (3.2.2)
Installing collected packages: ogr2osm
Attempting uninstall: ogr2osm
Found existing installation: ogr2osm 0.1
Uninstalling ogr2osm-0.1:
Successfully uninstalled ogr2osm-0.1
Successfully installed ogr2osm-1.1.1
Nevilles-iMac:~ Nn$ /Users/Nn/ogr2osm/ogr2osm.py /Volumes/Samsung\ SSD/GIS\ Resources/Dedicated\ Indigenous\ Protected\ Areas\ 2020/As_downloaded/ipa_dedicated_public.shp --translation=/Volumes/Samsung\ SSD/GIS\ Resources/OGR2OSM_tag_translations_roelderickx_version/Dedicated_IPA_2020_tags.py --never-upload --output=/Volumes/Samsung\ SSD/GIS\ Resources/Dedicated\ Indigenous\ Protected\ Areas\ 2020/As_downloaded/ipa_dedicated_public.osm
running with lxml.etree
Preparing to convert '/Volumes/Samsung SSD/GIS Resources/Dedicated Indigenous Protected Areas 2020/As_downloaded/ipa_dedicated_public.shp' to '/Volumes/Samsung SSD/GIS Resources/Dedicated Indigenous Protected Areas 2020/As_downloaded/ipa_dedicated_public.osm'.
Will try to detect projection from source metadata, or fall back to EPSG:4326
running with lxml.etree
Traceback (most recent call last):
File "/Users/Nn/ogr2osm/ogr2osm.py", line 772, in
main()
File "/Users/Nn/ogr2osm/ogr2osm.py", line 712, in main
TRANSLATIONS = import(OPTIONS.translationMethod, fromlist = [''])
File "/Volumes/Samsung SSD/GIS Resources/OGR2OSM_tag_translations_roelderickx_version/Dedicated_IPA_2020_tags.py", line 4, in
class Dedicated_IPA_2020_tagsTranslation(ogr2osm.TranslationBase):
AttributeError: module 'ogr2osm' has no attribute 'TranslationBase'

Ok we're getting somewhere. If it is installed you should just be able to run ogr2osm in stead of /Users/Nn/ogr2osm/ogr2osm.py

nevw commented

I tried...
-iMac:~ Nn$ ogr2osm /Volumes/Samsung\ SSD/GIS\ Resources/Dedicated\ Indigenous\ Protected\ Areas\ 2020/As_downloaded/ipa_dedicated_public.shp --translation=/Volumes/Samsung\ SSD/GIS\ Resources/OGR2OSM_tag_translations_roelderickx_version/Dedicated_IPA_2020_tags.py --never-upload --output=/Volumes/Samsung\ SSD/GIS\ Resources/Dedicated\ Indigenous\ Protected\ Areas\ 2020/As_downloaded/ipa_dedicated_public.osm
-bash: ogr2osm: command not found

not sure whereto new version is ...getting a bit weary now.
Will sleep on it and try again when refreshed.
Thanks for your help :)

nevw commented

Have found the new installed ogr2osm and run with...

-iMac:~ Nn$ /Library/Frameworks/Python.framework/Versions/3.9/bin/ogr2osm /Volumes/Samsung\ SSD/GIS\ Resources/Dedicated\ Indigenous\ Protected\ Areas\ 2020/As_downloaded/ipa_dedicated_public.shp --translation=/Volumes/Samsung\ SSD/GIS\ Resources/OGR2OSM_tag_translations_roelderickx_version/Dedicated_IPA_2020_tags.py --never-upload --output=/Volumes/Samsung\ SSD/GIS\ Resources/Dedicated\ Indigenous\ Protected\ Areas\ 2020/As_downloaded/ipa_dedicated_public.osm
Found valid translation class Dedicated_IPA_2020_tagsTranslation
Preparing to convert '/Volumes/Samsung SSD/GIS Resources/Dedicated Indigenous Protected Areas 2020/As_downloaded/ipa_dedicated_public.shp' to '/Volumes/Samsung SSD/GIS Resources/Dedicated Indigenous Protected Areas 2020/As_downloaded/ipa_dedicated_public.osm'.
Detected projection metadata:
GEOGCS["GDA94",
DATUM["Geocentric_Datum_of_Australia_1994",
SPHEROID["GRS 1980",6378137,298.257222101,
AUTHORITY["EPSG","7019"]],
AUTHORITY["EPSG","6283"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AXIS["Latitude",NORTH],
AXIS["Longitude",EAST],
AUTHORITY["EPSG","4283"]]
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/bin/ogr2osm", line 8, in
sys.exit(main())
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ogr2osm/ogr2osm.py", line 271, in main
osmdata.process(datasource)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ogr2osm/osm_data.py", line 406, in process
self.add_feature(ogrfeature, layer_fields, datasource.source_encoding, reproject)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ogr2osm/osm_data.py", line 345, in add_feature
feature_tags = self.__get_feature_tags(ogrfilteredfeature, layer_fields, source_encoding)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ogr2osm/osm_data.py", line 58, in __get_feature_tags
return self.translation.filter_tags(tags)
File "/Volumes/Samsung SSD/GIS Resources/OGR2OSM_tag_translations_roelderickx_version/Dedicated_IPA_2020_tags.py", line 20, in filter_tags
elif attrs["IUCN"].strip() == "II,VI":
KeyError: 'IUCN'

nevw commented

Ah...success...
You have done very well resolving my confused process, Roel.
All is working well now after fixing up a minor syntax in the tags.
Really appreciate your help.
You could probably delete this issue as it seems unlikely to be of much use to others.
Cheers
Nev

I'm glad it works now.
I will leave this issue open for a short time because I think I need to update the documentation. It is very useful to know that the PyPI package is installed in /Library/Frameworks/Python.framework/Versions/3.9/bin/ on macOS and that this path is not in the PATH environment by default.
Usually I close issues after everything is handled, but if you insist I will delete it afterwards. This may be applicable if you feel there is too much personal data in this issue.

nevw commented

Yes, I feel I need to update my path.
I don't mind if you close or delete... there is no private info of concern for me.
Again, thanks for your prompt help and for keeping the very useful ogr2osm up to date.
Nev

I added instructions to run ogr2osm as a module using python -m ogr2osm to the README. The installation directory depends on the logged in user, the operating system and the version of python, it's probably not a good idea to document all possibilities.