views.py
def insertStorm():
    """This function allows to insert the polygon into db"""
    if request.is_xhr and request.method=="POST":
        #print(type(request.form))
        #for a in request.form:
        #    print("dati:",a,request.form[a])
        polygonGeoJson = request.get_json()
        #print("Polygon da inserire con datetime: ",polygonGeoJson['properties']['dateStr'])
        #modifica data in stringa in datatime
        dateold = polygonGeoJson['properties']['dateStr']
        datenew = datetime(int(dateold[0:4]),int(dateold[4:6]),int(dateold[6:8]),int(dateold[9:11]))
        polygonGeoJson['properties']['dateStr'] = datenew
        #print("data nuova:",str(polygonGeoJson['properties']['dateStr']))
        polygonGeoJson["properties"]["name"] = polygonGeoJson["properties"]["name"].upper()
        #for key, value in polygonGeoJson.iteritems():
        #    print(key,value)
        #    print(" ")
        #print(type(polygonGeoJson))

        coords = []
        for i in range(0,len(polygonGeoJson["geometry"]["coordinates"][0])):
            coords.append(tuple((polygonGeoJson["geometry"]["coordinates"][0][i][0],polygonGeoJson["geometry"]["coordinates"][0][i][1])))
        polyA = Polygon(coords)
        print(polygonGeoJson)
        print(polyA)

        count,cursorPolygon = managedb.getPolygonOnDate(datenew)
        if count > 0:
            polygons = []
            for polygon in cursorPolygon:
                coords1 = []
                for i in range(0,len(polygon["geometry"]["coordinates"][0])):
                    print("lng:",polygon["geometry"]["coordinates"][0][i][0],"lat:",polygon["geometry"]["coordinates"][0][i][1])
                    coords1.append(tuple((polygon["geometry"]["coordinates"][0][i][0],polygon["geometry"]["coordinates"][0][i][1])))
                poly = Polygon(coords1)
                polygons.append(poly)
            flag1=False
            flag2=False
            flag3=False
            flag4=False
            for i in range(0,len(polygons)):
                if(polygons[i].overlaps(polyA)):
                    flag1=True
                if (polygons[i].equals(polyA)):
                    flag2 = True
                if (polygons[i].contains(polyA)):
                    flag3 = True
                if (polygons[i].within(polyA)):
                    flag4 = True
            if flag1 or flag3 or flag4:
                return json.dumps({"result": "intersection"})
            if flag2:
                return json.dumps({"result": "alreadyinserted"})
        print(session["username"])
        try:
            count1 = managedb.getCountLoginDB(session["username"])
            if count1 == 0:
                return json.dumps({"result": "exit"})
            result,id = managedb.insertPolygonDB(polygonGeoJson)
            if result==True:
                # print("Polygon da inserire con idDB:",str(id))
                return json.dumps({"result":"correct","id":str(id)})
            else:
                return json.dumps({"result": "alreadyinserted"})
        except Exception as e:
            print("exception error DB",str(e))
            return json.dumps({"result": "error"})
This function allows to insert the polygon into db
This function allows to insert the polygon into db
This function allows to insert the polygon into db
def insertStorm():
    if request.is_xhr and request.method=="POST":
        polygonGeoJson = request.get_json()
        dateold = polygonGeoJson['properties']['dateStr']
        datenew = datetime(int(dateold[0:4]),int(dateold[4:6]),int(dateold[6:8]),int(dateold[9:11]))
        polygonGeoJson['properties']['dateStr'] = datenew
        polygonGeoJson["properties"]["name"] = polygonGeoJson["properties"]["name"].upper()
        coords = []
        for i in range(0,len(polygonGeoJson["geometry"]["coordinates"][0])):
            coords.append(tuple((polygonGeoJson["geometry"]["coordinates"][0][i][0],polygonGeoJson["geometry"]["coordinates"][0][i][1])))
        polyA = Polygon(coords)
        print(polygonGeoJson)
        print(polyA)
        count,cursorPolygon = managedb.getPolygonOnDate(datenew)
        if count > 0:
            polygons = []
            for polygon in cursorPolygon:
                coords1 = []
                for i in range(0,len(polygon["geometry"]["coordinates"][0])):
                    print("lng:",polygon["geometry"]["coordinates"][0][i][0],"lat:",polygon["geometry"]["coordinates"][0][i][1])
                    coords1.append(tuple((polygon["geometry"]["coordinates"][0][i][0],polygon["geometry"]["coordinates"][0][i][1])))
                poly = Polygon(coords1)
                polygons.append(poly)
            flag1=False
            flag2=False
            flag3=False
            flag4=False
            for i in range(0,len(polygons)):
                if(polygons[i].overlaps(polyA)):
                    flag1=True
                if (polygons[i].equals(polyA)):
                    flag2 = True
                if (polygons[i].contains(polyA)):
                    flag3 = True
                if (polygons[i].within(polyA)):
                    flag4 = True
            if flag1 or flag3 or flag4:
                return json.dumps({"result": "intersection"})
            if flag2:
                return json.dumps({"result": "alreadyinserted"})
        print(session["username"])
        try:
            count1 = managedb.getCountLoginDB(session["username"])
            if count1 == 0:
                return json.dumps({"result": "exit"})
            result,id = managedb.insertPolygonDB(polygonGeoJson)
            if result==True:
                return json.dumps({"result":"correct","id":str(id)})
            else:
                return json.dumps({"result": "alreadyinserted"})
        except Exception as e:
            print("exception error DB",str(e))
            return json.dumps({"result": "error"})
def insertStorm ( ) : if request . is_xhr and request . method == "POST" : polygonGeoJson = request . get_json ( ) dateold = polygonGeoJson [ 'properties' ] [ 'dateStr' ] datenew = datetime ( int ( dateold [ 0 : 4 ] ) , int ( dateold [ 4 : 6 ] ) , int ( dateold [ 6 : 8 ] ) , int ( dateold [ 9 : 11 ] ) ) polygonGeoJson [ 'properties' ] [ 'dateStr' ] = datenew polygonGeoJson [ "properties" ] [ "name" ] = polygonGeoJson [ "properties" ] [ "name" ] . upper ( ) coords = [ ] for i in range ( 0 , len ( polygonGeoJson [ "geometry" ] [ "coordinates" ] [ 0 ] ) ) : coords . append ( tuple ( ( polygonGeoJson [ "geometry" ] [ "coordinates" ] [ 0 ] [ i ] [ 0 ] , polygonGeoJson [ "geometry" ] [ "coordinates" ] [ 0 ] [ i ] [ 1 ] ) ) ) polyA = Polygon ( coords ) print ( polygonGeoJson ) print ( polyA ) count , cursorPolygon = managedb . getPolygonOnDate ( datenew ) if count > 0 : polygons = [ ] for polygon in cursorPolygon : coords1 = [ ] for i in range ( 0 , len ( polygon [ "geometry" ] [ "coordinates" ] [ 0 ] ) ) : print ( "lng:" , polygon [ "geometry" ] [ "coordinates" ] [ 0 ] [ i ] [ 0 ] , "lat:" , polygon [ "geometry" ] [ "coordinates" ] [ 0 ] [ i ] [ 1 ] ) coords1 . append ( tuple ( ( polygon [ "geometry" ] [ "coordinates" ] [ 0 ] [ i ] [ 0 ] , polygon [ "geometry" ] [ "coordinates" ] [ 0 ] [ i ] [ 1 ] ) ) ) poly = Polygon ( coords1 ) polygons . append ( poly ) flag1 = False flag2 = False flag3 = False flag4 = False for i in range ( 0 , len ( polygons ) ) : if ( polygons [ i ] . overlaps ( polyA ) ) : flag1 = True if ( polygons [ i ] . equals ( polyA ) ) : flag2 = True if ( polygons [ i ] . contains ( polyA ) ) : flag3 = True if ( polygons [ i ] . within ( polyA ) ) : flag4 = True if flag1 or flag3 or flag4 : return json . dumps ( { "result" : "intersection" } ) if flag2 : return json . dumps ( { "result" : "alreadyinserted" } ) print ( session [ "username" ] ) try : count1 = managedb . getCountLoginDB ( session [ "username" ] ) if count1 == 0 : return json . dumps ( { "result" : "exit" } ) result , id = managedb . insertPolygonDB ( polygonGeoJson ) if result == True : return json . dumps ( { "result" : "correct" , "id" : str ( id ) } ) else : return json . dumps ( { "result" : "alreadyinserted" } ) except Exception as e : print ( "exception error DB" , str ( e ) ) return json . dumps ( { "result" : "error" } )
This function allows to insert the polygon into db
This function allows to insert the polygon into db
"""This function allows to insert the polygon into db""" #print(type(request.form)) #for a in request.form: #    print("dati:",a,request.form[a]) #print("Polygon da inserire con datetime: ",polygonGeoJson['properties']['dateStr']) #modifica data in stringa in datatime #print("data nuova:",str(polygonGeoJson['properties']['dateStr'])) #for key, value in polygonGeoJson.iteritems(): #    print(key,value) #    print(" ") #print(type(polygonGeoJson)) # print("Polygon da inserire con idDB:",str(id))