コード例 #1
0
ファイル: utilities.py プロジェクト: antonis123/maps
def store(row):
    shp = ShpParser(None)
    entry = []
    for col in row:
        entry.append(col)
        
    pts = shp.convert_point_to_WGS84(entry[3], entry[4])
    point = Point(float(entry[3]), float(entry[4]), srid=27700)
    neighbourhoods = Neighbourhood.objects.filter(poly__contains=point)
    
    nb = None
    
    if len(neighbourhoods) >= 1:
        nb = neighbourhoods[0]
    # Else the crime is not covered by any neighbouhood polygon (e.g. River thames)
    
    # Convert to format YYYY-MM-DD by replacing all occurences of "/" with "-".
    d = entry[0]
    d = d.replace('/', '-')
    d += "-01"

    c = Crimepoint(crimecat=entry[6], pt = Point(pts[1], pts[0]), 
                   streetname=entry[5], month=d, 
                   neighbourhood=nb)
    c.save()
コード例 #2
0
ファイル: updatepolice.py プロジェクト: antonis123/maps
    def store(self, city=None):
        c = '' if city is None else str(city)
        allfiles = [f for f in os.listdir(config.filteredDir) 
                    if os.path.isfile(os.path.join(config.filteredDir,f)) and
                    (".csv" in f) and (c in f)]
        
        print "Storing crimes..."
        print "c:", c
        print "allfiles:", allfiles
        count = 0;
        
        for f in allfiles:
            ifile = open(config.filteredDir+f, "rb")
            reader = csv.reader(ifile)
            shp = ShpParser(None)
            print "Storing from file:", config.filteredDir+f
            for row in reader:
                entry = []
                for col in row:
                    entry.append(col)
                    
                assert(len(entry) == 8)
                
                pts = shp.convert_point_to_WGS84(entry[3], entry[4])
                point = Point(float(entry[3]), float(entry[4]), srid=27700)
                
                neighbourhoods = Neighbourhood.objects.filter(poly__intersects=point)
                
                nb = None
                
                if len(neighbourhoods) == 0:
                    # Else the crime is not covered by any neighbouhood polygon (e.g. River thames)
                    print "No neighbourhood found for point:", pts, "OSGB36:", point
                elif len(neighbourhoods) == 1:
                    nb = neighbourhoods[0]
                else:
#                    print "More than one polygons (",len(neighbourhoods),")  found for point:", pts, "OSGB36:", point
                    nb = neighbourhoods[0]
                
                # Convert to format YYYY-MM-DD by replacing all occurences of "/" with "-".
                d = entry[0]
                d = d.replace('/', '-')
                d += "-01"

                c = Crimepoint(crimecat=entry[6], pt = point, 
                               streetname=entry[5], month=d, 
                               neighbourhood=nb)
                c.save()
                    
                count += 1
            
        print "Stored", count, "crimes."