lieblerj / poi_converter

Convert openandromaps poi databases into Locus osm.db format
Apache License 2.0
7 stars 3 forks source link

Add 'way-id' OSM-links to database when processing .pbf-files #8

Open Tiemichael opened 4 years ago

Tiemichael commented 4 years ago

Currently (<=v0.6) only 'node-ids' are working links to the OSM-database when processing .pbf-files:

Here is a proposal how to add the same functionality for 'way-ids'

File: fileimporter.py (after modification)

import osmium
from poiconverter.poi import Poi
from osmium._osmium import InvalidLocationError
import sys
import shapely.wkb as wkblib

wkbfab = osmium.geom.WKBFactory()
def create_multipolygon(area):
    try:
        building_wkb = wkbfab.create_multipolygon(area)
        return (building_wkb)
    except InvalidLocationError:
        print('Error: Encountered invalid location in area')
        return None
    except RuntimeError as ex:
        print('Error importing way: - Runtime Error')
        return None
class FileImporter(osmium.SimpleHandler):

    def __init__(self, callback, tag_filter):
        osmium.SimpleHandler.__init__(self)
        self.callback = callback
        self.tag_filter = tag_filter

    def handle_node(self, node):
        node_tags = dict()
        for k,v in node.tags:
            node_tags[k] = v
        node_type = self.tag_filter.tag_matched(node_tags)
        if node_type:
            name = node.tags.get('name', '')
            #print('Name:',name)
            #for att in dir(node):
            #    print(att, getattr(node, att))
            poi = Poi(node.id, name, node.location.lat, node.location.lon)
            poi.set_type(node_type)
            poi.add_tags(node_tags)
            poi.set_osm_type('P')
            self.callback(poi)

    def handle_area(self, node):
        node_tags = dict()
        for k,v in node.tags:
            node_tags[k] = v
        node_type = self.tag_filter.tag_matched(node_tags)
        if node_type:
            name = node.tags.get('name', '')
            wkb = create_multipolygon(node)
            if wkb:
                poly = wkblib.loads(wkb, hex=True)
                centroid = poly.representative_point()
                w_id = int(int(node.id)/2)
                poi = Poi(w_id, name, centroid.y, centroid.x)
                poi.set_type(node_type)
                poi.add_tags(node_tags)
                poi.set_osm_type('W')
                self.callback(poi)
    def node(self, node):
        self.handle_node(node)
    def area(self, area):
        self.handle_area(area)

My Python skills are quite basic ...., but it seems working

lieblerj commented 4 years ago

Hi Michael,

unfortunately the PBF support is still very basic as i started with this format but only focused on the OpenAndromaps poi files after i got it working and therefore skipped any effort on PBF. Recently i thought of removing PBF support completely.

Additonally it seems the the Locus toolchain is also available on github (https://github.com/asamm/lomaps-generator) so i'm not sure it makes sense to spend time for PBF.

Thank you for your interest but I'm sorry as i do not plan any enhancement in this area at the moment.

Regards,

Juergen

Tiemichael commented 4 years ago

Hi Juergen, no problem!

As OAM-maps are only updated every 3-4 months (Asia), and there are always new roads, buildings, etc here in Singapore, I prefer to download the most recent map directly from OSM, and compile my own Locus-map and POI-database once a month or so.

Recently there have been a lot of advancements in creating/providing LOCUS-map POI-files, and I think your contribution to this was essential. Thanks for providing this app!

Best regards Michael