Esempio n. 1
0
def foundNearNode(geom,api):
    """ Function to found the nearest node of a geometry 
    geom = geometry of first / last point
    api = pythonOsmApi object
    
    """
    osmData = funct.getMapData(geom,api,buf=0.0002)
    osmNodes = funct.getPointData(osmData,line=True)
Esempio n. 2
0
def loadPoint(layer, api):
    """ The function to load point vector inside OSM DB
    layer = OGR layer object
    api = PythonOsmApi object
    """
    # fields name of input vector
    fields = funct.fieldsName(layer)
    # loop inside the feature
    feature = layer.GetNextFeature()
    # first id for (after it will be sobstitute on osmdb
    iD = -1
    n_feature = 0
    while feature:
        # define the tags for the feature
        tags = funct.tagDef(feature, fields)
        # get the geometry of the feature
        geom = feature.GetGeometryRef()
        # get osm data near the feature (look function getMapData)
        osmData = funct.getMapData(geom, api)
        # from osm data extract only point
        pointData = funct.getPointData(osmData)
        # made some control to search if feature already exist on osm db
        if checkNewPoint(geom, tags, pointData):
            # if the function return true it create the new point
            nodeDef = {
                unicode("id"): iD,
                unicode("lon"): geom.GetX(),
                unicode("lat"): geom.GetY(),
                unicode("tag"): tags,
            }
            api.NodeCreate(nodeDef)
            n_feature += 1
            iD = iD - 1
        feature = layer.GetNextFeature()
        # load data on OSM database
    api.flush()
    return n_feature