示例#1
0
文件: osm.py 项目: mharnold/spiderosm
def test():
    # tiny OSM area in Berkeley Marina
    clip_rect = (-122.31851, 37.86517, -122.31635, 37.86687)
    osm_data = OSMData(clip_rect=clip_rect)

    def feature_func(feature, props):
        if props.get("name") != "Seawall Drive":
            return False
        return True

    found = geofeatures.filter_features(osm_data, feature_func=feature_func, geom_type="LineString")
    assert len(found) > 0

    print "osm PASS"
示例#2
0
def mismatched_names_report():
    conf = config.settings

    def mismatchFunc(feature,props):
        if props.get('match$score',0)<50: return False
        if props.get('match$score_name',100)==100: return False
        if 'osm$verified:name' in props: return False
        if props.get('osm$source:name'): return False
        props['report$wayURL'] = 'http://www.openstreetmap.org/way/%d' % props['osm$way_id']
        return True

    log('generating mismatched name report...')

    # read in matched network
    osm_matched = pnwk.PNwk(
            filename=os.path.join(conf['out_dir'], 'osm_matched'),
            name = 'osm',
            units = 'meters')

    # find mismatches
    mismatches = geofeatures.filter_features(osm_matched, 
            feature_func=mismatchFunc, 
            geom_type='LineString')
    print '%d (RAW) NAME MISMATCHES' % len(mismatches)

    # filter props down for webmap
    webmap_specs= [
            ('osm', 'TEXT', 'osm_pnwk$name'),
            ('city', 'TEXT', 'city_pnwk$name'),
            ('wayId', 'BIGINT', 'osm$way_id'),
            ('fixme', 'TEXT', 'osm$fixme:name')
            ]
    webmap = geofeatures.filter_features(mismatches, 
            col_specs=webmap_specs)

    # htlml quote TEXT property values to guard against injection attacks.
    for feature in webmap:
        props = feature.properties
        for (name, t, ignore) in webmap_specs:
            if t != 'TEXT': continue
            if not name in props: continue
            props[name] = cgi.escape(props[name])

    # unproject for web map use
    conf['project_projection'].project_geo_features(webmap,rev=True)
    
    # write out geojson for webmap
    geo = geojson.FeatureCollection(webmap)
    fname = os.path.join(conf['out_dir'],'name_mismatches.geojson')
    with open(fname, 'w') as f:
        #geojson.dump(webmap,f,indent=2,sort_keys=True)
        geojson.dump(geo,f,indent=2,sort_keys=True)

    # make unique and sorted
    unique = []
    pairs = {}
    for feature in mismatches:
        props = feature['properties']
        pair = (props['osm_pnwk$name'], props['city_pnwk$name']) 
        if pair in pairs: continue
        unique.append(feature)
        pairs[pair] = True
    count = len(pairs)
    print '%d UNIQUE NAME MISMATCHES' % count
    def keyFunc(feature):
        p=feature['properties']
        return (p['osm_pnwk$name'], p['city_pnwk$name'])
    unique.sort(key=keyFunc)

    # write csv report
    title = 'Berkeley area name mismatches between city centerline and OSM (dateGenerated: %s)'  
    title = title % misc.date_ymdhms()

    csv_specs= [
            ('osm', 'TEXT', 'osm_pnwk$name'),
            ('city', 'TEXT', 'city_pnwk$name'),
            ('way', 'TEXT', 'report$wayURL')
            ]

    csvif.write(unique, os.path.join(conf['out_dir'],'name_mismatches.csv'), 
            col_specs=csv_specs,
            title=title)

    log('generating mismatched name report. DONE.')