2

I have a problem regarding the street numbers in OpenStreetMap. I have downloaded the .osm file of a city from the OpenStreetMap web. Then with QGIS I have obtained a shapefile with roads and a shapefile with the buildings.

What I want is to get in one file roads with street numbers and their position. Is there any way to get this?

I have only achieved to get one layer with the roads and one layer with the polygons, where the House numbers are, but I can't find a relation between both layers; also,the street names on the polygons layer are not correct always.

1

Here is some Python to move the points onto the road. You can then do a Spatial Join and attach the info if you require.

import arcpy

streets = []

# Geodatabase workspace, use either relative or absolute path
# Currently using relative path because script is in same folder as .gdb
arcpy.env.workspace = r".\TestDataset.gdb"

# Feature Classes
roads = "[YOUR_ROAD_DATA]"
points = "[YOUR_ADDRESS_DATA]"

# Get unique street names from road layer and assign to var 'street'
with arcpy.da.SearchCursor(roads, "[YOUR_STREET_NAME_FIELD]") as cursor:
    for row in cursor:        
        if row[0] is not None and row != "":
            if row[0] not in streets:
                streets.append(str(row[0]))

print "Found streets:"
for street in streets:
    print street,

arcpy.MakeFeatureLayer_management(roads, "roads_lyr")
arcpy.MakeFeatureLayer_management(points, "points_lyr")

for street in streets:
    try:

        print "\n" + street

        exp_roads = "[YOUR_STREET_NAME_FIELD] = '{0}'".format(street)
        arcpy.SelectLayerByAttribute_management("roads_lyr", "NEW_SELECTION", exp_roads)


    exp_points = "[YOUR_STREET_NAME_FIELD] LIKE '{0}%'".format(street)
    arcpy.SelectLayerByAttribute_management("points_lyr", "NEW_SELECTION", exp_points)

    # This tool modifies input data and does not create new data
    # Requires Standard or Advanced License
    arcpy.Snap_edit("points_lyr", [["roads_lyr", "EDGE", "50 Meters"]])
    print "...snapped"

        except:

        print "Error with street: " + street


print "\ndone"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.