Exemplo n.º 1
0
def loadLines(layer,api):
    """ The function to load line and polygon vector inside OSM DB
    layer = OGR layer object
    api = PythonOsmApi object
    """
    fields = funct.fieldsName(layer)
    feature = layer.GetNextFeature()
    listAllNodes = []
    while feature:
	geomFeat = feature.GetGeometryRef()
	tags = funct.tagDef(feature,fields)
	if geomFeat.GetGeometryType() == 3:
	    tags[unicode('area')] = unicode('yes')
	listNodes = createListNodes(geomFeat)
	correctEndNodes(listNodes,geomFeat,api)
	wayDef = {unicode('nd'):listNodes, unicode('tag'):tags}
	api.WayCreate(wayDef)
	feature=layer.GetNextFeature()
    api.flush()   	    
Exemplo 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